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