Compare commits

..
2 Commits
Author SHA1 Message Date
jasonhilder ec2efe79f0 Fixed funny resolution changing. 2026-10-15 05:36:11 +02:00
jasonhilder 73b04fc80c Fixed random bug, spacebar should not be confirm. 2026-10-15 05:35:38 +02:00
2 changed files with 28 additions and 6 deletions
+27 -5
View File
@@ -16,7 +16,11 @@ Resolution :: struct {
// Preset window dimensions // Preset window dimensions
RESOLUTIONS := [?]Resolution{ RESOLUTIONS := [?]Resolution{
{1280, 720, "1280x720"}, {0, 0, "Fullscreen"},
{1024, 768, "1024x768"},
{1280, 720, "1280x720"},
{1366, 768, "1366x768"},
{1600, 900, "1600x900"},
{1920, 1080, "1920x1080"}, {1920, 1080, "1920x1080"},
{2560, 1440, "2560x1440"}, {2560, 1440, "2560x1440"},
{3840, 2160, "3840x2160"}, {3840, 2160, "3840x2160"},
@@ -55,14 +59,16 @@ gamepad_compat := #load("../gamecontrollerdb.txt", string)
// Game Lifecycle // Game Lifecycle
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
game_init :: proc(game: ^Game) { game_init :: proc(game: ^Game) {
rl.SetConfigFlags({.WINDOW_ALWAYS_RUN, .MSAA_4X_HINT}) rl.SetConfigFlags({.WINDOW_ALWAYS_RUN, .MSAA_4X_HINT, .WINDOW_RESIZABLE})
game.res_index = 2 game.res_index = 0
game.window_w = RESOLUTIONS[game.res_index].width game.window_w = RESOLUTIONS[game.res_index].width
game.window_h = RESOLUTIONS[game.res_index].height game.window_h = RESOLUTIONS[game.res_index].height
rl.InitWindow(game.window_w, game.window_h, WINDOW_TITLE) rl.InitWindow(game.window_w, game.window_h, WINDOW_TITLE)
rl.SetTargetFPS(60) rl.SetTargetFPS(60)
rl.SetExitKey(.KEY_NULL) rl.SetExitKey(.KEY_NULL)
rl.ToggleBorderlessWindowed()
rl.HideCursor()
gamepad_cstr := strings.clone_to_cstring(gamepad_compat) gamepad_cstr := strings.clone_to_cstring(gamepad_compat)
defer delete(gamepad_cstr) defer delete(gamepad_cstr)
@@ -178,7 +184,7 @@ game_render :: proc(game: ^Game) {
render_game_to_window(game) render_game_to_window(game)
when DEBUG do rl.DrawFPS(10, game.window_h - 20) when DEBUG do rl.DrawFPS(10, rl.GetScreenHeight() - 20)
rl.EndDrawing() rl.EndDrawing()
} }
@@ -208,6 +214,17 @@ game_trigger_shake :: proc(game: ^Game, intensity: f32, duration: f32 = 0.15) {
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
game_set_resolution :: proc(game: ^Game, res_index: int) { game_set_resolution :: proc(game: ^Game, res_index: int) {
game.res_index = clamp(res_index, 0, len(RESOLUTIONS) - 1) game.res_index = clamp(res_index, 0, len(RESOLUTIONS) - 1)
borderless := rl.IsWindowState({.BORDERLESS_WINDOWED_MODE})
if game.res_index == 0 {
if !borderless do rl.ToggleBorderlessWindowed()
return
}
if borderless {
rl.ToggleBorderlessWindowed()
rl.RestoreWindow()
}
target_w := RESOLUTIONS[game.res_index].width target_w := RESOLUTIONS[game.res_index].width
target_h := RESOLUTIONS[game.res_index].height target_h := RESOLUTIONS[game.res_index].height
@@ -226,13 +243,18 @@ game_set_resolution :: proc(game: ^Game, res_index: int) {
render_game_to_window :: proc(game: ^Game) { render_game_to_window :: proc(game: ^Game) {
texture := game.viewport.texture texture := game.viewport.texture
w, h := f32(rl.GetScreenWidth()), f32(rl.GetScreenHeight())
s := min(w / VIEWPORT_W, h / VIEWPORT_H)
dst := rl.Rectangle{(w - VIEWPORT_W*s)/2, (h - VIEWPORT_H*s)/2, VIEWPORT_W*s, VIEWPORT_H*s}
rl.BeginShaderMode(game.crt_shader) rl.BeginShaderMode(game.crt_shader)
rl.DrawTexturePro( rl.DrawTexturePro(
texture, texture,
// src: inverted y coordinate flips opengl texture buffer correctly // src: inverted y coordinate flips opengl texture buffer correctly
rl.Rectangle{0, 0, f32(texture.width), -f32(texture.height)}, rl.Rectangle{0, 0, f32(texture.width), -f32(texture.height)},
// dst: scales viewport canvas to fill window resolution // dst: scales viewport canvas to fill window resolution
rl.Rectangle{0, 0, f32(game.window_w), f32(game.window_h)}, // rl.Rectangle{0, 0, f32(game.window_w), f32(game.window_h)},
dst,
rl.Vector2{}, rl.Vector2{},
0, 0,
rl.WHITE, rl.WHITE,
+1 -1
View File
@@ -86,7 +86,7 @@ poll_input :: proc() -> Input_Event {
input_event.right_pressed = rl.IsKeyPressed(.D) || rl.IsKeyPressed(.RIGHT) || input_event.right_pressed = rl.IsKeyPressed(.D) || rl.IsKeyPressed(.RIGHT) ||
(gamepad_active && rl.IsGamepadButtonPressed(gid, .LEFT_FACE_RIGHT)) (gamepad_active && rl.IsGamepadButtonPressed(gid, .LEFT_FACE_RIGHT))
input_event.confirm_pressed = rl.IsKeyPressed(.ENTER) || rl.IsKeyPressed(.SPACE) || input_event.confirm_pressed = rl.IsKeyPressed(.ENTER) ||
(gamepad_active && rl.IsGamepadButtonPressed(gid, .RIGHT_FACE_DOWN)) (gamepad_active && rl.IsGamepadButtonPressed(gid, .RIGHT_FACE_DOWN))
input_event.pause_pressed = rl.IsKeyPressed(.SPACE) || input_event.pause_pressed = rl.IsKeyPressed(.SPACE) ||