Compare commits

1 Commits

12 changed files with 39 additions and 125 deletions

View File

@@ -24,8 +24,8 @@
buildInputs = with pkgs; [
libGL
# X11 dependencies for Raylib
raylib
raygui
xorg.libX11
xorg.libXcursor
xorg.libXi
@@ -38,7 +38,6 @@
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${with pkgs; lib.makeLibraryPath [
libGL
raylib
raygui
xorg.libX11
xorg.libXcursor
xorg.libXi

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

View File

@@ -1,4 +0,0 @@
package main
GameState :: struct {}

View File

@@ -4,8 +4,6 @@ import "core:fmt"
import "core:strings"
import "vendor:raylib"
delta: f32
player: Player
main :: proc() {
@@ -15,18 +13,12 @@ main :: proc() {
raylib.SetConfigFlags(config_flags)
raylib.InitWindow(1920, 1080, "Game")
defer raylib.CloseWindow()
raylib.SetTargetFPS(60)
raylib.SetExitKey(nil)
init_pause_menu()
init_world()
defer deinit_world()
player = {
position = {300, 300},
position = {0, 0},
camera = {
zoom = 4,
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},
@@ -38,7 +30,7 @@ main :: proc() {
for (!raylib.WindowShouldClose()) {
if !is_paused do delta = raylib.GetFrameTime()
delta := raylib.GetFrameTime()
raylib.BeginDrawing()
raylib.ClearBackground(raylib.BLACK)
@@ -51,19 +43,17 @@ main :: proc() {
raylib.EndMode2D()
raylib.DrawFPS(20, 20)
draw_pause_menu()
draw_player_grid_debug()
raylib.EndDrawing()
update(delta)
}
raylib.CloseWindow()
}
@(private = "file")
update :: proc(delta: f32) {
process_pause_menu_input()
if is_paused do return
update_world(delta)
update_player(&player, delta)
}

View File

@@ -1,42 +0,0 @@
package main
import "core:fmt"
import rl "vendor:raylib"
test_pause_tex: rl.Texture2D
test_pause_button_rect: rl.Rectangle
is_paused := false
init_pause_menu :: proc() {
test_pause_tex = rl.LoadTexture("./assets/pause.jpg")
test_pause_button_rect = {
x = 200,
y = 200,
width = f32(test_pause_tex.width),
height = f32(test_pause_tex.height),
}
}
draw_pause_menu :: proc() {
if (is_paused) do rl.DrawTexture(test_pause_tex, 200, 200, rl.WHITE)
}
process_pause_menu_input :: proc() {
mouse_pos := rl.GetMousePosition()
if rl.IsKeyPressed(.ESCAPE) do is_paused = !is_paused
if !is_paused do return
if (rl.CheckCollisionPointRec(mouse_pos, test_pause_button_rect)) {
if (rl.IsMouseButtonPressed(rl.MouseButton.LEFT)) {
test_pause_click()
}
}
}
test_pause_click :: proc() {
is_paused = false
}

View File

@@ -3,15 +3,12 @@ package main
import "core:math"
import "vendor:raylib"
PLAYER_DEFAULT_SPRINT_SPEED :: 100
PLAYER_DEFAULT_SPEED :: 60
PLAYER_SPRINT_SPEED :: 2.5
PLAYER_SPEED :: 1.5
PLAYER_WIDTH :: 32
PLAYER_HEIGHT :: 32
PLAYER_SPRITE_PATH :: "assets/player/player.png"
player_speed := PLAYER_DEFAULT_SPEED
player_sprint_speed := PLAYER_DEFAULT_SPRINT_SPEED
spritesheet: raylib.Texture2D
framesX: i32
framesY: i32
@@ -52,42 +49,42 @@ handle_player_camera :: proc(p: ^Player, delta: f32) {
@(private = "file")
handle_player_input :: proc(p: ^Player, delta: f32) {
dir: raylib.Vector2 = {0, 0}
if raylib.IsKeyDown(.W) do dir.y -= 1
if raylib.IsKeyDown(.S) do dir.y += 1
if raylib.IsKeyDown(.A) do dir.x -= 1
if raylib.IsKeyDown(.D) do dir.x += 1
if dir.x != 0 || dir.y != 0 {
is_moving := dir.x != 0 || dir.y != 0
if is_moving {
is_sprinting := raylib.IsKeyDown(.LEFT_SHIFT)
dir = raylib.Vector2Normalize(dir)
speed_val := f32(is_sprinting ? player_sprint_speed : player_speed)
p.animator.anim.fps = is_sprinting ? i32(player_sprint_speed / 10) : i32(player_speed / 10)
speed: f32 = is_sprinting ? PLAYER_SPRINT_SPEED : PLAYER_SPEED
p.animator.anim.fps = is_sprinting ? 11 : 6
velocity := dir * speed_val * delta
velocity := dir * speed
foot_y := p.position.y + f32(p.sprite.height)
box_half_w: f32 = 4.0
center_offset_x := f32(p.sprite.width) * 0.5
new_pos_x := p.position
new_pos_x.x += velocity.x
next_x := p.position.x + velocity.x
if !is_wall_at({next_x + center_offset_x - box_half_w, foot_y}) &&
!is_wall_at({next_x + center_offset_x + box_half_w, foot_y}) {
p.position.x = next_x
foot_offset_y := f32(p.sprite.height)
foot_offset_x := f32(p.sprite.width) * 0.5
if !is_wall_at({new_pos_x.x + foot_offset_x, new_pos_x.y + foot_offset_y}) {
p.position.x = new_pos_x.x
}
next_y := p.position.y + velocity.y
if !is_wall_at(
{p.position.x + center_offset_x - box_half_w, next_y + f32(p.sprite.height)},
) &&
!is_wall_at(
{p.position.x + center_offset_x + box_half_w, next_y + f32(p.sprite.height)},
) {
p.position.y = next_y
new_pos_y := p.position
new_pos_y.y += velocity.y
if !is_wall_at({p.position.x + foot_offset_x, new_pos_y.y + foot_offset_y}) {
p.position.y = new_pos_y.y
}
if dir.x < 0 do p.facing_left = true
if dir.x > 0 do p.facing_left = false
p.state = .WALKING
} else {
p.state = .IDLE
@@ -116,9 +113,6 @@ update_player :: proc(p: ^Player, delta: f32) {
handle_player_input(p, delta)
handle_player_camera(p, delta)
// Remove this in release
handle_debug_inputs()
if (p.state == .IDLE) {
set_sprite_animation(&p.animator, &idle_animation)
}
@@ -148,25 +142,8 @@ is_wall_at :: proc(world_pos: raylib.Vector2) -> bool {
gx := int(math.floor(world_pos.x / tile_size))
gy := int(math.floor(world_pos.y / tile_size))
if gx < 0 || gx >= ground_layer_grid.width || gy < 0 || gy >= ground_layer_grid.height {
return true
}
tile := get_tile(&ground_layer_grid, gx, gy)
return tile != nil && tile.type == .WALL
}
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
}
}

View File

@@ -6,6 +6,7 @@ TILEMAP_TILE_SIZE :: 16
Tile :: struct {
frame_index: i32,
color: raylib.Color,
type: TileType,
interaction: InteractionType,
resource: ResourceType,
@@ -37,6 +38,7 @@ InteractionType :: enum {
nothing_tile := Tile {
type = .NOTHING,
frame_index = 0,
color = raylib.WHITE,
interaction = .NONE,
resource = .NONE,
animator = nil,
@@ -45,6 +47,7 @@ nothing_tile := Tile {
ground_tile := Tile {
type = .GROUND,
frame_index = 0,
color = raylib.WHITE,
interaction = .NONE,
resource = .NONE,
animator = nil,
@@ -52,7 +55,8 @@ ground_tile := Tile {
test_wall_tile := Tile {
type = .WALL,
frame_index = 5,
frame_index = 1,
color = raylib.WHITE,
interaction = .NONE,
resource = .NONE,
animator = nil,
@@ -61,6 +65,7 @@ test_wall_tile := Tile {
plant_tile := Tile {
type = .FLORA,
frame_index = 0,
color = raylib.WHITE,
interaction = .HARVEST,
resource = .FLORA,
animator = nil,
@@ -69,6 +74,7 @@ plant_tile := Tile {
plant_2_tile := Tile {
type = .FLORA,
frame_index = 1,
color = raylib.WHITE,
interaction = .HARVEST,
resource = .FLORA,
animator = nil,
@@ -77,6 +83,7 @@ plant_2_tile := Tile {
plant_3_tile := Tile {
type = .FLORA,
frame_index = 2,
color = raylib.WHITE,
interaction = .HARVEST,
resource = .FLORA,
animator = nil,

View File

@@ -55,12 +55,7 @@ update_tile_grid :: proc(grid: ^Grid, camera: ^raylib.Camera2D, tile_w, tile_h:
}
}
draw_tile_grid :: proc(
sheet: ^TilemapSpritesheet,
grid: ^Grid,
camera: ^raylib.Camera2D,
color: raylib.Color,
) {
draw_tile_grid :: proc(sheet: ^TilemapSpritesheet, grid: ^Grid, camera: ^raylib.Camera2D) {
tile_w := f32(sheet.tile_width)
tile_h := f32(sheet.tile_height)
@@ -73,7 +68,7 @@ draw_tile_grid :: proc(
if tile.type == .NOTHING do continue
pos := raylib.Vector2{f32(x) * tile_w, f32(y) * tile_h}
draw_tile(sheet, tile, pos, color)
draw_tile(sheet, tile, pos, raylib.WHITE)
}
}
}

View File

@@ -1,11 +1,8 @@
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
@@ -62,12 +59,7 @@ update_world :: proc(delta: f32) {
}
draw_world :: proc() {
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,
world_base_color,
)
draw_tile_grid(&ground_tilemap_sheet, &ground_layer_grid, &player.camera)
draw_tile_grid(&interactables_tilemap_sheet, &interactables_layer_grid, &player.camera)
}