diff --git a/Makefile b/Makefile index c32d29e..25efb0d 100644 --- a/Makefile +++ b/Makefile @@ -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 - diff --git a/assets/texture_atlas.png b/assets/texture_atlas.png index 723bd83..70d4050 100644 Binary files a/assets/texture_atlas.png and b/assets/texture_atlas.png differ diff --git a/game.odin b/game.odin index 54891bb..b3ac427 100644 --- a/game.odin +++ b/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) } diff --git a/main.odin b/main.odin index fad77f9..6c300cf 100644 --- a/main.odin +++ b/main.odin @@ -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) diff --git a/sprites.odin b/sprites.odin index 8a2f6c5..95707f3 100644 --- a/sprites.odin +++ b/sprites.odin @@ -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