Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ff471ac3c | |||
| 2d5babf060 | |||
|
|
f54bc5dc27 | ||
|
|
8b7ea3be9e | ||
| c937e0834c | |||
| 087fc4a16c | |||
| 9301fe2696 | |||
| c7cfd5eac0 | |||
| 4876b486a8 | |||
| 7390b1d6da | |||
|
|
352d69bdc6 |
@@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
libGL
|
libGL
|
||||||
# X11 dependencies for Raylib
|
|
||||||
raylib
|
raylib
|
||||||
|
raygui
|
||||||
xorg.libX11
|
xorg.libX11
|
||||||
xorg.libXcursor
|
xorg.libXcursor
|
||||||
xorg.libXi
|
xorg.libXi
|
||||||
@@ -38,6 +38,7 @@
|
|||||||
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${with pkgs; lib.makeLibraryPath [
|
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${with pkgs; lib.makeLibraryPath [
|
||||||
libGL
|
libGL
|
||||||
raylib
|
raylib
|
||||||
|
raygui
|
||||||
xorg.libX11
|
xorg.libX11
|
||||||
xorg.libXcursor
|
xorg.libXcursor
|
||||||
xorg.libXi
|
xorg.libXi
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
BIN
src/assets/pause.jpg
Normal file
BIN
src/assets/pause.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
4
src/gamestate.odin
Normal file
4
src/gamestate.odin
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
GameState :: struct {}
|
||||||
|
|
||||||
43
src/hue_shift.fs
Normal file
43
src/hue_shift.fs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
// Input from vertex shader
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
in vec4 fragColor;
|
||||||
|
|
||||||
|
// Output to the screen
|
||||||
|
out vec4 finalColor;
|
||||||
|
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform float hueShift;
|
||||||
|
|
||||||
|
// RGB to HSV conversion
|
||||||
|
vec3 rgb2hsv(vec3 c) {
|
||||||
|
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||||
|
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
||||||
|
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
||||||
|
float d = q.x - min(q.w, q.y);
|
||||||
|
float e = 1.0e-10;
|
||||||
|
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// HSV to RGB conversion
|
||||||
|
vec3 hsv2rgb(vec3 c) {
|
||||||
|
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||||
|
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||||
|
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// Standard Raylib texture lookup
|
||||||
|
vec4 texelColor = texture(texture0, fragTexCoord) * fragColor;
|
||||||
|
|
||||||
|
// Convert to HSV
|
||||||
|
vec3 hsv = rgb2hsv(texelColor.rgb);
|
||||||
|
|
||||||
|
// Shift the Hue (hsv.x) and wrap it around 1.0 using fract()
|
||||||
|
hsv.x = fract(hsv.x + hueShift);
|
||||||
|
|
||||||
|
// Convert back to RGB and output
|
||||||
|
vec3 rgb = hsv2rgb(hsv);
|
||||||
|
finalColor = vec4(rgb, texelColor.a);
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
|
import "core:strings"
|
||||||
import "vendor:raylib"
|
import "vendor:raylib"
|
||||||
|
|
||||||
|
shader: raylib.Shader
|
||||||
|
hue_loc: i32
|
||||||
|
|
||||||
|
delta: f32
|
||||||
player: Player
|
player: Player
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
@@ -12,12 +17,24 @@ main :: proc() {
|
|||||||
raylib.SetConfigFlags(config_flags)
|
raylib.SetConfigFlags(config_flags)
|
||||||
|
|
||||||
raylib.InitWindow(1920, 1080, "Game")
|
raylib.InitWindow(1920, 1080, "Game")
|
||||||
|
defer raylib.CloseWindow()
|
||||||
raylib.SetTargetFPS(60)
|
raylib.SetTargetFPS(60)
|
||||||
|
|
||||||
|
raylib.SetExitKey(nil)
|
||||||
|
|
||||||
|
init_pause_menu()
|
||||||
|
|
||||||
init_world()
|
init_world()
|
||||||
|
defer deinit_world()
|
||||||
|
|
||||||
|
// Test shader stuff
|
||||||
|
shader = raylib.LoadShader(nil, "hue_shift.fs")
|
||||||
|
hue_loc = raylib.GetShaderLocation(shader, "hueShift")
|
||||||
|
shift_value: f32 = 0.4
|
||||||
|
raylib.SetShaderValue(shader, hue_loc, &shift_value, .FLOAT)
|
||||||
|
|
||||||
player = {
|
player = {
|
||||||
position = {0, 0},
|
position = {300, 300},
|
||||||
camera = {
|
camera = {
|
||||||
zoom = 4,
|
zoom = 4,
|
||||||
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},
|
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},
|
||||||
@@ -29,7 +46,7 @@ main :: proc() {
|
|||||||
|
|
||||||
for (!raylib.WindowShouldClose()) {
|
for (!raylib.WindowShouldClose()) {
|
||||||
|
|
||||||
delta := raylib.GetFrameTime()
|
if !is_paused do delta = raylib.GetFrameTime()
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
raylib.BeginDrawing()
|
||||||
raylib.ClearBackground(raylib.BLACK)
|
raylib.ClearBackground(raylib.BLACK)
|
||||||
@@ -42,16 +59,19 @@ main :: proc() {
|
|||||||
|
|
||||||
raylib.EndMode2D()
|
raylib.EndMode2D()
|
||||||
raylib.DrawFPS(20, 20)
|
raylib.DrawFPS(20, 20)
|
||||||
|
draw_pause_menu()
|
||||||
|
draw_player_grid_debug()
|
||||||
raylib.EndDrawing()
|
raylib.EndDrawing()
|
||||||
|
|
||||||
update(delta)
|
update(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
@(private = "file")
|
||||||
update :: proc(delta: f32) {
|
update :: proc(delta: f32) {
|
||||||
|
process_pause_menu_input()
|
||||||
|
|
||||||
|
if is_paused do return
|
||||||
update_world(delta)
|
update_world(delta)
|
||||||
update_player(&player, delta)
|
update_player(&player, delta)
|
||||||
}
|
}
|
||||||
@@ -62,3 +82,16 @@ draw :: proc() {
|
|||||||
draw_player(&player)
|
draw_player(&player)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draw_player_grid_debug :: proc() {
|
||||||
|
gx, gy := player_pos_to_grid_pos()
|
||||||
|
|
||||||
|
tile := get_tile(&interactables_layer_grid, gx, gy)
|
||||||
|
type := tile.type
|
||||||
|
|
||||||
|
s := fmt.tprintf("Player Grid Pos: (%d, %d) | Tile: %v", gx, gy, type)
|
||||||
|
cs := strings.clone_to_cstring(s, context.temp_allocator)
|
||||||
|
|
||||||
|
|
||||||
|
raylib.DrawText(cs, 20, 40, 20, raylib.GREEN)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
42
src/pausemenu.odin
Normal file
42
src/pausemenu.odin
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
111
src/player.odin
111
src/player.odin
@@ -1,15 +1,17 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:fmt"
|
import "core:math"
|
||||||
import "core:strings"
|
|
||||||
import "vendor:raylib"
|
import "vendor:raylib"
|
||||||
|
|
||||||
PLAYER_SPRINT_SPEED :: 2.5
|
PLAYER_DEFAULT_SPRINT_SPEED :: 100
|
||||||
PLAYER_SPEED :: 1.5
|
PLAYER_DEFAULT_SPEED :: 60
|
||||||
PLAYER_WIDTH :: 32
|
PLAYER_WIDTH :: 32
|
||||||
PLAYER_HEIGHT :: 32
|
PLAYER_HEIGHT :: 32
|
||||||
PLAYER_SPRITE_PATH :: "assets/player/player.png"
|
PLAYER_SPRITE_PATH :: "assets/player/player.png"
|
||||||
|
|
||||||
|
player_speed := PLAYER_DEFAULT_SPEED
|
||||||
|
player_sprint_speed := PLAYER_DEFAULT_SPRINT_SPEED
|
||||||
|
|
||||||
spritesheet: raylib.Texture2D
|
spritesheet: raylib.Texture2D
|
||||||
framesX: i32
|
framesX: i32
|
||||||
framesY: i32
|
framesY: i32
|
||||||
@@ -50,52 +52,48 @@ handle_player_camera :: proc(p: ^Player, delta: f32) {
|
|||||||
@(private = "file")
|
@(private = "file")
|
||||||
handle_player_input :: proc(p: ^Player, delta: f32) {
|
handle_player_input :: proc(p: ^Player, delta: f32) {
|
||||||
dir: raylib.Vector2 = {0, 0}
|
dir: raylib.Vector2 = {0, 0}
|
||||||
|
|
||||||
if raylib.IsKeyDown(.W) do dir.y -= 1
|
if raylib.IsKeyDown(.W) do dir.y -= 1
|
||||||
if raylib.IsKeyDown(.S) do dir.y += 1
|
if raylib.IsKeyDown(.S) do dir.y += 1
|
||||||
if raylib.IsKeyDown(.A) do dir.x -= 1
|
if raylib.IsKeyDown(.A) do dir.x -= 1
|
||||||
if raylib.IsKeyDown(.D) do dir.x += 1
|
if raylib.IsKeyDown(.D) do dir.x += 1
|
||||||
|
|
||||||
is_moving := dir.x != 0 || dir.y != 0
|
if dir.x != 0 || dir.y != 0 {
|
||||||
|
is_sprinting := raylib.IsKeyDown(.LEFT_SHIFT)
|
||||||
if (is_moving) {
|
|
||||||
is_sprinting := false
|
|
||||||
|
|
||||||
if raylib.IsKeyDown(.LEFT_SHIFT) {
|
|
||||||
is_sprinting = true
|
|
||||||
} else {
|
|
||||||
is_sprinting = false
|
|
||||||
}
|
|
||||||
|
|
||||||
dir = raylib.Vector2Normalize(dir)
|
dir = raylib.Vector2Normalize(dir)
|
||||||
|
|
||||||
if is_sprinting {
|
speed_val := f32(is_sprinting ? player_sprint_speed : player_speed)
|
||||||
dir = dir * PLAYER_SPRINT_SPEED
|
p.animator.anim.fps = is_sprinting ? i32(player_sprint_speed / 10) : i32(player_speed / 10)
|
||||||
p.animator.anim.fps = 11
|
|
||||||
} else {
|
velocity := dir * speed_val * delta
|
||||||
dir = dir * PLAYER_SPEED
|
|
||||||
p.animator.anim.fps = 6
|
foot_y := p.position.y + f32(p.sprite.height)
|
||||||
|
box_half_w: f32 = 4.0
|
||||||
|
center_offset_x := f32(p.sprite.width) * 0.5
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
p.position = p.position + dir
|
next_y := p.position.y + velocity.y
|
||||||
|
if !is_wall_at(
|
||||||
if dir.x < 0 {
|
{p.position.x + center_offset_x - box_half_w, next_y + f32(p.sprite.height)},
|
||||||
p.facing_left = true
|
) &&
|
||||||
}
|
!is_wall_at(
|
||||||
|
{p.position.x + center_offset_x + box_half_w, next_y + f32(p.sprite.height)},
|
||||||
if dir.x > 0 {
|
) {
|
||||||
p.facing_left = false
|
p.position.y = next_y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dir.x < 0 do p.facing_left = true
|
||||||
|
if dir.x > 0 do p.facing_left = false
|
||||||
p.state = .WALKING
|
p.state = .WALKING
|
||||||
} else {
|
} else {
|
||||||
p.state = .IDLE
|
p.state = .IDLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
idle_animation: SpriteAnimation = {
|
idle_animation: SpriteAnimation = {
|
||||||
start_frame = 0,
|
start_frame = 0,
|
||||||
end_frame = 5,
|
end_frame = 5,
|
||||||
@@ -111,10 +109,6 @@ player_walk_anim: SpriteAnimation = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw_player :: proc(p: ^Player) {
|
draw_player :: proc(p: ^Player) {
|
||||||
// raylib.DrawRectangle(i32(p.position.x), i32(p.position.y), 32, 32, raylib.BLACK)
|
|
||||||
|
|
||||||
// draw_sprite_frame(&p.sprite, {0, 0}, p.position, raylib.WHITE)
|
|
||||||
|
|
||||||
draw_sprite_animated(&p.sprite, &p.animator, p.position, p.facing_left, false, raylib.WHITE)
|
draw_sprite_animated(&p.sprite, &p.animator, p.position, p.facing_left, false, raylib.WHITE)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +116,9 @@ update_player :: proc(p: ^Player, delta: f32) {
|
|||||||
handle_player_input(p, delta)
|
handle_player_input(p, delta)
|
||||||
handle_player_camera(p, delta)
|
handle_player_camera(p, delta)
|
||||||
|
|
||||||
|
// Remove this in release
|
||||||
|
handle_debug_inputs()
|
||||||
|
|
||||||
if (p.state == .IDLE) {
|
if (p.state == .IDLE) {
|
||||||
set_sprite_animation(&p.animator, &idle_animation)
|
set_sprite_animation(&p.animator, &idle_animation)
|
||||||
}
|
}
|
||||||
@@ -133,3 +130,43 @@ update_player :: proc(p: ^Player, delta: f32) {
|
|||||||
update_animator(&p.animator, delta)
|
update_animator(&p.animator, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player_pos_to_grid_pos :: proc() -> (gx: int, gy: int) {
|
||||||
|
tile_size := f32(TILEMAP_TILE_SIZE)
|
||||||
|
|
||||||
|
foot_x := player.position.x + (f32(player.sprite.width) * 0.5)
|
||||||
|
foot_y := player.position.y + f32(player.sprite.height)
|
||||||
|
|
||||||
|
gx = int(math.floor(foot_x / tile_size))
|
||||||
|
gy = int(math.floor(foot_y / tile_size))
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
is_wall_at :: proc(world_pos: raylib.Vector2) -> bool {
|
||||||
|
tile_size := f32(TILEMAP_TILE_SIZE)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ TILEMAP_TILE_SIZE :: 16
|
|||||||
|
|
||||||
Tile :: struct {
|
Tile :: struct {
|
||||||
frame_index: i32,
|
frame_index: i32,
|
||||||
color: raylib.Color,
|
|
||||||
type: TileType,
|
type: TileType,
|
||||||
interaction: InteractionType,
|
interaction: InteractionType,
|
||||||
resource: ResourceType,
|
resource: ResourceType,
|
||||||
@@ -35,52 +34,6 @@ InteractionType :: enum {
|
|||||||
EXAMINE,
|
EXAMINE,
|
||||||
}
|
}
|
||||||
|
|
||||||
nothing_tile := Tile {
|
|
||||||
type = .NOTHING,
|
|
||||||
frame_index = 0,
|
|
||||||
color = raylib.WHITE,
|
|
||||||
interaction = .NONE,
|
|
||||||
resource = .NONE,
|
|
||||||
animator = nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
ground_tile := Tile {
|
|
||||||
type = .GROUND,
|
|
||||||
frame_index = 0,
|
|
||||||
color = raylib.WHITE,
|
|
||||||
interaction = .NONE,
|
|
||||||
resource = .NONE,
|
|
||||||
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,
|
||||||
@@ -116,7 +69,3 @@ update_tile_anim :: proc(tile: ^Tile, delta: f32) {
|
|||||||
tile.frame_index = tile.animator.current_frame
|
tile.frame_index = tile.animator.current_frame
|
||||||
}
|
}
|
||||||
|
|
||||||
set_tile :: proc(grid: [][]Tile, x: int, y: int, tile: Tile) {
|
|
||||||
grid[y][x] = tile
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
129
src/tile_definitions.odin
Normal file
129
src/tile_definitions.odin
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
Ground_Tile_ID :: enum {
|
||||||
|
NOTHING,
|
||||||
|
GROUND,
|
||||||
|
WALL,
|
||||||
|
}
|
||||||
|
|
||||||
|
Interactive_Tile_ID :: enum {
|
||||||
|
PEPE_1,
|
||||||
|
PEPE_2,
|
||||||
|
PEPE_3,
|
||||||
|
FLOWER_1,
|
||||||
|
FLOWER_2,
|
||||||
|
FLOWER_3,
|
||||||
|
MINERAL_1,
|
||||||
|
MINERAL_2,
|
||||||
|
MINERAL_3,
|
||||||
|
MINERAL_4,
|
||||||
|
MINERAL_5,
|
||||||
|
MINERAL_6,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GROUND_TILES_MAP := [Ground_Tile_ID]Tile {
|
||||||
|
.NOTHING = {
|
||||||
|
type = .NOTHING,
|
||||||
|
frame_index = 0,
|
||||||
|
interaction = .NONE,
|
||||||
|
resource = .NONE,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.GROUND = {
|
||||||
|
type = .GROUND,
|
||||||
|
frame_index = 0,
|
||||||
|
interaction = .NONE,
|
||||||
|
resource = .NONE,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.WALL = {type = .WALL, frame_index = 5, interaction = .NONE, resource = .NONE, animator = nil},
|
||||||
|
}
|
||||||
|
|
||||||
|
INTERACTIVE_TILES_MAP := [Interactive_Tile_ID]Tile {
|
||||||
|
.PEPE_1 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 0,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.PEPE_2 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 1,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.PEPE_3 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 2,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.FLOWER_1 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 3,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.FLOWER_2 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 4,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.FLOWER_3 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 5,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.MINERAL_1 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 6,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.MINERAL_2 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 7,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.MINERAL_3 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 8,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.MINERAL_4 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 9,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.MINERAL_5 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 10,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
.MINERAL_6 = {
|
||||||
|
type = .FLORA,
|
||||||
|
frame_index = 11,
|
||||||
|
interaction = .HARVEST,
|
||||||
|
resource = .FLORA,
|
||||||
|
animator = nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:fmt"
|
|
||||||
import "vendor:raylib"
|
import "vendor:raylib"
|
||||||
|
|
||||||
TilemapSpritesheet :: struct {
|
TilemapSpritesheet :: struct {
|
||||||
@@ -16,6 +15,12 @@ VisibleTileRange :: struct {
|
|||||||
end_x, end_y: int,
|
end_x, end_y: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Grid :: struct {
|
||||||
|
width: int,
|
||||||
|
height: int,
|
||||||
|
tiles: []Tile,
|
||||||
|
}
|
||||||
|
|
||||||
load_tilemap_sheet :: proc(path: cstring, tile_width, tile_height: i32) -> TilemapSpritesheet {
|
load_tilemap_sheet :: proc(path: cstring, tile_width, tile_height: i32) -> TilemapSpritesheet {
|
||||||
tex := raylib.LoadTexture(path)
|
tex := raylib.LoadTexture(path)
|
||||||
|
|
||||||
@@ -28,60 +33,57 @@ load_tilemap_sheet :: proc(path: cstring, tile_width, tile_height: i32) -> Tilem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
create_tile_grid :: proc(width, height: i32, fill_tile: Tile) -> [][]Tile {
|
create_tile_grid :: proc(width, height: i32, fill_tile: Tile) -> Grid {
|
||||||
grid: [][]Tile = make([][]Tile, height)
|
w, h := int(width), int(height)
|
||||||
for y := 0; y < int(height); y += 1 {
|
grid_slice := make([]Tile, w * h)
|
||||||
grid[y] = make([]Tile, width)
|
|
||||||
for x := 0; x < int(width); x += 1 {
|
for i := 0; i < len(grid_slice); i += 1 {
|
||||||
grid[y][x] = fill_tile
|
grid_slice[i] = fill_tile
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return grid
|
|
||||||
|
return Grid{width = w, height = h, tiles = grid_slice}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_tile_grid :: proc(
|
update_tile_grid :: proc(grid: ^Grid, camera: ^raylib.Camera2D, tile_w, tile_h: f32, delta: f32) {
|
||||||
grid: [][]Tile,
|
|
||||||
camera: ^raylib.Camera2D,
|
|
||||||
tile_w, tile_h: f32,
|
|
||||||
delta: f32,
|
|
||||||
) {
|
|
||||||
range := get_visible_tile_range(grid, tile_w, tile_h, camera)
|
range := get_visible_tile_range(grid, tile_w, tile_h, camera)
|
||||||
|
|
||||||
for y := range.start_y; y <= range.end_y; y += 1 {
|
for y := range.start_y; y <= range.end_y; y += 1 {
|
||||||
row := grid[y]
|
|
||||||
for x := range.start_x; x <= range.end_x; x += 1 {
|
for x := range.start_x; x <= range.end_x; x += 1 {
|
||||||
update_tile_anim(&row[x], delta)
|
tile := &grid.tiles[y * grid.width + x]
|
||||||
|
update_tile_anim(tile, delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draw_tile_grid :: proc(
|
||||||
draw_tile_grid :: proc(sheet: ^TilemapSpritesheet, grid: [][]Tile, camera: ^raylib.Camera2D) {
|
sheet: ^TilemapSpritesheet,
|
||||||
|
grid: ^Grid,
|
||||||
|
camera: ^raylib.Camera2D,
|
||||||
|
color: raylib.Color,
|
||||||
|
) {
|
||||||
tile_w := f32(sheet.tile_width)
|
tile_w := f32(sheet.tile_width)
|
||||||
tile_h := f32(sheet.tile_height)
|
tile_h := f32(sheet.tile_height)
|
||||||
|
|
||||||
range := get_visible_tile_range(grid, tile_w, tile_h, camera)
|
range := get_visible_tile_range(grid, tile_w, tile_h, camera)
|
||||||
|
|
||||||
for y := range.start_y; y <= range.end_y; y += 1 {
|
for y := range.start_y; y <= range.end_y; y += 1 {
|
||||||
row := grid[y]
|
|
||||||
for x := range.start_x; x <= range.end_x; x += 1 {
|
for x := range.start_x; x <= range.end_x; x += 1 {
|
||||||
tile := &row[x]
|
tile := &grid.tiles[y * grid.width + x]
|
||||||
if tile.type == TileType.NOTHING do continue
|
|
||||||
|
if tile.type == .NOTHING do continue
|
||||||
|
|
||||||
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, color)
|
||||||
draw_tile(sheet, tile, pos, raylib.WHITE)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get_visible_tile_range :: proc(
|
get_visible_tile_range :: proc(
|
||||||
grid: [][]Tile,
|
grid: ^Grid,
|
||||||
tile_w, tile_h: f32,
|
tile_w, tile_h: f32,
|
||||||
camera: ^raylib.Camera2D,
|
camera: ^raylib.Camera2D,
|
||||||
padding: int = 1,
|
padding: int = 1,
|
||||||
) -> VisibleTileRange {
|
) -> VisibleTileRange {
|
||||||
|
|
||||||
screen_w := f32(raylib.GetScreenWidth())
|
screen_w := f32(raylib.GetScreenWidth())
|
||||||
screen_h := f32(raylib.GetScreenHeight())
|
screen_h := f32(raylib.GetScreenHeight())
|
||||||
|
|
||||||
@@ -98,12 +100,27 @@ get_visible_tile_range :: proc(
|
|||||||
end_x := int(max_x / tile_w) + padding
|
end_x := int(max_x / tile_w) + padding
|
||||||
end_y := int(max_y / tile_h) + padding
|
end_y := int(max_y / tile_h) + padding
|
||||||
|
|
||||||
start_x = max(start_x, 0)
|
return VisibleTileRange {
|
||||||
start_y = max(start_y, 0)
|
start_x = clamp(start_x, 0, grid.width - 1),
|
||||||
|
start_y = clamp(start_y, 0, grid.height - 1),
|
||||||
end_x = min(end_x, len(grid[0]) - 1)
|
end_x = clamp(end_x, 0, grid.width - 1),
|
||||||
end_y = min(end_y, len(grid) - 1)
|
end_y = clamp(end_y, 0, grid.height - 1),
|
||||||
|
}
|
||||||
return VisibleTileRange{start_x = start_x, start_y = start_y, end_x = end_x, end_y = end_y}
|
}
|
||||||
|
|
||||||
|
get_tile :: proc(grid: ^Grid, x, y: int) -> ^Tile {
|
||||||
|
if x < 0 || x >= grid.width || y < 0 || y >= grid.height do return nil
|
||||||
|
return &grid.tiles[y * grid.width + x]
|
||||||
|
}
|
||||||
|
|
||||||
|
set_tile :: proc(grid: ^Grid, x: int, y: int, tile: Tile) {
|
||||||
|
if x < 0 || x >= grid.width || y < 0 || y >= grid.height do return
|
||||||
|
grid.tiles[y * grid.width + x] = tile
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_tile_grid :: proc(grid: ^Grid) {
|
||||||
|
delete(grid.tiles)
|
||||||
|
grid.width = 0
|
||||||
|
grid.height = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "vendor:raylib"
|
||||||
WORLD_SIZE_X :: 1000
|
WORLD_SIZE_X :: 1000
|
||||||
WORLD_SIZE_Y :: 1000
|
WORLD_SIZE_Y :: 1000
|
||||||
|
|
||||||
ground_layer_grid: [][]Tile
|
world_base_color := raylib.WHITE
|
||||||
|
|
||||||
|
ground_layer_grid: Grid
|
||||||
ground_tilemap_sheet: TilemapSpritesheet
|
ground_tilemap_sheet: TilemapSpritesheet
|
||||||
|
|
||||||
interactables_layer_grid: [][]Tile
|
interactables_layer_grid: Grid
|
||||||
interactables_tilemap_sheet: TilemapSpritesheet
|
interactables_tilemap_sheet: TilemapSpritesheet
|
||||||
|
|
||||||
init_world :: proc() {
|
init_world :: proc() {
|
||||||
|
|
||||||
|
|
||||||
ground_tilemap_sheet = load_tilemap_sheet(
|
ground_tilemap_sheet = load_tilemap_sheet(
|
||||||
"assets/tiles/master_tilemap.png",
|
"assets/tiles/master_tilemap.png",
|
||||||
TILEMAP_TILE_SIZE,
|
TILEMAP_TILE_SIZE,
|
||||||
@@ -22,34 +27,57 @@ init_world :: proc() {
|
|||||||
TILEMAP_TILE_SIZE,
|
TILEMAP_TILE_SIZE,
|
||||||
)
|
)
|
||||||
|
|
||||||
ground_layer_grid = create_tile_grid(WORLD_SIZE_X, WORLD_SIZE_Y, ground_tile)
|
ground_layer_grid = create_tile_grid(WORLD_SIZE_X, WORLD_SIZE_Y, GROUND_TILES_MAP[.GROUND])
|
||||||
interactables_layer_grid = create_tile_grid(WORLD_SIZE_X, WORLD_SIZE_Y, nothing_tile)
|
interactables_layer_grid = create_tile_grid(
|
||||||
|
WORLD_SIZE_X,
|
||||||
|
WORLD_SIZE_Y,
|
||||||
|
GROUND_TILES_MAP[.NOTHING],
|
||||||
|
)
|
||||||
|
|
||||||
set_tile(interactables_layer_grid, 2, 2, plant_tile)
|
|
||||||
set_tile(interactables_layer_grid, 4, 2, plant_2_tile)
|
for i := 0; i < 11; i += 1 {
|
||||||
set_tile(interactables_layer_grid, 6, 2, plant_3_tile)
|
id := Interactive_Tile_ID(i)
|
||||||
|
set_tile(&interactables_layer_grid, i, 5, INTERACTIVE_TILES_MAP[id])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit_world :: proc() {
|
||||||
|
delete_tile_grid(&ground_layer_grid)
|
||||||
|
delete_tile_grid(&interactables_layer_grid)
|
||||||
}
|
}
|
||||||
|
|
||||||
update_world :: proc(delta: f32) {
|
update_world :: proc(delta: f32) {
|
||||||
update_tile_grid(
|
update_tile_grid(
|
||||||
ground_layer_grid,
|
&ground_layer_grid,
|
||||||
&player.camera,
|
&player.camera,
|
||||||
f32(ground_tilemap_sheet.tile_width),
|
f32(TILEMAP_TILE_SIZE),
|
||||||
f32(ground_tilemap_sheet.tile_height),
|
f32(TILEMAP_TILE_SIZE),
|
||||||
delta,
|
delta,
|
||||||
)
|
)
|
||||||
|
|
||||||
update_tile_grid(
|
update_tile_grid(
|
||||||
interactables_layer_grid,
|
&interactables_layer_grid,
|
||||||
&player.camera,
|
&player.camera,
|
||||||
f32(interactables_tilemap_sheet.tile_width),
|
f32(TILEMAP_TILE_SIZE),
|
||||||
f32(interactables_tilemap_sheet.tile_height),
|
f32(TILEMAP_TILE_SIZE),
|
||||||
delta,
|
delta,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_world :: proc() {
|
draw_world :: proc() {
|
||||||
draw_tile_grid(&ground_tilemap_sheet, ground_layer_grid, &player.camera)
|
raylib.BeginShaderMode(shader)
|
||||||
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
raylib.EndShaderMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user