Fixed moving blocks
This commit is contained in:
1 parent
e7e33fa481
commit
22abac2f11
9 files changed
+132
-23
No files matched your search
@@ -4,6 +4,7 @@
|
|||||||
[ext_resource type="PackedScene" uid="uid://ckqable762x8v" path="res://block.tscn" id="2_se82m"]
|
[ext_resource type="PackedScene" uid="uid://ckqable762x8v" path="res://block.tscn" id="2_se82m"]
|
||||||
|
|
||||||
[node name="HiddenHorizontalLongBlock" type="RigidBody2D" unique_id=925152188]
|
[node name="HiddenHorizontalLongBlock" type="RigidBody2D" unique_id=925152188]
|
||||||
|
visible = false
|
||||||
rotation = 3.1415927
|
rotation = 3.1415927
|
||||||
gravity_scale = 0.0
|
gravity_scale = 0.0
|
||||||
freeze = true
|
freeze = true
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://ckn8q0fyt01j3
|
||||||
@@ -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"]
|
||||||
@@ -2,6 +2,7 @@ extends Node2D
|
|||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
add_to_group("Hidden")
|
add_to_group("Hidden")
|
||||||
|
modulate = Color.DARK_CYAN
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,21 +1,39 @@
|
|||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
var max_distance = position + Vector2(1,0)
|
@export var max_distance = 260.0
|
||||||
var move_speed = 0.01
|
@export var moving = true
|
||||||
|
var alt_position = Vector2(position.x + max_distance,0)
|
||||||
|
@export var move_speed = 0.01
|
||||||
|
|
||||||
func _ready() -> void:
|
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")
|
add_to_group("MovingPlatform")
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
print(max_distance)
|
if position.x != alt_position.x:
|
||||||
position.x = move_toward(position.x, max_distance.x, move_speed)
|
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:
|
func on_enter(body) -> void:
|
||||||
print("ON MOVING PLATFORM")
|
if %Player2D.is_on_floor() and body == %Player2D:
|
||||||
if %Player2D.is_on_floor():
|
print("Player on moving platform.")
|
||||||
%Player2D.is_on_moving_platform = true
|
|
||||||
%Player2D.platform_speed = move_speed
|
%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:
|
func on_leave(body) -> void:
|
||||||
print("OFF MOVING PLATFORM")
|
if body == %Player2D:
|
||||||
%Player2D.is_on_moving_platform = false
|
%Player2D.is_on_moving_platform = false
|
||||||
|
#%Player2D.platform_speed = 0.0
|
||||||
@@ -4,18 +4,18 @@
|
|||||||
[ext_resource type="Texture2D" uid="uid://blbaaqyrt8dtk" path="res://art/block/block.png" id="1_m1vtb"]
|
[ext_resource type="Texture2D" uid="uid://blbaaqyrt8dtk" path="res://art/block/block.png" id="1_m1vtb"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_f3sb7"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_f3sb7"]
|
||||||
size = Vector2(32, 16)
|
size = Vector2(32, 13)
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3uo2v"]
|
[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
|
gravity_scale = 0.0
|
||||||
freeze = true
|
freeze = true
|
||||||
script = ExtResource("1_3uo2v")
|
script = ExtResource("1_3uo2v")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1866755047]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1866755047]
|
||||||
position = Vector2(0, -2)
|
position = Vector2(0, -1.5)
|
||||||
shape = SubResource("RectangleShape2D_f3sb7")
|
shape = SubResource("RectangleShape2D_f3sb7")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1680278216]
|
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1680278216]
|
||||||
@@ -29,12 +29,11 @@ position = Vector2(8, -2)
|
|||||||
texture = ExtResource("1_m1vtb")
|
texture = ExtResource("1_m1vtb")
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="." unique_id=1910272404]
|
[node name="Area2D" type="Area2D" parent="." unique_id=1910272404]
|
||||||
|
rotation = -6.834404e-05
|
||||||
|
|
||||||
[node name="ShapeCast2D" type="CollisionShape2D" parent="Area2D" unique_id=934904308]
|
[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")
|
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_entered" from="Area2D" to="." method="on_enter"]
|
||||||
[connection signal="body_exited" from="Area2D" to="." method="on_leave"]
|
[connection signal="body_exited" from="Area2D" to="." method="on_leave"]
|
||||||
+10
-7
@@ -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)
|
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 is_on_moving_platform = false
|
||||||
var platform_speed = 0
|
var platform_speed = 0.0
|
||||||
|
|
||||||
var death_cooldown = 0.0
|
var death_cooldown = 0.0
|
||||||
var fall_timer = 0.0
|
var fall_timer = 0.0
|
||||||
@@ -122,6 +122,10 @@ func on_death(instant = false, player_position = position):
|
|||||||
death_cooldown = 0
|
death_cooldown = 0
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
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):
|
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
|
controller_ui = false
|
||||||
elif Input.get_action_strength("move_horizontal") > 0:
|
elif Input.get_action_strength("move_horizontal") > 0:
|
||||||
@@ -131,8 +135,6 @@ func _process(delta: float) -> void:
|
|||||||
get_tree().reload_current_scene()
|
get_tree().reload_current_scene()
|
||||||
|
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
if is_on_moving_platform:
|
|
||||||
%Player2D.position.x += platform_speed
|
|
||||||
last_ground_point = global_position
|
last_ground_point = global_position
|
||||||
#spawn_point = last_ground_point
|
#spawn_point = last_ground_point
|
||||||
|
|
||||||
@@ -162,9 +164,10 @@ func _process(delta: float) -> void:
|
|||||||
velocity.y = -(0.001 * JUMP_VELOCITY)
|
velocity.y = -(0.001 * JUMP_VELOCITY)
|
||||||
|
|
||||||
if Input.is_action_pressed("jump") and is_on_wall_only():
|
if Input.is_action_pressed("jump") and is_on_wall_only():
|
||||||
print("WALL HANGING")
|
pass
|
||||||
#velocity.y = 0
|
#print("WALL HANGING")
|
||||||
#velocity.x = 0
|
#velocity.y = 0
|
||||||
|
#velocity.x = 0
|
||||||
|
|
||||||
var direction = Input.get_axis("move_left","move_right")
|
var direction = Input.get_axis("move_left","move_right")
|
||||||
|
|
||||||
@@ -199,7 +202,7 @@ func _process(delta: float) -> void:
|
|||||||
$Sprite2D.play("running")
|
$Sprite2D.play("running")
|
||||||
$Sprite2D/HatSprite.play("running")
|
$Sprite2D/HatSprite.play("running")
|
||||||
|
|
||||||
elif !dashing:
|
elif !dashing and !is_on_moving_platform:
|
||||||
velocity.x = move_toward(velocity.x, 0, FRICTION)
|
velocity.x = move_toward(velocity.x, 0, FRICTION)
|
||||||
$Sprite2D.play("idle")
|
$Sprite2D.play("idle")
|
||||||
$Sprite2D/HatSprite.play("idle")
|
$Sprite2D/HatSprite.play("idle")
|
||||||
|
|||||||
@@ -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://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://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://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]
|
[node name="World" type="Node2D" unique_id=1327991900]
|
||||||
process_mode = 1
|
process_mode = 1
|
||||||
@@ -1355,4 +1356,8 @@ position = Vector2(-4866, 311.15155)
|
|||||||
[node name="VerticalLongBlock10" parent="." unique_id=952105658 instance=ExtResource("4_pkg7o")]
|
[node name="VerticalLongBlock10" parent="." unique_id=952105658 instance=ExtResource("4_pkg7o")]
|
||||||
position = Vector2(-5189, 322.96738)
|
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"]
|
[connection signal="toggled" from="CanvasLayer/MusicButton" to="CanvasLayer/MusicButton" method="_on_toggled"]
|
||||||
Reference in new issue
Block a user