Added energy and replenishment

This commit is contained in:
Martin Felis
2024-01-27 23:30:23 +01:00
parent a04f8196f9
commit c467182087
5 changed files with 43 additions and 13 deletions
+25 -7
View File
@@ -24,7 +24,7 @@ enum PlayerState {
}
var score : int = 0
var energy : float = 1.0
var energy : float = 100.0
var state : PlayerState = PlayerState.Alive
var state_last : PlayerState = PlayerState.Dead
@@ -39,7 +39,10 @@ var coloring_bomb_sprite : Sprite2D
const SPEED = 5.0
const DASH_SPEED: float = 20
const DASH_DURATION: float = 0.2
const DASH_ENERGY: float = 40
const BOMB_DURATION: float = 0.1
const BOMB_ENERGY: float = 60
const ENERGY_REPLENISH_RATE: float = 0.5;
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@@ -53,6 +56,9 @@ func _ready():
coloring_bomb_sprite.visible = false
func _physics_process(delta):
if energy < 100:
energy = min (100, energy + delta + ENERGY_REPLENISH_RATE)
if state_last != state:
if state == PlayerState.Alive:
on_player_spawn()
@@ -85,9 +91,10 @@ func _physics_process(delta):
coloring_bomb_sprite.visible = false
bomb_time = 0
else:
if Input.is_action_just_pressed(bomb_action) and state == PlayerState.Alive:
coloring_bomb_sprite.visible = true;
bomb_time = BOMB_DURATION
if Input.is_action_just_pressed(bomb_action) \
and state == PlayerState.Alive \
and energy > BOMB_ENERGY:
on_drop_bomb()
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
@@ -103,9 +110,10 @@ func _physics_process(delta):
velocity.z = move_toward(velocity.z, 0, SPEED)
geometry.global_basis = Basis.from_euler(Vector3(0, -angle, 0))
if state == PlayerState.Alive and Input.is_action_just_pressed(dash_action):
is_dashing = true;
dash_time = DASH_DURATION
if Input.is_action_just_pressed(dash_action) \
and state == PlayerState.Alive \
and energy > DASH_ENERGY:
on_dash()
if is_dashing:
velocity.x = sin(angle) * DASH_SPEED
@@ -134,3 +142,13 @@ func on_player_falling():
func on_player_dead():
print ("Player " + str(self) + ": death")
func on_dash():
is_dashing = true;
dash_time = DASH_DURATION
energy = max (0, energy - DASH_ENERGY)
func on_drop_bomb():
coloring_bomb_sprite.visible = true;
bomb_time = BOMB_DURATION
energy = max (0, energy - BOMB_ENERGY)