Added wall states

This commit is contained in:
2026-06-28 19:59:18 +03:00
parent 204546b93a
commit 84ab412658
8 changed files with 136 additions and 6 deletions
@@ -7,6 +7,9 @@ const ANIMATION_RUN_LEFT = "run_left"
const ANIMATION_RUN_RIGHT = "run_right"
const ANIMATION_JUMP_LEFT = "jump_left"
const ANIMATION_JUMP_RIGHT = "jump_right"
const ANIMATION_WALL_LEFT = "wall_left"
const ANIMATION_WALL_RIGHT = "wall_right"
const ANIMATION_ATTACK = "attack"
+4 -1
View File
@@ -44,6 +44,9 @@ var _last_wall_normal: = 0.0
@onready var wall_attach_timer : Timer = $WallAttachTimer
@onready var attack_cooldown_timer : Timer = $AttackCooldownTimer
@onready var wall_left_particles : GPUParticles2D = $WallLeftParticles
@onready var wall_right_particles : GPUParticles2D = $WallRightParticles
@onready var _max_speed := move_max_speed_normal
@@ -117,7 +120,7 @@ func _physics_process(delta: float) -> void:
func _input(event: InputEvent) -> void:
if event.is_action_pressed("attack"):
if not _slow_down_tween or not _slow_down_tween.is_running():
if not is_on_floor() or not is_zero_approx(velocity.x):
if not is_on_wall() and not is_on_floor() or not is_zero_approx(velocity.x):
_attack()
+76 -3
View File
@@ -6,6 +6,7 @@
[ext_resource type="PackedScene" uid="uid://btu3hxif2xpvu" path="res://game/entities/player/states/idle_state.tscn" id="3_cjfdk"]
[ext_resource type="PackedScene" uid="uid://35g5buv0k1s6" path="res://game/entities/player/states/running_state.tscn" id="5_oic1i"]
[ext_resource type="PackedScene" uid="uid://bboaskqiwnbsb" path="res://game/entities/player/states/jump_state.tscn" id="6_v0nmi"]
[ext_resource type="PackedScene" uid="uid://ba5sknbijujl2" path="res://game/entities/player/states/wall_state.tscn" id="7_dhej3"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_bhunq"]
radius = 4.5
@@ -111,6 +112,14 @@ region = Rect2(128, 96, 32, 32)
atlas = ExtResource("2_cjfdk")
region = Rect2(160, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_66tqw"]
atlas = ExtResource("2_cjfdk")
region = Rect2(96, 256, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_n4muq"]
atlas = ExtResource("2_cjfdk")
region = Rect2(0, 256, 32, 32)
[sub_resource type="SpriteFrames" id="SpriteFrames_bhunq"]
animations = [{
"frames": [{
@@ -215,6 +224,22 @@ animations = [{
"loop": 1,
"name": &"run_right",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_66tqw")
}],
"loop": 1,
"name": &"wall_left",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_n4muq")
}],
"loop": 1,
"name": &"wall_right",
"speed": 5.0
}]
[sub_resource type="AtlasTexture" id="AtlasTexture_2mee4"]
@@ -499,6 +524,23 @@ animations = [{
"speed": 20.0
}]
[sub_resource type="Gradient" id="Gradient_qr0ht"]
interpolation_mode = 1
colors = PackedColorArray(0.99215686, 0.99607843, 0.5372549, 1, 1, 0.7529412, 0.46666667, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_riqys"]
gradient = SubResource("Gradient_qr0ht")
width = 2
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_bhunq"]
lifetime_randomness = 0.5
particle_flag_disable_z = true
direction = Vector3(1, -1, 0)
initial_velocity_min = 10.0
initial_velocity_max = 10.0
gravity = Vector3(0, 0, 0)
color_ramp = SubResource("GradientTexture1D_riqys")
[node name="Player" type="CharacterBody2D" unique_id=763780926]
script = ExtResource("1_1a4jd")
@@ -508,7 +550,7 @@ shape = SubResource("CapsuleShape2D_bhunq")
[node name="PlayerSprite" type="AnimatedSprite2D" parent="." unique_id=2025942250]
sprite_frames = SubResource("SpriteFrames_bhunq")
animation = &"idle"
animation = &"wall_right"
[node name="BladeSprite" type="AnimatedSprite2D" parent="." unique_id=1561250707]
position = Vector2(0, 8)
@@ -552,19 +594,35 @@ jump = NodePath("../JumpRightState")
jump_another_direction = NodePath("../JumpLeftState")
player = NodePath("../..")
[node name="JumpLeftState" parent="StateMachine" unique_id=914600878 node_paths=PackedStringArray("idle", "another_direction", "run", "run_another_direction", "player") instance=ExtResource("6_v0nmi")]
[node name="JumpLeftState" parent="StateMachine" unique_id=914600878 node_paths=PackedStringArray("idle", "another_direction", "run", "run_another_direction", "wall", "player") instance=ExtResource("6_v0nmi")]
idle = NodePath("../IdleState")
another_direction = NodePath("../JumpRightState")
run = NodePath("../RunningLeftState")
run_another_direction = NodePath("../JumpRightState")
wall = NodePath("../WallRightState")
player = NodePath("../..")
[node name="JumpRightState" parent="StateMachine" unique_id=470310632 node_paths=PackedStringArray("idle", "another_direction", "run", "run_another_direction", "player") instance=ExtResource("6_v0nmi")]
[node name="JumpRightState" parent="StateMachine" unique_id=470310632 node_paths=PackedStringArray("idle", "another_direction", "run", "run_another_direction", "wall", "player") instance=ExtResource("6_v0nmi")]
direction = 1
idle = NodePath("../IdleState")
another_direction = NodePath("../JumpLeftState")
run = NodePath("../RunningRightState")
run_another_direction = NodePath("../RunningLeftState")
wall = NodePath("../WallLeftState")
player = NodePath("../..")
[node name="WallLeftState" parent="StateMachine" unique_id=1609653446 node_paths=PackedStringArray("idle", "jump", "particles", "player") instance=ExtResource("7_dhej3")]
direction = 0
idle = NodePath("../IdleState")
jump = NodePath("../JumpLeftState")
particles = NodePath("../../WallRightParticles")
player = NodePath("../..")
[node name="WallRightState" parent="StateMachine" unique_id=1873321719 node_paths=PackedStringArray("idle", "jump", "particles", "player") instance=ExtResource("7_dhej3")]
direction = 1
idle = NodePath("../IdleState")
jump = NodePath("../JumpRightState")
particles = NodePath("../../WallLeftParticles")
player = NodePath("../..")
[node name="JumpBufferTimer" type="Timer" parent="." unique_id=1845152635]
@@ -590,3 +648,18 @@ one_shot = true
[node name="AttackCooldownTimer" type="Timer" parent="." unique_id=1208896947]
process_callback = 0
wait_time = 0.75
[node name="WallLeftParticles" type="GPUParticles2D" parent="." unique_id=2009522894]
position = Vector2(-4, 4)
emitting = false
amount = 32
lifetime = 0.5
process_material = SubResource("ParticleProcessMaterial_bhunq")
[node name="WallRightParticles" type="GPUParticles2D" parent="." unique_id=1737496790]
position = Vector2(5, 4)
rotation = -1.5707964
emitting = false
amount = 32
lifetime = 0.5
process_material = SubResource("ParticleProcessMaterial_bhunq")
@@ -13,6 +13,7 @@ enum Direction {
@export var another_direction : AbstractPlayerState
@export var run : AbstractPlayerState
@export var run_another_direction : AbstractPlayerState
@export var wall : AbstractPlayerState
func enter() -> void:
@@ -47,6 +48,8 @@ func physics_process(_delta: float) -> void:
switch_state.emit(run)
else:
switch_state.emit(run_another_direction)
elif player.is_on_wall():
switch_state.emit(wall)
else:
if not is_zero_approx(player.velocity.x):
match direction:
+40
View File
@@ -0,0 +1,40 @@
extends AbstractPlayerState
const PARTICLE_FACTOR = 100.0
enum Direction {
Left,
Right,
}
@export var direction := Direction.Left
@export var idle : AbstractPlayerState
@export var jump : AbstractPlayerState
@export var particles : GPUParticles2D
func enter() -> void:
particles.emitting = true
match direction:
Direction.Left:
player.player_sprite.play(ANIMATION_WALL_LEFT)
Direction.Right:
player.player_sprite.play(ANIMATION_WALL_RIGHT)
func exit() -> void:
particles.emitting = false
func physics_process(_delta: float) -> void:
particles.amount_ratio = clampf(player.velocity.y / PARTICLE_FACTOR, 0.0, 1.0)
if player.is_on_floor():
switch_state.emit(idle)
elif not player.is_on_wall():
switch_state.emit(jump)
@@ -0,0 +1 @@
uid://bghqpnc7vmmlh
@@ -0,0 +1,7 @@
[gd_scene format=3 uid="uid://ba5sknbijujl2"]
[ext_resource type="PackedScene" uid="uid://dqkewlpol05ap" path="res://game/entities/player/abstract_player_state.tscn" id="1_vvc6s"]
[ext_resource type="Script" uid="uid://bghqpnc7vmmlh" path="res://game/entities/player/states/wall_state.gd" id="2_kmlwa"]
[node name="WallState" unique_id=836520368 instance=ExtResource("1_vvc6s")]
script = ExtResource("2_kmlwa")
Binary file not shown.