Small refactor and rename of struct field.
This commit is contained in:
+3
-3
@@ -33,7 +33,7 @@ debug_camera_init :: proc(player: Player) -> rl.Camera2D {
|
||||
offset_adjust := (TILE_SIZE / 2) * 0.3
|
||||
|
||||
return rl.Camera2D {
|
||||
target = player.pos,
|
||||
target = player.position,
|
||||
offset = rl.Vector2{ f32(GAME_WIDTH/2 - offset_adjust), f32(GAME_HEIGHT/2 - offset_adjust) },
|
||||
rotation = 0,
|
||||
zoom = 0.3
|
||||
@@ -79,8 +79,8 @@ debug_bounds :: proc(game: ^Game) {
|
||||
if game.debug.bounds_active {
|
||||
// player
|
||||
player := game.player
|
||||
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)
|
||||
player_collider := get_player_collider(&game.player, game.player.position)
|
||||
rl.DrawRectangleLines( i32(player.position.x), i32(player.position.y), TILE_SIZE, TILE_SIZE, rl.GREEN)
|
||||
rl.DrawRectangleLinesEx(player_collider, 1, rl.BLUE)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -23,7 +23,7 @@ game_init :: proc() -> Game {
|
||||
game.world = rl.LoadRenderTexture(GAME_WIDTH, GAME_HEIGHT)
|
||||
game.current_map = map_init()
|
||||
|
||||
// DEBUG
|
||||
// @ DEBUG
|
||||
debug_init(&game)
|
||||
|
||||
return game
|
||||
@@ -35,9 +35,9 @@ game_should_run :: proc(game: ^Game) -> bool {
|
||||
|
||||
game_update :: proc(game: ^Game) {
|
||||
update_player(&game.player, &game.assets.player, game.camera, game.current_map)
|
||||
update_camera(&game.player, &game.camera)
|
||||
update_camera(&game.player, &game.camera, game.current_map.width_px, game.current_map.height_px)
|
||||
|
||||
// DEBUG
|
||||
// @ DEBUG
|
||||
debug_camera_update(&game.debug)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ game_draw :: proc(game: ^Game) {
|
||||
draw_map(game.current_map)
|
||||
draw_player(&game.player)
|
||||
|
||||
// DEBUG
|
||||
// @ DEBUG
|
||||
debug_camera_draw(&game.camera, game.debug.camera_active)
|
||||
debug_bounds(game)
|
||||
rl.EndMode2D()
|
||||
@@ -80,7 +80,7 @@ game_draw :: proc(game: ^Game) {
|
||||
rl.WHITE,
|
||||
)
|
||||
|
||||
// DEBUG
|
||||
// @ DEBUG
|
||||
debug_fps()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
+9
-2
@@ -13,9 +13,11 @@ Tile_Type :: enum {
|
||||
}
|
||||
|
||||
Game_Map :: struct {
|
||||
tile_size: int,
|
||||
width: int,
|
||||
height: int,
|
||||
tile_size: int,
|
||||
width_px: f32,
|
||||
height_px: f32,
|
||||
data: [400]int
|
||||
}
|
||||
|
||||
@@ -47,12 +49,17 @@ map_init :: proc() -> Game_Map {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
}
|
||||
|
||||
return Game_Map{
|
||||
game := Game_Map{
|
||||
width = 20,
|
||||
height = 20,
|
||||
tile_size = TILE_SIZE,
|
||||
data = map_data,
|
||||
}
|
||||
|
||||
game.width_px = f32(game.width * game.tile_size)
|
||||
game.height_px = f32(game.height * game.tile_size)
|
||||
|
||||
return game
|
||||
}
|
||||
|
||||
// requires raw window-space
|
||||
|
||||
+13
-13
@@ -6,7 +6,7 @@ import rl "vendor:raylib"
|
||||
Player_State :: enum { IDLE, WALK, ATTACK }
|
||||
|
||||
Player :: struct {
|
||||
pos: rl.Vector2,
|
||||
position: rl.Vector2,
|
||||
|
||||
velocity: rl.Vector2,
|
||||
speed: f32, // max move speed
|
||||
@@ -24,10 +24,10 @@ Player :: struct {
|
||||
|
||||
player_init :: proc(assets: ^Player_Assets) -> Player {
|
||||
player := Player{}
|
||||
player.pos = {39, 39}
|
||||
player.speed = 100
|
||||
player.accel = 600
|
||||
player.friction = 500
|
||||
player.position = {39, 39}
|
||||
player.speed = 180
|
||||
player.accel = 720
|
||||
player.friction = 640
|
||||
player.state = .IDLE
|
||||
player.collider_offset = rl.Vector2{8, 15}
|
||||
player.collider_w = 16
|
||||
@@ -39,8 +39,8 @@ player_init :: proc(assets: ^Player_Assets) -> Player {
|
||||
|
||||
get_player_center :: proc(player: ^Player) -> rl.Vector2 {
|
||||
return rl.Vector2{
|
||||
player.pos.x + TILE_SIZE / 2,
|
||||
player.pos.y + TILE_SIZE / 2,
|
||||
player.position.x + TILE_SIZE / 2,
|
||||
player.position.y + TILE_SIZE / 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,16 +78,16 @@ update_player :: proc(player: ^Player, assets: ^Player_Assets, camera: rl.Camera
|
||||
|
||||
// Check for collisions
|
||||
new_position := player.velocity * dt
|
||||
new_x_pos := rl.Vector2{player.pos.x + new_position.x, player.pos.y}
|
||||
new_x_pos := rl.Vector2{player.position.x + new_position.x, player.position.y}
|
||||
if !check_map_collision(get_player_collider(player, new_x_pos), game_map) {
|
||||
player.pos.x = new_x_pos.x
|
||||
player.position.x = new_x_pos.x
|
||||
} else {
|
||||
player.velocity.x = 0
|
||||
}
|
||||
|
||||
new_y_pos := rl.Vector2{player.pos.x, player.pos.y + new_position.y}
|
||||
new_y_pos := rl.Vector2{player.position.x, player.position.y + new_position.y}
|
||||
if !check_map_collision(get_player_collider(player, new_y_pos), game_map) {
|
||||
player.pos.y = new_y_pos.y
|
||||
player.position.y = new_y_pos.y
|
||||
} else {
|
||||
player.velocity.y = 0
|
||||
}
|
||||
@@ -121,8 +121,8 @@ draw_player :: proc(player: ^Player) {
|
||||
}
|
||||
|
||||
dst_rect := rl.Rectangle{
|
||||
x = player.pos.x,
|
||||
y = player.pos.y,
|
||||
x = player.position.x,
|
||||
y = player.position.y,
|
||||
width = f32(clip.frame_width),
|
||||
height = f32(clip.frame_height),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user