Skip to content

Commit

Permalink
v4.2 update
Browse files Browse the repository at this point in the history
  • Loading branch information
ReloadedK-git committed Dec 7, 2023
1 parent 6c2d1db commit f3e999e
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 79 deletions.
7 changes: 7 additions & 0 deletions Objects/Player/objJumpParticle.tscn
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ process_material = ExtResource("1_iqyat")
lifetime = 0.6
explosiveness = 1.0
script = ExtResource("1_thvsk")

[node name="Timer" type="Timer" parent="."]
wait_time = 0.6
one_shot = true
autostart = true

[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
Empty file modified Objects/Player/objPlayer.tscn
100755 → 100644
Empty file.
Empty file modified Objects/Room_objects/objWarp.tscn
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion Objects/System/objHUD.tscn
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ anchor_right = 1.0
offset_left = -120.0
offset_top = 8.0
offset_right = -8.0
offset_bottom = 116.0
offset_bottom = 108.0
grow_horizontal = 0
theme_override_constants/margin_top = 0

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,16 @@ You can check the [engine's documentation](https://github.com/ReloadedK-git/Relo
### v1.5 (24-10-23)

* Small fix for the player script. The input for the controller stick doesn't need to go all the way to get detected.

### v1.6 (07-12-23)

* Engine ported to Godot v4.2 while maintaining compatibility with older versions.
* Modified ***objPlayer***. The xscale variable is now a boolean instead of a float. The function ***set_first_time_saving()*** is called from ***_physics_process()*** due to v4.2's changes.
* Jump particles generated from the player now use a timer to free themselves.
* Save points don't autostart their timers by default.
* Renamed some variables for ***objInvisibleBlock*** so they don't conflict with engine variable names.
* Modified ***objWarp***'s script to be compatible with v4.2.
* ***objHUD***'s debug mode mouse pointer now follows ***objPlayer***'s xscale, and is compatible with v4.2.
* Modified ***scrGlobalGame*** to work with v4.2.
* ***scrSettingsMenu*** now shows "Reset to Defaults" instead of "Reset".
* FileSystem folders are now colored.
6 changes: 2 additions & 4 deletions Resources/Materials/matJumpParticle.tres
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0)
gradient = SubResource("Gradient_mw11i")

[resource]
particle_flag_disable_z = true
emission_shape = 3
emission_box_extents = Vector3(4, 4, 1)
particle_flag_disable_z = true
direction = Vector3(0, 1, 0)
spread = 30.0
gravity = Vector3(0, 0, 0)
initial_velocity_min = 6.0
initial_velocity_max = 12.0
orbit_velocity_min = 0.0
orbit_velocity_max = 0.0
gravity = Vector3(0, 0, 0)
scale_min = 4.0
scale_max = 6.0
color = Color(0.827451, 0.827451, 0.827451, 1)
Expand Down
4 changes: 1 addition & 3 deletions Resources/Materials/matJumpRefresher.tres
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ gradient = SubResource("Gradient_3l5tl")
[resource]
particle_flag_disable_z = true
spread = 180.0
gravity = Vector3(0, 0, 0)
initial_velocity_min = 16.0
initial_velocity_max = 48.0
orbit_velocity_min = 0.0
orbit_velocity_max = 0.0
gravity = Vector3(0, 0, 0)
damping_min = 20.0
damping_max = 40.0
scale_min = 4.0
Expand Down
12 changes: 6 additions & 6 deletions Scripts/Gimmicks/scrInvisibleBlock.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ extends StaticBody2D

@onready var sprite_node = get_node("Sprite2D")
@onready var area_shape_node = get_node("Area2D/CollisionShape2D")
var is_visible: bool = false
var is_on_screen: bool = false
var block_is_visible: bool = false
var block_is_on_screen: bool = false
var area_shape_scaling: float = 1.006


Expand All @@ -15,19 +15,19 @@ func _ready():

# Makes the object visible and plays the classic sndBlockChange sound
func make_visible():
if !is_visible:
if !block_is_visible:
sprite_node.visible = true
GLOBAL_SOUNDS.play_sound(GLOBAL_SOUNDS.sndBlockChange)
is_visible = true
block_is_visible = true


# Checks if the object is inside or outside of the screen. This helps
# performance since we're not constantly checking for collisions every frame
func _on_visible_on_screen_notifier_2d_screen_entered():
is_on_screen = true
block_is_on_screen = true

func _on_visible_on_screen_notifier_2d_screen_exited():
is_on_screen = false
block_is_on_screen = false

# Makes the object's sprite visible when touched
func _on_area_2d_body_entered(_body):
Expand Down
27 changes: 14 additions & 13 deletions Scripts/Globals/scrGlobalGame.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,21 @@ func set_vsync():
# Checks the current scene/room's name. We use this to make sure we're not
# doing things like restarting or pausing on menu related scenes
func is_valid_room():
current_scene_name = get_tree().get_current_scene().name

match current_scene_name:
"rMainMenu":
return false
"rSettingsMenu":
return false
"rControlsMenu":
return false
_:
return true
# We also need to check if our scene tree is not null. Only then it gets
# its name (needed for godot v4.2 onwards)
if get_tree().get_current_scene() != null:
current_scene_name = get_tree().get_current_scene().name

match current_scene_name:
"rMainMenu":
return false
"rSettingsMenu":
return false
"rControlsMenu":
return false
_:
return true


# Returns a string of text, according to our input device.
Expand All @@ -243,6 +247,3 @@ func get_input_name(button_id, input_device):
# Controller
if input_device == CONTROLLER:
return str(InputMap.action_get_events(button_id)[input_device].as_text().trim_prefix("Joypad ").left(9).trim_suffix(" "))



8 changes: 2 additions & 6 deletions Scripts/Globals/scrGlobalSaveload.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const defaultGameData = {
"first_time_saving" : true,
"player_x" : 0,
"player_y" : 0,
"player_sprite_flipped" : 1,
"player_sprite_flipped" : false,
"room_name" : ""
}

Expand All @@ -39,11 +39,9 @@ func _ready():
# We store our settings, saves and screenshots here
if not dir.dir_exists("user://Data"):
dir.make_dir("Data")




##############################################################################################################################
# Loads a save file (1, 2 or 3, depends on saveFileID), and if it doesn't
# exist (is "null"), creates a save file with default data
func load_data():
Expand Down Expand Up @@ -91,8 +89,6 @@ func save_default_data():
file = null



##############################################################################################################################
# Deletes save data after checking if such files exist (both savefiles and save
# previews/screenshots)
func delete_data():
Expand All @@ -105,6 +101,7 @@ func delete_data():
dir.remove(DATA_PATH + str(saveFileID) + ".png")



# Takes a screenshot and resizes it. Made to be shown on the main menu screen.
# You should tell this autoload to take screenshots when you want it to and
# not automatically, for more control (e.g. on objSavePoint when saving)
Expand All @@ -113,7 +110,6 @@ func take_screenshot() -> void:
img.resize(SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT, Image.INTERPOLATE_NEAREST)
img.save_png(DATA_PATH + str(saveFileID) + ".png")
return ImageTexture.create_from_image(img)
##############################################################################################################################


# Saves the player's coordinates, sprite state and room name. Also takes a
Expand Down
7 changes: 3 additions & 4 deletions Scripts/Player/scrJumpParticle.gd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ func _ready():
one_shot = true


func _physics_process(_delta):
if not emitting:
queue_free()

# Frees particles using a timer
func _on_timer_timeout():
queue_free()
76 changes: 39 additions & 37 deletions Scripts/Player/scrPlayer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var h_speed: int = 150
var s_jump_speed: int = 400
var d_jump_speed: int = 330
var jump_release_falloff: float = 0.50
var xscale: float = 1.0
var xscale: bool = true
var frozen: bool = false
var d_jump: bool = true
var d_jump_aux: bool = false
Expand All @@ -26,13 +26,9 @@ func _ready():

# If a savefile exists (we've saved at least once), we move the player to
# the saved position, and also set its sprite state (flipped or not).
# If we haven't saved before, it makes a special type of save which sets
# things up for the rest of the game
if (GLOBAL_SAVELOAD.variableGameData.first_time_saving == false):
set_position_on_load()
flip_sprites_on_creation()
else:
set_first_time_saving()

# Sets a very important global variable. Lets everything know that the
# player does in fact exist and assigns it with its "id"
Expand All @@ -44,6 +40,14 @@ func _ready():
"""
func _physics_process(delta):

# If we haven't saved before, it makes a special type of save which sets
# things up for the rest of the game.
# NOTE: This function used to be executed in _ready(), but due to some of
# the timing related changes made in v4.2, this was moved here and works
# again.
if (GLOBAL_SAVELOAD.variableGameData.first_time_saving == true):
set_first_time_saving()

# More specific logic is handled inside of methods, which keeps the main
# loop clean and easier to read.
# These methods should only work if the player isn't in the middle of a
Expand Down Expand Up @@ -113,23 +117,21 @@ func set_position_on_load():
# This is done to prevent a common issue that happens when restarting with a
# clean save (otherwise it would teleport the player to 0,0 and to an undefined
# room).
# A room reload is also required to update the values inside GLOBAL_SAVELOAD
func set_first_time_saving():

GLOBAL_SAVELOAD.variableGameData.player_x = position.x
GLOBAL_SAVELOAD.variableGameData.player_y = position.y
GLOBAL_SAVELOAD.variableGameData.player_sprite_flipped = xscale
GLOBAL_SAVELOAD.variableGameData.room_name = get_tree().get_current_scene().get_scene_file_path()
GLOBAL_SAVELOAD.variableGameData.first_time_saving = false

# After changing the variable game data to the proper values, we save them.
GLOBAL_SAVELOAD.save_data()

# After saving for the fist time in-game, a reload is needed.
# Then, after saving for the fist time in-game, a reload is needed.
# What this does is replacing the old default values with the new ones
# we just saved, reading them once through loading.
GLOBAL_SAVELOAD.load_data()

# Finally, we reload the same room we were in to update GLOBAL_SAVELOAD's
# "room_name"
get_tree().change_scene_to_file(get_tree().get_current_scene().get_scene_file_path())


# Handles gravity / falling
Expand All @@ -156,10 +158,13 @@ func handle_movement() -> void:
# of a variable and executed by using "call()".
# Useful for keeping code cleaner and less repetitive in certain cases,
# but it's not mandatory.
# Changes xscale using a direction argument
# Changes xscale using a direction argument, as long as the player is
# moving
var xscale_to_direction = func(h_direction):

# Player needs to be moving in order to flip the xscale
if velocity.x != 0:
xscale = h_direction
xscale = h_direction > 0

# Extra keys off/on
if !GLOBAL_SETTINGS.EXTRA_KEYS:
Expand All @@ -176,7 +181,7 @@ func handle_movement() -> void:
# Controller stick deadzone correction (values go from -1.0 to 1.0)
if extra_direction_keys > 0:
extra_direction_keys = 1
elif extra_direction_keys < 0:
if extra_direction_keys < 0:
extra_direction_keys = -1

# Adds velocity from extra_direction_keys, the secondary direction
Expand All @@ -185,7 +190,6 @@ func handle_movement() -> void:
xscale_to_direction.call(extra_direction_keys)



# Jumping logic
func handle_jumping() -> void:

Expand Down Expand Up @@ -333,7 +337,10 @@ func handle_shooting():
# and global position, makes a sound and then adds it to the main scene
# (the actual game)
var create_bullet_id: AnimatableBody2D = create_bullet.instantiate()
create_bullet_id.looking_at = xscale
if xscale:
create_bullet_id.looking_at = 1
else:
create_bullet_id.looking_at = -1

# Bullet's x coordinate:
# -Takes into account the global x
Expand Down Expand Up @@ -368,28 +375,17 @@ func handle_animations() -> void:

# If we are slidding/walljumping, we set the proper animation
animated_sprite.play("slidding")


# Flips the player sprite using the "looking_at" variable
if xscale == -1:
animated_sprite.flip_h = true
elif xscale == 1:
animated_sprite.flip_h = false

# Flips the player sprite using the "xscale" variable
animated_sprite.flip_h = !xscale


# Checks the scrGlobalSaveload autoload in order to know if the sprite should
# be flipped horizontally on creation. Also sets "looking_at" accordingly
# be flipped horizontally on creation
func flip_sprites_on_creation() -> void:
if (GLOBAL_SAVELOAD.variableGameData.player_sprite_flipped == 1):

# Right
animated_sprite.flip_h = false
xscale = 1
else:

# Left
animated_sprite.flip_h = true
xscale = -1

animated_sprite.flip_h = !GLOBAL_SAVELOAD.variableGameData.player_sprite_flipped
xscale = GLOBAL_SAVELOAD.variableGameData.player_sprite_flipped

# Also rotates masks
handle_masks()
Expand All @@ -400,11 +396,14 @@ func flip_sprites_on_creation() -> void:
# Keep in mind, masks inside $extraCollisions might have different shapes,
# intended for different purposes
func handle_masks() -> void:
$playerMask.position.x = xscale
if xscale == true:
$playerMask.position.x = 1
else:
$playerMask.position.x = -1

# We rotate the scale for the collision containers, so we don't have to
# reference each one of them
$extraCollisions.scale.x = xscale
$extraCollisions.scale.x = $playerMask.position.x


# Interaction with water
Expand Down Expand Up @@ -436,7 +435,10 @@ func on_death():
var blood_emitter = load("res://Objects/Player/objBloodEmitter.tscn")
var blood_emitter_id = blood_emitter.instantiate()
blood_emitter_id.position = Vector2(position.x, position.y)
blood_emitter_id.side = xscale
if xscale:
blood_emitter_id.side = 1
else:
blood_emitter_id.side = -1

# We add a sibling node to the player, not a child node, since the
# player object gets freed!
Expand Down
Loading

0 comments on commit f3e999e

Please sign in to comment.