end of scaling issues (tm)
This commit is contained in:
parent
799e5ad9eb
commit
7eaa303d6f
4 changed files with 22 additions and 34 deletions
17
game.odin
17
game.odin
|
|
@ -54,8 +54,8 @@ setup_game :: proc(state: ^GameState) {
|
|||
using state
|
||||
|
||||
player_pos = glm.vec2 {
|
||||
f32(screen_width) / (2 * camera.zoom),
|
||||
f32(screen_height) / camera.zoom - PLAYER_RECT.x,
|
||||
f32(screen_width) / 2,
|
||||
f32(screen_height) - PLAYER_RECT.x,
|
||||
}
|
||||
player_score = 0
|
||||
player_health = 3
|
||||
|
|
@ -101,14 +101,8 @@ update_game :: proc(state: ^GameState) {
|
|||
// update bullet frame idx
|
||||
if frame_counter % 10 == 0 {BULLET_FRAME_ANIM = (BULLET_FRAME_ANIM + 1) % len(BULLET_TO)}
|
||||
|
||||
// Press enter to change to ENDING screen
|
||||
if (rl.IsKeyPressed(rl.KeyboardKey.ENTER)) {
|
||||
state.screen = .ENDING
|
||||
log.info("Updated screen enum", state.screen)
|
||||
}
|
||||
|
||||
// Press space to change to fire
|
||||
if (rl.IsKeyPressed(rl.KeyboardKey.SPACE)) {
|
||||
if (rl.IsKeyPressed(rl.KeyboardKey.SPACE) || rl.IsKeyPressed(rl.KeyboardKey.ENTER)) {
|
||||
fire_bullet(&bullets, &bullet_index)
|
||||
}
|
||||
|
||||
|
|
@ -147,6 +141,7 @@ update_game :: proc(state: ^GameState) {
|
|||
|
||||
if game_over {
|
||||
screen = .ENDING
|
||||
log.info("Game over!", game_end)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -177,7 +172,7 @@ update_game :: proc(state: ^GameState) {
|
|||
corner_alien_pos :=
|
||||
shuffle_dir == .RIGHT ? aliens[ALIENS_PER_ROW - 1].position : aliens[0].position
|
||||
if corner_alien_pos.x <= SPRITE_CELL ||
|
||||
corner_alien_pos.x >= f32(screen_width / GLOBAL_SPRITE_SCALE) - SPRITE_CELL ||
|
||||
corner_alien_pos.x >= f32(screen_width) - SPRITE_CELL ||
|
||||
shuffle_dir == .DOWN {
|
||||
switch shuffle_dir {
|
||||
case .RIGHT:
|
||||
|
|
@ -373,7 +368,7 @@ draw_game :: proc(state: ^GameState) {
|
|||
texture_atlas,
|
||||
{HEART_TO.x, HEART_TO.y, SPRITE_CELL, SPRITE_CELL},
|
||||
{
|
||||
f32(screen_width / GLOBAL_SPRITE_SCALE) - f32(hi * SPRITE_CELL * GLOBAL_SPRITE_SCALE),
|
||||
f32(screen_width) - f32(hi * SPRITE),
|
||||
0,
|
||||
f32(PLAYER_RECT.x),
|
||||
f32(PLAYER_RECT.y),
|
||||
|
|
|
|||
14
main.odin
14
main.odin
|
|
@ -26,14 +26,15 @@ camera := rl.Camera2D {
|
|||
zoom = GLOBAL_SPRITE_SCALE,
|
||||
}
|
||||
|
||||
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()
|
||||
screen_width = rl.GetMonitorWidth(monitor)
|
||||
screen_height = rl.GetMonitorHeight(monitor)
|
||||
window_width = rl.GetMonitorWidth(monitor)
|
||||
window_height = rl.GetMonitorHeight(monitor)
|
||||
|
||||
current_frame_time = rl.GetTime()
|
||||
previous_screen = .TITLE
|
||||
|
|
@ -74,7 +75,7 @@ draw :: proc(state: ^GameState) {
|
|||
target.texture,
|
||||
{0, 0, f32(target.texture.width), f32(-target.texture.height)},
|
||||
{
|
||||
f32((state.screen_width - (target.texture.width * ratio)) / 2),
|
||||
f32((window_width - (target.texture.width * ratio)) / 2),
|
||||
0,
|
||||
f32(target.texture.width * ratio),
|
||||
f32(target.texture.height * ratio),
|
||||
|
|
@ -99,11 +100,12 @@ main :: proc() {
|
|||
rl.SetWindowState({.WINDOW_RESIZABLE, .WINDOW_MAXIMIZED})
|
||||
|
||||
setup(&state)
|
||||
state.screen_width = 720
|
||||
state.screen_height = 520
|
||||
|
||||
width: i32 = 720;height: i32 = 520
|
||||
target = rl.LoadRenderTexture(width, height)
|
||||
target = rl.LoadRenderTexture(state.screen_width, state.screen_height)
|
||||
defer rl.UnloadRenderTexture(target)
|
||||
ratio = i32(state.screen_height / target.texture.height)
|
||||
ratio = i32(window_height / target.texture.height)
|
||||
|
||||
texture_atlas_image = rl.LoadImage(TEXTURE_ATLAS_PATH)
|
||||
texture_atlas = rl.LoadTextureFromImage(texture_atlas_image)
|
||||
|
|
|
|||
19
screens.odin
19
screens.odin
|
|
@ -50,22 +50,13 @@ draw_screen :: proc(state: ^GameState) {
|
|||
switch state.screen {
|
||||
case .TITLE:
|
||||
{
|
||||
rl.DrawRectangle(0, 0, state.screen_width, state.screen_height, rl.WHITE)
|
||||
rl.DrawRectangle(0, 0, state.screen_width, state.screen_height, rl.BLACK)
|
||||
|
||||
rl.DrawCircle(0, 0, 20, rl.RED)
|
||||
rl.DrawTexturePro(
|
||||
texture_atlas,
|
||||
{LOGO_TO[0].x, LOGO_TO[0].y, LOGO_TO[1].x, LOGO_TO[1].y},
|
||||
{
|
||||
f32(screen_width / GLOBAL_SPRITE_SCALE),
|
||||
f32(screen_height / GLOBAL_SPRITE_SCALE),
|
||||
LOGO_TO[1].x * 4,
|
||||
LOGO_TO[1].y * 4,
|
||||
},
|
||||
{
|
||||
f32(screen_width / GLOBAL_SPRITE_SCALE),
|
||||
f32(screen_height / GLOBAL_SPRITE_SCALE),
|
||||
},
|
||||
{0, 0, LOGO_TO[1].x * 4, LOGO_TO[1].y * 4},
|
||||
{f32(-screen_width/4), f32(-screen_height/3)},
|
||||
0,
|
||||
rl.GREEN,
|
||||
)
|
||||
|
|
@ -73,8 +64,8 @@ draw_screen :: proc(state: ^GameState) {
|
|||
size := rl.MeasureText(text, 20)
|
||||
rl.DrawText(
|
||||
text,
|
||||
(screen_width / 4) - (size / 2),
|
||||
(screen_height / 2) - 20,
|
||||
(screen_width / 2) - (size / 2),
|
||||
screen_height - 20,
|
||||
20,
|
||||
rl.DARKGREEN,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,17 +15,17 @@ ALIEN_ROWS :: 5
|
|||
ALIENS_PER_ROW :: 11
|
||||
ALIENS :: ALIEN_ROWS * ALIENS_PER_ROW
|
||||
ALIEN_SIDE_STEP :: 20 * GLOBAL_SPRITE_SCALE
|
||||
ALIEN_RECT :: glm.vec2{SPRITE_CELL * GLOBAL_SPRITE_SCALE, SPRITE_CELL * GLOBAL_SPRITE_SCALE}
|
||||
ALIEN_RECT :: glm.vec2{SPRITE, SPRITE}
|
||||
// note: this multiplication by GLOBAL_SPRITE_SCALE is a hack, but it's a weekend project
|
||||
// so i won't bother refactoring it
|
||||
|
||||
MAX_BULLETS :: 100
|
||||
BULLET_SPEED :: 240
|
||||
BULLET_RECT :: glm.vec2{SPRITE_CELL * GLOBAL_SPRITE_SCALE, SPRITE_CELL * GLOBAL_SPRITE_SCALE}
|
||||
BULLET_RECT :: glm.vec2{SPRITE, SPRITE}
|
||||
|
||||
MAX_PLAYER_HEALTH :: 3
|
||||
PLAYER_SPEED :: 120
|
||||
PLAYER_RECT :: glm.vec2{SPRITE_CELL * GLOBAL_SPRITE_SCALE, SPRITE_CELL * GLOBAL_SPRITE_SCALE}
|
||||
PLAYER_RECT :: glm.vec2{SPRITE, SPRITE}
|
||||
|
||||
// texture offset for ship
|
||||
SHIP_TO :: glm.vec2{0, 112}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue