31 Commits

Author SHA1 Message Date
9ff471ac3c forgot to push the world 2026-02-18 23:06:19 -06:00
2d5babf060 Tile rework and shader fun 2026-02-18 23:00:09 -06:00
WiseNoodle
f54bc5dc27 Merge branch 'develop' into art 2026-02-18 23:09:36 -05:00
WiseNoodle
8b7ea3be9e Add 6 mineral sprites and add 3 flower sprites 2026-02-18 23:09:08 -05:00
c937e0834c ui testing 2026-02-18 21:58:08 -06:00
087fc4a16c making sure the world is cleaned up after main loop 2026-02-16 18:23:45 -06:00
9301fe2696 Various cleanups and fixes 2026-02-16 15:29:10 -06:00
c7cfd5eac0 small player speed refactor 2026-02-16 13:17:51 -06:00
4876b486a8 can no longer go outside the grid, widened collision box 2026-02-16 13:02:01 -06:00
7390b1d6da Major tilemap/grid refactor, collision detection, interactable detection 2026-02-16 12:11:46 -06:00
WiseNoodle
352d69bdc6 Fix inconsistent pixels with player 2026-02-16 00:23:43 -05:00
e6ad65992a remove ideas.md 2026-02-15 23:09:11 -06:00
7e5960ef02 Seperate world and add interactable grid layer 2026-02-15 23:05:38 -06:00
WiseNoodle
53d717dee4 Add El Pepe plant sprite 2026-02-15 23:46:35 -05:00
WiseNoodle
a26ec7afed Merge branch 'develop' into art 2026-02-15 23:36:17 -05:00
WiseNoodle
5c60c9b74d Add interactables/props sprite project 2026-02-15 23:36:00 -05:00
175f44692a Only visible tiles update 2026-02-15 22:35:49 -06:00
7e8ab5e180 Only render tiles in camera view 2026-02-15 22:18:33 -06:00
WiseNoodle
678c14b680 Add player sprint and anim change while sprinting 2026-02-15 22:16:16 -05:00
7f7cbc567b Set config flagsset config flags 2026-02-15 20:59:04 -06:00
aaf04c9e1a More tilemap stuff 2026-02-15 19:08:58 -06:00
b5e07700b0 Tilemap and grid 2026-02-15 18:53:45 -06:00
WiseNoodle
671a5172ab Merge branch 'develop' into art 2026-02-15 18:37:07 -05:00
WiseNoodle
a8a0126d11 Exit player and create master tilemap
Also removed test tiles
2026-02-15 18:36:16 -05:00
cc479131d8 Fixed animation now being the same when flipped 2026-02-15 17:32:35 -06:00
7b19fbcf53 Sprites and Animations 2026-02-15 16:55:22 -06:00
WiseNoodle
997aa3f16b export player spritesheet 2026-02-15 15:39:54 -05:00
WiseNoodle
5c5a77ea32 Create test tile 2026-02-15 15:38:24 -05:00
WiseNoodle
1d6d3726c6 fixy 2026-02-15 15:26:50 -05:00
WiseNoodle
1ae587e7ff Merge branch 'master' into art 2026-02-15 15:22:29 -05:00
WiseNoodle
3b6277fce0 create player art and basic animation 2026-02-15 15:19:44 -05:00
26 changed files with 812 additions and 25 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

View File

@@ -0,0 +1,9 @@
0 - martian ground
1 - martian ground barrier UP
2 - martian ground barrier DOWN
3 - martian ground barrier LEFT
4 - martian ground barrier RIGHT
5 - martian ground barrier TOP RIGHT CORNER
6 - martian ground barrier TOP LEFT CORNER
7 - martian ground barrier BOTTOM RIGHT CORNER
8 - martian ground barrier BOTTOM LEFT CORNER

BIN
builds/linux/game Executable file

Binary file not shown.

View File

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

View File

@@ -1,4 +0,0 @@
# Ideas
- Lovecraftian/liminal space
- Space exploration/research

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

BIN
src/assets/pause.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

View File

@@ -0,0 +1,9 @@
0 - martian ground
1 - martian ground barrier UP
2 - martian ground barrier DOWN
3 - martian ground barrier LEFT
4 - martian ground barrier RIGHT
5 - martian ground barrier TOP RIGHT CORNER
6 - martian ground barrier TOP LEFT CORNER
7 - martian ground barrier BOTTOM RIGHT CORNER
8 - martian ground barrier BOTTOM LEFT CORNER

4
src/gamestate.odin Normal file
View File

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

43
src/hue_shift.fs Normal file
View 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);
}

View File

@@ -1,53 +1,97 @@
package main
import "core:fmt"
import "core:strings"
import "vendor:raylib"
shader: raylib.Shader
hue_loc: i32
delta: f32
player: Player
main :: proc() {
fmt.println("Brackey's Game Jam 2026 :) ")
config_flags: raylib.ConfigFlags = {.WINDOW_RESIZABLE}
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()
// 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 = {
position = {0, 0},
position = {300, 300},
camera = {
zoom = 2,
zoom = 4,
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},
target = {player.position.x + (32 / 2), player.position.y + (32 / 2)},
},
sprite = load_sprite(PLAYER_SPRITE_PATH, PLAYER_WIDTH, PLAYER_HEIGHT),
}
for (!raylib.WindowShouldClose()) {
delta := raylib.GetFrameTime()
if !is_paused do delta = raylib.GetFrameTime()
raylib.BeginDrawing()
raylib.ClearBackground(raylib.DARKBLUE)
raylib.ClearBackground(raylib.BLACK)
raylib.BeginMode2D(player.camera)
raylib.DrawText("Ur mom", 100, 100, 50, raylib.BLACK)
draw()
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)
}
@(private = "file")
draw :: proc() {
draw_world()
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
View 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
}

View File

@@ -1,20 +1,43 @@
package main
import "core:fmt"
import "core:math"
import "vendor:raylib"
PLAYER_SPEED :: 5
PLAYER_DEFAULT_SPRINT_SPEED :: 100
PLAYER_DEFAULT_SPEED :: 60
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
Player :: struct {
sprite: Sprite,
health: int,
current_world: string,
camera: raylib.Camera2D,
position: raylib.Vector2,
animator: SpriteAnimator,
state: PlayerState,
facing_left: bool,
}
PlayerState :: enum {
IDLE,
WALKING,
}
@(private = "file")
handle_player_camera :: proc(p: ^Player, delta: f32) {
player_center := raylib.Vector2{p.position.x + 16, p.position.y + 16}
player_center := raylib.Vector2 {
p.position.x + (PLAYER_WIDTH / 2),
p.position.y + (PLAYER_HEIGHT / 2),
}
smooth_speed :: 10.0
@@ -24,37 +47,126 @@ handle_player_camera :: proc(p: ^Player, delta: f32) {
if (raylib.IsWindowResized()) {
p.camera.offset = {f32(raylib.GetScreenWidth()) * 0.5, f32(raylib.GetScreenHeight()) * 0.5}
}
// p.camera.target = {p.position.x + (32 / 2), p.position.y + (32 / 2)}
// if raylib.IsWindowResized() {
// p.camera.offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2}
// }
}
@(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_sprinting := raylib.IsKeyDown(.LEFT_SHIFT)
dir = raylib.Vector2Normalize(dir)
dir = dir * PLAYER_SPEED
p.position = p.position + 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)
velocity := dir * speed_val * delta
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
}
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
}
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
}
}
idle_animation: SpriteAnimation = {
start_frame = 0,
end_frame = 5,
fps = 6,
loop = true,
}
player_walk_anim: SpriteAnimation = {
start_frame = 6,
end_frame = 11,
fps = 6,
loop = true,
}
draw_player :: proc(p: ^Player) {
raylib.DrawRectangle(i32(p.position.x), i32(p.position.y), 32, 32, raylib.BLACK)
draw_sprite_animated(&p.sprite, &p.animator, p.position, p.facing_left, false, raylib.WHITE)
}
update_player :: proc(p: ^Player, delta: f32) {
handle_player_input(p, delta)
handle_player_camera(p, delta)
// fmt.println(p.position)
// Remove this in release
handle_debug_inputs()
if (p.state == .IDLE) {
set_sprite_animation(&p.animator, &idle_animation)
}
if (p.state == .WALKING) {
set_sprite_animation(&p.animator, &player_walk_anim)
}
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
}
}

118
src/sprite.odin Normal file
View File

@@ -0,0 +1,118 @@
package main
import "vendor:raylib"
Sprite :: struct {
texture: raylib.Texture2D,
width: i32,
height: i32,
framesX: i32,
framesY: i32,
}
SpriteAnimation :: struct {
start_frame: i32,
end_frame: i32,
fps: i32,
loop: bool,
}
SpriteAnimator :: struct {
anim: ^SpriteAnimation,
current_frame: i32,
timer: f32,
}
load_sprite :: proc(image_path: cstring, w: i32, h: i32) -> Sprite {
new_texture: raylib.Texture2D = raylib.LoadTexture(image_path)
new_sprite: Sprite = {
texture = new_texture,
width = w,
height = h,
framesX = new_texture.width / w,
framesY = new_texture.height / h,
}
return new_sprite
}
draw_sprite_frame :: proc(
sprite: ^Sprite,
frame_pos: raylib.Vector2,
draw_pos: raylib.Vector2,
flipX: bool,
flipY: bool,
color: raylib.Color,
) {
widthf := f32(sprite.width)
heightf := f32(sprite.height)
source_rect := raylib.Rectangle {
x = frame_pos.x * widthf,
y = frame_pos.y * heightf,
width = widthf,
height = heightf,
}
if flipX do source_rect.width *= -1
if flipY do source_rect.height *= -1
origin := raylib.Vector2{widthf / 2, heightf / 2}
dest_rect := raylib.Rectangle {
x = draw_pos.x + origin.x,
y = draw_pos.y + origin.y,
width = widthf,
height = heightf,
}
raylib.DrawTexturePro(sprite.texture, source_rect, dest_rect, origin, 0.0, color)
}
set_sprite_animation :: proc(animator: ^SpriteAnimator, new_anim: ^SpriteAnimation) {
if (animator.anim == new_anim) do return
animator.anim = new_anim
animator.timer = 0
animator.current_frame = new_anim.start_frame
}
draw_sprite_animated :: proc(
sprite: ^Sprite,
animator: ^SpriteAnimator,
draw_pos: raylib.Vector2,
flipX: bool,
flipY: bool,
color: raylib.Color,
) {
frame_pos := frame_to_xy(sprite, animator.current_frame)
draw_sprite_frame(sprite, frame_pos, draw_pos, flipX, flipY, color)
}
update_animator :: proc(a: ^SpriteAnimator, delta: f32) {
if a.anim == nil do return
frame_time := 1.0 / f32(a.anim.fps)
a.timer += delta
if (a.timer >= frame_time) {
a.timer -= frame_time
a.current_frame += 1
if (a.current_frame > a.anim.end_frame) {
if (a.anim.loop) {
a.current_frame = a.anim.start_frame
} else {
a.current_frame = a.anim.end_frame
}
}
}
}
frame_to_xy :: proc(sprite: ^Sprite, frame: i32) -> raylib.Vector2 {
x := frame % sprite.framesX
y := frame / sprite.framesX
return raylib.Vector2{f32(x), f32(y)}
}

71
src/tile.odin Normal file
View File

@@ -0,0 +1,71 @@
package main
import "vendor:raylib"
TILEMAP_TILE_SIZE :: 16
Tile :: struct {
frame_index: i32,
type: TileType,
interaction: InteractionType,
resource: ResourceType,
animator: ^SpriteAnimator,
}
TileType :: enum {
NOTHING,
GROUND,
WALL,
DEPOSIT,
FLORA,
}
ResourceType :: enum {
NONE,
FLORA,
FAUNA,
MINERAL,
}
InteractionType :: enum {
NONE,
HARVEST,
DRILL,
EXAMINE,
}
draw_tile :: proc(
tilemap_sheet: ^TilemapSpritesheet,
tile: ^Tile,
pos: raylib.Vector2,
color: raylib.Color,
) {
frame_x := tile.frame_index % tilemap_sheet.tiles_x
frame_y := tile.frame_index / tilemap_sheet.tiles_x
src_rect := raylib.Rectangle {
x = f32(frame_x * tilemap_sheet.tile_width),
y = f32(frame_y * tilemap_sheet.tile_height),
width = f32(tilemap_sheet.tile_width),
height = f32(tilemap_sheet.tile_height),
}
dest_rect := raylib.Rectangle {
x = pos.x,
y = pos.y,
width = f32(tilemap_sheet.tile_width),
height = f32(tilemap_sheet.tile_height),
}
origin := raylib.Vector2{0, 0}
raylib.DrawTexturePro(tilemap_sheet.texture, src_rect, dest_rect, origin, 0.0, color)
}
update_tile_anim :: proc(tile: ^Tile, delta: f32) {
if (tile.animator == nil) do return
update_animator(tile.animator, delta)
tile.frame_index = tile.animator.current_frame
}

129
src/tile_definitions.odin Normal file
View 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,
},
}

126
src/tilemap.odin Normal file
View File

@@ -0,0 +1,126 @@
package main
import "vendor:raylib"
TilemapSpritesheet :: struct {
texture: raylib.Texture2D,
tile_width: i32,
tile_height: i32,
tiles_x: i32,
tiles_y: i32,
}
VisibleTileRange :: struct {
start_x, start_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 {
tex := raylib.LoadTexture(path)
return TilemapSpritesheet {
texture = tex,
tile_width = tile_width,
tile_height = tile_height,
tiles_x = tex.width / tile_width,
tiles_y = tex.height / tile_height,
}
}
create_tile_grid :: proc(width, height: i32, fill_tile: Tile) -> Grid {
w, h := int(width), int(height)
grid_slice := make([]Tile, w * h)
for i := 0; i < len(grid_slice); i += 1 {
grid_slice[i] = fill_tile
}
return Grid{width = w, height = h, tiles = grid_slice}
}
update_tile_grid :: proc(grid: ^Grid, camera: ^raylib.Camera2D, tile_w, tile_h: f32, delta: f32) {
range := get_visible_tile_range(grid, tile_w, tile_h, camera)
for y := range.start_y; y <= range.end_y; y += 1 {
for x := range.start_x; x <= range.end_x; x += 1 {
tile := &grid.tiles[y * grid.width + x]
update_tile_anim(tile, delta)
}
}
}
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)
range := get_visible_tile_range(grid, tile_w, tile_h, camera)
for y := range.start_y; y <= range.end_y; y += 1 {
for x := range.start_x; x <= range.end_x; x += 1 {
tile := &grid.tiles[y * grid.width + x]
if tile.type == .NOTHING do continue
pos := raylib.Vector2{f32(x) * tile_w, f32(y) * tile_h}
draw_tile(sheet, tile, pos, color)
}
}
}
get_visible_tile_range :: proc(
grid: ^Grid,
tile_w, tile_h: f32,
camera: ^raylib.Camera2D,
padding: int = 1,
) -> VisibleTileRange {
screen_w := f32(raylib.GetScreenWidth())
screen_h := f32(raylib.GetScreenHeight())
world_w := screen_w / camera.zoom
world_h := screen_h / camera.zoom
min_x := camera.target.x - world_w * 0.5
min_y := camera.target.y - world_h * 0.5
max_x := min_x + world_w
max_y := min_y + world_h
start_x := int(min_x / tile_w) - padding
start_y := int(min_y / tile_h) - padding
end_x := int(max_x / tile_w) + padding
end_y := int(max_y / tile_h) + padding
return VisibleTileRange {
start_x = clamp(start_x, 0, grid.width - 1),
start_y = clamp(start_y, 0, grid.height - 1),
end_x = clamp(end_x, 0, grid.width - 1),
end_y = clamp(end_y, 0, grid.height - 1),
}
}
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
}

83
src/world.odin Normal file
View File

@@ -0,0 +1,83 @@
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
interactables_layer_grid: Grid
interactables_tilemap_sheet: TilemapSpritesheet
init_world :: proc() {
ground_tilemap_sheet = load_tilemap_sheet(
"assets/tiles/master_tilemap.png",
TILEMAP_TILE_SIZE,
TILEMAP_TILE_SIZE,
)
interactables_tilemap_sheet = load_tilemap_sheet(
"assets/interactables/interactables_spritesheet.png",
TILEMAP_TILE_SIZE,
TILEMAP_TILE_SIZE,
)
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,
GROUND_TILES_MAP[.NOTHING],
)
for i := 0; i < 11; i += 1 {
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_tile_grid(
&ground_layer_grid,
&player.camera,
f32(TILEMAP_TILE_SIZE),
f32(TILEMAP_TILE_SIZE),
delta,
)
update_tile_grid(
&interactables_layer_grid,
&player.camera,
f32(TILEMAP_TILE_SIZE),
f32(TILEMAP_TILE_SIZE),
delta,
)
}
draw_world :: proc() {
raylib.BeginShaderMode(shader)
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()
}