Skip to content

Commit

Permalink
added some wall code
Browse files Browse the repository at this point in the history
  • Loading branch information
themangomago committed Sep 26, 2023
1 parent 36ec12f commit 4980b51
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 42 deletions.
30 changes: 15 additions & 15 deletions examples_fsm/celeste/art/dust.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

[ext_resource type="Texture2D" uid="uid://ba5mdd12dm5ai" path="res://examples_fsm/celeste/art/dust.png" id="1_0bcjs"]

[sub_resource type="Animation" id="Animation_p6pjb"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [1]
}

[sub_resource type="Animation" id="Animation_glklj"]
resource_name = "pop"
length = 0.3
Expand Down Expand Up @@ -32,21 +47,6 @@ tracks/1/keys = {
}]
}

[sub_resource type="Animation" id="Animation_p6pjb"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [1]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_dxuwo"]
_data = {
"RESET": SubResource("Animation_p6pjb"),
Expand Down
30 changes: 15 additions & 15 deletions examples_fsm/celeste/art/shade.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

[ext_resource type="Texture2D" uid="uid://d36yy8klxfl0h" path="res://examples_fsm/celeste/art/shade.png" id="1_cgon4"]

[sub_resource type="Animation" id="Animation_hwbjb"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 0.788235)]
}

[sub_resource type="Animation" id="Animation_0ykdt"]
resource_name = "fade"
length = 0.2
Expand Down Expand Up @@ -33,21 +48,6 @@ tracks/1/keys = {
}]
}

[sub_resource type="Animation" id="Animation_hwbjb"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 0.788235)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_lsdsw"]
_data = {
"RESET": SubResource("Animation_hwbjb"),
Expand Down
47 changes: 36 additions & 11 deletions examples_fsm/celeste/godette.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const MAX_SPEED: Vector2 = Vector2(450, 900)
const GRAVITY: float = 2100.0
const JUMP_HEIGHT: float = 36000.0
const ACCELERATION = 3000
const DASH_SPEED = Vector2(50000,50000)
const DASH_SPEED = Vector2(75000,75000)
const DASH_TIME_MAX = 10

const AGILITY_GROUND: float = 1.0
Expand Down Expand Up @@ -41,13 +41,8 @@ func _physics_process(delta):
# Get player input
_get_input()


# State processing
fsm.physics_process(delta)

# Apply gravity
if velocity.y <= MAX_SPEED.y and not is_dashing:
velocity.y += GRAVITY * delta

# Direction
if input.x < 0:
Expand All @@ -57,6 +52,8 @@ func _physics_process(delta):

# Perform movement
move_and_slide()

$Label.set_text(str(velocity))


func _on_idle_state_physic_processing(delta):
Expand All @@ -83,9 +80,17 @@ func move(delta: float, agility: float):

else:
velocity.x = move_toward(velocity.x, 0, ACCELERATION * delta)
$Label.set_text(str(input) + "\n" + str(velocity))





func gravity(delta: float):
# Apply gravity
if velocity.y <= MAX_SPEED.y and not is_dashing:
velocity.y += GRAVITY * delta




func _on_jump_state_physic_processing(delta):
Expand Down Expand Up @@ -125,6 +130,9 @@ func _on_air_state_physics_process(delta):
fsm.transition(state_ground)
animationState.travel("jump_end")
dust()
if $flip/RayCast2D.is_colliding():
fsm.transition(state_wall)
animationState.travel("wall")

if Input.is_action_just_pressed("dash"):
if can_dash and input_last != Vector2.ZERO:
Expand All @@ -134,27 +142,40 @@ func _on_air_state_physics_process(delta):
return

move(delta, AGILITY_AIR)
gravity(delta)



func _on_dash_state_physics_process(delta):
dash_time += 100 * delta


if dash_time >= DASH_TIME_MAX:
dash_time = 0
velocity = Vector2(0, 0)
fsm.transition(state_air)

if int(dash_time) % 3:
if ShadeNode:
var shade = ShadeNode.instantiate()
shade.global_position = global_position
get_parent().add_child(shade)

gravity(delta)

func _on_wall_state_physics_process(delta):
pass # Replace with function body.

if not $flip/RayCast2D.is_colliding():
animationState.travel("jump")
fsm.transition(state_air)
return

if is_on_floor():
fsm.transition(state_ground)
return

if Input.is_action_just_pressed("jump"):
velocity.y = -JUMP_HEIGHT * delta * 0.8
velocity.x = -$flip.scale.x * JUMP_HEIGHT/2 * delta
animationState.travel("jump_pre")
return

func _on_air_state_entered():
is_in_air = true
Expand Down Expand Up @@ -182,3 +203,7 @@ func _on_dash_available_state_entered():

func _on_dash_spended_state_entered():
$flip/Sprite2D.modulate = Color("#a1b7bf")


func _on_wall_state_entered():
velocity = Vector2(0, 0)
3 changes: 2 additions & 1 deletion examples_fsm/celeste/godette.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ hframes = 11

[node name="RayCast2D" type="RayCast2D" parent="flip"]
position = Vector2(0, -24)
target_position = Vector2(24, 0)
target_position = Vector2(16, 0)

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
Expand Down Expand Up @@ -483,6 +483,7 @@ target_state = NodePath("../../DashAvailable")
[connection signal="state_entered" from="NbChart/GodetteFSM/dash" to="." method="_on_dash_state_entered"]
[connection signal="state_exited" from="NbChart/GodetteFSM/dash" to="." method="_on_dash_state_exited"]
[connection signal="state_physics_process" from="NbChart/GodetteFSM/dash" to="." method="_on_dash_state_physics_process"]
[connection signal="state_entered" from="NbChart/GodetteFSM/wall" to="." method="_on_wall_state_entered"]
[connection signal="state_physics_process" from="NbChart/GodetteFSM/wall" to="." method="_on_wall_state_physics_process"]
[connection signal="state_entered" from="NbChart/ParallelFSM/DashAvailable" to="." method="_on_dash_available_state_entered"]
[connection signal="state_entered" from="NbChart/ParallelFSM/DashSpended" to="." method="_on_dash_spended_state_entered"]

0 comments on commit 4980b51

Please sign in to comment.