working game loop, lacking alien shooting

This commit is contained in:
Stefan Stefanov 2024-02-10 14:59:13 +02:00
parent 0aa534c4d1
commit 19bff3176d
4 changed files with 194 additions and 76 deletions

View file

@ -11,8 +11,13 @@ import rl "vendor:raylib"
TEXTURE_ATLAS_PATH :: "./assets/texture_atlas.png"
DEBUG_MODE :: true
DEBUG_MODE :: false
GameEndType :: enum {
AllAliensKilled,
PlayerDied,
AliensReachedPlayer,
}
GameState :: struct {
// window
@ -29,6 +34,7 @@ GameState :: struct {
screen: GameScreen,
previous_screen: GameScreen,
last_frame_screen: GameScreen,
game_end: GameEndType,
reset_game: bool,
aliens: #soa[ALIENS]Alien,
bullets: #soa[MAX_BULLETS]Bullet,
@ -37,17 +43,23 @@ GameState :: struct {
player_health: c.int,
player_score: c.int,
player_high_score: c.int,
shuffle_dir: ShuffleDirection,
last_shuffle_dir: ShuffleDirection,
}
state: GameState
texture_atlas_image : rl.Image
texture_atlas : rl.Texture2D
texture_atlas_image: rl.Image
texture_atlas: rl.Texture2D
camera := rl.Camera2D {
zoom = 2,
}
setup :: proc(state: ^GameState) {
using state
target_fps = 60
screen_width = 800
screen_height = 600
screen_width = 800 * 2
screen_height = 600 * 2
title = "Space Invaders (raylib+odin-lang edition)"
current_frame_time = rl.GetTime()
@ -72,7 +84,9 @@ update :: proc(state: ^GameState) {
draw :: proc(state: ^GameState) {
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE)
rl.BeginMode2D(camera)
draw_screen(state)
rl.EndMode2D()
rl.EndDrawing()
}