Files
raylib_reference/src/game.odin
T
2026-07-16 07:50:01 +02:00

93 lines
1.9 KiB
Odin

package game
import rl "vendor:raylib"
Game :: struct {
assets: Asset_Manager,
camera: rl.Camera2D,
world: rl.RenderTexture2D,
current_map: Game_Map,
player: Player,
debug: Debug
}
game_init :: proc() -> Game {
game := Game{}
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)
rl.SetTargetFPS(60)
game.assets = asset_manager_init()
game.player = player_init(&game.assets.player)
game.camera = camera_init(game.player, 1)
game.world = rl.LoadRenderTexture(GAME_WIDTH, GAME_HEIGHT)
game.current_map = map_init()
// DEBUG
debug_init(&game)
return game
}
game_should_run :: proc(game: ^Game) -> bool {
return !rl.WindowShouldClose()
}
game_update :: proc(game: ^Game) {
update_player(&game.player, &game.assets.player, game.camera)
update_camera(game.player.pos, &game.camera)
// DEBUG
debug_camera_update(&game.debug)
}
game_draw :: proc(game: ^Game) {
cam := game.camera
if game.debug.camera_active {
cam = game.debug.camera
}
rl.BeginTextureMode(game.world)
rl.ClearBackground(rl.BLACK)
rl.BeginMode2D(cam)
draw_map(game.current_map)
draw_player(&game.player)
// DEBUG
debug_camera_draw(&game.camera, game.debug.camera_active)
debug_bounds(game)
rl.EndMode2D()
rl.EndTextureMode()
rl.BeginDrawing()
rl.ClearBackground(rl.BLACK)
rl.DrawTexturePro(
game.world.texture,
rl.Rectangle{
x = 0, y = 0,
width = f32(game.world.texture.width),
// raylib opengl negative to flip Y?
height = -f32(game.world.texture.height),
},
rl.Rectangle{
x = 0, y = 0,
width = f32(rl.GetScreenWidth()),
height = f32(rl.GetScreenHeight()),
},
rl.Vector2{},
0,
rl.WHITE,
)
// DEBUG
debug_fps()
rl.EndDrawing()
}
game_close :: proc(game: ^Game) {
asset_manager_destroy(&game.assets)
rl.UnloadRenderTexture(game.world)
rl.CloseWindow()
}