From 4b42a8ba26f21e2c6c766fa747c8b93a115a53b2 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Sun, 5 Jun 2022 09:18:35 -0600 Subject: added new tiles to ground tilemap, moved player to state machine paradigm --- src/entities/actors/snake/scripts/normal_state.gd | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/entities/actors/snake/scripts/normal_state.gd (limited to 'src/entities/actors/snake/scripts/normal_state.gd') diff --git a/src/entities/actors/snake/scripts/normal_state.gd b/src/entities/actors/snake/scripts/normal_state.gd new file mode 100644 index 0000000..11981a3 --- /dev/null +++ b/src/entities/actors/snake/scripts/normal_state.gd @@ -0,0 +1,28 @@ +extends Node + +var fsm: StateMachine + + +func enter(): + if fsm.DEBUG: + print("Got inside %s." % name) + + +func exit(next_state): + fsm.change_to(next_state) + + +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_SPEED_BACKUP) + + +func input(event: InputEvent) -> void: + if fsm.player.can_dash and event.is_action_pressed("dash"): + 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") -- cgit v1.2.3