Skip to content

Commit

Permalink
player can no longer fire infinitely
Browse files Browse the repository at this point in the history
  • Loading branch information
Acepie committed Apr 25, 2024
1 parent fdc8681 commit 6530ef4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/bullet_heck_gleam.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ fn on_key_released(key: String, _: Int, state: WorldState) -> WorldState {
}

fn on_mouse_clicked(x: Float, y: Float, state: WorldState) -> WorldState {
let GameRunning(_dungeon, player, bullets) = state
use <- bool.guard(!player.can_player_fire(player), state)

let firing_direction =
vector.vector_2d(vector.subtract(
vector.Vector(x, y, 0.0),
state.player.position,
))
let player.Player(position: p, ..) = state.player
vector.vector_2d(vector.subtract(vector.Vector(x, y, 0.0), player.position))
let player.Player(position: p, ..) = player
GameRunning(
..state,
bullets: [
bullet.spawn_bullet(vector.Vector(p.x, p.y, 0.0), firing_direction, True),
..state.bullets
..bullets
],
)
}
Expand Down
7 changes: 6 additions & 1 deletion src/player.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ pub fn is_player_dead(player: Player) -> Bool {

/// Is the player currently invulnerable.
pub fn is_player_invulnerable(player: Player) -> Bool {
player.last_hit_time + invulnerability_time <= utils.now_in_milliseconds()
player.last_hit_time + invulnerability_time >= utils.now_in_milliseconds()
}

/// Can the player fire a bullet at the moment.
pub fn can_player_fire(player: Player) -> Bool {
player.last_fire_time + time_between_fire <= utils.now_in_milliseconds()
}

const dead_fill_color = "#000000"
Expand Down

0 comments on commit 6530ef4

Please sign in to comment.