added health sprite to the game
This commit is contained in:
parent
d21ccf3dc8
commit
ec8ced3958
5 changed files with 37 additions and 13 deletions
34
game.odin
34
game.odin
|
|
@ -155,10 +155,10 @@ update_game :: proc(state: ^GameState) {
|
|||
// to shoot a bullet towards the player
|
||||
for alien_idx in 0 ..< ALIENS_PER_ROW {
|
||||
result := rand.uint32(&rng)
|
||||
for row := ALIEN_ROWS-1; row >= 0; row -= 1 {
|
||||
for row := ALIEN_ROWS - 1; row >= 0; row -= 1 {
|
||||
alien := aliens[(row * ALIENS_PER_ROW) + alien_idx]
|
||||
if alien.alive {
|
||||
if result % 3 == 0 {
|
||||
if result % 6 == 0 && frame_counter % int(target_fps * 1) == 0 {
|
||||
fire_bullet(&bullets, &bullet_index, false, &alien)
|
||||
}
|
||||
break
|
||||
|
|
@ -171,7 +171,7 @@ update_game :: proc(state: ^GameState) {
|
|||
for &bullet, bi in bullets {
|
||||
if !bullet.alive {continue}
|
||||
// Update bullet pos first
|
||||
bullet_dir : f32 = bullet.player_bullet ? -1 : 1
|
||||
bullet_dir: f32 = bullet.player_bullet ? -1 : 1
|
||||
bullet.position.y += f32(BULLET_SPEED * delta_time) * bullet_dir
|
||||
}
|
||||
corner_alien_pos :=
|
||||
|
|
@ -213,8 +213,14 @@ update_game :: proc(state: ^GameState) {
|
|||
for &bullet, bi in bullets {
|
||||
if !bullet.alive {continue}
|
||||
// Collision check bullet
|
||||
if collideAABB(ALIEN_RECT, alien.position, BULLET_RECT, bullet.position) {
|
||||
bullet, alien = damage_alien(state, bullets[bi], aliens[ai])
|
||||
if bullet.player_bullet {
|
||||
if collideAABB(ALIEN_RECT, alien.position, BULLET_RECT, bullet.position) {
|
||||
bullet, alien = damage_alien(state, bullets[bi], aliens[ai])
|
||||
}
|
||||
} else {
|
||||
if collideAABB(PLAYER_RECT, player_pos, BULLET_RECT, bullet.position) {
|
||||
bullet = damage_player(state, bullets[bi])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -361,6 +367,22 @@ draw_game :: proc(state: ^GameState) {
|
|||
)
|
||||
}
|
||||
|
||||
rl.DrawText(rl.TextFormat("Score: %d", player_score), 20, 0, 20, rl.WHITE)
|
||||
rl.DrawText(rl.TextFormat("SCORE: %d", player_score), 20, 0, 20, rl.WHITE)
|
||||
for heart, hi in 0..= player_health {
|
||||
rl.DrawTexturePro(
|
||||
texture_atlas,
|
||||
{HEART_TO.x, HEART_TO.y, SPRITE_CELL, SPRITE_CELL},
|
||||
{
|
||||
f32(screen_width / GLOBAL_SPRITE_SCALE) - f32(hi * SPRITE_CELL * GLOBAL_SPRITE_SCALE),
|
||||
0,
|
||||
f32(PLAYER_RECT.x),
|
||||
f32(PLAYER_RECT.y),
|
||||
},
|
||||
{0,0},
|
||||
0,
|
||||
rl.WHITE,
|
||||
)
|
||||
}
|
||||
|
||||
// rl.DrawText("GAMEPLAY SCREEN", 20, 20, 40, rl.MAROON)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue