added health sprite to the game

This commit is contained in:
Stefan Stefanov 2024-02-10 18:11:18 +02:00
parent d21ccf3dc8
commit ec8ced3958
5 changed files with 37 additions and 13 deletions

View file

@ -3,6 +3,12 @@ REL_FOLDER=release_x64_win
DEB_FOLDER=debug_x64_win
BIN_FOLDER=./bin
run: build
${BIN_FOLDER}/${EXE}.exe
run_rel: build_release
${BIN_FOLDER}/${EXE}_rel.exe
build: clean
odin build . -out:${BIN_FOLDER}/${EXE}.exe -debug
@ -19,10 +25,3 @@ package: build_release
cp -r ./assets/ ${BIN_FOLDER}/${REL_FOLDER}/
cp ${BIN_FOLDER}/${EXE}_rel.exe ${BIN_FOLDER}/${REL_FOLDER}/${EXE}.exe
tar.exe -a -c -f ${BIN_FOLDER}/release_x64_win.zip ${BIN_FOLDER}/release_x64_win
run: build
${BIN_FOLDER}/${EXE}.exe
run_rel: build_release
${BIN_FOLDER}/${EXE}_rel.exe

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

@ -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)
}

View file

@ -103,6 +103,8 @@ main :: proc() {
if !ODIN_DEBUG {
rl.SetExitKey(nil)
} else {
log.info("Built with Odin compiler version: ", ODIN_VERSION)
}
texture_atlas_image = rl.LoadImage(TEXTURE_ATLAS_PATH)

View file

@ -28,6 +28,7 @@ PLAYER_RECT :: glm.vec2{SPRITE_CELL * GLOBAL_SPRITE_SCALE, SPRITE_CELL * GLOBAL_
// texture offset for ship
SHIP_TO :: glm.vec2{0, 112}
HEART_TO :: glm.vec2{16, 112}
BULLET_TO := [2]glm.vec2{{0, 80}, {16, 80}}
BULLET_FRAME_ANIM := 0