Game States kind of working
This commit is contained in:
+25
-8
@@ -26,6 +26,7 @@ enum PlayerState {
|
||||
var score : int = 0
|
||||
var energy : float = 1.0
|
||||
var state : PlayerState = PlayerState.Alive
|
||||
var state_last : PlayerState = PlayerState.Dead
|
||||
|
||||
var radius = 0.15
|
||||
var angle = 0
|
||||
@@ -36,7 +37,6 @@ var coloring_sprite : Sprite2D
|
||||
var coloring_bomb_sprite : Sprite2D
|
||||
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
const DASH_SPEED: float = 20
|
||||
const DASH_DURATION: float = 0.2
|
||||
const BOMB_DURATION: float = 0.1
|
||||
@@ -53,8 +53,19 @@ func _ready():
|
||||
coloring_bomb_sprite.visible = false
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
if state_last != state:
|
||||
if state == PlayerState.Alive:
|
||||
on_player_spawn()
|
||||
elif state == PlayerState.Falling:
|
||||
on_player_falling()
|
||||
elif state == PlayerState.Dead:
|
||||
on_player_dead()
|
||||
|
||||
state_last = state
|
||||
|
||||
if global_position.y < -5:
|
||||
state = PlayerState.Dead
|
||||
elif not is_on_floor():
|
||||
if not is_dashing:
|
||||
velocity.y -= gravity * delta
|
||||
state = PlayerState.Falling
|
||||
@@ -62,15 +73,12 @@ func _physics_process(delta):
|
||||
state = PlayerState.Alive
|
||||
elif state == PlayerState.Dead:
|
||||
visible = false
|
||||
return
|
||||
elif state == PlayerState.Alive:
|
||||
visible = true
|
||||
|
||||
coloring_sprite.visible = state == PlayerState.Alive
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
if bomb_time > 0:
|
||||
bomb_time -= delta
|
||||
if bomb_time <= 0:
|
||||
@@ -95,7 +103,7 @@ func _physics_process(delta):
|
||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
geometry.global_basis = Basis.from_euler(Vector3(0, -angle, 0))
|
||||
|
||||
if Input.is_action_just_pressed(dash_action):
|
||||
if state == PlayerState.Alive and Input.is_action_just_pressed(dash_action):
|
||||
is_dashing = true;
|
||||
dash_time = DASH_DURATION
|
||||
|
||||
@@ -117,3 +125,12 @@ func _physics_process(delta):
|
||||
func calc_coloring_position():
|
||||
var result = Vector2 (global_position.x * 10 + 512, global_position.z * 10 + 512)
|
||||
return result;
|
||||
|
||||
func on_player_spawn():
|
||||
print ("Player " + str(self) + ": spawning")
|
||||
|
||||
func on_player_falling():
|
||||
print ("Player " + str(self) + ": falling")
|
||||
|
||||
func on_player_dead():
|
||||
print ("Player " + str(self) + ": death")
|
||||
|
||||
@@ -16,7 +16,7 @@ func on_player_enter(node: Node3D):
|
||||
if node == null:
|
||||
return
|
||||
|
||||
if not near_players.find(player):
|
||||
if near_players.find(player) == -1:
|
||||
near_players.append(player)
|
||||
|
||||
func on_player_exited(node: Node3D):
|
||||
|
||||
Reference in New Issue
Block a user