From 84ab412658d0df4150ef7553bc1b1067e728fec6 Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Sun, 28 Jun 2026 19:59:18 +0300 Subject: [PATCH] Added wall states --- game/entities/player/abstract_player_state.gd | 3 + game/entities/player/player.gd | 5 +- game/entities/player/player.tscn | 79 ++++++++++++++++++- game/entities/player/states/jump_state.gd | 3 + game/entities/player/states/wall_state.gd | 40 ++++++++++ game/entities/player/states/wall_state.gd.uid | 1 + game/entities/player/states/wall_state.tscn | 7 ++ images/entities/player.png | 4 +- 8 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 game/entities/player/states/wall_state.gd create mode 100644 game/entities/player/states/wall_state.gd.uid create mode 100644 game/entities/player/states/wall_state.tscn diff --git a/game/entities/player/abstract_player_state.gd b/game/entities/player/abstract_player_state.gd index 584de4e..737d4f8 100644 --- a/game/entities/player/abstract_player_state.gd +++ b/game/entities/player/abstract_player_state.gd @@ -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" diff --git a/game/entities/player/player.gd b/game/entities/player/player.gd index 56607e5..b038ffa 100644 --- a/game/entities/player/player.gd +++ b/game/entities/player/player.gd @@ -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() diff --git a/game/entities/player/player.tscn b/game/entities/player/player.tscn index 535d1ad..e07966a 100644 --- a/game/entities/player/player.tscn +++ b/game/entities/player/player.tscn @@ -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") diff --git a/game/entities/player/states/jump_state.gd b/game/entities/player/states/jump_state.gd index c220d16..8bccb7c 100644 --- a/game/entities/player/states/jump_state.gd +++ b/game/entities/player/states/jump_state.gd @@ -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: diff --git a/game/entities/player/states/wall_state.gd b/game/entities/player/states/wall_state.gd new file mode 100644 index 0000000..bb74802 --- /dev/null +++ b/game/entities/player/states/wall_state.gd @@ -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) diff --git a/game/entities/player/states/wall_state.gd.uid b/game/entities/player/states/wall_state.gd.uid new file mode 100644 index 0000000..85bd592 --- /dev/null +++ b/game/entities/player/states/wall_state.gd.uid @@ -0,0 +1 @@ +uid://bghqpnc7vmmlh diff --git a/game/entities/player/states/wall_state.tscn b/game/entities/player/states/wall_state.tscn new file mode 100644 index 0000000..544831d --- /dev/null +++ b/game/entities/player/states/wall_state.tscn @@ -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") diff --git a/images/entities/player.png b/images/entities/player.png index 7676629..5bb7316 100644 --- a/images/entities/player.png +++ b/images/entities/player.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:70f3fe089abb54652cd7f77b9a8efc39dda41a0b2bce30e0453d5c57feb2fc98 -size 2985 +oid sha256:6907dd643370dcc3c6a776d567aa449a28c8d7a5bcd6b91c7a3dd88b684642c5 +size 3200