From e0c53290d7b93adf8ac7562758bdb09cf3d82a8c Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Sun, 26 Jul 2026 21:45:24 +0200 Subject: [PATCH] New debug procs and small clean ups. --- src/debug.odin | 111 ++++++++++++++++++++++++++++++++++++++++++++++--- src/game.odin | 27 ++++++------ src/main.odin | 2 +- 3 files changed, 122 insertions(+), 18 deletions(-) diff --git a/src/debug.odin b/src/debug.odin index db025bf..5f39cdd 100644 --- a/src/debug.odin +++ b/src/debug.odin @@ -4,15 +4,16 @@ import rl "vendor:raylib" Debug :: struct { active: bool, + grid_active: bool, bounds_active: bool, camera_active: bool, camera: rl.Camera2D, } -debug_init :: proc(game: ^Game) { +debug_init :: proc(game: ^Game, camera_enabled: bool) { when DEBUG_MODE { game.debug.active = true - game.debug.camera_active = false + game.debug.camera_active = camera_enabled game.debug.camera = debug_camera_init(game.player) log_info("!! Debug Mode Enabled") @@ -42,13 +43,14 @@ debug_camera_init :: proc(player: Player) -> rl.Camera2D { target = player.position, offset = rl.Vector2{ f32(GAME_WIDTH/2 - offset_adjust), f32(GAME_HEIGHT/2 - offset_adjust) }, rotation = 0, - zoom = 0.3 + zoom = 0.35 } } } debug_camera_update :: proc(debug: ^Debug) { when DEBUG_MODE { + // @TODO: wrap scroll and drag in control key pressed or spacebar scroll := rl.GetMouseWheelMove() if scroll != 0.0 { debug.camera.zoom += scroll * 0.1 @@ -60,13 +62,17 @@ debug_camera_update :: proc(debug: ^Debug) { debug.camera.target -= ((mouse_move * sensitivity) / debug.camera.zoom) } - if rl.IsKeyPressed(.ONE) { + if rl.IsKeyPressed(.F1) { debug.camera_active = !debug.camera_active } - if rl.IsKeyPressed(.TWO) { + if rl.IsKeyPressed(.F2) { debug.bounds_active = !debug.bounds_active } + + if rl.IsKeyPressed(.F3) { + debug.grid_active = !debug.grid_active + } } } @@ -83,6 +89,100 @@ debug_camera_draw :: proc(camera: ^rl.Camera2D, active: bool) { } } +debug_grid_draw :: proc(camera: ^rl.Camera2D, active: bool) { + when DEBUG_MODE { + if !active { + return + } + + view_width := GAME_WIDTH / camera.zoom + view_height := GAME_HEIGHT / camera.zoom + top_left := camera.target - rl.Vector2{ f32(view_width)/2, f32(view_height)/2 } + + map_width: i32 = 20 + map_height: i32 = 20 + + // clamp visible range to actual map bounds, in tile coords + start_x := max(i32(top_left.x / TILE_SIZE), 0) + start_y := max(i32(top_left.y / TILE_SIZE), 0) + end_x := min(i32((top_left.x + view_width) / TILE_SIZE) + 1, map_width) + end_y := min(i32((top_left.y + view_height) / TILE_SIZE) + 1, map_height) + + for x in start_x..=end_x { + px := x * TILE_SIZE + rl.DrawLine(px, start_y * TILE_SIZE, px, end_y * TILE_SIZE, rl.Fade(rl.WHITE, 0.2)) + } + for y in start_y..=end_y { + py := y * TILE_SIZE + rl.DrawLine(start_x * TILE_SIZE, py, end_x * TILE_SIZE, py, rl.Fade(rl.WHITE, 0.2)) + } + + // per-cell triangle + // pad: f32 = TILE_SIZE * 0.2 + // for x in start_x.. Game { - game := Game{} rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE) rl.SetTargetFPS(60) @@ -32,6 +31,9 @@ game_init :: proc() -> Game { defer delete(gamepad_cstr) rl.SetGamepadMappings(gamepad_cstr) + // ! game setup + game := Game{} + game.assets = asset_manager_init() game.player = player_init(&game.assets.player) game.camera = camera_init(&game.player, 1) @@ -39,10 +41,10 @@ game_init :: proc() -> Game { game.current_map = map_init() // ! init timers - game.enenmy_spawn_timer = init_timer(1, true) + game.enenmy_spawn_timer = init_timer(0.1, true) // @ DEBUG - debug_init(&game) + debug_init(&game, false) return game } @@ -58,7 +60,7 @@ game_update :: proc(game: ^Game) { if update_timer(&game.enenmy_spawn_timer, dt) { spawn_enemy(&game.enemies, &game.assets.enemy, &game.enemy_count, game.current_map) } - update_enemies(&game.enemies, &game.assets.enemy, dt) + update_enemies(&game.enemies, &game.assets.enemy, game.enemy_count, dt) // @ DEBUG debug_camera_update(&game.debug) @@ -67,22 +69,23 @@ game_update :: proc(game: ^Game) { game_draw :: proc(game: ^Game) { cam := game.camera - if game.debug.camera_active { - cam = game.debug.camera - } + if game.debug.camera_active do cam = game.debug.camera rl.BeginTextureMode(game.world) rl.ClearBackground(rl.BLACK) rl.BeginMode2D(cam) draw_map(game.current_map) - // draw objects - draw_enemies(&game.enemies) - draw_player(&game.player) - // @ DEBUG - debug_camera_draw(&game.camera, game.debug.camera_active) debug_bounds(game) + debug_camera_draw(&game.camera, game.debug.camera_active) + debug_grid_draw(&game.debug.camera, game.debug.grid_active) + + + // draw objects + draw_enemies(&game.enemies, game.enemy_count) + draw_player(&game.player) + rl.EndMode2D() rl.EndTextureMode() diff --git a/src/main.odin b/src/main.odin index aac5f17..bbe379d 100644 --- a/src/main.odin +++ b/src/main.odin @@ -12,7 +12,7 @@ WINDOW_WIDTH :: 1920 WINDOW_HEIGHT :: 1080 GAME_WIDTH :: 480 GAME_HEIGHT :: 270 -MAX_ENEMIES :: 140 +MAX_ENEMIES :: 10 MAX_PROPS :: 64 TILE_SIZE :: 32