Seperate world and add interactable grid layer
This commit is contained in:
@@ -4,8 +4,6 @@ import "core:fmt"
|
|||||||
import "vendor:raylib"
|
import "vendor:raylib"
|
||||||
|
|
||||||
player: Player
|
player: Player
|
||||||
grid: [][]Tile
|
|
||||||
tilemap_sheet: TilemapSpritesheet
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
fmt.println("Brackey's Game Jam 2026 :) ")
|
fmt.println("Brackey's Game Jam 2026 :) ")
|
||||||
@@ -16,15 +14,10 @@ main :: proc() {
|
|||||||
raylib.InitWindow(1920, 1080, "Game")
|
raylib.InitWindow(1920, 1080, "Game")
|
||||||
raylib.SetTargetFPS(60)
|
raylib.SetTargetFPS(60)
|
||||||
|
|
||||||
tilemap_sheet = load_tilemap_sheet(
|
init_world()
|
||||||
"assets/tiles/master_tilemap.png",
|
|
||||||
TILEMAP_TILE_SIZE,
|
|
||||||
TILEMAP_TILE_SIZE,
|
|
||||||
)
|
|
||||||
grid = create_tile_grid(5000, 5000)
|
|
||||||
|
|
||||||
player = {
|
player = {
|
||||||
position = {1500, 500},
|
position = {0, 0},
|
||||||
camera = {
|
camera = {
|
||||||
zoom = 4,
|
zoom = 4,
|
||||||
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},
|
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},
|
||||||
@@ -33,7 +26,6 @@ main :: proc() {
|
|||||||
sprite = load_sprite(PLAYER_SPRITE_PATH, PLAYER_WIDTH, PLAYER_HEIGHT),
|
sprite = load_sprite(PLAYER_SPRITE_PATH, PLAYER_WIDTH, PLAYER_HEIGHT),
|
||||||
}
|
}
|
||||||
|
|
||||||
set_tile(grid, 10, 10, nothing_tile)
|
|
||||||
|
|
||||||
for (!raylib.WindowShouldClose()) {
|
for (!raylib.WindowShouldClose()) {
|
||||||
|
|
||||||
@@ -60,19 +52,13 @@ main :: proc() {
|
|||||||
|
|
||||||
@(private = "file")
|
@(private = "file")
|
||||||
update :: proc(delta: f32) {
|
update :: proc(delta: f32) {
|
||||||
|
update_world(delta)
|
||||||
update_player(&player, delta)
|
update_player(&player, delta)
|
||||||
update_tile_grid(
|
|
||||||
grid,
|
|
||||||
&player.camera,
|
|
||||||
f32(tilemap_sheet.tile_width),
|
|
||||||
f32(tilemap_sheet.tile_height),
|
|
||||||
delta,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
@(private = "file")
|
||||||
draw :: proc() {
|
draw :: proc() {
|
||||||
draw_tile_grid(&tilemap_sheet, grid, &player.camera)
|
draw_world()
|
||||||
draw_player(&player)
|
draw_player(&player)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,34 @@ ground_tile := Tile {
|
|||||||
animator = nil,
|
animator = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plant_tile := Tile {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 0,
|
||||||
|
color = raylib.WHITE,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
plant_2_tile := Tile {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 1,
|
||||||
|
color = raylib.WHITE,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
plant_3_tile := Tile {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 2,
|
||||||
|
color = raylib.WHITE,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
draw_tile :: proc(
|
draw_tile :: proc(
|
||||||
tilemap_sheet: ^TilemapSpritesheet,
|
tilemap_sheet: ^TilemapSpritesheet,
|
||||||
tile: ^Tile,
|
tile: ^Tile,
|
||||||
@@ -89,6 +117,6 @@ update_tile_anim :: proc(tile: ^Tile, delta: f32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_tile :: proc(grid: [][]Tile, x: int, y: int, tile: Tile) {
|
set_tile :: proc(grid: [][]Tile, x: int, y: int, tile: Tile) {
|
||||||
grid[x][y] = tile
|
grid[y][x] = tile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ load_tilemap_sheet :: proc(path: cstring, tile_width, tile_height: i32) -> Tilem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
create_tile_grid :: proc(width, height: i32) -> [][]Tile {
|
create_tile_grid :: proc(width, height: i32, fill_tile: Tile) -> [][]Tile {
|
||||||
grid: [][]Tile = make([][]Tile, height)
|
grid: [][]Tile = make([][]Tile, height)
|
||||||
for y := 0; y < int(height); y += 1 {
|
for y := 0; y < int(height); y += 1 {
|
||||||
grid[y] = make([]Tile, width)
|
grid[y] = make([]Tile, width)
|
||||||
for x := 0; x < int(width); x += 1 {
|
for x := 0; x < int(width); x += 1 {
|
||||||
grid[y][x] = ground_tile
|
grid[y][x] = fill_tile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return grid
|
return grid
|
||||||
@@ -70,7 +70,7 @@ draw_tile_grid :: proc(sheet: ^TilemapSpritesheet, grid: [][]Tile, camera: ^rayl
|
|||||||
|
|
||||||
pos := raylib.Vector2{f32(x) * tile_w, f32(y) * tile_h}
|
pos := raylib.Vector2{f32(x) * tile_w, f32(y) * tile_h}
|
||||||
|
|
||||||
draw_tile(sheet, tile, pos, raylib.Color{0, 136, 200, 255})
|
draw_tile(sheet, tile, pos, raylib.WHITE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,55 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
WORLD_SIZE_X :: 1000
|
||||||
|
WORLD_SIZE_Y :: 1000
|
||||||
|
|
||||||
|
ground_layer_grid: [][]Tile
|
||||||
|
ground_tilemap_sheet: TilemapSpritesheet
|
||||||
|
|
||||||
|
interactables_layer_grid: [][]Tile
|
||||||
|
interactables_tilemap_sheet: TilemapSpritesheet
|
||||||
|
|
||||||
|
init_world :: proc() {
|
||||||
|
ground_tilemap_sheet = load_tilemap_sheet(
|
||||||
|
"assets/tiles/master_tilemap.png",
|
||||||
|
TILEMAP_TILE_SIZE,
|
||||||
|
TILEMAP_TILE_SIZE,
|
||||||
|
)
|
||||||
|
|
||||||
|
interactables_tilemap_sheet = load_tilemap_sheet(
|
||||||
|
"assets/interactables/interactables_spritesheet.png",
|
||||||
|
TILEMAP_TILE_SIZE,
|
||||||
|
TILEMAP_TILE_SIZE,
|
||||||
|
)
|
||||||
|
|
||||||
|
ground_layer_grid = create_tile_grid(WORLD_SIZE_X, WORLD_SIZE_Y, ground_tile)
|
||||||
|
interactables_layer_grid = create_tile_grid(WORLD_SIZE_X, WORLD_SIZE_Y, nothing_tile)
|
||||||
|
|
||||||
|
set_tile(interactables_layer_grid, 2, 2, plant_tile)
|
||||||
|
set_tile(interactables_layer_grid, 4, 2, plant_2_tile)
|
||||||
|
set_tile(interactables_layer_grid, 6, 2, plant_3_tile)
|
||||||
|
}
|
||||||
|
|
||||||
|
update_world :: proc(delta: f32) {
|
||||||
|
update_tile_grid(
|
||||||
|
ground_layer_grid,
|
||||||
|
&player.camera,
|
||||||
|
f32(ground_tilemap_sheet.tile_width),
|
||||||
|
f32(ground_tilemap_sheet.tile_height),
|
||||||
|
delta,
|
||||||
|
)
|
||||||
|
|
||||||
|
update_tile_grid(
|
||||||
|
interactables_layer_grid,
|
||||||
|
&player.camera,
|
||||||
|
f32(interactables_tilemap_sheet.tile_width),
|
||||||
|
f32(interactables_tilemap_sheet.tile_height),
|
||||||
|
delta,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_world :: proc() {
|
||||||
|
draw_tile_grid(&ground_tilemap_sheet, ground_layer_grid, &player.camera)
|
||||||
|
draw_tile_grid(&interactables_tilemap_sheet, interactables_layer_grid, &player.camera)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user