Added more flexible scaling
This commit is contained in:
parent
7eaa303d6f
commit
bb4393557a
1 changed files with 18 additions and 12 deletions
30
main.odin
30
main.odin
|
|
@ -17,24 +17,22 @@ GameEndType :: enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
state: GameState
|
state: GameState
|
||||||
ratio: i32
|
ratio: f32
|
||||||
|
|
||||||
texture_atlas_image: rl.Image
|
texture_atlas_image: rl.Image
|
||||||
texture_atlas: rl.Texture2D
|
texture_atlas: rl.Texture2D
|
||||||
|
|
||||||
camera := rl.Camera2D {
|
window_width: i32
|
||||||
zoom = GLOBAL_SPRITE_SCALE,
|
window_height: i32
|
||||||
}
|
|
||||||
|
|
||||||
window_width : i32; window_height: i32
|
|
||||||
// orignal resolution of space invaders: 256 x 224 px
|
// orignal resolution of space invaders: 256 x 224 px
|
||||||
setup :: proc(state: ^GameState) {
|
setup :: proc(state: ^GameState) {
|
||||||
using state
|
using state
|
||||||
target_fps = 60
|
target_fps = 60
|
||||||
|
|
||||||
monitor := rl.GetCurrentMonitor()
|
// monitor := rl.GetCurrentMonitor()
|
||||||
window_width = rl.GetMonitorWidth(monitor)
|
window_width = rl.GetScreenWidth()
|
||||||
window_height = rl.GetMonitorHeight(monitor)
|
window_height = rl.GetScreenHeight()
|
||||||
|
|
||||||
current_frame_time = rl.GetTime()
|
current_frame_time = rl.GetTime()
|
||||||
previous_screen = .TITLE
|
previous_screen = .TITLE
|
||||||
|
|
@ -60,6 +58,7 @@ update :: proc(state: ^GameState) {
|
||||||
|
|
||||||
update_screen(state)
|
update_screen(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
target: rl.RenderTexture2D
|
target: rl.RenderTexture2D
|
||||||
draw :: proc(state: ^GameState) {
|
draw :: proc(state: ^GameState) {
|
||||||
rl.BeginTextureMode(target)
|
rl.BeginTextureMode(target)
|
||||||
|
|
@ -75,10 +74,10 @@ draw :: proc(state: ^GameState) {
|
||||||
target.texture,
|
target.texture,
|
||||||
{0, 0, f32(target.texture.width), f32(-target.texture.height)},
|
{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,
|
0,
|
||||||
f32(target.texture.width * ratio),
|
f32(target.texture.width) * ratio,
|
||||||
f32(target.texture.height * ratio),
|
f32(target.texture.height) * ratio,
|
||||||
},
|
},
|
||||||
{0, 0},
|
{0, 0},
|
||||||
0,
|
0,
|
||||||
|
|
@ -103,9 +102,11 @@ main :: proc() {
|
||||||
state.screen_width = 720
|
state.screen_width = 720
|
||||||
state.screen_height = 520
|
state.screen_height = 520
|
||||||
|
|
||||||
|
rl.SetWindowMinSize(state.screen_width, state.screen_height)
|
||||||
|
|
||||||
target = rl.LoadRenderTexture(state.screen_width, state.screen_height)
|
target = rl.LoadRenderTexture(state.screen_width, state.screen_height)
|
||||||
defer rl.UnloadRenderTexture(target)
|
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_image = rl.LoadImage(TEXTURE_ATLAS_PATH)
|
||||||
texture_atlas = rl.LoadTextureFromImage(texture_atlas_image)
|
texture_atlas = rl.LoadTextureFromImage(texture_atlas_image)
|
||||||
|
|
@ -113,6 +114,11 @@ main :: proc() {
|
||||||
log.info("Loaded images")
|
log.info("Loaded images")
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
if rl.IsWindowResized() {
|
||||||
|
window_width = rl.GetScreenWidth()
|
||||||
|
window_height = rl.GetScreenHeight()
|
||||||
|
ratio = f32(window_height) / f32(target.texture.height)
|
||||||
|
}
|
||||||
update(&state)
|
update(&state)
|
||||||
draw(&state)
|
draw(&state)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue