From 21ae1a2cb8402eb2c032afba9c93c5490a623778 Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Mon, 20 Jul 2026 08:08:45 +0200 Subject: [PATCH] Made camera control the center point of view. --- src/camera.odin | 14 +++++++++----- src/debug.odin | 14 ++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/camera.odin b/src/camera.odin index 04e0928..3b2d01e 100644 --- a/src/camera.odin +++ b/src/camera.odin @@ -1,17 +1,21 @@ package game -import "core:math/linalg" import rl "vendor:raylib" -camera_init :: proc(player: Player, camera_zoom: f32) -> rl.Camera2D { +camera_init :: proc(player: ^Player, camera_zoom: f32) -> rl.Camera2D { return rl.Camera2D { - target = player.pos, + // screen space center point offset = rl.Vector2{ f32(GAME_WIDTH/2), f32(GAME_HEIGHT/2) }, + // world point to center on + target = get_player_center(player), rotation = 0, zoom = camera_zoom } } -update_camera :: proc(player_pos: rl.Vector2, camera: ^rl.Camera2D) { - camera.target = linalg.lerp(camera.target, player_pos, 0.18) +update_camera :: proc(player: ^Player, camera: ^rl.Camera2D) { + player_pos := get_player_center(player) + // camera.target = linalg.lerp(camera.target, player_pos, 0.18) + camera_target := get_player_center(player) + camera.target = camera_target } diff --git a/src/debug.odin b/src/debug.odin index a055d9a..c8b716f 100644 --- a/src/debug.odin +++ b/src/debug.odin @@ -3,7 +3,7 @@ package game import rl "vendor:raylib" Debug :: struct { - active: bool, + active: bool, bounds_active: bool, camera_active: bool, camera: rl.Camera2D, @@ -21,13 +21,13 @@ debug_init :: proc(game: ^Game) { debug_fps :: proc() { when DEBUG_MODE { - rl.DrawFPS(20, 20) + rl.DrawFPS(20, 20) } } -// DEBUG CAMERA +// DEBUG CAMERA debug_camera_init :: proc(player: Player) -> rl.Camera2D { - when !DEBUG_MODE { return rl.Camera2D{} } + when !DEBUG_MODE { return rl.Camera2D{} } when DEBUG_MODE { offset_adjust := (TILE_SIZE / 2) * 0.3 @@ -55,7 +55,7 @@ debug_camera_update :: proc(debug: ^Debug) { scroll := rl.GetMouseWheelMove() if scroll != 0.0 { debug.camera.zoom += scroll * 0.1 - } + } } } } @@ -79,7 +79,9 @@ debug_bounds :: proc(game: ^Game) { 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) + player_collider := get_player_collider(&game.player, game.player.pos) + rl.DrawRectangleLines( i32(player.pos.x), i32(player.pos.y), TILE_SIZE, TILE_SIZE, rl.GREEN) + rl.DrawRectangleLinesEx(player_collider, 1, rl.BLUE) } } }