Refined debug to only work in debug mode + dedicated struct
This commit is contained in:
+67
-16
@@ -2,33 +2,84 @@ package game
|
|||||||
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
debug_init :: proc() {
|
Debug :: struct {
|
||||||
rl.TraceLog(.INFO, "Game initialized")
|
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() {
|
debug_fps :: proc() {
|
||||||
if !DEBUG_MODE do return
|
when DEBUG_MODE {
|
||||||
rl.DrawFPS(20, 20)
|
rl.DrawFPS(20, 20)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG CAMERA
|
// DEBUG CAMERA
|
||||||
debug_camera_init :: proc(player: Player) -> rl.Camera2D {
|
debug_camera_init :: proc(player: Player) -> rl.Camera2D {
|
||||||
offset_adjust := (TILE_SIZE / 2) * 0.3
|
when !DEBUG_MODE { return rl.Camera2D{} }
|
||||||
|
|
||||||
return rl.Camera2D {
|
when DEBUG_MODE {
|
||||||
target = player.pos,
|
offset_adjust := (TILE_SIZE / 2) * 0.3
|
||||||
offset = rl.Vector2{ f32(GAME_WIDTH/2 - offset_adjust), f32(GAME_HEIGHT/2 - offset_adjust) },
|
|
||||||
rotation = 0,
|
return rl.Camera2D {
|
||||||
zoom = 0.3
|
target = player.pos,
|
||||||
|
offset = rl.Vector2{ f32(GAME_WIDTH/2 - offset_adjust), f32(GAME_HEIGHT/2 - offset_adjust) },
|
||||||
|
rotation = 0,
|
||||||
|
zoom = 0.3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_debug_camera :: proc(camera: ^rl.Camera2D) {
|
debug_camera_update :: proc(debug: ^Debug) {
|
||||||
if rl.IsKeyDown(.LEFT_CONTROL) {
|
when DEBUG_MODE {
|
||||||
scroll := rl.GetMouseWheelMove()
|
if rl.IsKeyPressed(.ONE) {
|
||||||
if scroll != 0.0 {
|
debug.camera_active = !debug.camera_active
|
||||||
camera.zoom += scroll * 0.1
|
}
|
||||||
}
|
|
||||||
|
if rl.IsKeyPressed(.TWO) {
|
||||||
|
debug.bounds_active = !debug.bounds_active
|
||||||
|
}
|
||||||
|
|
||||||
|
if rl.IsKeyDown(.LEFT_CONTROL) {
|
||||||
|
scroll := rl.GetMouseWheelMove()
|
||||||
|
if scroll != 0.0 {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user