diff --git a/main.odin b/main.odin index 85a7d5a..291bab2 100644 --- a/main.odin +++ b/main.odin @@ -17,24 +17,22 @@ GameEndType :: enum { } state: GameState -ratio: i32 +ratio: f32 texture_atlas_image: rl.Image texture_atlas: rl.Texture2D -camera := rl.Camera2D { - zoom = GLOBAL_SPRITE_SCALE, -} +window_width: i32 +window_height: i32 -window_width : i32; window_height: i32 // orignal resolution of space invaders: 256 x 224 px setup :: proc(state: ^GameState) { using state target_fps = 60 - monitor := rl.GetCurrentMonitor() - window_width = rl.GetMonitorWidth(monitor) - window_height = rl.GetMonitorHeight(monitor) + // monitor := rl.GetCurrentMonitor() + window_width = rl.GetScreenWidth() + window_height = rl.GetScreenHeight() current_frame_time = rl.GetTime() previous_screen = .TITLE @@ -60,6 +58,7 @@ update :: proc(state: ^GameState) { update_screen(state) } + target: rl.RenderTexture2D draw :: proc(state: ^GameState) { rl.BeginTextureMode(target) @@ -75,10 +74,10 @@ draw :: proc(state: ^GameState) { target.texture, {0, 0, f32(target.texture.width), f32(-target.texture.height)}, { - f32((window_width - (target.texture.width * ratio)) / 2), + (f32(window_width) - (f32(target.texture.width) * ratio)) / 2, 0, - f32(target.texture.width * ratio), - f32(target.texture.height * ratio), + f32(target.texture.width) * ratio, + f32(target.texture.height) * ratio, }, {0, 0}, 0, @@ -103,9 +102,11 @@ main :: proc() { state.screen_width = 720 state.screen_height = 520 + rl.SetWindowMinSize(state.screen_width, state.screen_height) + target = rl.LoadRenderTexture(state.screen_width, state.screen_height) defer rl.UnloadRenderTexture(target) - ratio = i32(window_height / target.texture.height) + ratio = f32(window_height) / f32(target.texture.height) texture_atlas_image = rl.LoadImage(TEXTURE_ATLAS_PATH) texture_atlas = rl.LoadTextureFromImage(texture_atlas_image) @@ -113,6 +114,11 @@ main :: proc() { log.info("Loaded images") for !rl.WindowShouldClose() { + if rl.IsWindowResized() { + window_width = rl.GetScreenWidth() + window_height = rl.GetScreenHeight() + ratio = f32(window_height) / f32(target.texture.height) + } update(&state) draw(&state) }