added different scaling, breaking change
This commit is contained in:
parent
8bc4572ae3
commit
799e5ad9eb
4 changed files with 92 additions and 57 deletions
94
main.odin
94
main.odin
|
|
@ -6,9 +6,6 @@ import glm "core:math/linalg/glsl"
|
|||
|
||||
import rl "vendor:raylib"
|
||||
|
||||
// orignal resolution of space invaders
|
||||
// 256 x 224 px
|
||||
|
||||
TEXTURE_ATLAS_PATH :: "./assets/texture_atlas.png"
|
||||
|
||||
DEBUG_MODE :: false
|
||||
|
|
@ -19,55 +16,36 @@ GameEndType :: enum {
|
|||
AliensReachedPlayer,
|
||||
}
|
||||
|
||||
GameState :: struct {
|
||||
// window
|
||||
target_fps: c.int,
|
||||
title: cstring,
|
||||
screen_width: c.int,
|
||||
screen_height: c.int,
|
||||
// frame stats
|
||||
frame_counter: int,
|
||||
current_frame_time: f64,
|
||||
last_frame_time: f64,
|
||||
delta_time: f64,
|
||||
// game vars
|
||||
screen: GameScreen,
|
||||
previous_screen: GameScreen,
|
||||
last_frame_screen: GameScreen,
|
||||
game_end: GameEndType,
|
||||
reset_game: bool,
|
||||
aliens: #soa[ALIENS]Alien,
|
||||
bullets: #soa[MAX_BULLETS]Bullet,
|
||||
bullet_index: int,
|
||||
player_last_time_fired: f64,
|
||||
player_pos: glm.vec2,
|
||||
player_health: c.int,
|
||||
player_score: c.int,
|
||||
player_high_score: c.int,
|
||||
shuffle_dir: ShuffleDirection,
|
||||
last_shuffle_dir: ShuffleDirection,
|
||||
}
|
||||
state: GameState
|
||||
ratio: i32
|
||||
|
||||
texture_atlas_image: rl.Image
|
||||
texture_atlas: rl.Texture2D
|
||||
|
||||
camera := rl.Camera2D {
|
||||
zoom = 2,
|
||||
zoom = GLOBAL_SPRITE_SCALE,
|
||||
}
|
||||
|
||||
// orignal resolution of space invaders: 256 x 224 px
|
||||
setup :: proc(state: ^GameState) {
|
||||
using state
|
||||
target_fps = 60
|
||||
screen_width = 800 * 2
|
||||
screen_height = 600 * 2
|
||||
title = "Space Invaders (raylib+odin-lang edition)"
|
||||
|
||||
monitor := rl.GetCurrentMonitor()
|
||||
screen_width = rl.GetMonitorWidth(monitor)
|
||||
screen_height = rl.GetMonitorHeight(monitor)
|
||||
|
||||
current_frame_time = rl.GetTime()
|
||||
previous_screen = .TITLE
|
||||
screen = .TITLE
|
||||
|
||||
rl.SetTargetFPS(target_fps)
|
||||
|
||||
if !ODIN_DEBUG {
|
||||
rl.SetExitKey(nil)
|
||||
} else {
|
||||
log.info("Built with Odin compiler version: ", ODIN_VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
update :: proc(state: ^GameState) {
|
||||
|
|
@ -81,13 +59,31 @@ update :: proc(state: ^GameState) {
|
|||
|
||||
update_screen(state)
|
||||
}
|
||||
|
||||
target: rl.RenderTexture2D
|
||||
draw :: proc(state: ^GameState) {
|
||||
rl.BeginTextureMode(target)
|
||||
{
|
||||
draw_screen(state)
|
||||
}
|
||||
rl.EndTextureMode()
|
||||
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RAYWHITE)
|
||||
rl.BeginMode2D(camera)
|
||||
draw_screen(state)
|
||||
rl.EndMode2D()
|
||||
{
|
||||
rl.ClearBackground(rl.RAYWHITE)
|
||||
rl.DrawTexturePro(
|
||||
target.texture,
|
||||
{0, 0, f32(target.texture.width), f32(-target.texture.height)},
|
||||
{
|
||||
f32((state.screen_width - (target.texture.width * ratio)) / 2),
|
||||
0,
|
||||
f32(target.texture.width * ratio),
|
||||
f32(target.texture.height * ratio),
|
||||
},
|
||||
{0, 0},
|
||||
0,
|
||||
rl.WHITE,
|
||||
)
|
||||
}
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
|
|
@ -96,16 +92,18 @@ main :: proc() {
|
|||
|
||||
log.info(state.screen)
|
||||
|
||||
|
||||
rl.InitWindow(1200, 720, "title")
|
||||
defer rl.CloseWindow()
|
||||
rl.RestoreWindow()
|
||||
rl.SetWindowState({.WINDOW_RESIZABLE, .WINDOW_MAXIMIZED})
|
||||
|
||||
setup(&state)
|
||||
|
||||
rl.InitWindow(state.screen_width, state.screen_height, state.title)
|
||||
defer rl.CloseWindow()
|
||||
|
||||
if !ODIN_DEBUG {
|
||||
rl.SetExitKey(nil)
|
||||
} else {
|
||||
log.info("Built with Odin compiler version: ", ODIN_VERSION)
|
||||
}
|
||||
width: i32 = 720;height: i32 = 520
|
||||
target = rl.LoadRenderTexture(width, height)
|
||||
defer rl.UnloadRenderTexture(target)
|
||||
ratio = i32(state.screen_height / target.texture.height)
|
||||
|
||||
texture_atlas_image = rl.LoadImage(TEXTURE_ATLAS_PATH)
|
||||
texture_atlas = rl.LoadTextureFromImage(texture_atlas_image)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue