Various cleanups and fixes
This commit is contained in:
@@ -15,6 +15,8 @@ main :: proc() {
|
||||
raylib.InitWindow(1920, 1080, "Game")
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
raylib.SetExitKey(nil)
|
||||
|
||||
init_world()
|
||||
|
||||
player = {
|
||||
|
||||
@@ -51,6 +51,9 @@ handle_player_camera :: proc(p: ^Player, delta: f32) {
|
||||
|
||||
@(private = "file")
|
||||
handle_player_input :: proc(p: ^Player, delta: f32) {
|
||||
|
||||
if raylib.IsKeyPressed(.ESCAPE) do return
|
||||
|
||||
dir: raylib.Vector2 = {0, 0}
|
||||
if raylib.IsKeyDown(.W) do dir.y -= 1
|
||||
if raylib.IsKeyDown(.S) do dir.y += 1
|
||||
@@ -62,7 +65,7 @@ handle_player_input :: proc(p: ^Player, delta: f32) {
|
||||
dir = raylib.Vector2Normalize(dir)
|
||||
|
||||
speed_val := f32(is_sprinting ? player_sprint_speed : player_speed)
|
||||
p.animator.anim.fps = is_sprinting ? 11 : 6
|
||||
p.animator.anim.fps = is_sprinting ? i32(player_sprint_speed / 10) : i32(player_speed / 10)
|
||||
|
||||
velocity := dir * speed_val * delta
|
||||
|
||||
@@ -159,5 +162,14 @@ is_wall_at :: proc(world_pos: raylib.Vector2) -> bool {
|
||||
handle_debug_inputs :: proc() {
|
||||
if (raylib.IsKeyPressed(.KP_ADD)) do player_sprint_speed += 10
|
||||
if (raylib.IsKeyPressed(.KP_SUBTRACT)) do player_sprint_speed -= 10
|
||||
|
||||
if (raylib.IsKeyDown(.LEFT_CONTROL) && raylib.IsKeyPressed(.EQUAL)) {
|
||||
player.camera.zoom += 0.5
|
||||
}
|
||||
|
||||
if (raylib.IsKeyDown(.LEFT_CONTROL) && raylib.IsKeyPressed(.MINUS)) {
|
||||
player.camera.zoom -= 0.5
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ TILEMAP_TILE_SIZE :: 16
|
||||
|
||||
Tile :: struct {
|
||||
frame_index: i32,
|
||||
color: raylib.Color,
|
||||
type: TileType,
|
||||
interaction: InteractionType,
|
||||
resource: ResourceType,
|
||||
@@ -38,7 +37,6 @@ InteractionType :: enum {
|
||||
nothing_tile := Tile {
|
||||
type = .NOTHING,
|
||||
frame_index = 0,
|
||||
color = raylib.WHITE,
|
||||
interaction = .NONE,
|
||||
resource = .NONE,
|
||||
animator = nil,
|
||||
@@ -47,7 +45,6 @@ nothing_tile := Tile {
|
||||
ground_tile := Tile {
|
||||
type = .GROUND,
|
||||
frame_index = 0,
|
||||
color = raylib.WHITE,
|
||||
interaction = .NONE,
|
||||
resource = .NONE,
|
||||
animator = nil,
|
||||
@@ -55,8 +52,7 @@ ground_tile := Tile {
|
||||
|
||||
test_wall_tile := Tile {
|
||||
type = .WALL,
|
||||
frame_index = 1,
|
||||
color = raylib.WHITE,
|
||||
frame_index = 5,
|
||||
interaction = .NONE,
|
||||
resource = .NONE,
|
||||
animator = nil,
|
||||
@@ -65,7 +61,6 @@ test_wall_tile := Tile {
|
||||
plant_tile := Tile {
|
||||
type = .FLORA,
|
||||
frame_index = 0,
|
||||
color = raylib.WHITE,
|
||||
interaction = .HARVEST,
|
||||
resource = .FLORA,
|
||||
animator = nil,
|
||||
@@ -74,7 +69,6 @@ plant_tile := Tile {
|
||||
plant_2_tile := Tile {
|
||||
type = .FLORA,
|
||||
frame_index = 1,
|
||||
color = raylib.WHITE,
|
||||
interaction = .HARVEST,
|
||||
resource = .FLORA,
|
||||
animator = nil,
|
||||
@@ -83,7 +77,6 @@ plant_2_tile := Tile {
|
||||
plant_3_tile := Tile {
|
||||
type = .FLORA,
|
||||
frame_index = 2,
|
||||
color = raylib.WHITE,
|
||||
interaction = .HARVEST,
|
||||
resource = .FLORA,
|
||||
animator = nil,
|
||||
|
||||
@@ -55,7 +55,12 @@ update_tile_grid :: proc(grid: ^Grid, camera: ^raylib.Camera2D, tile_w, tile_h:
|
||||
}
|
||||
}
|
||||
|
||||
draw_tile_grid :: proc(sheet: ^TilemapSpritesheet, grid: ^Grid, camera: ^raylib.Camera2D) {
|
||||
draw_tile_grid :: proc(
|
||||
sheet: ^TilemapSpritesheet,
|
||||
grid: ^Grid,
|
||||
camera: ^raylib.Camera2D,
|
||||
color: raylib.Color,
|
||||
) {
|
||||
tile_w := f32(sheet.tile_width)
|
||||
tile_h := f32(sheet.tile_height)
|
||||
|
||||
@@ -68,7 +73,7 @@ draw_tile_grid :: proc(sheet: ^TilemapSpritesheet, grid: ^Grid, camera: ^raylib.
|
||||
if tile.type == .NOTHING do continue
|
||||
|
||||
pos := raylib.Vector2{f32(x) * tile_w, f32(y) * tile_h}
|
||||
draw_tile(sheet, tile, pos, raylib.WHITE)
|
||||
draw_tile(sheet, tile, pos, color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package main
|
||||
|
||||
import "vendor:raylib"
|
||||
WORLD_SIZE_X :: 1000
|
||||
WORLD_SIZE_Y :: 1000
|
||||
|
||||
world_base_color := raylib.WHITE
|
||||
|
||||
ground_layer_grid: Grid
|
||||
ground_tilemap_sheet: TilemapSpritesheet
|
||||
|
||||
@@ -10,6 +13,9 @@ interactables_layer_grid: Grid
|
||||
interactables_tilemap_sheet: TilemapSpritesheet
|
||||
|
||||
init_world :: proc() {
|
||||
|
||||
world_base_color = {0, 150, 255, 255}
|
||||
|
||||
ground_tilemap_sheet = load_tilemap_sheet(
|
||||
"assets/tiles/master_tilemap.png",
|
||||
TILEMAP_TILE_SIZE,
|
||||
@@ -59,7 +65,12 @@ update_world :: proc(delta: f32) {
|
||||
}
|
||||
|
||||
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)
|
||||
draw_tile_grid(&ground_tilemap_sheet, &ground_layer_grid, &player.camera, world_base_color)
|
||||
draw_tile_grid(
|
||||
&interactables_tilemap_sheet,
|
||||
&interactables_layer_grid,
|
||||
&player.camera,
|
||||
raylib.WHITE,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user