Collision detection, better camera stuff, random trees, etc
This commit is contained in:
@@ -16,6 +16,10 @@ camera : rl.Camera2D
|
||||
main :: proc() {
|
||||
|
||||
rl.InitWindow(1280, 720, "Odin game")
|
||||
flags : rl.ConfigFlags = {.VSYNC_HINT}
|
||||
rl.SetConfigFlags(flags)
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
player.position.x = CELL_SIZE * 5
|
||||
player.position.y = CELL_SIZE * 5
|
||||
@@ -29,7 +33,7 @@ main :: proc() {
|
||||
|
||||
fill_world_grid_with_nothing(&world)
|
||||
|
||||
random_trees(&world)
|
||||
place_random_trees(&world)
|
||||
|
||||
game_loop()
|
||||
}
|
||||
@@ -53,10 +57,12 @@ game_loop :: proc() {
|
||||
|
||||
rl.DrawFPS(5,5)
|
||||
|
||||
pos_string = fmt.aprint("Player POS:", get_player_grid_position(&player))
|
||||
pos_cstring = strings.clone_to_cstring(pos_string)
|
||||
player_grid_pos := get_player_grid_position(&player)
|
||||
player_grid_pos_tile := get_grid_tile(&world, vec2_to_vec2i(player_grid_pos))
|
||||
pos_string := rl.TextFormat("POS: %v : %v", player_grid_pos, player_grid_pos_tile.type)
|
||||
|
||||
rl.DrawText(pos_string, 5, 25, 20, rl.RED)
|
||||
|
||||
rl.DrawText(pos_cstring, 5, 25, 20, rl.RED)
|
||||
|
||||
rl.EndDrawing()
|
||||
}
|
||||
@@ -67,9 +73,10 @@ game_loop :: proc() {
|
||||
|
||||
update :: proc() {
|
||||
|
||||
handle_player_input(&player, &world)
|
||||
handle_window_resize()
|
||||
camera.target = {player.position.x + (CELL_SIZE / 2), player.position.y + (CELL_SIZE / 2)}
|
||||
|
||||
handle_player_input(&player)
|
||||
}
|
||||
|
||||
draw :: proc() {
|
||||
@@ -77,21 +84,16 @@ draw :: proc() {
|
||||
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)
|
||||
}
|
||||
handle_window_resize :: proc() {
|
||||
if rl.IsWindowResized() {
|
||||
camera.offset = {f32(rl.GetScreenWidth()) / 2, f32(rl.GetScreenHeight()) / 2}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print_grid :: proc() {
|
||||
for x in 0..< len(world.grid) {
|
||||
for y in 0..< len(world.grid) {
|
||||
fmt.printfln("[%d, %d] %v", x, y, world.grid[x][y].type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user