Made camera control the center point of view.
This commit is contained in:
+9
-5
@@ -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
|
||||
}
|
||||
|
||||
+8
-6
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user