From f3e999ebf0fbd1b66ab39f0f29fe918761c82e30 Mon Sep 17 00:00:00 2001 From: Kevin Suarez Date: Thu, 7 Dec 2023 17:36:46 -0300 Subject: [PATCH] v4.2 update --- Objects/Player/objJumpParticle.tscn | 7 +++ Objects/Player/objPlayer.tscn | 0 Objects/Room_objects/objWarp.tscn | 0 Objects/System/objHUD.tscn | 2 +- README.md | 13 ++++ Resources/Materials/matJumpParticle.tres | 6 +- Resources/Materials/matJumpRefresher.tres | 4 +- Scripts/Gimmicks/scrInvisibleBlock.gd | 12 ++-- Scripts/Globals/scrGlobalGame.gd | 27 ++++---- Scripts/Globals/scrGlobalSaveload.gd | 8 +-- Scripts/Player/scrJumpParticle.gd | 7 +-- Scripts/Player/scrPlayer.gd | 76 ++++++++++++----------- Scripts/Room_objects/scrWarp.gd | 14 ++++- Scripts/System/scrHUD.gd | 6 +- Scripts/UI/scrMainMenu.gd | 0 Scripts/UI/scrSettingsMenu.gd | 2 +- project.godot | 13 +++- 17 files changed, 118 insertions(+), 79 deletions(-) mode change 100755 => 100644 Objects/Player/objJumpParticle.tscn mode change 100755 => 100644 Objects/Player/objPlayer.tscn mode change 100755 => 100644 Objects/Room_objects/objWarp.tscn mode change 100755 => 100644 Objects/System/objHUD.tscn mode change 100755 => 100644 Scripts/Globals/scrGlobalGame.gd mode change 100755 => 100644 Scripts/Globals/scrGlobalSaveload.gd mode change 100755 => 100644 Scripts/Player/scrJumpParticle.gd mode change 100755 => 100644 Scripts/Room_objects/scrWarp.gd mode change 100755 => 100644 Scripts/System/scrHUD.gd mode change 100755 => 100644 Scripts/UI/scrMainMenu.gd diff --git a/Objects/Player/objJumpParticle.tscn b/Objects/Player/objJumpParticle.tscn old mode 100755 new mode 100644 index 1603ac3..ea29d87 --- a/Objects/Player/objJumpParticle.tscn +++ b/Objects/Player/objJumpParticle.tscn @@ -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"] diff --git a/Objects/Player/objPlayer.tscn b/Objects/Player/objPlayer.tscn old mode 100755 new mode 100644 diff --git a/Objects/Room_objects/objWarp.tscn b/Objects/Room_objects/objWarp.tscn old mode 100755 new mode 100644 diff --git a/Objects/System/objHUD.tscn b/Objects/System/objHUD.tscn old mode 100755 new mode 100644 index 2a4122d..d489cd3 --- a/Objects/System/objHUD.tscn +++ b/Objects/System/objHUD.tscn @@ -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 diff --git a/README.md b/README.md index 3061c5d..30570e3 100755 --- a/README.md +++ b/README.md @@ -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. diff --git a/Resources/Materials/matJumpParticle.tres b/Resources/Materials/matJumpParticle.tres index ac7d0f8..fa9486a 100644 --- a/Resources/Materials/matJumpParticle.tres +++ b/Resources/Materials/matJumpParticle.tres @@ -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) diff --git a/Resources/Materials/matJumpRefresher.tres b/Resources/Materials/matJumpRefresher.tres index b551afc..bce4845 100644 --- a/Resources/Materials/matJumpRefresher.tres +++ b/Resources/Materials/matJumpRefresher.tres @@ -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 diff --git a/Scripts/Gimmicks/scrInvisibleBlock.gd b/Scripts/Gimmicks/scrInvisibleBlock.gd index 8f49f80..fbc4303 100644 --- a/Scripts/Gimmicks/scrInvisibleBlock.gd +++ b/Scripts/Gimmicks/scrInvisibleBlock.gd @@ -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 @@ -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): diff --git a/Scripts/Globals/scrGlobalGame.gd b/Scripts/Globals/scrGlobalGame.gd old mode 100755 new mode 100644 index 6905027..6f39043 --- a/Scripts/Globals/scrGlobalGame.gd +++ b/Scripts/Globals/scrGlobalGame.gd @@ -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. @@ -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(" ")) - - - diff --git a/Scripts/Globals/scrGlobalSaveload.gd b/Scripts/Globals/scrGlobalSaveload.gd old mode 100755 new mode 100644 index 2e1e213..c295fc1 --- a/Scripts/Globals/scrGlobalSaveload.gd +++ b/Scripts/Globals/scrGlobalSaveload.gd @@ -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" : "" } @@ -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(): @@ -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(): @@ -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) @@ -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 diff --git a/Scripts/Player/scrJumpParticle.gd b/Scripts/Player/scrJumpParticle.gd old mode 100755 new mode 100644 index 382a792..ff0b753 --- a/Scripts/Player/scrJumpParticle.gd +++ b/Scripts/Player/scrJumpParticle.gd @@ -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() diff --git a/Scripts/Player/scrPlayer.gd b/Scripts/Player/scrPlayer.gd index 579df3c..ba2795f 100644 --- a/Scripts/Player/scrPlayer.gd +++ b/Scripts/Player/scrPlayer.gd @@ -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 @@ -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" @@ -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 @@ -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 @@ -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: @@ -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 @@ -185,7 +190,6 @@ func handle_movement() -> void: xscale_to_direction.call(extra_direction_keys) - # Jumping logic func handle_jumping() -> void: @@ -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 @@ -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() @@ -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 @@ -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! diff --git a/Scripts/Room_objects/scrWarp.gd b/Scripts/Room_objects/scrWarp.gd old mode 100755 new mode 100644 index 40180db..0e94dd7 --- a/Scripts/Room_objects/scrWarp.gd +++ b/Scripts/Room_objects/scrWarp.gd @@ -9,6 +9,16 @@ extends Node2D @export_file("*.tscn") var warp_to: String @export var warp_transition: bool = false @export var warp_to_point: Vector2 = Vector2.ZERO +var is_warping: bool = false + + +# Changes the scene after a player collision. This didn't need to exist +# before, but since v4.2, it's not a good idea to change the entire scene +# tree inside a collision event, so we just set a variable there and activate +# the "warping" here +func _physics_process(_delta): + if (is_warping == true): + get_tree().change_scene_to_file(warp_to) # When colliding with the player, it changes the scene @@ -41,5 +51,5 @@ func _on_area_2d_body_entered(_body): # Clear/reset our global trigger array GLOBAL_GAME.triggered_events.clear() - get_tree().change_scene_to_file(warp_to) - + # Tells the warp it should change the scene on the next physics frame + is_warping = true diff --git a/Scripts/System/scrHUD.gd b/Scripts/System/scrHUD.gd old mode 100755 new mode 100644 index 2e726ed..0d0efd8 --- a/Scripts/System/scrHUD.gd +++ b/Scripts/System/scrHUD.gd @@ -22,10 +22,14 @@ func handle_debug_mode() -> void: $Display/MarginContainer/VBoxContainer/textDebug1.text = str(" Player X: ", round(GLOBAL_INSTANCES.objPlayerID.position.x), " ") $Display/MarginContainer/VBoxContainer/textDebug2.text = str(" Player Y: ", round(GLOBAL_INSTANCES.objPlayerID.position.y), " ") $Display/MarginContainer/VBoxContainer/textDebug3.text = str(" FPS: %d" % Engine.get_frames_per_second(), " ") - $Display/MarginContainer/VBoxContainer/textDebug4.text = str(" Room: ", get_tree().get_current_scene().name, " ") + + # Extra check added for v4.2 compatibility + if get_tree().get_current_scene() != null: + $Display/MarginContainer/VBoxContainer/textDebug4.text = str(" Room: ", get_tree().get_current_scene().name, " ") $Sprite2D.set_visible(true) $Sprite2D.position = get_global_mouse_position() + $Sprite2D.flip_h = !GLOBAL_INSTANCES.objPlayerID.xscale else: $Display.set_visible(false) $Sprite2D.set_visible(false) diff --git a/Scripts/UI/scrMainMenu.gd b/Scripts/UI/scrMainMenu.gd old mode 100755 new mode 100644 diff --git a/Scripts/UI/scrSettingsMenu.gd b/Scripts/UI/scrSettingsMenu.gd index 4477ebd..2b2204f 100644 --- a/Scripts/UI/scrSettingsMenu.gd +++ b/Scripts/UI/scrSettingsMenu.gd @@ -148,7 +148,7 @@ func set_labels_text(): $SettingsContainer/Vsync/Label.text = "Vsync: " + str(bool_to_on_off(vsync_on)) $SettingsContainer/AutoReset/Label.text = "Reset on Death: " + str(bool_to_on_off(autoreset_on)) $SettingsContainer/ExtraKeys/Label.text = "Extra keys: " + str(bool_to_on_off(extra_keys_on)) - $SettingsContainer/Reset/Label.text = "Reset" + $SettingsContainer/Reset/Label.text = "Reset to Defaults" $SettingsContainer/Controls/Label.text = "Controls" $SettingsContainer/Back/Label.text = "Back" diff --git a/project.godot b/project.godot index 2219271..af20b42 100644 --- a/project.godot +++ b/project.godot @@ -13,7 +13,7 @@ config_version=5 config/name="ReloadedK's Godot Fangame Engine" config/tags=PackedStringArray("fangame_engine") run/main_scene="res://Rooms/00_Title_and_menus/rMainMenu.tscn" -config/features=PackedStringArray("4.1", "Mobile") +config/features=PackedStringArray("4.2", "Mobile") boot_splash/bg_color=Color(0.141176, 0.141176, 0.141176, 1) boot_splash/show_image=false config/icon="res://Resources/Project/icon.png" @@ -45,6 +45,17 @@ window/size/viewport_height=608 window/size/resizable=false window/stretch/mode="viewport" +[file_customization] + +folder_colors={ +"res://Audio/": "blue", +"res://Graphics/": "yellow", +"res://Objects/": "red", +"res://Resources/": "purple", +"res://Rooms/": "green", +"res://Scripts/": "gray" +} + [filesystem] import/blender/enabled=false