New debug procs and small clean ups.
This commit is contained in:
+106
-5
@@ -4,15 +4,16 @@ import rl "vendor:raylib"
|
|||||||
|
|
||||||
Debug :: struct {
|
Debug :: struct {
|
||||||
active: bool,
|
active: bool,
|
||||||
|
grid_active: bool,
|
||||||
bounds_active: bool,
|
bounds_active: bool,
|
||||||
camera_active: bool,
|
camera_active: bool,
|
||||||
camera: rl.Camera2D,
|
camera: rl.Camera2D,
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_init :: proc(game: ^Game) {
|
debug_init :: proc(game: ^Game, camera_enabled: bool) {
|
||||||
when DEBUG_MODE {
|
when DEBUG_MODE {
|
||||||
game.debug.active = true
|
game.debug.active = true
|
||||||
game.debug.camera_active = false
|
game.debug.camera_active = camera_enabled
|
||||||
game.debug.camera = debug_camera_init(game.player)
|
game.debug.camera = debug_camera_init(game.player)
|
||||||
|
|
||||||
log_info("!! Debug Mode Enabled")
|
log_info("!! Debug Mode Enabled")
|
||||||
@@ -42,13 +43,14 @@ debug_camera_init :: proc(player: Player) -> rl.Camera2D {
|
|||||||
target = player.position,
|
target = player.position,
|
||||||
offset = rl.Vector2{ f32(GAME_WIDTH/2 - offset_adjust), f32(GAME_HEIGHT/2 - offset_adjust) },
|
offset = rl.Vector2{ f32(GAME_WIDTH/2 - offset_adjust), f32(GAME_HEIGHT/2 - offset_adjust) },
|
||||||
rotation = 0,
|
rotation = 0,
|
||||||
zoom = 0.3
|
zoom = 0.35
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_camera_update :: proc(debug: ^Debug) {
|
debug_camera_update :: proc(debug: ^Debug) {
|
||||||
when DEBUG_MODE {
|
when DEBUG_MODE {
|
||||||
|
// @TODO: wrap scroll and drag in control key pressed or spacebar
|
||||||
scroll := rl.GetMouseWheelMove()
|
scroll := rl.GetMouseWheelMove()
|
||||||
if scroll != 0.0 {
|
if scroll != 0.0 {
|
||||||
debug.camera.zoom += scroll * 0.1
|
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)
|
debug.camera.target -= ((mouse_move * sensitivity) / debug.camera.zoom)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rl.IsKeyPressed(.ONE) {
|
if rl.IsKeyPressed(.F1) {
|
||||||
debug.camera_active = !debug.camera_active
|
debug.camera_active = !debug.camera_active
|
||||||
}
|
}
|
||||||
|
|
||||||
if rl.IsKeyPressed(.TWO) {
|
if rl.IsKeyPressed(.F2) {
|
||||||
debug.bounds_active = !debug.bounds_active
|
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..<end_x {
|
||||||
|
// for y in start_y..<end_y {
|
||||||
|
// cell_x := f32(x * TILE_SIZE)
|
||||||
|
// cell_y := f32(y * TILE_SIZE)
|
||||||
|
|
||||||
|
// // raylib expects counter-clockwise winding
|
||||||
|
// top := rl.Vector2{ cell_x + TILE_SIZE/2, cell_y + pad }
|
||||||
|
// left := rl.Vector2{ cell_x + pad, cell_y + TILE_SIZE - pad }
|
||||||
|
// right := rl.Vector2{ cell_x + TILE_SIZE - pad, cell_y + TILE_SIZE - pad }
|
||||||
|
// rl.DrawTriangle(top, left, right, rl.Fade(rl.YELLOW, 0.3))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw_direction_triangle :: proc(center: rl.Vector2, direction: rl.Vector2, size: f32, color: rl.Color) {
|
||||||
|
// if direction == {0, 0} {
|
||||||
|
// return // no direction to draw (e.g. goal cell, or unreachable cell)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// angle := math.atan2(direction.y, direction.x)
|
||||||
|
|
||||||
|
// // base triangle pointing right (angle = 0), relative to center
|
||||||
|
// p0 := rl.Vector2{ size * 0.6, 0 }
|
||||||
|
// p1 := rl.Vector2{ -size * 0.4, size * 0.4 }
|
||||||
|
// p2 := rl.Vector2{ -size * 0.4, -size * 0.4 }
|
||||||
|
|
||||||
|
// rl.DrawTriangle(
|
||||||
|
// center + rl.Vector2Rotate(p0, angle),
|
||||||
|
// center + rl.Vector2Rotate(p1, angle),
|
||||||
|
// center + rl.Vector2Rotate(p2, angle),
|
||||||
|
// color,
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
|
||||||
|
// debug_flow_field_draw :: proc(camera: ^rl.Camera2D, active: bool, field: ^Flow_Field) {
|
||||||
|
// 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 }
|
||||||
|
|
||||||
|
// 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, field.width)
|
||||||
|
// end_y := min(i32((top_left.y + view_height) / TILE_SIZE) + 1, field.height)
|
||||||
|
|
||||||
|
// for x in start_x..<end_x {
|
||||||
|
// for y in start_y..<end_y {
|
||||||
|
// cell := field.cells[y * field.width + x]
|
||||||
|
// center := rl.Vector2{
|
||||||
|
// f32(x) * TILE_SIZE + TILE_SIZE/2,
|
||||||
|
// f32(y) * TILE_SIZE + TILE_SIZE/2,
|
||||||
|
// }
|
||||||
|
// draw_direction_triangle(center, cell.direction, TILE_SIZE * 0.35, rl.Fade(rl.SKYBLUE, 0.6))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
// Collision stuff
|
// Collision stuff
|
||||||
debug_bounds :: proc(game: ^Game) {
|
debug_bounds :: proc(game: ^Game) {
|
||||||
when DEBUG_MODE {
|
when DEBUG_MODE {
|
||||||
@@ -102,3 +202,4 @@ debug_bounds :: proc(game: ^Game) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-12
@@ -24,7 +24,6 @@ Game :: struct {
|
|||||||
gamepad_compat := #load("../gamecontrollerdb.txt", string)
|
gamepad_compat := #load("../gamecontrollerdb.txt", string)
|
||||||
|
|
||||||
game_init :: proc() -> Game {
|
game_init :: proc() -> Game {
|
||||||
game := Game{}
|
|
||||||
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)
|
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
@@ -32,6 +31,9 @@ game_init :: proc() -> Game {
|
|||||||
defer delete(gamepad_cstr)
|
defer delete(gamepad_cstr)
|
||||||
rl.SetGamepadMappings(gamepad_cstr)
|
rl.SetGamepadMappings(gamepad_cstr)
|
||||||
|
|
||||||
|
// ! game setup
|
||||||
|
game := Game{}
|
||||||
|
|
||||||
game.assets = asset_manager_init()
|
game.assets = asset_manager_init()
|
||||||
game.player = player_init(&game.assets.player)
|
game.player = player_init(&game.assets.player)
|
||||||
game.camera = camera_init(&game.player, 1)
|
game.camera = camera_init(&game.player, 1)
|
||||||
@@ -39,10 +41,10 @@ game_init :: proc() -> Game {
|
|||||||
game.current_map = map_init()
|
game.current_map = map_init()
|
||||||
|
|
||||||
// ! init timers
|
// ! init timers
|
||||||
game.enenmy_spawn_timer = init_timer(1, true)
|
game.enenmy_spawn_timer = init_timer(0.1, true)
|
||||||
|
|
||||||
// @ DEBUG
|
// @ DEBUG
|
||||||
debug_init(&game)
|
debug_init(&game, false)
|
||||||
|
|
||||||
return game
|
return game
|
||||||
}
|
}
|
||||||
@@ -58,7 +60,7 @@ game_update :: proc(game: ^Game) {
|
|||||||
if update_timer(&game.enenmy_spawn_timer, dt) {
|
if update_timer(&game.enenmy_spawn_timer, dt) {
|
||||||
spawn_enemy(&game.enemies, &game.assets.enemy, &game.enemy_count, game.current_map)
|
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
|
||||||
debug_camera_update(&game.debug)
|
debug_camera_update(&game.debug)
|
||||||
@@ -67,22 +69,23 @@ game_update :: proc(game: ^Game) {
|
|||||||
|
|
||||||
game_draw :: proc(game: ^Game) {
|
game_draw :: proc(game: ^Game) {
|
||||||
cam := game.camera
|
cam := game.camera
|
||||||
if game.debug.camera_active {
|
if game.debug.camera_active do cam = game.debug.camera
|
||||||
cam = game.debug.camera
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.BeginTextureMode(game.world)
|
rl.BeginTextureMode(game.world)
|
||||||
rl.ClearBackground(rl.BLACK)
|
rl.ClearBackground(rl.BLACK)
|
||||||
rl.BeginMode2D(cam)
|
rl.BeginMode2D(cam)
|
||||||
draw_map(game.current_map)
|
draw_map(game.current_map)
|
||||||
// draw objects
|
|
||||||
draw_enemies(&game.enemies)
|
|
||||||
draw_player(&game.player)
|
|
||||||
|
|
||||||
|
|
||||||
// @ DEBUG
|
// @ DEBUG
|
||||||
debug_camera_draw(&game.camera, game.debug.camera_active)
|
|
||||||
debug_bounds(game)
|
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.EndMode2D()
|
||||||
rl.EndTextureMode()
|
rl.EndTextureMode()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ WINDOW_WIDTH :: 1920
|
|||||||
WINDOW_HEIGHT :: 1080
|
WINDOW_HEIGHT :: 1080
|
||||||
GAME_WIDTH :: 480
|
GAME_WIDTH :: 480
|
||||||
GAME_HEIGHT :: 270
|
GAME_HEIGHT :: 270
|
||||||
MAX_ENEMIES :: 140
|
MAX_ENEMIES :: 10
|
||||||
MAX_PROPS :: 64
|
MAX_PROPS :: 64
|
||||||
TILE_SIZE :: 32
|
TILE_SIZE :: 32
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user