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