Refined debug to only work in debug mode + dedicated struct

This commit is contained in:
2026-07-15 08:18:49 +02:00
parent 99cecd1118
commit 0df61f5a76
+56 -5
View File
@@ -2,17 +2,34 @@ package game
import rl "vendor:raylib"
debug_init :: proc() {
rl.TraceLog(.INFO, "Game initialized")
Debug :: struct {
active: bool,
bounds_active: bool,
camera_active: bool,
camera: rl.Camera2D,
}
debug_init :: proc(game: ^Game) {
when DEBUG_MODE {
game.debug.active = true
game.debug.camera_active = false
game.debug.camera = debug_camera_init(game.player)
log_info("!! Debug Mode Enabled")
}
}
debug_fps :: proc() {
if !DEBUG_MODE do return
when DEBUG_MODE {
rl.DrawFPS(20, 20)
}
}
// DEBUG CAMERA
debug_camera_init :: proc(player: Player) -> rl.Camera2D {
when !DEBUG_MODE { return rl.Camera2D{} }
when DEBUG_MODE {
offset_adjust := (TILE_SIZE / 2) * 0.3
return rl.Camera2D {
@@ -21,14 +38,48 @@ debug_camera_init :: proc(player: Player) -> rl.Camera2D {
rotation = 0,
zoom = 0.3
}
}
}
update_debug_camera :: proc(camera: ^rl.Camera2D) {
debug_camera_update :: proc(debug: ^Debug) {
when DEBUG_MODE {
if rl.IsKeyPressed(.ONE) {
debug.camera_active = !debug.camera_active
}
if rl.IsKeyPressed(.TWO) {
debug.bounds_active = !debug.bounds_active
}
if rl.IsKeyDown(.LEFT_CONTROL) {
scroll := rl.GetMouseWheelMove()
if scroll != 0.0 {
camera.zoom += scroll * 0.1
debug.camera.zoom += scroll * 0.1
}
}
}
}
debug_camera_draw :: proc(camera: ^rl.Camera2D, active: bool) {
when DEBUG_MODE {
if active {
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 }
rl.DrawRectangleLines(i32(top_left.x), i32(top_left.y), i32(view_width), i32(view_height), rl.RED)
}
}
}
// Collision stuff
debug_bounds :: proc(game: ^Game) {
when DEBUG_MODE {
if game.debug.bounds_active {
// player
player := game.player
rl.DrawRectangleLines( i32(player.pos.x - (TILE_SIZE / 2)), i32(player.pos.y - (TILE_SIZE / 2)), TILE_SIZE, TILE_SIZE, rl.GREEN)
}
}
}