Compare commits
66 Commits
v1.0.2
...
08c6e3a870
| Author | SHA1 | Date | |
|---|---|---|---|
| 08c6e3a870 | |||
| 6bfe08e76c | |||
| 24481b1f33 | |||
| 2b12373ed8 | |||
| 3bb2fb9d8a | |||
| 8812915d3e | |||
| 4ea9eea776 | |||
| 713be75d90 | |||
| 22c0912ea2 | |||
| 95539bcf5d | |||
| ed657514a3 | |||
| 5c766913d1 | |||
| 22475d78c2 | |||
| 59d71a4c57 | |||
| cbfbd9f4d8 | |||
| e72e17f7ca | |||
| 0c7e0f7c74 | |||
| 1cd95eea6b | |||
| fc3129cd02 | |||
| e4be7d1c39 | |||
| d5b8210773 | |||
| f0b10a193b | |||
| c48ab801da | |||
| 6535f0e032 | |||
| 8ec34e1285 | |||
| 489c89e1ac | |||
| b5b2c7691b | |||
| 60c36d8666 | |||
| 8b1635aad8 | |||
| 09311bbf2b | |||
| f7a55d75ae | |||
| 56daf32a16 | |||
| e2dee3f801 | |||
| aa7b392edc | |||
| ebc0133a82 | |||
| 0dff01da11 | |||
| 80d8785a71 | |||
| 530ea16f11 | |||
| a0b35ef4a4 | |||
| 1f25c93fc1 | |||
| 2562366d8a | |||
| b62b24dbbc | |||
| b0e497172f | |||
| 39cd68432e | |||
| 230f39cf54 | |||
| c3522f5417 | |||
| a5a3fa2acf | |||
| 1e617715f3 | |||
| 8d2ce976ec | |||
| 8d9cff9735 | |||
| c0de81481e | |||
| 67c5f8e4d5 | |||
| 63710b691b | |||
| 81d81ae103 | |||
| 37b5b698a6 | |||
| 7f12066244 | |||
| ecc1fbc05a | |||
| 2973cfab2e | |||
| 08f0988870 | |||
| 36c123ea5d | |||
| f870bd4dfe | |||
| 0d525dd6dd | |||
| f58b713806 | |||
| f5ef92ce98 | |||
| 0092c72a64 | |||
| cd74b87ca2 |
@@ -17,3 +17,5 @@ mono_crash.*.json
|
||||
|
||||
export
|
||||
|
||||
*.tmp
|
||||
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
# OneBitGameJam8
|
||||
# Cult Manor
|
||||
|
||||
My third Godot game. A simple 2D puzzle-platformer. Made for 1-Bit Jam 8 (theme: 'Into the depths').
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://d37eyum03h83i"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bx0luh4vdob3q" path="res://game/characters/abstract_enemy.tscn" id="1_12hr0"]
|
||||
[ext_resource type="Script" uid="uid://das7ujanefsn0" path="res://game/characters/abstract_color_enemy.gd" id="2_rd56i"]
|
||||
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="3_e5cea"]
|
||||
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="3_r5rx0"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ybui5"]
|
||||
resource_local_to_scene = true
|
||||
shader = ExtResource("3_r5rx0")
|
||||
shader_parameter/black_color = Color(0, 0, 0, 1)
|
||||
shader_parameter/white_color = Color(1, 1, 1, 1)
|
||||
shader_parameter/switch_colors = false
|
||||
shader_parameter/threshold = 0.5
|
||||
shader_parameter/speed = 5.0
|
||||
shader_parameter/intensity = 1.0
|
||||
shader_parameter/scale = 20.0
|
||||
|
||||
[node name="AbstractColorEnemy" instance=ExtResource("1_12hr0")]
|
||||
script = ExtResource("2_rd56i")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." index="0"]
|
||||
material = SubResource("ShaderMaterial_ybui5")
|
||||
|
||||
[node name="CollisionSwitcher" parent="." index="2" node_paths=PackedStringArray("object") instance=ExtResource("3_e5cea")]
|
||||
object = NodePath("..")
|
||||
@@ -1,314 +0,0 @@
|
||||
class_name AbstractEnemy
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
enum Type {
|
||||
Standing,
|
||||
Walking,
|
||||
Random,
|
||||
}
|
||||
|
||||
enum Facing {
|
||||
Front,
|
||||
Rear,
|
||||
}
|
||||
|
||||
enum State {
|
||||
Idle,
|
||||
WalkLeft,
|
||||
WalkRight,
|
||||
LookAround,
|
||||
ChasingLeft,
|
||||
ChasingRight,
|
||||
}
|
||||
|
||||
|
||||
const ANIMATION_FALL_DOWN = "fall_down"
|
||||
const ANIMATION_FALL_DOWN_LEFT = "fall_down_left"
|
||||
const ANIMATION_FALL_DOWN_RIGHT = "fall_down_right"
|
||||
const ANIMATION_FALL_UP = "fall_up"
|
||||
const ANIMATION_FALL_UP_LEFT = "fall_up_left"
|
||||
const ANIMATION_FALL_UP_RIGHT = "fall_up_right"
|
||||
const ANIMATION_IDLE_FRONT = "idle_front"
|
||||
const ANIMATION_IDLE_REAR = "idle_rear"
|
||||
const ANIMATION_LOOK_AROUND_FRONT_1 = "look_around_front_1"
|
||||
const ANIMATION_LOOK_AROUND_FRONT_2 = "look_around_front_2"
|
||||
const ANIMATION_LOOK_AROUND_REAR_1 = "look_around_rear_1"
|
||||
const ANIMATION_LOOK_AROUND_REAR_2 = "look_around_rear_2"
|
||||
const ANIMATION_WALK_LEFT = "walk_left"
|
||||
const ANIMATION_WALK_RIGHT = "walk_right"
|
||||
const ANIMATION_CHASE_LEFT = "chase_left"
|
||||
const ANIMATION_CHASE_RIGHT = "chase_right"
|
||||
|
||||
const LOOK_AROUND_FRONT_ANIMATIONS : Array[String] = [
|
||||
ANIMATION_LOOK_AROUND_FRONT_1,
|
||||
ANIMATION_LOOK_AROUND_FRONT_2,
|
||||
]
|
||||
const LOOK_AROUND_REAR_ANIMATIONS : Array[String] = [
|
||||
ANIMATION_LOOK_AROUND_REAR_1,
|
||||
ANIMATION_LOOK_AROUND_REAR_2,
|
||||
]
|
||||
|
||||
const MAX_WALK_SPEED = 85
|
||||
const MAX_CHASE_SPEED = 170
|
||||
const ACCELERATION = 600.0
|
||||
const LOOK_AROUND_CHANCE = 25
|
||||
const WALK_CHANCE = 25
|
||||
|
||||
const DIRECTION_LEFT = -1
|
||||
const DIRECTION_RIGHT = 1
|
||||
|
||||
|
||||
@export var type : Type = Type.Standing
|
||||
@export var facing : Facing = Facing.Front
|
||||
@export var initial_state : State = State.Idle
|
||||
|
||||
|
||||
var _target_x := 0.0
|
||||
var _target_found := false
|
||||
|
||||
|
||||
@onready var _state : State = initial_state:
|
||||
set = _set_state
|
||||
|
||||
@onready var sprite : AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
@onready var left_wall_ray : RayCast2D = $%LeftWallRay
|
||||
@onready var right_wall_ray : RayCast2D = $%RightWallRay
|
||||
|
||||
@onready var left_player_close_ray : RayCast2D = $%LeftPlayerCloseRay
|
||||
@onready var right_player_close_ray : RayCast2D = $%RightPlayerCloseRay
|
||||
|
||||
@onready var left_player_distant_ray : RayCast2D = $%LeftPlayerDistantRay
|
||||
@onready var right_player_distant_ray : RayCast2D = $%RightPlayerDistantRay
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
match _state:
|
||||
State.ChasingLeft:
|
||||
_process_player_ray(left_player_distant_ray)
|
||||
if position.x < _target_x:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_player_lost, global_position)
|
||||
_state = State.LookAround
|
||||
else:
|
||||
_update_x_velocity(DIRECTION_LEFT, MAX_CHASE_SPEED, delta)
|
||||
_check_wall_collision_and_switch_state(DIRECTION_LEFT)
|
||||
State.ChasingRight:
|
||||
_process_player_ray(right_player_distant_ray)
|
||||
if position.x > _target_x:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_player_lost, global_position)
|
||||
_state = State.LookAround
|
||||
else:
|
||||
_update_x_velocity(DIRECTION_RIGHT, MAX_CHASE_SPEED, delta)
|
||||
_check_wall_collision_and_switch_state(DIRECTION_RIGHT)
|
||||
State.WalkLeft:
|
||||
if _process_player_ray(left_player_distant_ray):
|
||||
_set_chase_state()
|
||||
_update_x_velocity(DIRECTION_LEFT, MAX_WALK_SPEED, delta)
|
||||
_check_wall_collision_and_switch_state(DIRECTION_LEFT)
|
||||
State.WalkRight:
|
||||
if _process_player_ray(right_player_distant_ray):
|
||||
_set_chase_state()
|
||||
_update_x_velocity(DIRECTION_RIGHT, MAX_WALK_SPEED, delta)
|
||||
_check_wall_collision_and_switch_state(DIRECTION_RIGHT)
|
||||
State.LookAround:
|
||||
_update_x_velocity(0, MAX_WALK_SPEED * 2, delta)
|
||||
if not _target_found:
|
||||
var close_rays : Array[RayCast2D] = [left_player_close_ray, right_player_close_ray]
|
||||
_target_found = _process_player_rays(close_rays)
|
||||
|
||||
_update_animation()
|
||||
|
||||
move_and_slide()
|
||||
|
||||
|
||||
func _set_state(value: State) -> void:
|
||||
_state = value
|
||||
|
||||
left_player_close_ray.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
right_player_close_ray.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
left_player_distant_ray.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
right_player_distant_ray.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
|
||||
match _state:
|
||||
State.ChasingLeft, State.WalkLeft:
|
||||
left_player_distant_ray.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
State.ChasingRight, State.WalkRight:
|
||||
left_player_distant_ray.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
State.LookAround:
|
||||
left_player_close_ray.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
right_player_distant_ray.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
|
||||
|
||||
func _process_player_ray(ray: RayCast2D) -> bool:
|
||||
if ray.is_colliding():
|
||||
ray.force_raycast_update()
|
||||
var collider := ray.get_collider()
|
||||
if collider is Player:
|
||||
_target_x = collider.position.x
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _process_player_rays(rays: Array[RayCast2D]) -> bool:
|
||||
for ray in rays:
|
||||
if _process_player_ray(ray):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _update_x_velocity(direction: int, max_speed: float, delta: float) -> void:
|
||||
velocity.x = move_toward(velocity.x, direction * max_speed, ACCELERATION * delta)
|
||||
|
||||
|
||||
func _check_wall_collision_and_switch_state(direction: int) -> void:
|
||||
var this_wall_ray := _get_wall_ray(direction)
|
||||
var other_wall_ray := _get_wall_ray(-direction)
|
||||
|
||||
if this_wall_ray.is_colliding():
|
||||
if other_wall_ray.is_colliding():
|
||||
_state = State.LookAround
|
||||
else:
|
||||
match _state:
|
||||
State.WalkLeft:
|
||||
_state = State.WalkRight
|
||||
State.WalkRight:
|
||||
_state = State.WalkLeft
|
||||
State.ChasingLeft, State.ChasingRight:
|
||||
var stream := SoundManager.sfx_stream_player_lost
|
||||
SoundManager.play_sfx_stream(stream, global_position)
|
||||
_state = State.LookAround
|
||||
|
||||
|
||||
func _get_wall_ray(direction: int) -> RayCast2D:
|
||||
if direction < 0:
|
||||
return left_wall_ray
|
||||
else:
|
||||
return right_wall_ray
|
||||
|
||||
|
||||
func _update_animation() -> void:
|
||||
if is_zero_approx(velocity.y):
|
||||
match _state:
|
||||
State.WalkLeft:
|
||||
_play_animation(ANIMATION_WALK_LEFT)
|
||||
State.WalkRight:
|
||||
_play_animation(ANIMATION_WALK_RIGHT)
|
||||
State.ChasingLeft:
|
||||
_play_animation(ANIMATION_CHASE_LEFT)
|
||||
State.ChasingRight:
|
||||
_play_animation(ANIMATION_CHASE_RIGHT)
|
||||
State.Idle:
|
||||
_play_idle_animation()
|
||||
State.LookAround:
|
||||
_play_look_around_animation()
|
||||
else:
|
||||
_play_fall_animation()
|
||||
|
||||
|
||||
func _play_idle_animation() -> void:
|
||||
match facing:
|
||||
Facing.Front:
|
||||
_play_animation(ANIMATION_IDLE_FRONT)
|
||||
Facing.Rear:
|
||||
_play_animation(ANIMATION_IDLE_REAR)
|
||||
|
||||
|
||||
func _play_look_around_animation() -> void:
|
||||
if _is_current_animation_look_around(): return
|
||||
|
||||
match facing:
|
||||
Facing.Front:
|
||||
var animation := _get_random_animation(LOOK_AROUND_FRONT_ANIMATIONS)
|
||||
_play_animation(animation)
|
||||
Facing.Rear:
|
||||
var animation := _get_random_animation(LOOK_AROUND_REAR_ANIMATIONS)
|
||||
_play_animation(animation)
|
||||
|
||||
|
||||
func _play_fall_animation() -> void:
|
||||
if is_zero_approx(velocity.x):
|
||||
var animation := ANIMATION_FALL_UP if velocity.y < 0 else ANIMATION_FALL_DOWN
|
||||
_play_animation(animation)
|
||||
elif velocity.x < 0:
|
||||
var animation := ANIMATION_FALL_UP_LEFT if velocity.y < 0 else ANIMATION_FALL_DOWN_LEFT
|
||||
_play_animation(animation)
|
||||
else:
|
||||
var animation := ANIMATION_FALL_UP_RIGHT if velocity.y < 0 else ANIMATION_FALL_DOWN_RIGHT
|
||||
_play_animation(animation)
|
||||
|
||||
|
||||
func _is_current_animation_look_around() -> bool:
|
||||
if not sprite.is_playing(): return false
|
||||
if sprite.animation in LOOK_AROUND_FRONT_ANIMATIONS: return true
|
||||
if sprite.animation in LOOK_AROUND_REAR_ANIMATIONS: return true
|
||||
return false
|
||||
|
||||
|
||||
func _get_random_animation(animations: Array[String]) -> String:
|
||||
var index := randi_range(0, animations.size() - 1)
|
||||
return animations[index]
|
||||
|
||||
|
||||
func _play_animation(animation: String) -> void:
|
||||
if not sprite.is_playing() or sprite.animation != animation:
|
||||
sprite.play(animation)
|
||||
|
||||
|
||||
func _set_walking_state() -> void:
|
||||
var is_left_colliding := left_wall_ray.is_colliding()
|
||||
var is_right_colliding := right_wall_ray.is_colliding()
|
||||
|
||||
if is_left_colliding and is_right_colliding:
|
||||
_state = State.Idle
|
||||
elif not is_left_colliding and not is_right_colliding:
|
||||
_state = State.WalkLeft if randi_range(1, 2) == 1 else State.WalkRight
|
||||
elif not is_left_colliding:
|
||||
_state = State.WalkLeft
|
||||
else:
|
||||
_state = State.WalkRight
|
||||
|
||||
|
||||
func _set_chase_state() -> void:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_player_spoted, global_position)
|
||||
if _target_x < position.x:
|
||||
_state = State.ChasingLeft
|
||||
else:
|
||||
_state = State.ChasingRight
|
||||
|
||||
|
||||
func _is_walking_state() -> bool:
|
||||
return _state == State.WalkLeft or _state == State.WalkRight
|
||||
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
if _target_found:
|
||||
_set_chase_state()
|
||||
_target_found = false
|
||||
return
|
||||
|
||||
match type:
|
||||
Type.Standing:
|
||||
_state = State.Idle
|
||||
Type.Walking:
|
||||
_set_walking_state()
|
||||
Type.Random:
|
||||
if randi_range(1, 100) <= WALK_CHANCE:
|
||||
_set_walking_state()
|
||||
else:
|
||||
_state = State.Idle
|
||||
|
||||
|
||||
func _on_animation_looped() -> void:
|
||||
if _state == State.Idle or (type == Type.Random and _is_walking_state()):
|
||||
if randi_range(1, 100) <= LOOK_AROUND_CHANCE:
|
||||
_state = State.LookAround
|
||||
|
||||
|
||||
func _on_player_touch_area_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
_target_x = body.position.x
|
||||
_set_chase_state()
|
||||
@@ -1,73 +0,0 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://bx0luh4vdob3q"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://but5aeh7y1s0f" path="res://game/characters/abstract_enemy.gd" id="1_2wrno"]
|
||||
[ext_resource type="PackedScene" uid="uid://dtxiercm8dsfm" path="res://game/characters/enemy_sprite.tscn" id="2_tjvyk"]
|
||||
[ext_resource type="PackedScene" uid="uid://dpvsvsd8pcjqn" path="res://game/player_killer.tscn" id="4_vecdo"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_mocsw"]
|
||||
radius = 4.0
|
||||
height = 28.0
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vecdo"]
|
||||
size = Vector2(32, 28)
|
||||
|
||||
[node name="AbstractEnemy" type="CharacterBody2D"]
|
||||
collision_layer = 0
|
||||
script = ExtResource("1_2wrno")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." instance=ExtResource("2_tjvyk")]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 2)
|
||||
shape = SubResource("CapsuleShape2D_mocsw")
|
||||
|
||||
[node name="PlayerKiller" parent="." instance=ExtResource("4_vecdo")]
|
||||
|
||||
[node name="WallCheck" type="Node2D" parent="."]
|
||||
position = Vector2(0, 9)
|
||||
|
||||
[node name="LeftWallRay" type="RayCast2D" parent="WallCheck"]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(-16, 0)
|
||||
|
||||
[node name="RightWallRay" type="RayCast2D" parent="WallCheck"]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(16, 0)
|
||||
|
||||
[node name="PlayerCloseCheck" type="Node2D" parent="."]
|
||||
position = Vector2(0, 9)
|
||||
|
||||
[node name="LeftPlayerCloseRay" type="RayCast2D" parent="PlayerCloseCheck"]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(-48, 0)
|
||||
collision_mask = 0
|
||||
|
||||
[node name="RightPlayerCloseRay" type="RayCast2D" parent="PlayerCloseCheck"]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(48, 0)
|
||||
collision_mask = 0
|
||||
|
||||
[node name="PlayerDistantCheck" type="Node2D" parent="."]
|
||||
position = Vector2(0, 9)
|
||||
|
||||
[node name="LeftPlayerDistantRay" type="RayCast2D" parent="PlayerDistantCheck"]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(-320, 0)
|
||||
collision_mask = 0
|
||||
|
||||
[node name="RightPlayerDistantRay" type="RayCast2D" parent="PlayerDistantCheck"]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(320, 0)
|
||||
collision_mask = 0
|
||||
|
||||
[node name="PlayerTouchArea" type="Area2D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerTouchArea"]
|
||||
position = Vector2(0, 2)
|
||||
shape = SubResource("RectangleShape2D_vecdo")
|
||||
|
||||
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]
|
||||
[connection signal="animation_looped" from="AnimatedSprite2D" to="." method="_on_animation_looped"]
|
||||
[connection signal="body_entered" from="PlayerTouchArea" to="." method="_on_player_touch_area_entered"]
|
||||
@@ -1,2 +0,0 @@
|
||||
class_name BlackEnemy
|
||||
extends AbstractColorEnemy
|
||||
@@ -1,39 +0,0 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cutjutvd8dqqc"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://d37eyum03h83i" path="res://game/characters/abstract_color_enemy.tscn" id="1_gj2ks"]
|
||||
[ext_resource type="Script" uid="uid://c2knsjcp6faf6" path="res://game/characters/black_enemy.gd" id="2_332ds"]
|
||||
[ext_resource type="Material" uid="uid://dggr8t4b30e3n" path="res://game/materials/enemy_black.tres" id="3_3jy5n"]
|
||||
|
||||
[node name="BlackEnemy" instance=ExtResource("1_gj2ks")]
|
||||
collision_layer = 4
|
||||
collision_mask = 3
|
||||
script = ExtResource("2_332ds")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." index="0"]
|
||||
material = ExtResource("3_3jy5n")
|
||||
|
||||
[node name="CollisionSwitcher" parent="." index="2"]
|
||||
initial_state = 0
|
||||
|
||||
[node name="LeftWallRay" parent="WallCheck" index="0"]
|
||||
collision_mask = 3
|
||||
|
||||
[node name="RightWallRay" parent="WallCheck" index="1"]
|
||||
collision_mask = 3
|
||||
|
||||
[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" index="0"]
|
||||
target_position = Vector2(-32, 0)
|
||||
collision_mask = 11
|
||||
|
||||
[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" index="1"]
|
||||
target_position = Vector2(32, 0)
|
||||
collision_mask = 11
|
||||
|
||||
[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" index="0"]
|
||||
collision_mask = 11
|
||||
|
||||
[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" index="1"]
|
||||
collision_mask = 11
|
||||
|
||||
[node name="PlayerTouchArea" parent="." index="7"]
|
||||
collision_mask = 8
|
||||
+3
-2
@@ -1,9 +1,10 @@
|
||||
class_name AbstractColorEnemy
|
||||
extends AbstractEnemy
|
||||
class_name AbstractColorCultist
|
||||
extends AbstractCultist
|
||||
|
||||
|
||||
@onready var collision_switcher : CollisionSwitcher = $CollisionSwitcher
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
collision_switcher.material = sprite.material
|
||||
@@ -0,0 +1,17 @@
|
||||
[gd_scene format=3 uid="uid://d37eyum03h83i"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bx0luh4vdob3q" path="res://game/characters/enemies/abstract_cultist.tscn" id="1_12hr0"]
|
||||
[ext_resource type="Script" uid="uid://das7ujanefsn0" path="res://game/characters/enemies/abstract_color_cultist.gd" id="2_rd56i"]
|
||||
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="3_e5cea"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_c7l74"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[node name="AbstractColorCultist" unique_id=644641841 instance=ExtResource("1_12hr0")]
|
||||
script = ExtResource("2_rd56i")
|
||||
|
||||
[node name="CultistSprite" parent="." index="0" unique_id=797412888]
|
||||
texture = SubResource("ViewportTexture_c7l74")
|
||||
|
||||
[node name="CollisionSwitcher" parent="." index="2" unique_id=991274552 node_paths=PackedStringArray("object") instance=ExtResource("3_e5cea")]
|
||||
object = NodePath("..")
|
||||
@@ -0,0 +1,71 @@
|
||||
class_name AbstractCultist
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
const MAX_WALK_SPEED = 85
|
||||
const MAX_CHASE_SPEED = 170
|
||||
const ACCELERATION = 600.0
|
||||
const JUMP_VELOCITY = 222.0
|
||||
const JUMP_GRAVITY_FACTOR = 1.0
|
||||
const FALL_GRAVITY_FACTOR = 1.5
|
||||
|
||||
|
||||
var target_x := 0.0
|
||||
|
||||
|
||||
@onready var sprite : Sprite2D = $CultistSprite
|
||||
@onready var water_splash : GPUParticles2D = $WaterSplash
|
||||
@onready var animated_sprite : AnimatedSprite2D = $SubViewport/CultistSprite
|
||||
|
||||
@onready var left_wall_high_ray : RayCast2D = $WallCheckHigh/LeftWallRay
|
||||
@onready var right_wall_high_ray : RayCast2D = $WallCheckHigh/RightWallRay
|
||||
|
||||
@onready var left_wall_low_ray : RayCast2D = $WallCheckLow/LeftWallRay
|
||||
@onready var right_wall_low_ray : RayCast2D = $WallCheckLow/RightWallRay
|
||||
|
||||
@onready var left_player_close_ray : RayCast2D = $%LeftPlayerCloseRay
|
||||
@onready var right_player_close_ray : RayCast2D = $%RightPlayerCloseRay
|
||||
|
||||
@onready var left_player_distant_ray : RayCast2D = $%LeftPlayerDistantRay
|
||||
@onready var right_player_distant_ray : RayCast2D = $%RightPlayerDistantRay
|
||||
|
||||
@onready var state_machine : CultistStateMachine = $CultistStateMachine
|
||||
@onready var chase_left_state : CultistState = $CultistStateMachine/ChaseLeftState
|
||||
@onready var chase_right_state : CultistState = $CultistStateMachine/ChaseRightState
|
||||
@onready var look_around_state : CultistState = $CultistStateMachine/LookAroundState
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_set_ray_cast_enable(left_player_close_ray, false)
|
||||
_set_ray_cast_enable(right_player_close_ray, false)
|
||||
_set_ray_cast_enable(left_player_distant_ray, false)
|
||||
_set_ray_cast_enable(right_player_distant_ray, false)
|
||||
|
||||
state_machine.init()
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
state_machine.physics_process(delta)
|
||||
move_and_slide()
|
||||
|
||||
|
||||
func kill(type := KillingArea.Type.None) -> void:
|
||||
match type:
|
||||
KillingArea.Type.Water:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_splash, global_position)
|
||||
water_splash.finished.connect(queue_free)
|
||||
water_splash.restart()
|
||||
_:
|
||||
queue_free()
|
||||
|
||||
|
||||
func update_x_velocity(direction: int, max_speed: float, delta: float) -> void:
|
||||
velocity.x = move_toward(velocity.x, direction * max_speed, ACCELERATION * delta)
|
||||
|
||||
|
||||
func get_gravity_factor() -> float:
|
||||
return JUMP_GRAVITY_FACTOR if velocity.y < 0.0 else FALL_GRAVITY_FACTOR
|
||||
|
||||
|
||||
func _set_ray_cast_enable(ray_cast: RayCast2D, enabled: bool) -> void:
|
||||
ray_cast.process_mode = Node.PROCESS_MODE_INHERIT if enabled else Node.PROCESS_MODE_DISABLED
|
||||
@@ -0,0 +1,171 @@
|
||||
[gd_scene format=3 uid="uid://bx0luh4vdob3q"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://but5aeh7y1s0f" path="res://game/characters/enemies/abstract_cultist.gd" id="1_2wrno"]
|
||||
[ext_resource type="PackedScene" uid="uid://dtxiercm8dsfm" path="res://game/characters/enemies/cultist_sprite.tscn" id="2_tjvyk"]
|
||||
[ext_resource type="PackedScene" uid="uid://8yd8f5x1hujv" path="res://game/characters/water_splash.tscn" id="2_w1t0g"]
|
||||
[ext_resource type="PackedScene" uid="uid://dike8xgbqdut2" path="res://game/killing_area.tscn" id="3_tjvyk"]
|
||||
[ext_resource type="PackedScene" uid="uid://bg7k6ovbk1xgm" path="res://game/characters/enemies/state_machine/cultist_state_machine.tscn" id="4_yu28k"]
|
||||
[ext_resource type="PackedScene" uid="uid://bq1v55jv4c6qe" path="res://game/characters/enemies/state_machine/cultist_state.tscn" id="5_tu2pi"]
|
||||
[ext_resource type="Script" uid="uid://bqnq6m0s4etqh" path="res://game/characters/enemies/state_machine/fall_state.gd" id="7_7tkj8"]
|
||||
[ext_resource type="Script" uid="uid://b8o0lvuy6a5q1" path="res://game/characters/enemies/state_machine/fall_left_state.gd" id="8_2opx4"]
|
||||
[ext_resource type="Script" uid="uid://cxg54u14yb6go" path="res://game/characters/enemies/state_machine/fall_right_state.gd" id="9_lu83c"]
|
||||
[ext_resource type="Script" uid="uid://bfp8gywqqkju7" path="res://game/characters/enemies/state_machine/look_around_state.gd" id="10_lu83c"]
|
||||
[ext_resource type="Script" uid="uid://hgn4yll571hp" path="res://game/characters/enemies/state_machine/walk_left_state.gd" id="11_lh753"]
|
||||
[ext_resource type="Script" uid="uid://bwwhmjxhg2adp" path="res://game/characters/enemies/state_machine/walk_right_state.gd" id="12_lh753"]
|
||||
[ext_resource type="Script" uid="uid://cn2lfl4kuxvjk" path="res://game/characters/enemies/state_machine/chase_left_state.gd" id="13_42ivi"]
|
||||
[ext_resource type="Script" uid="uid://cqlym4lqahsd3" path="res://game/characters/enemies/state_machine/cultist_jump_left_state.gd" id="14_42ivi"]
|
||||
[ext_resource type="Script" uid="uid://3kl84tu1vwiv" path="res://game/characters/enemies/state_machine/chase_right_state.gd" id="14_cqp7f"]
|
||||
[ext_resource type="Script" uid="uid://cf52bjcpasft1" path="res://game/characters/enemies/state_machine/cultist_jump_right_state.gd" id="15_cqp7f"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_cqp7f"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_mocsw"]
|
||||
radius = 4.0
|
||||
height = 28.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_tjvyk"]
|
||||
radius = 4.0
|
||||
height = 28.0
|
||||
|
||||
[node name="AbstractCultist" type="CharacterBody2D" unique_id=1676614852]
|
||||
collision_layer = 0
|
||||
script = ExtResource("1_2wrno")
|
||||
|
||||
[node name="WaterSplash" parent="." unique_id=658940825 instance=ExtResource("2_w1t0g")]
|
||||
position = Vector2(0, -14)
|
||||
|
||||
[node name="CultistSprite" type="Sprite2D" parent="." unique_id=797412888]
|
||||
texture = SubResource("ViewportTexture_cqp7f")
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="." unique_id=903152885]
|
||||
transparent_bg = true
|
||||
canvas_item_default_texture_filter = 0
|
||||
size = Vector2i(32, 32)
|
||||
|
||||
[node name="CultistSprite" parent="SubViewport" unique_id=1997264413 instance=ExtResource("2_tjvyk")]
|
||||
material = null
|
||||
position = Vector2(16, 16)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=185651284]
|
||||
position = Vector2(0, 2)
|
||||
shape = SubResource("CapsuleShape2D_mocsw")
|
||||
|
||||
[node name="WallCheckHigh" type="Node2D" parent="." unique_id=1697845810]
|
||||
position = Vector2(0, -8)
|
||||
|
||||
[node name="LeftWallRay" type="RayCast2D" parent="WallCheckHigh" unique_id=1026693538]
|
||||
target_position = Vector2(-16, 0)
|
||||
|
||||
[node name="RightWallRay" type="RayCast2D" parent="WallCheckHigh" unique_id=1129233918]
|
||||
target_position = Vector2(16, 0)
|
||||
|
||||
[node name="WallCheckLow" type="Node2D" parent="." unique_id=782156094]
|
||||
position = Vector2(0, 9)
|
||||
|
||||
[node name="LeftWallRay" type="RayCast2D" parent="WallCheckLow" unique_id=521416854]
|
||||
target_position = Vector2(-16, 0)
|
||||
|
||||
[node name="RightWallRay" type="RayCast2D" parent="WallCheckLow" unique_id=1457669135]
|
||||
target_position = Vector2(16, 0)
|
||||
|
||||
[node name="PlayerCloseCheck" type="Node2D" parent="." unique_id=1593775088]
|
||||
position = Vector2(0, -8)
|
||||
|
||||
[node name="LeftPlayerCloseRay" type="RayCast2D" parent="PlayerCloseCheck" unique_id=947570027]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(-48, 0)
|
||||
collision_mask = 0
|
||||
|
||||
[node name="RightPlayerCloseRay" type="RayCast2D" parent="PlayerCloseCheck" unique_id=1559118218]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(48, 0)
|
||||
collision_mask = 0
|
||||
|
||||
[node name="PlayerDistantCheck" type="Node2D" parent="." unique_id=1597489123]
|
||||
position = Vector2(0, -8)
|
||||
|
||||
[node name="LeftPlayerDistantRay" type="RayCast2D" parent="PlayerDistantCheck" unique_id=1491085518]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(-320, 0)
|
||||
collision_mask = 0
|
||||
|
||||
[node name="RightPlayerDistantRay" type="RayCast2D" parent="PlayerDistantCheck" unique_id=1377654831]
|
||||
unique_name_in_owner = true
|
||||
target_position = Vector2(320, 0)
|
||||
collision_mask = 0
|
||||
|
||||
[node name="KillingArea" parent="." unique_id=1891922549 instance=ExtResource("3_tjvyk")]
|
||||
collision_mask = 0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="KillingArea" unique_id=1710758452]
|
||||
position = Vector2(0, 2)
|
||||
shape = SubResource("CapsuleShape2D_tjvyk")
|
||||
|
||||
[node name="CultistStateMachine" parent="." unique_id=633169960 node_paths=PackedStringArray("cultist", "initial_state") instance=ExtResource("4_yu28k")]
|
||||
cultist = NodePath("..")
|
||||
initial_state = NodePath("WalkLeftState")
|
||||
|
||||
[node name="FallState" parent="CultistStateMachine" unique_id=1764777802 node_paths=PackedStringArray("look_around_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("7_7tkj8")
|
||||
look_around_state = NodePath("../LookAroundState")
|
||||
cultist = NodePath("../..")
|
||||
|
||||
[node name="FallLeftState" parent="CultistStateMachine" unique_id=1011952297 node_paths=PackedStringArray("fall_state", "look_around_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("8_2opx4")
|
||||
fall_state = NodePath("../FallState")
|
||||
look_around_state = NodePath("../LookAroundState")
|
||||
cultist = NodePath("../..")
|
||||
|
||||
[node name="FallRightState" parent="CultistStateMachine" unique_id=1932915544 node_paths=PackedStringArray("fall_state", "look_around_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("9_lu83c")
|
||||
fall_state = NodePath("../FallState")
|
||||
look_around_state = NodePath("../LookAroundState")
|
||||
cultist = NodePath("../..")
|
||||
|
||||
[node name="LookAroundState" parent="CultistStateMachine" unique_id=2025927882 node_paths=PackedStringArray("fall_state", "walk_left_state", "walk_right_state", "chase_left_state", "chase_right_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("10_lu83c")
|
||||
fall_state = NodePath("../FallState")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
chase_left_state = NodePath("../ChaseLeftState")
|
||||
chase_right_state = NodePath("../ChaseRightState")
|
||||
cultist = NodePath("../..")
|
||||
|
||||
[node name="WalkLeftState" parent="CultistStateMachine" unique_id=276543931 node_paths=PackedStringArray("chase_state", "another_direction_walk_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("11_lh753")
|
||||
chase_state = NodePath("../ChaseLeftState")
|
||||
another_direction_walk_state = NodePath("../WalkRightState")
|
||||
fall_state = NodePath("../FallLeftState")
|
||||
cultist = NodePath("../..")
|
||||
|
||||
[node name="WalkRightState" parent="CultistStateMachine" unique_id=1671686910 node_paths=PackedStringArray("chase_state", "another_direction_walk_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("12_lh753")
|
||||
chase_state = NodePath("../ChaseRightState")
|
||||
another_direction_walk_state = NodePath("../WalkLeftState")
|
||||
fall_state = NodePath("../FallRightState")
|
||||
cultist = NodePath("../..")
|
||||
|
||||
[node name="ChaseLeftState" parent="CultistStateMachine" unique_id=209480830 node_paths=PackedStringArray("look_around_state", "jump_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("13_42ivi")
|
||||
look_around_state = NodePath("../LookAroundState")
|
||||
jump_state = NodePath("../JumpLeftState")
|
||||
fall_state = NodePath("../FallState")
|
||||
cultist = NodePath("../..")
|
||||
|
||||
[node name="ChaseRightState" parent="CultistStateMachine" unique_id=383038915 node_paths=PackedStringArray("look_around_state", "jump_state", "fall_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("14_cqp7f")
|
||||
look_around_state = NodePath("../LookAroundState")
|
||||
jump_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath("../FallState")
|
||||
cultist = NodePath("../..")
|
||||
|
||||
[node name="JumpLeftState" parent="CultistStateMachine" unique_id=739226464 node_paths=PackedStringArray("chase_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("14_42ivi")
|
||||
chase_state = NodePath("../ChaseLeftState")
|
||||
cultist = NodePath("../..")
|
||||
|
||||
[node name="JumpRightState" parent="CultistStateMachine" unique_id=756126836 node_paths=PackedStringArray("chase_state", "cultist") instance=ExtResource("5_tu2pi")]
|
||||
script = ExtResource("15_cqp7f")
|
||||
chase_state = NodePath("../ChaseRightState")
|
||||
cultist = NodePath("../..")
|
||||
@@ -0,0 +1,2 @@
|
||||
class_name BlackCultist
|
||||
extends AbstractColorCultist
|
||||
@@ -0,0 +1,43 @@
|
||||
[gd_scene format=3 uid="uid://cutjutvd8dqqc"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://d37eyum03h83i" path="res://game/characters/enemies/abstract_color_cultist.tscn" id="1_gj2ks"]
|
||||
[ext_resource type="Script" uid="uid://c2knsjcp6faf6" path="res://game/characters/enemies/black_cultist.gd" id="2_332ds"]
|
||||
[ext_resource type="Material" uid="uid://dggr8t4b30e3n" path="res://game/materials/enemy_black.tres" id="3_v1if5"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_q6bby"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[node name="BlackCultist" unique_id=1910124567 instance=ExtResource("1_gj2ks")]
|
||||
collision_layer = 4
|
||||
collision_mask = 3
|
||||
script = ExtResource("2_332ds")
|
||||
|
||||
[node name="CultistSprite" parent="." index="0" unique_id=797412888]
|
||||
material = ExtResource("3_v1if5")
|
||||
texture = SubResource("ViewportTexture_q6bby")
|
||||
|
||||
[node name="CollisionSwitcher" parent="." index="2" unique_id=991274552]
|
||||
initial_state = 0
|
||||
|
||||
[node name="LeftWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="0" unique_id=521416854]
|
||||
collision_mask = 3
|
||||
|
||||
[node name="RightWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="1" unique_id=1457669135]
|
||||
collision_mask = 3
|
||||
|
||||
[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="0" unique_id=947570027]
|
||||
target_position = Vector2(-32, 0)
|
||||
collision_mask = 11
|
||||
|
||||
[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="1" unique_id=1559118218]
|
||||
target_position = Vector2(32, 0)
|
||||
collision_mask = 11
|
||||
|
||||
[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="0" unique_id=1491085518]
|
||||
collision_mask = 11
|
||||
|
||||
[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="1" unique_id=1377654831]
|
||||
collision_mask = 11
|
||||
|
||||
[node name="KillingArea" parent="." index="8" unique_id=1891922549]
|
||||
collision_mask = 8
|
||||
@@ -0,0 +1,23 @@
|
||||
class_name CultistSprite
|
||||
extends AnimatedSprite2D
|
||||
|
||||
|
||||
const ANIMATION_FALL = "fall"
|
||||
const ANIMATION_FALL_LEFT = "fall_left"
|
||||
const ANIMATION_FALL_RIGHT = "fall_right"
|
||||
const ANIMATION_JUMP = "jump"
|
||||
const ANIMATION_JUMP_LEFT = "jump_left"
|
||||
const ANIMATION_JUMP_RIGHT = "jump_right"
|
||||
const ANIMATION_IDLE = "idle"
|
||||
const ANIMATION_LOOK_AROUND = "look_around"
|
||||
const ANIMATION_LOOK_AROUND_1 = "look_around_1"
|
||||
const ANIMATION_LOOK_AROUND_2 = "look_around_2"
|
||||
const ANIMATION_WALK_LEFT = "walk_left"
|
||||
const ANIMATION_WALK_RIGHT = "walk_right"
|
||||
const ANIMATION_CHASE_LEFT = "chase_left"
|
||||
const ANIMATION_CHASE_RIGHT = "chase_right"
|
||||
|
||||
const LOOK_AROUND_ANIMATIONS : Array[String] = [
|
||||
ANIMATION_LOOK_AROUND_1,
|
||||
ANIMATION_LOOK_AROUND_2,
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
uid://dkxmwkjttbf2d
|
||||
@@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=47 format=3 uid="uid://dtxiercm8dsfm"]
|
||||
[gd_scene format=3 uid="uid://dtxiercm8dsfm"]
|
||||
|
||||
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="1_b6aoy"]
|
||||
[ext_resource type="Texture2D" uid="uid://drk8j57acajrq" path="res://images/characters/cultist.png" id="2_yjsd7"]
|
||||
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="1_ew6gn"]
|
||||
[ext_resource type="Texture2D" uid="uid://drk8j57acajrq" path="res://images/characters/cultist.png" id="2_g4n4l"]
|
||||
[ext_resource type="Script" uid="uid://dkxmwkjttbf2d" path="res://game/characters/enemies/cultist_sprite.gd" id="3_ef0vi"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_vecdo"]
|
||||
shader = ExtResource("1_b6aoy")
|
||||
shader = ExtResource("1_ew6gn")
|
||||
shader_parameter/black_color = Color(0, 0, 0, 1)
|
||||
shader_parameter/white_color = Color(1, 1, 1, 1)
|
||||
shader_parameter/switch_colors = false
|
||||
@@ -14,173 +15,141 @@ shader_parameter/intensity = 1.0
|
||||
shader_parameter/scale = 20.0
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_l58xb"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(0, 64, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_jrclg"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(32, 64, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wwwee"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(64, 64, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_law7y"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(96, 64, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hme24"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(128, 64, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qawtf"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(160, 64, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_srxh4"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(192, 64, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_x6npu"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(224, 64, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xavx3"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(0, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_8t4m8"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(32, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_3seah"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(64, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_koyeg"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(96, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_uw3v1"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(128, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_265lf"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(160, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_tav7c"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(192, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0xs27"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(224, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_tjvyk"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(128, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_vecdo"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(64, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qly8p"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(0, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_klrad"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(160, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_rjy0i"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(96, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ps2ar"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(32, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ijx3p"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_nm8xp"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(32, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_mocsw"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(128, 0, 32, 32)
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_klrad"]
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(160, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_y256a"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(160, 0, 32, 32)
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_rjy0i"]
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(96, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ps2ar"]
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(32, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_yjsd7"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(64, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_b6aoy"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_voddl"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(96, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_soo8x"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_vbirv"]
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_8wpvf"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(64, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_vbirv"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ntvg2"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(96, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ssc8d"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(96, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hrljr"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ssc8d"]
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(96, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ng7ok"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
atlas = ExtResource("2_g4n4l")
|
||||
region = Rect2(64, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_8s45y"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(192, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qbqct"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(128, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ga5mk"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(224, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_yu2nn"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(224, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_g4v8m"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(128, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_20lqo"]
|
||||
atlas = ExtResource("2_yjsd7")
|
||||
region = Rect2(192, 0, 32, 32)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_2wrno"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
@@ -246,7 +215,7 @@ animations = [{
|
||||
"texture": SubResource("AtlasTexture_tjvyk")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_down",
|
||||
"name": &"fall",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
@@ -254,7 +223,7 @@ animations = [{
|
||||
"texture": SubResource("AtlasTexture_vecdo")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_down_left",
|
||||
"name": &"fall_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
@@ -262,31 +231,7 @@ animations = [{
|
||||
"texture": SubResource("AtlasTexture_qly8p")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_down_right",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 5.0,
|
||||
"texture": SubResource("AtlasTexture_klrad")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_up",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 5.0,
|
||||
"texture": SubResource("AtlasTexture_rjy0i")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_up_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 5.0,
|
||||
"texture": SubResource("AtlasTexture_ps2ar")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_up_right",
|
||||
"name": &"fall_right",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
@@ -300,21 +245,31 @@ animations = [{
|
||||
"texture": SubResource("AtlasTexture_ijx3p")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"idle_front",
|
||||
"name": &"idle",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 4.0,
|
||||
"texture": SubResource("AtlasTexture_mocsw")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_y256a")
|
||||
}, {
|
||||
"duration": 5.0,
|
||||
"texture": SubResource("AtlasTexture_mocsw")
|
||||
"texture": SubResource("AtlasTexture_klrad")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"idle_rear",
|
||||
"name": &"jump",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 5.0,
|
||||
"texture": SubResource("AtlasTexture_rjy0i")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"jump_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 5.0,
|
||||
"texture": SubResource("AtlasTexture_ps2ar")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"jump_right",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
@@ -336,6 +291,9 @@ animations = [{
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_vbirv")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_8wpvf")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
@@ -343,13 +301,19 @@ animations = [{
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ntvg2")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_vbirv")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"look_around_front_1",
|
||||
"name": &"look_around_1",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_hrljr")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ssc8d")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
@@ -357,37 +321,12 @@ animations = [{
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ng7ok")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_hrljr")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"look_around_front_2",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_8s45y")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_qbqct")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ga5mk")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"look_around_rear_1",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_yu2nn")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_g4v8m")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_20lqo")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"look_around_rear_2",
|
||||
"name": &"look_around_2",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
@@ -449,7 +388,8 @@ animations = [{
|
||||
"speed": 10.0
|
||||
}]
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D"]
|
||||
[node name="CultistSprite" type="AnimatedSprite2D" unique_id=351120861]
|
||||
material = SubResource("ShaderMaterial_vecdo")
|
||||
sprite_frames = SubResource("SpriteFrames_2wrno")
|
||||
animation = &"look_around"
|
||||
animation = &"idle"
|
||||
script = ExtResource("3_ef0vi")
|
||||
@@ -0,0 +1,2 @@
|
||||
class_name GrayCultist
|
||||
extends AbstractCultist
|
||||
@@ -0,0 +1,38 @@
|
||||
[gd_scene format=3 uid="uid://cb0w6mt8g4mer"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bx0luh4vdob3q" path="res://game/characters/enemies/abstract_cultist.tscn" id="1_q3s46"]
|
||||
[ext_resource type="Script" uid="uid://cern5veiqkrkc" path="res://game/characters/enemies/gray_cultist.gd" id="2_olede"]
|
||||
[ext_resource type="Material" uid="uid://dbkn3k0batj5w" path="res://game/materials/enemy_gray.tres" id="3_ho47d"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_b3gyl"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[node name="GrayCultist" unique_id=139812221 instance=ExtResource("1_q3s46")]
|
||||
collision_layer = 16
|
||||
collision_mask = 35
|
||||
script = ExtResource("2_olede")
|
||||
|
||||
[node name="CultistSprite" parent="." index="0" unique_id=797412888]
|
||||
material = ExtResource("3_ho47d")
|
||||
texture = SubResource("ViewportTexture_b3gyl")
|
||||
|
||||
[node name="LeftWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="0" unique_id=521416854]
|
||||
collision_mask = 35
|
||||
|
||||
[node name="RightWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="1" unique_id=1457669135]
|
||||
collision_mask = 35
|
||||
|
||||
[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="0" unique_id=947570027]
|
||||
collision_mask = 171
|
||||
|
||||
[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="1" unique_id=1559118218]
|
||||
collision_mask = 171
|
||||
|
||||
[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="0" unique_id=1491085518]
|
||||
collision_mask = 171
|
||||
|
||||
[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="1" unique_id=1377654831]
|
||||
collision_mask = 171
|
||||
|
||||
[node name="KillingArea" parent="." index="7" unique_id=1891922549]
|
||||
collision_mask = 136
|
||||
@@ -0,0 +1,16 @@
|
||||
extends CultistChaseState
|
||||
|
||||
|
||||
func init() -> void:
|
||||
_direction = DIRECTION_LEFT
|
||||
_wall_high_ray_cast = cultist.left_wall_high_ray
|
||||
_wall_low_ray_cast = cultist.left_wall_low_ray
|
||||
_player_ray_cast = cultist.left_player_distant_ray
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist.animated_sprite.play(CultistSprite.ANIMATION_CHASE_LEFT)
|
||||
|
||||
|
||||
func _is_target_reached() -> bool:
|
||||
return cultist.position.x <= cultist.target_x
|
||||
@@ -0,0 +1 @@
|
||||
uid://cn2lfl4kuxvjk
|
||||
@@ -0,0 +1,16 @@
|
||||
extends CultistChaseState
|
||||
|
||||
|
||||
func init() -> void:
|
||||
_direction = DIRECTION_RIGHT
|
||||
_wall_high_ray_cast = cultist.right_wall_high_ray
|
||||
_wall_low_ray_cast = cultist.right_wall_low_ray
|
||||
_player_ray_cast = cultist.right_player_distant_ray
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist.animated_sprite.play(CultistSprite.ANIMATION_CHASE_RIGHT)
|
||||
|
||||
|
||||
func _is_target_reached() -> bool:
|
||||
return cultist.position.x >= cultist.target_x
|
||||
@@ -0,0 +1 @@
|
||||
uid://3kl84tu1vwiv
|
||||
@@ -0,0 +1,29 @@
|
||||
@abstract
|
||||
class_name CultistChaseState
|
||||
extends CultistMoveState
|
||||
|
||||
|
||||
@export var look_around_state: CultistState
|
||||
@export var jump_state: CultistState
|
||||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
if not cultist.is_on_floor():
|
||||
switch_state.emit(fall_state)
|
||||
else:
|
||||
var player := _get_colliding_player(_player_ray_cast)
|
||||
if player != null:
|
||||
cultist.target_x = player.position.x
|
||||
|
||||
if _is_target_reached() or _wall_high_ray_cast.is_colliding():
|
||||
var stream := SoundManager.sfx_stream_player_lost
|
||||
SoundManager.play_sfx_stream(stream, cultist.global_position)
|
||||
switch_state.emit(look_around_state)
|
||||
elif _wall_low_ray_cast.is_colliding():
|
||||
switch_state.emit(jump_state)
|
||||
else:
|
||||
cultist.update_x_velocity(_direction, cultist.MAX_CHASE_SPEED, delta)
|
||||
|
||||
|
||||
@abstract
|
||||
func _is_target_reached() -> bool
|
||||
@@ -0,0 +1 @@
|
||||
uid://beu06w0gntfay
|
||||
@@ -0,0 +1,7 @@
|
||||
extends CultistJumpState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
super.enter()
|
||||
_direction = DIRECTION_LEFT
|
||||
cultist.animated_sprite.play(CultistSprite.ANIMATION_JUMP_LEFT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cqlym4lqahsd3
|
||||
@@ -0,0 +1,7 @@
|
||||
extends CultistJumpState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
super.enter()
|
||||
_direction = DIRECTION_RIGHT
|
||||
cultist.animated_sprite.play(CultistSprite.ANIMATION_JUMP_RIGHT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cf52bjcpasft1
|
||||
@@ -0,0 +1,19 @@
|
||||
class_name CultistState
|
||||
extends AbstractState
|
||||
|
||||
|
||||
const DIRECTION_LEFT = -1
|
||||
const DIRECTION_RIGHT = 1
|
||||
|
||||
|
||||
@export var cultist: AbstractCultist
|
||||
|
||||
|
||||
func _get_colliding_player(ray_cast: RayCast2D) -> Player:
|
||||
ray_cast.force_raycast_update()
|
||||
|
||||
if ray_cast.is_colliding():
|
||||
var collider := ray_cast.get_collider()
|
||||
if collider is Player:
|
||||
return collider
|
||||
return null
|
||||
@@ -0,0 +1 @@
|
||||
uid://c2et1lt2xgk45
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://bq1v55jv4c6qe"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://c7adrbfobmvl8" path="res://game/state_machine/abstract_state.tscn" id="1_qehp8"]
|
||||
[ext_resource type="Script" uid="uid://c2et1lt2xgk45" path="res://game/characters/enemies/state_machine/cultist_state.gd" id="2_3mu4s"]
|
||||
|
||||
[node name="CultistState" unique_id=739226464 instance=ExtResource("1_qehp8")]
|
||||
script = ExtResource("2_3mu4s")
|
||||
@@ -0,0 +1,5 @@
|
||||
class_name CultistStateMachine
|
||||
extends StateMachine
|
||||
|
||||
|
||||
@export var cultist: AbstractCultist
|
||||
@@ -0,0 +1 @@
|
||||
uid://dhaq52d5t5eq0
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://bg7k6ovbk1xgm"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://3ll3i1fgktg2" path="res://game/state_machine/state_machine.tscn" id="1_xnlud"]
|
||||
[ext_resource type="Script" uid="uid://dhaq52d5t5eq0" path="res://game/characters/enemies/state_machine/cultist_state_machine.gd" id="2_avauf"]
|
||||
|
||||
[node name="CultistStateMachine" unique_id=633169960 instance=ExtResource("1_xnlud")]
|
||||
script = ExtResource("2_avauf")
|
||||
@@ -0,0 +1,5 @@
|
||||
extends CultistFallSidewaysState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist.animated_sprite.play(CultistSprite.ANIMATION_FALL_LEFT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://b8o0lvuy6a5q1
|
||||
@@ -0,0 +1,5 @@
|
||||
extends CultistFallSidewaysState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist.animated_sprite.play(CultistSprite.ANIMATION_FALL_RIGHT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cxg54u14yb6go
|
||||
@@ -0,0 +1,11 @@
|
||||
class_name CultistFallSidewaysState
|
||||
extends CultistFallState
|
||||
|
||||
|
||||
@export var fall_state: CultistState
|
||||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
var is_on_floor := _move_down_and_check_floor(delta)
|
||||
if not is_on_floor and is_zero_approx(cultist.velocity.x):
|
||||
switch_state.emit(fall_state)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dknrtf0f5wgnr
|
||||
@@ -0,0 +1,22 @@
|
||||
class_name CultistFallState
|
||||
extends CultistState
|
||||
|
||||
|
||||
@export var look_around_state: CultistState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist.animated_sprite.play(CultistSprite.ANIMATION_FALL)
|
||||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
_move_down_and_check_floor(delta)
|
||||
|
||||
|
||||
func _move_down_and_check_floor(delta: float) -> bool:
|
||||
cultist.velocity += cultist.get_gravity() * delta
|
||||
cultist.move_and_slide()
|
||||
if cultist.is_on_floor():
|
||||
switch_state.emit(look_around_state)
|
||||
return true
|
||||
return false
|
||||
@@ -0,0 +1 @@
|
||||
uid://bqnq6m0s4etqh
|
||||
@@ -0,0 +1,21 @@
|
||||
@abstract
|
||||
class_name CultistJumpState
|
||||
extends CultistState
|
||||
|
||||
|
||||
@export var chase_state: CultistState
|
||||
|
||||
|
||||
var _direction := 0
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist.velocity.y -= cultist.JUMP_VELOCITY
|
||||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
if cultist.is_on_floor():
|
||||
switch_state.emit(chase_state)
|
||||
else:
|
||||
cultist.velocity += cultist.get_gravity() * cultist.get_gravity_factor() * delta
|
||||
cultist.update_x_velocity(_direction, cultist.MAX_WALK_SPEED, delta)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cxvl7a8o7bc1p
|
||||
@@ -0,0 +1,45 @@
|
||||
extends CultistState
|
||||
|
||||
|
||||
@export var fall_state: CultistState
|
||||
@export var walk_left_state: CultistState
|
||||
@export var walk_right_state: CultistState
|
||||
@export var chase_left_state: CultistState
|
||||
@export var chase_right_state: CultistState
|
||||
|
||||
|
||||
var state_by_ray_cast : Dictionary[RayCast2D, CultistState]
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist.animated_sprite.animation_finished.connect(_on_animation_finished)
|
||||
cultist.animated_sprite.play(CultistSprite.LOOK_AROUND_ANIMATIONS.pick_random())
|
||||
cultist.velocity = Vector2.ZERO
|
||||
cultist._set_ray_cast_enable(cultist.left_player_close_ray, true)
|
||||
cultist._set_ray_cast_enable(cultist.right_player_close_ray, true)
|
||||
|
||||
state_by_ray_cast = {
|
||||
cultist.left_player_close_ray: chase_left_state,
|
||||
cultist.right_player_close_ray: chase_right_state,
|
||||
}
|
||||
|
||||
|
||||
func physics_process(_delta: float) -> void:
|
||||
if not cultist.is_on_floor():
|
||||
switch_state.emit(fall_state)
|
||||
else:
|
||||
for ray_cast in state_by_ray_cast:
|
||||
var player := _get_colliding_player(ray_cast)
|
||||
if player != null:
|
||||
switch_state.emit(state_by_ray_cast[ray_cast])
|
||||
break
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
cultist.animated_sprite.animation_finished.disconnect(_on_animation_finished)
|
||||
cultist._set_ray_cast_enable(cultist.left_player_close_ray, false)
|
||||
cultist._set_ray_cast_enable(cultist.right_player_close_ray, false)
|
||||
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
switch_state.emit([walk_left_state, walk_right_state].pick_random())
|
||||
@@ -0,0 +1 @@
|
||||
uid://bfp8gywqqkju7
|
||||
@@ -0,0 +1,23 @@
|
||||
@abstract
|
||||
class_name CultistMoveState
|
||||
extends CultistState
|
||||
|
||||
|
||||
@export var fall_state: CultistState
|
||||
|
||||
|
||||
@warning_ignore("unused_private_class_variable")
|
||||
var _direction := 0
|
||||
@warning_ignore("unused_private_class_variable")
|
||||
var _wall_high_ray_cast : RayCast2D
|
||||
@warning_ignore("unused_private_class_variable")
|
||||
var _wall_low_ray_cast : RayCast2D
|
||||
var _player_ray_cast : RayCast2D
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist._set_ray_cast_enable(_player_ray_cast, true)
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
cultist._set_ray_cast_enable(_player_ray_cast, false)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cw5hhiv8uih7d
|
||||
@@ -0,0 +1,12 @@
|
||||
extends CultistWalkState
|
||||
|
||||
|
||||
func init() -> void:
|
||||
_direction = DIRECTION_LEFT
|
||||
_wall_high_ray_cast = cultist.left_wall_high_ray
|
||||
_wall_low_ray_cast = cultist.left_wall_low_ray
|
||||
_player_ray_cast = cultist.left_player_distant_ray
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist.animated_sprite.play(CultistSprite.ANIMATION_WALK_LEFT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://hgn4yll571hp
|
||||
@@ -0,0 +1,12 @@
|
||||
extends CultistWalkState
|
||||
|
||||
|
||||
func init() -> void:
|
||||
_direction = DIRECTION_RIGHT
|
||||
_wall_high_ray_cast = cultist.right_wall_high_ray
|
||||
_wall_low_ray_cast = cultist.right_wall_low_ray
|
||||
_player_ray_cast = cultist.right_player_distant_ray
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
cultist.animated_sprite.play(CultistSprite.ANIMATION_WALK_RIGHT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bwwhmjxhg2adp
|
||||
@@ -0,0 +1,21 @@
|
||||
@abstract
|
||||
class_name CultistWalkState
|
||||
extends CultistMoveState
|
||||
|
||||
|
||||
@export var chase_state: CultistState
|
||||
@export var another_direction_walk_state: CultistState
|
||||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
if not cultist.is_on_floor():
|
||||
switch_state.emit(fall_state)
|
||||
else:
|
||||
var player := _get_colliding_player(_player_ray_cast)
|
||||
if player != null:
|
||||
switch_state.emit(chase_state)
|
||||
else:
|
||||
if _wall_low_ray_cast.is_colliding() or _wall_high_ray_cast.is_colliding():
|
||||
switch_state.emit(another_direction_walk_state)
|
||||
else:
|
||||
cultist.update_x_velocity(_direction, cultist.MAX_WALK_SPEED, delta)
|
||||
@@ -0,0 +1 @@
|
||||
uid://lplif1gcjbai
|
||||
@@ -0,0 +1,2 @@
|
||||
class_name WhiteCultist
|
||||
extends AbstractColorCultist
|
||||
@@ -0,0 +1,40 @@
|
||||
[gd_scene format=3 uid="uid://bv2gahb4wxgb1"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://d37eyum03h83i" path="res://game/characters/enemies/abstract_color_cultist.tscn" id="1_3yi7g"]
|
||||
[ext_resource type="Script" uid="uid://dmcpkytgiuedi" path="res://game/characters/enemies/white_cultist.gd" id="2_c7pdf"]
|
||||
[ext_resource type="Material" uid="uid://ci7xuso12af5" path="res://game/materials/enemy_white.tres" id="3_36f86"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_fb5t4"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[node name="WhiteEnemy" unique_id=486389199 instance=ExtResource("1_3yi7g")]
|
||||
collision_layer = 64
|
||||
collision_mask = 33
|
||||
script = ExtResource("2_c7pdf")
|
||||
|
||||
[node name="CultistSprite" parent="." index="0" unique_id=797412888]
|
||||
material = ExtResource("3_36f86")
|
||||
texture = SubResource("ViewportTexture_fb5t4")
|
||||
|
||||
[node name="LeftWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="0" unique_id=521416854]
|
||||
collision_mask = 33
|
||||
|
||||
[node name="RightWallRay" parent="WallCheckLow" parent_id_path=PackedInt32Array(782156094) index="1" unique_id=1457669135]
|
||||
collision_mask = 33
|
||||
|
||||
[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="0" unique_id=947570027]
|
||||
target_position = Vector2(-32, 0)
|
||||
collision_mask = 161
|
||||
|
||||
[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" parent_id_path=PackedInt32Array(1593775088) index="1" unique_id=1559118218]
|
||||
target_position = Vector2(32, 0)
|
||||
collision_mask = 161
|
||||
|
||||
[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="0" unique_id=1491085518]
|
||||
collision_mask = 161
|
||||
|
||||
[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" parent_id_path=PackedInt32Array(1597489123) index="1" unique_id=1377654831]
|
||||
collision_mask = 161
|
||||
|
||||
[node name="KillingArea" parent="." index="8" unique_id=1891922549]
|
||||
collision_mask = 128
|
||||
@@ -1,2 +0,0 @@
|
||||
class_name GrayEnemy
|
||||
extends AbstractEnemy
|
||||
@@ -1,34 +0,0 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cb0w6mt8g4mer"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bx0luh4vdob3q" path="res://game/characters/abstract_enemy.tscn" id="1_q3s46"]
|
||||
[ext_resource type="Script" uid="uid://cern5veiqkrkc" path="res://game/characters/gray_enemy.gd" id="2_olede"]
|
||||
[ext_resource type="Material" uid="uid://dbkn3k0batj5w" path="res://game/materials/enemy_gray.tres" id="3_ho47d"]
|
||||
|
||||
[node name="GrayEnemy" instance=ExtResource("1_q3s46")]
|
||||
collision_layer = 16
|
||||
collision_mask = 35
|
||||
script = ExtResource("2_olede")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." index="0"]
|
||||
material = ExtResource("3_ho47d")
|
||||
|
||||
[node name="LeftWallRay" parent="WallCheck" index="0"]
|
||||
collision_mask = 35
|
||||
|
||||
[node name="RightWallRay" parent="WallCheck" index="1"]
|
||||
collision_mask = 35
|
||||
|
||||
[node name="LeftPlayerCloseRay" parent="PlayerCloseCheck" index="0"]
|
||||
collision_mask = 171
|
||||
|
||||
[node name="RightPlayerCloseRay" parent="PlayerCloseCheck" index="1"]
|
||||
collision_mask = 171
|
||||
|
||||
[node name="LeftPlayerDistantRay" parent="PlayerDistantCheck" index="0"]
|
||||
collision_mask = 171
|
||||
|
||||
[node name="RightPlayerDistantRay" parent="PlayerDistantCheck" index="1"]
|
||||
collision_mask = 171
|
||||
|
||||
[node name="PlayerTouchArea" parent="." index="6"]
|
||||
collision_mask = 136
|
||||
@@ -1,187 +0,0 @@
|
||||
class_name Player
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
signal dead
|
||||
|
||||
|
||||
const ANIMATION_IDLE = "idle"
|
||||
const ANIMATION_LOOK_AROUND_1 = "look_around_1"
|
||||
const ANIMATION_LOOK_AROUND_2 = "look_around_2"
|
||||
const ANIMATION_WALK_LEFT = "walk_left"
|
||||
const ANIMATION_WALK_RIGHT = "walk_right"
|
||||
const ANIMATION_FALL_DOWN = "fall_down"
|
||||
const ANIMATION_FALL_DOWN_LEFT = "fall_down_left"
|
||||
const ANIMATION_FALL_DOWN_RIGHT = "fall_down_right"
|
||||
const ANIMATION_FALL_UP = "fall_up"
|
||||
const ANIMATION_FALL_UP_LEFT = "fall_up_left"
|
||||
const ANIMATION_FALL_UP_RIGHT = "fall_up_right"
|
||||
const ANIMATION_DEATH = "death"
|
||||
|
||||
const LOOK_AROUND_CHANCE = 25
|
||||
const PICKUP_OFFSET = 16.0
|
||||
|
||||
|
||||
@export_range(0.0, 1000.0) var max_speed := 160
|
||||
@export_range(0.0, 1000.0) var max_fall_speed := 640
|
||||
@export_range(0.0, 1000.0) var acceleration := 600.0
|
||||
@export_range(0.0, 1000.0) var jump_velocity := 320.0
|
||||
@export_range(0.0, 2.0) var jump_gravity_factor := 1.0
|
||||
@export_range(0.0, 2.0) var fall_gravity_factor := 1.5
|
||||
@export_range(0.0, 1.0) var passive_jump_factor := 0.5
|
||||
|
||||
|
||||
var _is_alive := true
|
||||
|
||||
|
||||
@onready var sprite : AnimatedSprite2D = $AnimatedSprite2D
|
||||
@onready var collision_switcher : CollisionSwitcher = $CollisionSwitcher
|
||||
@onready var pickups : Node2D = $Pickups
|
||||
@onready var jump_buffer_timer : Timer = $JumpBufferTimer
|
||||
@onready var coyote_time_timer : Timer = $CoyoteTimeTimer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
collision_switcher.material = sprite.material
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if is_on_floor():
|
||||
coyote_time_timer.start()
|
||||
if is_on_ceiling_only() and velocity.y < 0.0:
|
||||
velocity.y = 0.0
|
||||
|
||||
if not is_on_floor():
|
||||
var gravity_factor := jump_gravity_factor if velocity.y < 0.0 else fall_gravity_factor
|
||||
|
||||
if velocity.y < 0.0 and not Input.is_action_pressed("jump"):
|
||||
velocity.y *= passive_jump_factor
|
||||
|
||||
velocity += get_gravity() * gravity_factor * delta
|
||||
velocity.y = clampf(velocity.y, -max_fall_speed, max_fall_speed)
|
||||
|
||||
if not _is_alive:
|
||||
_slow_down(delta)
|
||||
else:
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
jump_buffer_timer.start()
|
||||
|
||||
if not coyote_time_timer.is_stopped() and not jump_buffer_timer.is_stopped():
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_jump, global_position)
|
||||
velocity.y = -jump_velocity
|
||||
jump_buffer_timer.stop()
|
||||
|
||||
var direction := Input.get_axis("move_left", "move_right")
|
||||
if direction:
|
||||
velocity.x = move_toward(velocity.x, direction * max_speed, acceleration * delta)
|
||||
else:
|
||||
_slow_down(delta)
|
||||
|
||||
_update_animation()
|
||||
|
||||
var was_collided := move_and_slide()
|
||||
if was_collided and _is_alive:
|
||||
for i in range(get_slide_collision_count()):
|
||||
var collision := get_slide_collision(i)
|
||||
if _is_killing_collider(collision.get_collider()) and _is_alive:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_death, global_position)
|
||||
_is_alive = false
|
||||
collision_mask = 1
|
||||
get_tree().paused = true
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
sprite.play(ANIMATION_DEATH)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("switch_color") and _is_alive:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_switch, global_position)
|
||||
collision_switcher.switch_color()
|
||||
|
||||
|
||||
func add_pickup(pickup: AbstractPickup) -> void:
|
||||
pickup.reparent.call_deferred(pickups)
|
||||
_rearrange_pickups.call_deferred()
|
||||
|
||||
|
||||
func remove_pickup(pickup: AbstractPickup) -> void:
|
||||
if pickup in pickups.get_children():
|
||||
pickups.remove_child(pickup)
|
||||
pickup.queue_free()
|
||||
_rearrange_pickups()
|
||||
|
||||
|
||||
func _slow_down(delta: float) -> void:
|
||||
velocity.x = move_toward(velocity.x, 0, acceleration * delta)
|
||||
|
||||
|
||||
func _is_killing_collider(collider: Object) -> bool:
|
||||
if not collider is Node: return false
|
||||
|
||||
var node := collider as Node
|
||||
return node.has_node("PlayerKiller")
|
||||
|
||||
|
||||
func _update_animation() -> void:
|
||||
var animation := _get_animation()
|
||||
if sprite.animation != animation:
|
||||
sprite.play(animation)
|
||||
|
||||
|
||||
func _get_animation() -> String:
|
||||
if is_on_floor():
|
||||
if velocity.x > 0:
|
||||
return ANIMATION_WALK_RIGHT
|
||||
elif velocity.x < 0:
|
||||
return ANIMATION_WALK_LEFT
|
||||
else:
|
||||
if is_zero_approx(velocity.x):
|
||||
if velocity.y > 0:
|
||||
return ANIMATION_FALL_DOWN
|
||||
else:
|
||||
return ANIMATION_FALL_UP
|
||||
if velocity.x > 0:
|
||||
if velocity.y > 0:
|
||||
return ANIMATION_FALL_DOWN_RIGHT
|
||||
else:
|
||||
return ANIMATION_FALL_UP_RIGHT
|
||||
elif velocity.x < 0:
|
||||
if velocity.y > 0:
|
||||
return ANIMATION_FALL_DOWN_LEFT
|
||||
else:
|
||||
return ANIMATION_FALL_UP_LEFT
|
||||
|
||||
if sprite.animation in [ANIMATION_LOOK_AROUND_1, ANIMATION_LOOK_AROUND_2]:
|
||||
return sprite.animation
|
||||
|
||||
return ANIMATION_IDLE
|
||||
|
||||
|
||||
func _rearrange_pickups() -> void:
|
||||
var children := pickups.get_children()
|
||||
var pickup_shift := (children.size() - 1) * PICKUP_OFFSET / 2.0
|
||||
|
||||
for i in range(children.size()):
|
||||
if not children[i] is Node2D: continue
|
||||
var node := children[i] as Node2D
|
||||
node.position.x = i * PICKUP_OFFSET - pickup_shift
|
||||
node.position.y = 0
|
||||
|
||||
|
||||
func _play_look_around_animation() -> void:
|
||||
sprite.play(ANIMATION_LOOK_AROUND_1 if randi_range(1, 2) == 1 else ANIMATION_LOOK_AROUND_2)
|
||||
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
match sprite.animation:
|
||||
ANIMATION_LOOK_AROUND_1, ANIMATION_LOOK_AROUND_2:
|
||||
sprite.play(ANIMATION_IDLE)
|
||||
ANIMATION_DEATH:
|
||||
dead.emit()
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_animation_looped() -> void:
|
||||
match sprite.animation:
|
||||
ANIMATION_IDLE:
|
||||
if randi_range(1, 100) <= LOOK_AROUND_CHANCE:
|
||||
_play_look_around_animation()
|
||||
@@ -1,40 +0,0 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://dtcad8tdx78tg"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bb8kc32sggrn2" path="res://game/characters/player.gd" id="1_xln5q"]
|
||||
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="2_j06tb"]
|
||||
[ext_resource type="PackedScene" uid="uid://cvx6akiplg21s" path="res://game/characters/player_sprite.tscn" id="2_n6ad3"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"]
|
||||
radius = 4.0
|
||||
|
||||
[node name="Player" type="CharacterBody2D"]
|
||||
collision_layer = 128
|
||||
collision_mask = 113
|
||||
script = ExtResource("1_xln5q")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." instance=ExtResource("2_n6ad3")]
|
||||
animation = &"death"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 1)
|
||||
shape = SubResource("CapsuleShape2D_xln5q")
|
||||
|
||||
[node name="CollisionSwitcher" parent="." node_paths=PackedStringArray("object") instance=ExtResource("2_j06tb")]
|
||||
object = NodePath("..")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position_smoothing_enabled = true
|
||||
|
||||
[node name="Pickups" type="Node2D" parent="."]
|
||||
position = Vector2(0, -24)
|
||||
|
||||
[node name="JumpBufferTimer" type="Timer" parent="."]
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[node name="CoyoteTimeTimer" type="Timer" parent="."]
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]
|
||||
[connection signal="animation_looped" from="AnimatedSprite2D" to="." method="_on_animation_looped"]
|
||||
@@ -0,0 +1,143 @@
|
||||
class_name Player
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
signal dead
|
||||
signal interacted
|
||||
|
||||
|
||||
const PICKUP_OFFSET = 16.0
|
||||
|
||||
|
||||
@export_range(0.0, 1000.0) var max_speed := 160
|
||||
@export_range(0.0, 1000.0) var max_fall_speed := 640
|
||||
@export_range(0.0, 1000.0) var acceleration := 600.0
|
||||
@export_range(0.0, 1000.0) var jump_velocity := 333.0
|
||||
@export_range(0.0, 2.0) var jump_gravity_factor := 1.0
|
||||
@export_range(0.0, 2.0) var fall_gravity_factor := 1.5
|
||||
@export_range(0.0, 1.0) var passive_jump_factor := 0.5
|
||||
|
||||
|
||||
var can_switch_color: bool = true
|
||||
var is_dead := false
|
||||
var _is_switching_needed := false
|
||||
|
||||
|
||||
@onready var camera : Camera2D = $Camera2D
|
||||
@onready var water_splash : GPUParticles2D = $WaterSplash
|
||||
@onready var sprite : AnimatedSprite2D = $PlayerSprite
|
||||
@onready var particles : GPUParticles2D = $GPUParticles2D
|
||||
@onready var collision_switcher : CollisionSwitcher = $CollisionSwitcher
|
||||
@onready var pickups : Node2D = $Pickups
|
||||
@onready var jump_buffer_timer : Timer = $JumpBufferTimer
|
||||
@onready var coyote_time_timer : Timer = $CoyoteTimeTimer
|
||||
@onready var center_area : Area2D = $CenterArea2D
|
||||
@onready var state_machine : PlayerStateMachine = $PlayerStateMachine
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
collision_switcher.material = sprite.material
|
||||
|
||||
state_machine.init()
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if is_on_floor():
|
||||
coyote_time_timer.start()
|
||||
if is_on_ceiling_only() and velocity.y < 0.0:
|
||||
velocity.y = 0.0
|
||||
|
||||
if not is_on_floor():
|
||||
var gravity_factor := jump_gravity_factor if velocity.y < 0.0 else fall_gravity_factor
|
||||
|
||||
if velocity.y < 0.0 and not Input.is_action_pressed("jump"):
|
||||
velocity.y *= passive_jump_factor
|
||||
|
||||
velocity += get_gravity() * gravity_factor * delta
|
||||
velocity.y = clampf(velocity.y, -max_fall_speed, max_fall_speed)
|
||||
|
||||
if is_dead:
|
||||
_slow_down(delta*3)
|
||||
else:
|
||||
if Input.is_action_pressed("interact"):
|
||||
interacted.emit()
|
||||
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
jump_buffer_timer.start()
|
||||
|
||||
if not coyote_time_timer.is_stopped() and not jump_buffer_timer.is_stopped():
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_jump, global_position)
|
||||
velocity.y = -jump_velocity
|
||||
jump_buffer_timer.stop()
|
||||
coyote_time_timer.stop()
|
||||
|
||||
var direction := Input.get_axis("move_left", "move_right")
|
||||
if direction:
|
||||
velocity.x = move_toward(velocity.x, direction * max_speed, acceleration * delta)
|
||||
else:
|
||||
_slow_down(delta)
|
||||
|
||||
if _is_switching_needed:
|
||||
_switch()
|
||||
|
||||
move_and_slide()
|
||||
state_machine.physics_process(delta)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("switch_color") and can_switch_color and not particles.emitting:
|
||||
_switch()
|
||||
|
||||
|
||||
func _switch() -> void:
|
||||
_is_switching_needed = false
|
||||
|
||||
if is_dead:
|
||||
return
|
||||
|
||||
if center_area.get_overlapping_bodies().size() == 0:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_switch, global_position)
|
||||
collision_switcher.switch_color()
|
||||
particles.restart()
|
||||
else:
|
||||
_is_switching_needed = true
|
||||
|
||||
|
||||
func kill(type := KillingArea.Type.None) -> void:
|
||||
match type:
|
||||
KillingArea.Type.Water:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_splash, global_position)
|
||||
water_splash.restart()
|
||||
is_dead = true
|
||||
|
||||
|
||||
func process_dead() -> void:
|
||||
dead.emit()
|
||||
queue_free()
|
||||
|
||||
|
||||
func add_pickup(pickup: AbstractPickup) -> void:
|
||||
pickup.reparent.call_deferred(pickups)
|
||||
_rearrange_pickups.call_deferred()
|
||||
|
||||
|
||||
func remove_pickup(pickup: AbstractPickup) -> void:
|
||||
if pickup in pickups.get_children():
|
||||
pickups.remove_child(pickup)
|
||||
pickup.queue_free()
|
||||
_rearrange_pickups()
|
||||
|
||||
|
||||
func _slow_down(delta: float) -> void:
|
||||
velocity.x = move_toward(velocity.x, 0, acceleration * delta)
|
||||
|
||||
|
||||
func _rearrange_pickups() -> void:
|
||||
var children := pickups.get_children()
|
||||
var pickup_shift := (children.size() - 1) * PICKUP_OFFSET / 2.0
|
||||
|
||||
for i in range(children.size()):
|
||||
if not children[i] is Node2D: continue
|
||||
var node := children[i] as Node2D
|
||||
node.position.x = i * PICKUP_OFFSET - pickup_shift
|
||||
node.position.y = 0
|
||||
@@ -0,0 +1,242 @@
|
||||
[gd_scene format=3 uid="uid://dtcad8tdx78tg"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bb8kc32sggrn2" path="res://game/characters/player/player.gd" id="1_xln5q"]
|
||||
[ext_resource type="PackedScene" uid="uid://8yd8f5x1hujv" path="res://game/characters/water_splash.tscn" id="2_eeksw"]
|
||||
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="2_j06tb"]
|
||||
[ext_resource type="PackedScene" uid="uid://cvx6akiplg21s" path="res://game/characters/player/player_sprite.tscn" id="2_n6ad3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bdk23k2bypj8w" path="res://game/characters/player/state_machine/player_state_machine.tscn" id="4_ybe51"]
|
||||
[ext_resource type="PackedScene" uid="uid://c0d4wfdg7xjti" path="res://game/characters/player/state_machine/player_state.tscn" id="5_65114"]
|
||||
[ext_resource type="Script" uid="uid://bnxccvt265hlu" path="res://game/characters/player/state_machine/idle_state.gd" id="6_3qf5w"]
|
||||
[ext_resource type="Script" uid="uid://nc62375vpnsw" path="res://game/characters/player/state_machine/walk_left_state.gd" id="7_btbyc"]
|
||||
[ext_resource type="Script" uid="uid://cbv84l1duwfep" path="res://game/characters/player/state_machine/look_around_state.gd" id="7_ybe51"]
|
||||
[ext_resource type="Script" uid="uid://cxa3hf7tqpeoa" path="res://game/characters/player/state_machine/jump_state.gd" id="8_ebhjm"]
|
||||
[ext_resource type="Script" uid="uid://d2uiegcx4jeuk" path="res://game/characters/player/state_machine/dead_state.gd" id="9_gdxv1"]
|
||||
[ext_resource type="Script" uid="uid://kufq6bwnv80t" path="res://game/characters/player/state_machine/walk_right_state.gd" id="9_wdx7h"]
|
||||
[ext_resource type="Script" uid="uid://c0bbmif5ucw28" path="res://game/characters/player/state_machine/jump_left_state.gd" id="11_q2504"]
|
||||
[ext_resource type="Script" uid="uid://cr0hkb4wggcys" path="res://game/characters/player/state_machine/jump_right_state.gd" id="12_l8uo5"]
|
||||
[ext_resource type="Script" uid="uid://c7myrm50fnpfn" path="res://game/characters/player/state_machine/falingl_state.gd" id="13_m2bqk"]
|
||||
[ext_resource type="Script" uid="uid://cmimnl6jf78ao" path="res://game/characters/player/state_machine/falling_left_state.gd" id="14_2lnxg"]
|
||||
[ext_resource type="Script" uid="uid://5s7ko6pcqagy" path="res://game/characters/player/state_machine/falling_right_state.gd" id="15_bfpdl"]
|
||||
|
||||
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_bfpdl"]
|
||||
particle_flag_disable_z = true
|
||||
emission_shape = 3
|
||||
emission_box_extents = Vector3(4, 14, 1)
|
||||
inherit_velocity_ratio = 0.25
|
||||
direction = Vector3(0, -1, 0)
|
||||
initial_velocity_min = 15.0
|
||||
initial_velocity_max = 15.0
|
||||
gravity = Vector3(0, 0, 0)
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"]
|
||||
radius = 4.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_t6gq4"]
|
||||
radius = 2.0
|
||||
height = 20.0
|
||||
|
||||
[node name="Player" type="CharacterBody2D" unique_id=508706417]
|
||||
collision_layer = 128
|
||||
collision_mask = 33
|
||||
script = ExtResource("1_xln5q")
|
||||
|
||||
[node name="WaterSplash" parent="." unique_id=658940825 instance=ExtResource("2_eeksw")]
|
||||
position = Vector2(0, -16)
|
||||
|
||||
[node name="PlayerSprite" parent="." unique_id=237719081 instance=ExtResource("2_n6ad3")]
|
||||
animation = &"jump_right"
|
||||
|
||||
[node name="GPUParticles2D" type="GPUParticles2D" parent="." unique_id=405618377]
|
||||
emitting = false
|
||||
amount = 16
|
||||
lifetime = 0.25
|
||||
one_shot = true
|
||||
explosiveness = 0.5
|
||||
fixed_fps = 10
|
||||
process_material = SubResource("ParticleProcessMaterial_bfpdl")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1101386361]
|
||||
position = Vector2(0, 1)
|
||||
shape = SubResource("CapsuleShape2D_xln5q")
|
||||
|
||||
[node name="CollisionSwitcher" parent="." unique_id=601548821 node_paths=PackedStringArray("object") instance=ExtResource("2_j06tb")]
|
||||
object = NodePath("..")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=45512317]
|
||||
process_callback = 0
|
||||
position_smoothing_enabled = true
|
||||
position_smoothing_speed = 25.0
|
||||
drag_horizontal_enabled = true
|
||||
drag_vertical_enabled = true
|
||||
drag_left_margin = 0.1
|
||||
drag_top_margin = 0.1
|
||||
drag_right_margin = 0.1
|
||||
drag_bottom_margin = 0.1
|
||||
|
||||
[node name="Pickups" type="Node2D" parent="." unique_id=958829860]
|
||||
position = Vector2(0, -24)
|
||||
|
||||
[node name="JumpBufferTimer" type="Timer" parent="." unique_id=740877224]
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[node name="CoyoteTimeTimer" type="Timer" parent="." unique_id=117837002]
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[node name="CenterArea2D" type="Area2D" parent="." unique_id=490866430]
|
||||
collision_layer = 0
|
||||
collision_mask = 35
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CenterArea2D" unique_id=1350886064]
|
||||
position = Vector2(0, 1)
|
||||
shape = SubResource("CapsuleShape2D_t6gq4")
|
||||
|
||||
[node name="PlayerStateMachine" parent="." unique_id=633169960 node_paths=PackedStringArray("player", "initial_state") instance=ExtResource("4_ybe51")]
|
||||
player = NodePath("..")
|
||||
initial_state = NodePath("IdleState")
|
||||
|
||||
[node name="IdleState" parent="PlayerStateMachine" unique_id=739226464 node_paths=PackedStringArray("look_around_state", "player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("6_3qf5w")
|
||||
look_around_state = NodePath("../LookAroundState")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath(".")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath("../JumpState")
|
||||
jump_left_state = NodePath("../JumpLeftState")
|
||||
jump_right_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath("../FallState")
|
||||
fall_left_state = NodePath("../FallLeftState")
|
||||
fall_right_state = NodePath("../FallRightState")
|
||||
|
||||
[node name="WalkLeftState" parent="PlayerStateMachine" unique_id=195513070 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("7_btbyc")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_left_state = NodePath(".")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath("../JumpState")
|
||||
jump_left_state = NodePath("../JumpLeftState")
|
||||
jump_right_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath("../FallState")
|
||||
fall_left_state = NodePath("../FallLeftState")
|
||||
fall_right_state = NodePath("../FallRightState")
|
||||
|
||||
[node name="WalkRightState" parent="PlayerStateMachine" unique_id=224236087 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("9_wdx7h")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath(".")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath("../JumpState")
|
||||
jump_left_state = NodePath("../JumpLeftState")
|
||||
jump_right_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath("../FallState")
|
||||
fall_left_state = NodePath("../FallLeftState")
|
||||
fall_right_state = NodePath("../FallRightState")
|
||||
|
||||
[node name="DeadState" parent="PlayerStateMachine" unique_id=2135733235 node_paths=PackedStringArray("player") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("9_gdxv1")
|
||||
player = NodePath("../..")
|
||||
|
||||
[node name="JumpState" parent="PlayerStateMachine" unique_id=1592631166 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("8_ebhjm")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath(".")
|
||||
jump_left_state = NodePath("../JumpLeftState")
|
||||
jump_right_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath("../FallState")
|
||||
fall_left_state = NodePath("../FallLeftState")
|
||||
fall_right_state = NodePath("../FallRightState")
|
||||
|
||||
[node name="JumpLeftState" parent="PlayerStateMachine" unique_id=609248752 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("11_q2504")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath(".")
|
||||
jump_left_state = NodePath(".")
|
||||
jump_right_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath("../FallState")
|
||||
fall_left_state = NodePath("../FallLeftState")
|
||||
fall_right_state = NodePath("../FallRightState")
|
||||
|
||||
[node name="JumpRightState" parent="PlayerStateMachine" unique_id=1936273065 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("12_l8uo5")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath(".")
|
||||
jump_left_state = NodePath("../JumpLeftState")
|
||||
jump_right_state = NodePath(".")
|
||||
fall_state = NodePath("../FallState")
|
||||
fall_left_state = NodePath("../FallLeftState")
|
||||
fall_right_state = NodePath("../FallRightState")
|
||||
|
||||
[node name="FallState" parent="PlayerStateMachine" unique_id=329927506 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("13_m2bqk")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath(".")
|
||||
jump_left_state = NodePath("../JumpLeftState")
|
||||
jump_right_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath(".")
|
||||
fall_left_state = NodePath("../FallLeftState")
|
||||
fall_right_state = NodePath("../FallRightState")
|
||||
|
||||
[node name="FallLeftState" parent="PlayerStateMachine" unique_id=730552947 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("14_2lnxg")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath(".")
|
||||
jump_left_state = NodePath("../JumpLeftState")
|
||||
jump_right_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath("../FallState")
|
||||
fall_left_state = NodePath(".")
|
||||
fall_right_state = NodePath("../FallRightState")
|
||||
|
||||
[node name="FallRightState" parent="PlayerStateMachine" unique_id=347081029 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("15_bfpdl")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath(".")
|
||||
jump_left_state = NodePath("../JumpLeftState")
|
||||
jump_right_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath("../FallState")
|
||||
fall_left_state = NodePath("../FallLeftState")
|
||||
fall_right_state = NodePath(".")
|
||||
|
||||
[node name="LookAroundState" parent="PlayerStateMachine" unique_id=946166563 node_paths=PackedStringArray("player", "idle_state", "walk_left_state", "walk_right_state", "dead_state", "jump_state", "jump_left_state", "jump_right_state", "fall_state", "fall_left_state", "fall_right_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("7_ybe51")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_left_state = NodePath("../WalkLeftState")
|
||||
walk_right_state = NodePath("../WalkRightState")
|
||||
dead_state = NodePath("../DeadState")
|
||||
jump_state = NodePath("../JumpState")
|
||||
jump_left_state = NodePath("../JumpLeftState")
|
||||
jump_right_state = NodePath("../JumpRightState")
|
||||
fall_state = NodePath("../FallState")
|
||||
fall_left_state = NodePath("../FallLeftState")
|
||||
fall_right_state = NodePath("../FallRightState")
|
||||
@@ -0,0 +1,80 @@
|
||||
[gd_scene format=3 uid="uid://dtcad8tdx78tg"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bb8kc32sggrn2" path="res://game/characters/player/player.gd" id="1_xln5q"]
|
||||
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="2_j06tb"]
|
||||
[ext_resource type="PackedScene" uid="uid://cvx6akiplg21s" path="res://game/characters/player/player_sprite.tscn" id="2_n6ad3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bdk23k2bypj8w" path="res://game/characters/player/state_machine/player_state_machine.tscn" id="4_ybe51"]
|
||||
[ext_resource type="PackedScene" uid="uid://c0d4wfdg7xjti" path="res://game/characters/player/state_machine/player_state.tscn" id="5_65114"]
|
||||
[ext_resource type="Script" uid="uid://bnxccvt265hlu" path="res://game/characters/player/state_machine/idle_state.gd" id="6_3qf5w"]
|
||||
[ext_resource type="Script" uid="uid://nc62375vpnsw" path="res://game/characters/player/state_machine/walk_left_state.gd" id="7_btbyc"]
|
||||
[ext_resource type="Script" uid="uid://cbv84l1duwfep" path="res://game/characters/player/state_machine/look_around_state.gd" id="7_ybe51"]
|
||||
[ext_resource type="Script" uid="uid://cxa3hf7tqpeoa" path="res://game/characters/player/state_machine/jump_state.gd" id="8_ebhjm"]
|
||||
[ext_resource type="Script" uid="uid://d2uiegcx4jeuk" path="res://game/characters/player/state_machine/dead_state.gd" id="9_gdxv1"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"]
|
||||
radius = 4.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_t6gq4"]
|
||||
radius = 2.0
|
||||
height = 15.0
|
||||
|
||||
[node name="Player" type="CharacterBody2D" unique_id=508706417]
|
||||
collision_layer = 128
|
||||
collision_mask = 33
|
||||
script = ExtResource("1_xln5q")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." unique_id=237719081 instance=ExtResource("2_n6ad3")]
|
||||
animation = &"death"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1101386361]
|
||||
position = Vector2(0, 1)
|
||||
shape = SubResource("CapsuleShape2D_xln5q")
|
||||
|
||||
[node name="CollisionSwitcher" parent="." unique_id=601548821 node_paths=PackedStringArray("object") instance=ExtResource("2_j06tb")]
|
||||
object = NodePath("..")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=45512317]
|
||||
process_callback = 0
|
||||
position_smoothing_enabled = true
|
||||
|
||||
[node name="Pickups" type="Node2D" parent="." unique_id=958829860]
|
||||
position = Vector2(0, -24)
|
||||
|
||||
[node name="JumpBufferTimer" type="Timer" parent="." unique_id=740877224]
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[node name="CoyoteTimeTimer" type="Timer" parent="." unique_id=117837002]
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[node name="CenterArea2D" type="Area2D" parent="." unique_id=490866430]
|
||||
collision_layer = 0
|
||||
collision_mask = 35
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CenterArea2D" unique_id=1350886064]
|
||||
shape = SubResource("CapsuleShape2D_t6gq4")
|
||||
|
||||
[node name="PlayerStateMachine" parent="." unique_id=633169960 node_paths=PackedStringArray("player", "dead_state", "initial_state") instance=ExtResource("4_ybe51")]
|
||||
player = NodePath("..")
|
||||
dead_state = NodePath("DeadState")
|
||||
initial_state = NodePath("IdleState")
|
||||
|
||||
[node name="IdleState" parent="PlayerStateMachine" unique_id=739226464 node_paths=PackedStringArray("look_around_state", "player", "idle_state", "walk_state", "jump_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("6_3qf5w")
|
||||
look_around_state = NodePath("../LookAroundState")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath(".")
|
||||
walk_state = NodePath("../WalkLeftState")
|
||||
jump_state = NodePath("../JumpState")
|
||||
|
||||
[node name="LookAroundState" parent="PlayerStateMachine" unique_id=946166563 node_paths=PackedStringArray("player", "idle_state", "walk_state", "jump_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("7_ybe51")
|
||||
player = NodePath("../..")
|
||||
idle_state = NodePath("../IdleState")
|
||||
walk_state = NodePath("../WalkLeftState")
|
||||
jump_state = NodePath("../JumpState")
|
||||
|
||||
[node name="WalkLeftState" parent="PlayerStateMachine" unique_id=195513070 instance=ExtResource("5_65114")]
|
||||
script = ExtResource("7_btbyc")
|
||||
player = Object(CharacterBody2D,"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"proce
|
||||
@@ -0,0 +1,70 @@
|
||||
[gd_scene format=3 uid="uid://dtcad8tdx78tg"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bb8kc32sggrn2" path="res://game/characters/player/player.gd" id="1_xln5q"]
|
||||
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="2_j06tb"]
|
||||
[ext_resource type="PackedScene" uid="uid://cvx6akiplg21s" path="res://game/characters/player/player_sprite.tscn" id="2_n6ad3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bdk23k2bypj8w" path="res://game/characters/player/state_machine/player_state_machine.tscn" id="4_ybe51"]
|
||||
[ext_resource type="PackedScene" uid="uid://c0d4wfdg7xjti" path="res://game/characters/player/state_machine/player_state.tscn" id="5_65114"]
|
||||
[ext_resource type="Script" uid="uid://bnxccvt265hlu" path="res://game/characters/player/state_machine/idle_state.gd" id="6_3qf5w"]
|
||||
[ext_resource type="Script" uid="uid://nc62375vpnsw" path="res://game/characters/player/state_machine/walk_left_state.gd" id="7_btbyc"]
|
||||
[ext_resource type="Script" uid="uid://cbv84l1duwfep" path="res://game/characters/player/state_machine/look_around_state.gd" id="7_ybe51"]
|
||||
[ext_resource type="Script" uid="uid://cxa3hf7tqpeoa" path="res://game/characters/player/state_machine/jump_state.gd" id="8_ebhjm"]
|
||||
[ext_resource type="Script" uid="uid://d2uiegcx4jeuk" path="res://game/characters/player/state_machine/dead_state.gd" id="9_gdxv1"]
|
||||
[ext_resource type="Script" uid="uid://kufq6bwnv80t" path="res://game/characters/player/state_machine/walk_right_state.gd" id="9_wdx7h"]
|
||||
[ext_resource type="Script" uid="uid://c0bbmif5ucw28" path="res://game/characters/player/state_machine/jump_left_state.gd" id="11_q2504"]
|
||||
[ext_resource type="Script" uid="uid://cr0hkb4wggcys" path="res://game/characters/player/state_machine/jump_right_state.gd" id="12_l8uo5"]
|
||||
[ext_resource type="Script" uid="uid://c7myrm50fnpfn" path="res://game/characters/player/state_machine/fall_state.gd" id="13_m2bqk"]
|
||||
[ext_resource type="Script" uid="uid://cmimnl6jf78ao" path="res://game/characters/player/state_machine/fall_left_state.gd" id="14_2lnxg"]
|
||||
[ext_resource type="Script" uid="uid://5s7ko6pcqagy" path="res://game/characters/player/state_machine/fall_right_state.gd" id="15_bfpdl"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"]
|
||||
radius = 4.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_t6gq4"]
|
||||
radius = 2.0
|
||||
height = 15.0
|
||||
|
||||
[node name="Player" type="CharacterBody2D" unique_id=508706417]
|
||||
collision_layer = 128
|
||||
collision_mask = 33
|
||||
script = ExtResource("1_xln5q")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." unique_id=237719081 instance=ExtResource("2_n6ad3")]
|
||||
animation = &"jump_right"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1101386361]
|
||||
position = Vector2(0, 1)
|
||||
shape = SubResource("CapsuleShape2D_xln5q")
|
||||
|
||||
[node name="CollisionSwitcher" parent="." unique_id=601548821 node_paths=PackedStringArray("object") instance=ExtResource("2_j06tb")]
|
||||
object = NodePath("..")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=45512317]
|
||||
process_callback = 0
|
||||
position_smoothing_enabled = true
|
||||
|
||||
[node name="Pickups" type="Node2D" parent="." unique_id=958829860]
|
||||
position = Vector2(0, -24)
|
||||
|
||||
[node name="JumpBufferTimer" type="Timer" parent="." unique_id=740877224]
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[node name="CoyoteTimeTimer" type="Timer" parent="." unique_id=117837002]
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[node name="CenterArea2D" type="Area2D" parent="." unique_id=490866430]
|
||||
collision_layer = 0
|
||||
collision_mask = 35
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CenterArea2D" unique_id=1350886064]
|
||||
shape = SubResource("CapsuleShape2D_t6gq4")
|
||||
|
||||
[node name="PlayerStateMachine" parent="." unique_id=633169960 node_paths=PackedStringArray("player", "initial_state") instance=ExtResource("4_ybe51")]
|
||||
player = NodePath("..")
|
||||
initial_state = NodePath("IdleState")
|
||||
|
||||
[node name="IdleState" parent="PlayerStateMachine" unique_id=739226464 node_paths=PackedStringArray("look_around_state") instance=ExtResource("5_65114")]
|
||||
script = ExtResource("6_3qf5w")
|
||||
player = Object(CharacterBody2D,"unique_name_in_owner":false,"process_mod
|
||||
@@ -0,0 +1,24 @@
|
||||
class_name PlayerSprite
|
||||
extends AnimatedSprite2D
|
||||
|
||||
|
||||
|
||||
|
||||
const ANIMATION_IDLE = "idle"
|
||||
|
||||
const ANIMATION_LOOK_AROUND = "look_around"
|
||||
const ANIMATION_LOOK_AROUND_1 = "look_around_1"
|
||||
const ANIMATION_LOOK_AROUND_2 = "look_around_2"
|
||||
|
||||
const ANIMATION_FALL = "fall"
|
||||
const ANIMATION_FALL_LEFT = "fall_left"
|
||||
const ANIMATION_FALL_RIGHT = "fall_right"
|
||||
|
||||
const ANIMATION_JUMP = "jump"
|
||||
const ANIMATION_JUMP_LEFT = "jump_left"
|
||||
const ANIMATION_JUMP_RIGHT = "jump_right"
|
||||
|
||||
const ANIMATION_WALK_LEFT = "walk_left"
|
||||
const ANIMATION_WALK_RIGHT = "walk_right"
|
||||
|
||||
const ANIMATION_DEATH = "death"
|
||||
@@ -0,0 +1 @@
|
||||
uid://bpclheyn60yp7
|
||||
@@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=53 format=3 uid="uid://cvx6akiplg21s"]
|
||||
[gd_scene format=3 uid="uid://cvx6akiplg21s"]
|
||||
|
||||
[ext_resource type="Shader" uid="uid://lqq1mg6l1qqe" path="res://game/shaders/black_n_white.gdshader" id="1_57ht8"]
|
||||
[ext_resource type="Texture2D" uid="uid://bjccaucrio6ht" path="res://images/characters/player.png" id="2_mi53p"]
|
||||
[ext_resource type="Script" uid="uid://bpclheyn60yp7" path="res://game/characters/player/player_sprite.gd" id="3_ulfbe"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_i05k5"]
|
||||
shader = ExtResource("1_57ht8")
|
||||
@@ -81,18 +82,6 @@ region = Rect2(64, 96, 32, 32)
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(0, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_htqrf"]
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(160, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_vkuli"]
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(96, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_457no"]
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(32, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_n6ad3"]
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
@@ -113,6 +102,18 @@ region = Rect2(32, 0, 32, 32)
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_htqrf"]
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(160, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_vkuli"]
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(96, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_457no"]
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(32, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_mi53p"]
|
||||
atlas = ExtResource("2_mi53p")
|
||||
region = Rect2(96, 0, 32, 32)
|
||||
@@ -259,7 +260,7 @@ animations = [{
|
||||
"texture": SubResource("AtlasTexture_4u621")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_down",
|
||||
"name": &"fall",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
@@ -267,7 +268,7 @@ animations = [{
|
||||
"texture": SubResource("AtlasTexture_tqwgk")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_down_left",
|
||||
"name": &"fall_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
@@ -275,31 +276,7 @@ animations = [{
|
||||
"texture": SubResource("AtlasTexture_ly4f6")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_down_right",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_htqrf")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_up",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_vkuli")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_up_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_457no")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fall_up_right",
|
||||
"name": &"fall_right",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
@@ -323,6 +300,30 @@ animations = [{
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_htqrf")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"jump",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_vkuli")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"jump_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_457no")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"jump_right",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 3.0,
|
||||
"texture": SubResource("AtlasTexture_mi53p")
|
||||
}, {
|
||||
@@ -426,7 +427,8 @@ animations = [{
|
||||
"speed": 20.0
|
||||
}]
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D"]
|
||||
[node name="PlayerSprite2D" type="AnimatedSprite2D" unique_id=259457082]
|
||||
material = SubResource("ShaderMaterial_i05k5")
|
||||
sprite_frames = SubResource("SpriteFrames_v8w1g")
|
||||
animation = &"look_around"
|
||||
animation = &"idle"
|
||||
script = ExtResource("3_ulfbe")
|
||||
@@ -0,0 +1,23 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_death, player.global_position)
|
||||
player.sprite.animation_finished.connect(_on_aniimation_finished)
|
||||
player.process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
player.sprite.play(PlayerSprite.ANIMATION_DEATH)
|
||||
get_tree().paused = true
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
player.sprite.animation_finished.disconnect(_on_aniimation_finished)
|
||||
|
||||
|
||||
func physics_process(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_aniimation_finished() -> void:
|
||||
player.process_dead()
|
||||
@@ -0,0 +1 @@
|
||||
uid://d2uiegcx4jeuk
|
||||
@@ -0,0 +1,6 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.play(PlayerSprite.ANIMATION_FALL)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c7myrm50fnpfn
|
||||
@@ -0,0 +1,6 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.play(PlayerSprite.ANIMATION_FALL_LEFT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cmimnl6jf78ao
|
||||
@@ -0,0 +1,6 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.play(PlayerSprite.ANIMATION_FALL_RIGHT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://5s7ko6pcqagy
|
||||
@@ -0,0 +1,22 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
const LOOK_AROUND_CHANCE = 25
|
||||
|
||||
|
||||
@export var look_around_state: PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.animation_looped.connect(_on_animation_looped)
|
||||
player.sprite.play(PlayerSprite.ANIMATION_IDLE)
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
player.sprite.animation_looped.disconnect(_on_animation_looped)
|
||||
|
||||
|
||||
func _on_animation_looped() -> void:
|
||||
if randi_range(1, 100) <= LOOK_AROUND_CHANCE:
|
||||
switch_state.emit(look_around_state)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bnxccvt265hlu
|
||||
@@ -0,0 +1,6 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.play(PlayerSprite.ANIMATION_JUMP_LEFT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c0bbmif5ucw28
|
||||
@@ -0,0 +1,6 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.play(PlayerSprite.ANIMATION_JUMP_RIGHT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cr0hkb4wggcys
|
||||
@@ -0,0 +1,6 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.play(PlayerSprite.ANIMATION_JUMP)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cxa3hf7tqpeoa
|
||||
@@ -0,0 +1,22 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.animation_finished.connect(_on_animation_finished)
|
||||
player.sprite.play(_get_animation())
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
player.sprite.animation_finished.disconnect(_on_animation_finished)
|
||||
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
switch_state.emit(idle_state)
|
||||
|
||||
|
||||
func _get_animation() -> String:
|
||||
if randi_range(1, 2) == 1:
|
||||
return PlayerSprite.ANIMATION_LOOK_AROUND_1
|
||||
else:
|
||||
return PlayerSprite.ANIMATION_LOOK_AROUND_2
|
||||
@@ -0,0 +1 @@
|
||||
uid://cbv84l1duwfep
|
||||
@@ -0,0 +1,45 @@
|
||||
class_name PlayerState
|
||||
extends AbstractState
|
||||
|
||||
|
||||
@export var player: Player
|
||||
|
||||
|
||||
@export var idle_state: PlayerState
|
||||
@export var walk_left_state: PlayerState
|
||||
@export var walk_right_state: PlayerState
|
||||
@export var dead_state: PlayerState
|
||||
@export var jump_state: PlayerState
|
||||
@export var jump_left_state: PlayerState
|
||||
@export var jump_right_state: PlayerState
|
||||
@export var fall_state: PlayerState
|
||||
@export var fall_left_state: PlayerState
|
||||
@export var fall_right_state: PlayerState
|
||||
|
||||
|
||||
func physics_process(_delta: float) -> void:
|
||||
if player.is_dead:
|
||||
switch_state.emit(dead_state)
|
||||
elif player.velocity.is_zero_approx():
|
||||
switch_state.emit(idle_state)
|
||||
elif is_zero_approx(player.velocity.y):
|
||||
if player.velocity.x < 0:
|
||||
switch_state.emit(walk_left_state)
|
||||
else:
|
||||
switch_state.emit(walk_right_state)
|
||||
else:
|
||||
if player.velocity.y < 0:
|
||||
if is_zero_approx(player.velocity.x):
|
||||
switch_state.emit(jump_state)
|
||||
elif player.velocity.x < 0:
|
||||
switch_state.emit(jump_left_state)
|
||||
else:
|
||||
switch_state.emit(jump_right_state)
|
||||
else:
|
||||
if is_zero_approx(player.velocity.x):
|
||||
switch_state.emit(fall_state)
|
||||
elif player.velocity.x < 0:
|
||||
switch_state.emit(fall_left_state)
|
||||
else:
|
||||
switch_state.emit(fall_right_state)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://cl4tgf5j7xxvm
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://c0d4wfdg7xjti"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://c7adrbfobmvl8" path="res://game/state_machine/abstract_state.tscn" id="1_cun6f"]
|
||||
[ext_resource type="Script" uid="uid://cl4tgf5j7xxvm" path="res://game/characters/player/state_machine/player_state.gd" id="2_h7f7n"]
|
||||
|
||||
[node name="PlayerState" unique_id=739226464 instance=ExtResource("1_cun6f")]
|
||||
script = ExtResource("2_h7f7n")
|
||||
@@ -0,0 +1,5 @@
|
||||
class_name PlayerStateMachine
|
||||
extends StateMachine
|
||||
|
||||
|
||||
@export var player: Player
|
||||
@@ -0,0 +1 @@
|
||||
uid://dk3t8s0lt2r8n
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://bdk23k2bypj8w"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://3ll3i1fgktg2" path="res://game/state_machine/state_machine.tscn" id="1_7tog0"]
|
||||
[ext_resource type="Script" uid="uid://dk3t8s0lt2r8n" path="res://game/characters/player/state_machine/player_state_machine.gd" id="2_ydgfo"]
|
||||
|
||||
[node name="PlayerStateMachine" unique_id=633169960 instance=ExtResource("1_7tog0")]
|
||||
script = ExtResource("2_ydgfo")
|
||||
@@ -0,0 +1,11 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.play(PlayerSprite.ANIMATION_WALK_LEFT)
|
||||
|
||||
|
||||
func process(delta: float) -> void:
|
||||
player.sprite.speed_scale = -player.velocity.x / player.max_speed
|
||||
super.process(delta)
|
||||
@@ -0,0 +1 @@
|
||||
uid://nc62375vpnsw
|
||||
@@ -0,0 +1,11 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
player.sprite.speed_scale = 1
|
||||
player.sprite.play(PlayerSprite.ANIMATION_WALK_RIGHT)
|
||||
|
||||
|
||||
func process(delta: float) -> void:
|
||||
player.sprite.speed_scale = player.velocity.x / player.max_speed
|
||||
super.process(delta)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user