init, working screens from raylib screens example and basic bullets mechanics
This commit is contained in:
commit
178cf92f44
3 changed files with 301 additions and 0 deletions
83
main.odin
Normal file
83
main.odin
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
package space_invaders
|
||||
|
||||
import "core:c"
|
||||
import "core:log"
|
||||
import glm "core:math/linalg/glsl"
|
||||
|
||||
import rl "vendor:raylib"
|
||||
|
||||
// orignal resolution of space invaders
|
||||
// 256 x 224 px
|
||||
|
||||
GameState :: struct {
|
||||
// window
|
||||
target_fps: c.int,
|
||||
title: cstring,
|
||||
screen_width: c.int,
|
||||
screen_height: c.int,
|
||||
// frame stats
|
||||
frame_counter: int,
|
||||
current_frame_time: f64,
|
||||
last_frame_time: f64,
|
||||
delta_time: f64,
|
||||
// game vars
|
||||
screen: GameScreen,
|
||||
previous_screen: GameScreen,
|
||||
last_frame_screen: GameScreen,
|
||||
aliens: #soa[ALIENS]Alien,
|
||||
bullets: #soa[MAX_BULLETS]Bullet,
|
||||
bullet_index: int,
|
||||
player_pos: glm.vec2,
|
||||
player_health: c.int,
|
||||
player_score: c.int,
|
||||
}
|
||||
state: GameState
|
||||
|
||||
setup :: proc(state: ^GameState) {
|
||||
using state
|
||||
target_fps = 60
|
||||
screen_width = 800
|
||||
screen_height = 600
|
||||
title = "Space Invaders (raylib+odin-lang edition)"
|
||||
|
||||
current_frame_time = rl.GetTime()
|
||||
previous_screen = .LOGO
|
||||
screen = .GAMEPLAY
|
||||
|
||||
rl.SetTargetFPS(target_fps)
|
||||
}
|
||||
|
||||
update :: proc(state: ^GameState) {
|
||||
using state
|
||||
|
||||
frame_counter += 1
|
||||
|
||||
last_frame_time = current_frame_time
|
||||
current_frame_time = rl.GetTime()
|
||||
delta_time = current_frame_time - last_frame_time
|
||||
|
||||
update_screen(state)
|
||||
}
|
||||
|
||||
draw :: proc(state: ^GameState) {
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RAYWHITE)
|
||||
draw_screen(state)
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
context.logger = log.create_console_logger()
|
||||
|
||||
log.info(state.screen)
|
||||
|
||||
setup(&state)
|
||||
|
||||
rl.InitWindow(state.screen_width, state.screen_height, state.title)
|
||||
defer rl.CloseWindow()
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
update(&state)
|
||||
draw(&state)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue