Setup initial fixed resolution rendering.
This commit is contained in:
+36
-13
@@ -4,6 +4,8 @@ import rl "vendor:raylib"
|
||||
|
||||
Game :: struct {
|
||||
assets: Asset_Manager,
|
||||
camera: rl.Camera2D,
|
||||
world: rl.RenderTexture2D,
|
||||
player: Player
|
||||
}
|
||||
|
||||
@@ -13,11 +15,10 @@ game_init :: proc() -> Game {
|
||||
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
// inits
|
||||
game.assets = asset_manager_init()
|
||||
game.player = player_init(&game.assets.player)
|
||||
|
||||
if DEBUG_MODE do rl.TraceLog(.INFO, "Game initialized")
|
||||
game.camera = camera_init(game.player, 1)
|
||||
game.world = rl.LoadRenderTexture(GAME_WIDTH, GAME_HEIGHT)
|
||||
|
||||
return game
|
||||
}
|
||||
@@ -28,25 +29,47 @@ game_should_run :: proc(game: ^Game) -> bool {
|
||||
|
||||
game_update :: proc(game: ^Game) {
|
||||
update_player(&game.player, &game.assets.player)
|
||||
update_camera(game.player.pos, &game.camera)
|
||||
}
|
||||
|
||||
game_draw :: proc(game: ^Game) {
|
||||
rl.BeginDrawing()
|
||||
|
||||
// Do Draw Calls here
|
||||
rl.ClearBackground(rl.DARKGRAY)
|
||||
|
||||
if DEBUG_MODE do rl.DrawFPS(20, 20)
|
||||
|
||||
// Renderer calls
|
||||
rl.BeginTextureMode(game.world)
|
||||
rl.ClearBackground(rl.BLACK)
|
||||
rl.BeginMode2D(game.camera)
|
||||
draw_camera(&game.camera)
|
||||
renderer_draw_player(&game.player)
|
||||
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 functions
|
||||
// ---------
|
||||
debug_fps()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
game_close :: proc(game: ^Game) {
|
||||
// cleanup sub systems
|
||||
asset_manager_destroy(&game.assets)
|
||||
|
||||
rl.UnloadRenderTexture(game.world)
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user