summaryrefslogtreecommitdiff
path: root/src/entities/actors/snake/scripts
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-06-05 14:09:41 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-06-05 14:09:41 -0600
commit14538d486de312af41ce012836861468b8fb7897 (patch)
tree569d09c43fd7724a5fbb0898f5c1d1db3fd64b3d /src/entities/actors/snake/scripts
parent4b42a8ba26f21e2c6c766fa747c8b93a115a53b2 (diff)
finish all necessary for playability
Diffstat (limited to 'src/entities/actors/snake/scripts')
-rw-r--r--src/entities/actors/snake/scripts/dash_state.gd1
-rw-r--r--src/entities/actors/snake/scripts/head.gd14
-rw-r--r--src/entities/actors/snake/scripts/jump_state.gd18
-rw-r--r--src/entities/actors/snake/scripts/normal_state.gd5
-rw-r--r--src/entities/actors/snake/scripts/slow_state.gd1
-rw-r--r--src/entities/actors/snake/scripts/state_machine.gd13
6 files changed, 33 insertions, 19 deletions
diff --git a/src/entities/actors/snake/scripts/dash_state.gd b/src/entities/actors/snake/scripts/dash_state.gd
index 3eb0bdf..a23b241 100644
--- a/src/entities/actors/snake/scripts/dash_state.gd
+++ b/src/entities/actors/snake/scripts/dash_state.gd
@@ -19,6 +19,7 @@ func exit():
func physics_process(delta: float) -> void:
+ fsm.rotate_on_input()
fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED
fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity)
diff --git a/src/entities/actors/snake/scripts/head.gd b/src/entities/actors/snake/scripts/head.gd
index e6824a7..2853d00 100644
--- a/src/entities/actors/snake/scripts/head.gd
+++ b/src/entities/actors/snake/scripts/head.gd
@@ -12,9 +12,11 @@ var velocity: Vector2 = Vector2.ZERO
var direction: Vector2 = Vector2.UP
var _time_elapsed: float = 0.0
-var can_dash: bool = true
-var can_slow: bool = true
-var can_jump: bool = true
+var stats: Stats = SaveData.get_stats()
+
+var can_dash: bool = false
+var can_slow: bool = false
+var can_jump: bool = false
func _ready() -> void:
@@ -22,6 +24,12 @@ func _ready() -> void:
Event.connect("snake_started_dash", self, "_on_snake_started_dash")
Event.connect("snake_started_slow", self, "_on_snake_started_slow")
Event.connect("snake_started_jump", self, "_on_snake_started_jump")
+
+ print(stats.get_stats())
+ can_dash = stats.trait_dash
+ can_slow = stats.trait_slow
+ can_jump = stats.trait_jump
+
tongue_sprite.visible = false
diff --git a/src/entities/actors/snake/scripts/jump_state.gd b/src/entities/actors/snake/scripts/jump_state.gd
index 396ceb4..329b426 100644
--- a/src/entities/actors/snake/scripts/jump_state.gd
+++ b/src/entities/actors/snake/scripts/jump_state.gd
@@ -6,22 +6,24 @@ var fsm: StateMachine
func enter():
if fsm.DEBUG:
print("Got inside %s." % name)
- Event.emit_signal("snake_started_dash")
- Global.SNAKE_SPEED = Global.SNAKE_DASH_SPEED
- yield(get_tree().create_timer(Global.SNAKE_DASH_TIME), "timeout")
+ Event.emit_signal("snake_started_jump")
+ fsm.player.set_collision_mask_bit(1, false)
+ fsm.player.set_collision_mask_bit(2, false)
+ Global.SNAKE_SPEED = Global.SNAKE_JUMP_SPEED
+ yield(get_tree().create_timer(Global.SNAKE_JUMP_TIME), "timeout")
exit()
func exit():
- Event.emit_signal("snake_finished_dash")
+ fsm.player.set_collision_mask_bit(1, true)
+ fsm.player.set_collision_mask_bit(2, true)
Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP
+ Event.emit_signal("snake_finished_jump")
fsm.back()
-func physics_process(delta: float) -> float:
+func physics_process(delta: float) -> void:
fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED
fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity)
- fsm.slow_down_on_collisions(Global.SNAKE_DASH_SPEED)
-
- return delta
+ fsm.slow_down_on_collisions(Global.SNAKE_JUMP_SPEED)
diff --git a/src/entities/actors/snake/scripts/normal_state.gd b/src/entities/actors/snake/scripts/normal_state.gd
index 11981a3..1a9c1b1 100644
--- a/src/entities/actors/snake/scripts/normal_state.gd
+++ b/src/entities/actors/snake/scripts/normal_state.gd
@@ -13,6 +13,7 @@ func exit(next_state):
func physics_process(delta: float) -> void:
+ fsm.rotate_on_input()
fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED
fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity)
@@ -24,5 +25,5 @@ func input(event: InputEvent) -> void:
exit("DashState")
if fsm.player.can_slow and event.is_action_pressed("slow"):
exit("SlowState")
- # if fsm.player.can_jump and event.is_action_pressed("jump"):
- # exit("JumpState")
+ if fsm.player.can_jump and event.is_action_pressed("jump"):
+ exit("JumpState")
diff --git a/src/entities/actors/snake/scripts/slow_state.gd b/src/entities/actors/snake/scripts/slow_state.gd
index 8d54bfb..3a2c94b 100644
--- a/src/entities/actors/snake/scripts/slow_state.gd
+++ b/src/entities/actors/snake/scripts/slow_state.gd
@@ -19,6 +19,7 @@ func exit():
func physics_process(delta: float) -> float:
+ fsm.rotate_on_input()
fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED
fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity)
diff --git a/src/entities/actors/snake/scripts/state_machine.gd b/src/entities/actors/snake/scripts/state_machine.gd
index b63f272..93e76b9 100644
--- a/src/entities/actors/snake/scripts/state_machine.gd
+++ b/src/entities/actors/snake/scripts/state_machine.gd
@@ -40,20 +40,21 @@ func _process(delta: float) -> void:
func _physics_process(delta: float) -> void:
- if Input.is_action_pressed("move_left"):
- player.rotate_to(player.LEFT)
- if Input.is_action_pressed("move_right"):
- player.rotate_to(player.RIGHT)
-
# state specific code, move_and_slide is called here
if state.has_method("physics_process"):
state.physics_process(delta)
handle_slow_speeds()
-
player.handle_time_elapsed(delta)
+func rotate_on_input() -> void:
+ if Input.is_action_pressed("move_left"):
+ player.rotate_to(player.LEFT)
+ if Input.is_action_pressed("move_right"):
+ player.rotate_to(player.RIGHT)
+
+
func slow_down_on_collisions(speed_backup: float):
if player.get_last_slide_collision():
Global.SNAKE_SPEED = player.velocity.length()