camera, memory stuff, and random trees
This commit is contained in:
parent
6bd1c44fc8
commit
88a795264c
@ -2,11 +2,16 @@ package game
|
|||||||
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
import rand "core:math/rand"
|
||||||
|
import "core:strconv"
|
||||||
|
import "core:mem"
|
||||||
|
import "core:strings"
|
||||||
|
|
||||||
|
|
||||||
player : Player
|
player : Player
|
||||||
world : World
|
world : World
|
||||||
|
|
||||||
|
camera : rl.Camera2D
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
|
|
||||||
@ -15,55 +20,78 @@ main :: proc() {
|
|||||||
player.position.x = CELL_SIZE * 5
|
player.position.x = CELL_SIZE * 5
|
||||||
player.position.y = CELL_SIZE * 5
|
player.position.y = CELL_SIZE * 5
|
||||||
|
|
||||||
|
camera.target = {player.position.x + (CELL_SIZE / 2), player.position.y + (CELL_SIZE / 2)}
|
||||||
|
camera.zoom = 2
|
||||||
|
camera.offset = {f32(rl.GetScreenWidth()) / 2, f32(rl.GetScreenHeight()) / 2}
|
||||||
|
|
||||||
load_tilemap()
|
load_tilemap()
|
||||||
defer unload_tilemap()
|
defer unload_tilemap()
|
||||||
|
|
||||||
fill_world_grid_with_nothing(&world)
|
fill_world_grid_with_nothing(&world)
|
||||||
|
|
||||||
t := Tile {
|
random_trees(&world)
|
||||||
type = .WALL,
|
|
||||||
color = rl.WHITE,
|
|
||||||
tilemap_pos = {0,1},
|
|
||||||
}
|
|
||||||
t2 := Tile {
|
|
||||||
type = .WALL,
|
|
||||||
color = rl.WHITE,
|
|
||||||
tilemap_pos = {0,1},
|
|
||||||
}
|
|
||||||
t3 := Tile {
|
|
||||||
type = .WALL,
|
|
||||||
color = rl.WHITE,
|
|
||||||
tilemap_pos = {0,1},
|
|
||||||
}
|
|
||||||
|
|
||||||
set_grid_tile(&world, {3,3}, t)
|
|
||||||
set_grid_tile(&world, {3,4}, t2)
|
|
||||||
set_grid_tile(&world, {3,5}, t3)
|
|
||||||
|
|
||||||
fmt.println(world.grid[3][3])
|
|
||||||
|
|
||||||
game_loop()
|
game_loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
game_loop :: proc() {
|
game_loop :: proc() {
|
||||||
|
|
||||||
|
pos_string : string
|
||||||
|
pos_cstring : cstring
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
rl.ClearBackground(rl.BLACK)
|
rl.ClearBackground(rl.BLACK)
|
||||||
|
rl.BeginMode2D(camera)
|
||||||
|
|
||||||
draw()
|
draw()
|
||||||
|
|
||||||
|
rl.EndMode2D()
|
||||||
|
|
||||||
|
rl.DrawFPS(5,5)
|
||||||
|
|
||||||
|
pos_string = fmt.aprint("Player POS:", get_player_grid_position(&player))
|
||||||
|
pos_cstring = strings.clone_to_cstring(pos_string)
|
||||||
|
|
||||||
|
rl.DrawText(pos_cstring, 5, 25, 20, rl.RED)
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete(pos_string)
|
||||||
|
delete(pos_cstring)
|
||||||
}
|
}
|
||||||
|
|
||||||
update :: proc() {
|
update :: proc() {
|
||||||
|
|
||||||
|
camera.target = {player.position.x + (CELL_SIZE / 2), player.position.y + (CELL_SIZE / 2)}
|
||||||
|
|
||||||
handle_player_input(&player)
|
handle_player_input(&player)
|
||||||
}
|
}
|
||||||
|
|
||||||
draw :: proc() {
|
draw :: proc() {
|
||||||
draw_player(&player)
|
|
||||||
draw_world(&world)
|
draw_world(&world)
|
||||||
|
draw_player(&player)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
random_trees :: proc(world:^World) {
|
||||||
|
for x in 0..<len(world.grid) {
|
||||||
|
rand_y := rand.int_max(len(world.grid))
|
||||||
|
for y in 0..<len(world.grid) {
|
||||||
|
rand_x := rand.int_max(len(world.grid))
|
||||||
|
|
||||||
|
tree := Tile {
|
||||||
|
type = .WALL,
|
||||||
|
tilemap_pos = {0,1},
|
||||||
|
color = rl.RAYWHITE
|
||||||
|
}
|
||||||
|
|
||||||
|
set_grid_tile(world, {u32(rand_x),u32(rand_y), }, tree)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,5 +35,5 @@ get_player_grid_position :: proc(player:^Player) -> rl.Vector2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw_player :: proc(player:^Player) {
|
draw_player :: proc(player:^Player) {
|
||||||
draw_tile({27,0}, player.position, rl.WHITE)
|
draw_tile({27,0}, player.position, rl.DARKBLUE)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import "core:fmt"
|
|||||||
|
|
||||||
|
|
||||||
CELL_SIZE :: 16
|
CELL_SIZE :: 16
|
||||||
WORLD_SIZE :: 10
|
WORLD_SIZE :: 50
|
||||||
|
|
||||||
World :: struct {
|
World :: struct {
|
||||||
grid: [WORLD_SIZE][WORLD_SIZE]Tile
|
grid: [WORLD_SIZE][WORLD_SIZE]Tile
|
||||||
|
Loading…
Reference in New Issue
Block a user