Files
pong_raylib/src/game.odin
T

85 lines
2.4 KiB
Odin

package game
import rl "vendor:raylib"
WINDOW_TITLE :: "Pong"
// good 16:9 baseline res, scales up to 1080 or 4k clean.
VIEWPORT_WIDTH :: 1280
VIEWPORT_HEIGHT :: 720
// Window size is what the viewport scales to
//WINDOW_WIDTH :: 2560
// WINDOW_HEIGHT :: 1440
WINDOW_WIDTH :: 1280
WINDOW_HEIGHT :: 720
Game :: struct {
current_scene: Scene,
is_paused: bool,
score_player: int,
score_enemy: int,
}
// ------------------------------------------------------------------------------
// Game initializes and sets up any needed state
// - Then we load in the initial scene
// ------------------------------------------------------------------------------
game_init :: proc(game: ^Game) {
// Window configs
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)
rl.SetTargetFPS(60)
// initial state
game.score_player = 0
game.score_enemy = 0
game.is_paused = false
// initial scene (should be menu when setup)
game.current_scene = init_gameplay_scene()
// init any systems/managers
// game.input_manager = ....
// game.audio_manager = ....
}
// ------------------------------------------------------------------------------
// Game loop update phase
// - TODO: get inputs pressed and store them
// - apply any updates to the current scene
// ------------------------------------------------------------------------------
game_update :: proc(game: ^Game) {
dt := rl.GetFrameTime()
// TODO: Get an input manager here
// Update the current scene
scene_update(game, dt)
}
// ------------------------------------------------------------------------------
// Game loop integration phase
// - after the states and scene has been updated render whats active
// ------------------------------------------------------------------------------
game_render :: proc(game: ^Game) {
rl.BeginDrawing()
rl.ClearBackground(rl.BLACK)
// render the current scene
scene_render(game)
rl.EndDrawing()
}
// ------------------------------------------------------------------------------
// Game shutdown
// - before closing windows etc we cleanup free anything that was allocated
// ------------------------------------------------------------------------------
game_quit :: proc(game: ^Game) {
// TODO: any cleanup goes here before
// shutting down the window
rl.CloseWindow()
}
game_should_run :: proc() -> bool {
return !rl.WindowShouldClose()
}