Dynamically load/unload chunks around player
This commit is contained in:
@@ -2,10 +2,7 @@ package game
|
||||
|
||||
import "core:fmt"
|
||||
import rl "vendor:raylib"
|
||||
import rand "core:math/rand"
|
||||
import "core:strconv"
|
||||
import "core:mem"
|
||||
import "core:strings"
|
||||
import "core:os"
|
||||
|
||||
|
||||
player : Player
|
||||
@@ -13,6 +10,14 @@ world : World
|
||||
|
||||
main :: proc() {
|
||||
|
||||
if !os.is_dir("data") {
|
||||
os.make_directory("data")
|
||||
}
|
||||
|
||||
if !os.is_dir("data/worlds") {
|
||||
os.make_directory("data/worlds")
|
||||
}
|
||||
|
||||
rl.InitWindow(1280, 720, "Odin game")
|
||||
|
||||
flags : rl.ConfigFlags = {.VSYNC_HINT}
|
||||
@@ -22,7 +27,7 @@ main :: proc() {
|
||||
|
||||
|
||||
player = {
|
||||
position = {CELL_SIZE * 500, CELL_SIZE * 500},
|
||||
position = {CELL_SIZE * 10, CELL_SIZE * 10},
|
||||
camera = {
|
||||
zoom = 2,
|
||||
target = {player.position.x + (CELL_SIZE / 2), player.position.y + (CELL_SIZE / 2)},
|
||||
@@ -35,7 +40,6 @@ main :: proc() {
|
||||
defer unload_tilemap()
|
||||
|
||||
world = create_world("test_world")
|
||||
load_nearby_chunks(&world, player.position)
|
||||
|
||||
set_tile(&world, tree_tile, {400,400})
|
||||
|
||||
@@ -66,7 +70,7 @@ game_loop :: proc() {
|
||||
|
||||
player_grid_pos := get_player_grid_position(&player)
|
||||
player_grid_pos_tile := get_world_tile(&world, vec2_to_vec2i(player_grid_pos))
|
||||
status_string := rl.TextFormat("POS: %v : %v | MODE: %v", player_grid_pos, player_grid_pos_tile.type, player.mode)
|
||||
status_string := rl.TextFormat("POS: [%i,%i] : %v | MODE: %v", int(player_grid_pos.x), int(player_grid_pos.y), player_grid_pos_tile.type, player.mode)
|
||||
|
||||
rl.DrawText(status_string, 5, 25, 20, rl.RED)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user