From 22abac2f119d6eab614db7bc9edb3cc73d6ef7e7 Mon Sep 17 00:00:00 2001 From: debugman18 Date: Sun, 18 Oct 2026 18:43:49 -0500 Subject: [PATCH] Fixed moving blocks --- hidden_horizontal_long_block.tscn | 1 + hidden_horizontal_moving_block.gd | 41 +++++++++++++++++++++++++++ hidden_horizontal_moving_block.gd.uid | 1 + hidden_horizontal_moving_block.tscn | 40 ++++++++++++++++++++++++++ hidden_spike.gd | 1 + horizontal_moving_block.gd | 40 +++++++++++++++++++------- horizontal_moving_block.tscn | 13 ++++----- player_2d.gd | 19 +++++++------ world.tscn | 5 ++++ 9 files changed, 135 insertions(+), 26 deletions(-) create mode 100644 hidden_horizontal_moving_block.gd create mode 100644 hidden_horizontal_moving_block.gd.uid create mode 100644 hidden_horizontal_moving_block.tscn diff --git a/hidden_horizontal_long_block.tscn b/hidden_horizontal_long_block.tscn index 9dadd8e..fd1b6ef 100644 --- a/hidden_horizontal_long_block.tscn +++ b/hidden_horizontal_long_block.tscn @@ -4,6 +4,7 @@ [ext_resource type="PackedScene" uid="uid://ckqable762x8v" path="res://block.tscn" id="2_se82m"] [node name="HiddenHorizontalLongBlock" type="RigidBody2D" unique_id=925152188] +visible = false rotation = 3.1415927 gravity_scale = 0.0 freeze = true diff --git a/hidden_horizontal_moving_block.gd b/hidden_horizontal_moving_block.gd new file mode 100644 index 0000000..641f49b --- /dev/null +++ b/hidden_horizontal_moving_block.gd @@ -0,0 +1,41 @@ +extends RigidBody2D + +@export var max_distance = 260.0 +@export var moving = true +var alt_position = Vector2(position.x + max_distance,0) +@export var move_speed = 0.01 + +func _ready() -> void: + add_to_group("Hidden") + modulate = Color.DARK_CYAN + #Do not move collision boxes, it is fickle. + #on_leave(%Player2D) + alt_position = Vector2(position.x + max_distance,0) + add_to_group("MovingPlatform") + +func _process(delta: float) -> void: + if position.x != alt_position.x: + position.x = move_toward(position.x, alt_position.x, move_speed) + else: + moving = false + %Player2D.is_on_moving_platform = false + #%Player2D.platform_speed = 0.0 + +func on_enter(body) -> void: + if %Player2D.is_on_floor() and body == %Player2D: + print("Player on moving platform.") + %Player2D.platform_speed = move_speed + %Player2D.is_on_moving_platform = true + elif body == %Player2D and !%Player2D.is_on_wall_only: + print("Player but has not landed") + %Player2D.platform_speed = move_speed + %Player2D.is_on_moving_platform = true + elif body == %Player2D: + print("SOMETHING IS WRONG WITH PLAYER") + %Player2D.platform_speed = move_speed + %Player2D.is_on_moving_platform = true + +func on_leave(body) -> void: + if body == %Player2D: + %Player2D.is_on_moving_platform = false + #%Player2D.platform_speed = 0.0 diff --git a/hidden_horizontal_moving_block.gd.uid b/hidden_horizontal_moving_block.gd.uid new file mode 100644 index 0000000..051f0d6 --- /dev/null +++ b/hidden_horizontal_moving_block.gd.uid @@ -0,0 +1 @@ +uid://ckn8q0fyt01j3 diff --git a/hidden_horizontal_moving_block.tscn b/hidden_horizontal_moving_block.tscn new file mode 100644 index 0000000..f47db42 --- /dev/null +++ b/hidden_horizontal_moving_block.tscn @@ -0,0 +1,40 @@ +[gd_scene format=3 uid="uid://b61sumdnt0qqh"] + +[ext_resource type="Script" uid="uid://ckn8q0fyt01j3" path="res://hidden_horizontal_moving_block.gd" id="1_c4g4s"] +[ext_resource type="Texture2D" uid="uid://blbaaqyrt8dtk" path="res://art/block/block.png" id="2_c7hrt"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_f3sb7"] +size = Vector2(32, 13) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_3uo2v"] +size = Vector2(32, 4.0000687) + +[node name="HiddenHorizontalMovingBlock" type="RigidBody2D" unique_id=1409784601] +visible = false +gravity_scale = 0.0 +freeze = true +script = ExtResource("1_c4g4s") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1866755047] +position = Vector2(0, -1.5) +shape = SubResource("RectangleShape2D_f3sb7") + +[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1680278216] +texture_filter = 1 +position = Vector2(-8, -2) +texture = ExtResource("2_c7hrt") + +[node name="Sprite2D2" type="Sprite2D" parent="." unique_id=549053101] +texture_filter = 1 +position = Vector2(8, -2) +texture = ExtResource("2_c7hrt") + +[node name="Area2D" type="Area2D" parent="." unique_id=1910272404] +rotation = -6.834404e-05 + +[node name="ShapeCast2D" type="CollisionShape2D" parent="Area2D" unique_id=934904308] +position = Vector2(0.000615094, -8.999966) +shape = SubResource("RectangleShape2D_3uo2v") + +[connection signal="body_entered" from="Area2D" to="." method="on_enter"] +[connection signal="body_exited" from="Area2D" to="." method="on_leave"] diff --git a/hidden_spike.gd b/hidden_spike.gd index f1d144a..20fcbf5 100644 --- a/hidden_spike.gd +++ b/hidden_spike.gd @@ -2,6 +2,7 @@ extends Node2D func _ready() -> void: add_to_group("Hidden") + modulate = Color.DARK_CYAN func _process(delta: float) -> void: pass diff --git a/horizontal_moving_block.gd b/horizontal_moving_block.gd index 99ca09a..4f96e50 100644 --- a/horizontal_moving_block.gd +++ b/horizontal_moving_block.gd @@ -1,21 +1,39 @@ extends RigidBody2D -var max_distance = position + Vector2(1,0) -var move_speed = 0.01 +@export var max_distance = 260.0 +@export var moving = true +var alt_position = Vector2(position.x + max_distance,0) +@export var move_speed = 0.01 func _ready() -> void: + #Do not move collision boxes, it is fickle. + #on_leave(%Player2D) + alt_position = Vector2(position.x + max_distance,0) add_to_group("MovingPlatform") func _process(delta: float) -> void: - print(max_distance) - position.x = move_toward(position.x, max_distance.x, move_speed) - + if position.x != alt_position.x: + position.x = move_toward(position.x, alt_position.x, move_speed) + else: + moving = false + %Player2D.is_on_moving_platform = false + #%Player2D.platform_speed = 0.0 + func on_enter(body) -> void: - print("ON MOVING PLATFORM") - if %Player2D.is_on_floor(): - %Player2D.is_on_moving_platform = true + if %Player2D.is_on_floor() and body == %Player2D: + print("Player on moving platform.") %Player2D.platform_speed = move_speed - + %Player2D.is_on_moving_platform = true + elif body == %Player2D and !%Player2D.is_on_wall_only: + print("Player but has not landed") + %Player2D.platform_speed = move_speed + %Player2D.is_on_moving_platform = true + elif body == %Player2D: + print("SOMETHING IS WRONG WITH PLAYER") + %Player2D.platform_speed = move_speed + %Player2D.is_on_moving_platform = true + func on_leave(body) -> void: - print("OFF MOVING PLATFORM") - %Player2D.is_on_moving_platform = false + if body == %Player2D: + %Player2D.is_on_moving_platform = false + #%Player2D.platform_speed = 0.0 diff --git a/horizontal_moving_block.tscn b/horizontal_moving_block.tscn index 30b1ee8..97bbed0 100644 --- a/horizontal_moving_block.tscn +++ b/horizontal_moving_block.tscn @@ -4,18 +4,18 @@ [ext_resource type="Texture2D" uid="uid://blbaaqyrt8dtk" path="res://art/block/block.png" id="1_m1vtb"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_f3sb7"] -size = Vector2(32, 16) +size = Vector2(32, 13) [sub_resource type="RectangleShape2D" id="RectangleShape2D_3uo2v"] -size = Vector2(38, 23) +size = Vector2(32, 4.0000687) -[node name="Block" type="RigidBody2D" unique_id=1409784601] +[node name="HorizontalMovingBlock" type="RigidBody2D" unique_id=1409784601] gravity_scale = 0.0 freeze = true script = ExtResource("1_3uo2v") [node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1866755047] -position = Vector2(0, -2) +position = Vector2(0, -1.5) shape = SubResource("RectangleShape2D_f3sb7") [node name="Sprite2D" type="Sprite2D" parent="." unique_id=1680278216] @@ -29,12 +29,11 @@ position = Vector2(8, -2) texture = ExtResource("1_m1vtb") [node name="Area2D" type="Area2D" parent="." unique_id=1910272404] +rotation = -6.834404e-05 [node name="ShapeCast2D" type="CollisionShape2D" parent="Area2D" unique_id=934904308] -position = Vector2(0, -3.5) +position = Vector2(0.000615094, -8.999966) shape = SubResource("RectangleShape2D_3uo2v") -[connection signal="body_entered" from="." to="." method="on_enter"] -[connection signal="body_exited" from="." to="." method="on_leave"] [connection signal="body_entered" from="Area2D" to="." method="on_enter"] [connection signal="body_exited" from="Area2D" to="." method="on_leave"] diff --git a/player_2d.gd b/player_2d.gd index 8162268..015d649 100644 --- a/player_2d.gd +++ b/player_2d.gd @@ -12,7 +12,7 @@ const DASH_LENGTH = 0.2 const BACKGROUND_COLOR = Color(Color.ORANGE.r + 0.80,Color.ORANGE.g + 0.20,Color.ORANGE.b - 0.10) var is_on_moving_platform = false -var platform_speed = 0 +var platform_speed = 0.0 var death_cooldown = 0.0 var fall_timer = 0.0 @@ -122,6 +122,10 @@ func on_death(instant = false, player_position = position): death_cooldown = 0 func _process(delta: float) -> void: + + if is_on_moving_platform: + position.x = position.x + platform_speed + if Input.is_key_pressed(Key.KEY_W) or Input.is_key_pressed(Key.KEY_A) or Input.is_key_pressed(Key.KEY_S) or Input.is_key_pressed(Key.KEY_D): controller_ui = false elif Input.get_action_strength("move_horizontal") > 0: @@ -131,8 +135,6 @@ func _process(delta: float) -> void: get_tree().reload_current_scene() if is_on_floor(): - if is_on_moving_platform: - %Player2D.position.x += platform_speed last_ground_point = global_position #spawn_point = last_ground_point @@ -162,9 +164,10 @@ func _process(delta: float) -> void: velocity.y = -(0.001 * JUMP_VELOCITY) if Input.is_action_pressed("jump") and is_on_wall_only(): - print("WALL HANGING") - #velocity.y = 0 - #velocity.x = 0 + pass + #print("WALL HANGING") + #velocity.y = 0 + #velocity.x = 0 var direction = Input.get_axis("move_left","move_right") @@ -199,7 +202,7 @@ func _process(delta: float) -> void: $Sprite2D.play("running") $Sprite2D/HatSprite.play("running") - elif !dashing: + elif !dashing and !is_on_moving_platform: velocity.x = move_toward(velocity.x, 0, FRICTION) $Sprite2D.play("idle") $Sprite2D/HatSprite.play("idle") @@ -208,7 +211,7 @@ func _process(delta: float) -> void: if get_tree(): for hidden_object in get_tree().get_nodes_in_group("Hidden"): hidden_object.hide() - + #Falling to death. if position.y >= death_threshold: print("SLASH KILL") diff --git a/world.tscn b/world.tscn index c4194ee..fae3d15 100644 --- a/world.tscn +++ b/world.tscn @@ -34,6 +34,7 @@ [ext_resource type="PackedScene" uid="uid://big8haq2m0jxw" path="res://sign_arrow.tscn" id="30_bh8nc"] [ext_resource type="PackedScene" uid="uid://cue2gfw1bdfh7" path="res://sign_arrow_up.tscn" id="31_jjr1n"] [ext_resource type="PackedScene" uid="uid://div6quttr84u1" path="res://horizontal_moving_block.tscn" id="34_w44yn"] +[ext_resource type="PackedScene" uid="uid://b61sumdnt0qqh" path="res://hidden_horizontal_moving_block.tscn" id="35_6ah6f"] [node name="World" type="Node2D" unique_id=1327991900] process_mode = 1 @@ -1355,4 +1356,8 @@ position = Vector2(-4866, 311.15155) [node name="VerticalLongBlock10" parent="." unique_id=952105658 instance=ExtResource("4_pkg7o")] position = Vector2(-5189, 322.96738) +[node name="HiddenHorizontalMovingBlock" parent="." unique_id=821525141 instance=ExtResource("35_6ah6f")] +visible = true +position = Vector2(-5294, 414.54047) + [connection signal="toggled" from="CanvasLayer/MusicButton" to="CanvasLayer/MusicButton" method="_on_toggled"]