experimental rendering stuff that are experimental
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I7b6991f7342362033ad72ab4700fdb9f6a6a6964
This commit is contained in:
parent
e00424a918
commit
e5d6222d6e
15 changed files with 1877 additions and 100 deletions
23
build.zig
23
build.zig
|
|
@ -49,6 +49,28 @@ pub fn build(b: *std.Build) void {
|
|||
// utils.h is co-located with map.c
|
||||
map_lib.addIncludePath(b.path("libs/map"));
|
||||
|
||||
// Tileset library
|
||||
const tileset_obj = b.addObject(.{
|
||||
.name = "tileset",
|
||||
.root_module = b.createModule(.{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
}),
|
||||
});
|
||||
tileset_obj.addCSourceFiles(.{
|
||||
.files = &[_][]const u8{
|
||||
"libs/tileset/tileset.c",
|
||||
"libs/tileset/tileset_paint.c",
|
||||
},
|
||||
.flags = &c_flags,
|
||||
});
|
||||
// tileset.h includes settings.h which lives in src/
|
||||
tileset_obj.addIncludePath(b.path("src"));
|
||||
// tileset.c includes tileset.h which is co-located
|
||||
tileset_obj.addIncludePath(b.path("libs/tileset"));
|
||||
tileset_obj.linkSystemLibrary("raylib");
|
||||
|
||||
// Zig combat library. This must be compiled as an object and linked
|
||||
// directly to bypassing the archive step, or it yields a corrupt
|
||||
// archive that forces the user to clear the cache each time.
|
||||
|
|
@ -98,6 +120,7 @@ pub fn build(b: *std.Build) void {
|
|||
|
||||
exe.linkLibrary(rng_lib);
|
||||
exe.linkLibrary(map_lib);
|
||||
exe.addObject(tileset_obj);
|
||||
exe.addObject(combat_obj);
|
||||
exe.linkSystemLibrary("raylib");
|
||||
exe.linkSystemLibrary("m");
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "rng/rng.h"
|
||||
#include "settings.h"
|
||||
#include "utils.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ void map_init(Map *map) {
|
|||
int is_floor(const Map *map, int x, int y) {
|
||||
if (!in_bounds(x, y, MAP_WIDTH, MAP_HEIGHT))
|
||||
return 0;
|
||||
return map->tiles[y][x] == TILE_FLOOR || map->tiles[y][x] == TILE_STAIRS;
|
||||
return map->tiles[y][x] == TILE_FLOOR || map->tiles[y][x] == TILE_STAIRS || map->tiles[y][x] == TILE_DOOR_OPEN || map->tiles[y][x] == TILE_DOOR_RUINED;
|
||||
}
|
||||
|
||||
void get_room_center(Room *room, int *cx, int *cy) {
|
||||
|
|
@ -109,6 +110,32 @@ static int generate_rooms(Map *map, Room *rooms, int floor) {
|
|||
return room_count;
|
||||
}
|
||||
|
||||
// Check if a tile is at a room boundary (adjacent to wall but inside room)
|
||||
static int is_room_boundary(Map *map, int x, int y) {
|
||||
// Must be floor
|
||||
if (map->tiles[y][x] != TILE_FLOOR)
|
||||
return 0;
|
||||
// Must have at least one adjacent wall
|
||||
if (in_bounds(x - 1, y, MAP_WIDTH, MAP_HEIGHT) && map->tiles[y][x - 1] == TILE_WALL)
|
||||
return 1;
|
||||
if (in_bounds(x + 1, y, MAP_WIDTH, MAP_HEIGHT) && map->tiles[y][x + 1] == TILE_WALL)
|
||||
return 1;
|
||||
if (in_bounds(x, y - 1, MAP_WIDTH, MAP_HEIGHT) && map->tiles[y - 1][x] == TILE_WALL)
|
||||
return 1;
|
||||
if (in_bounds(x, y + 1, MAP_WIDTH, MAP_HEIGHT) && map->tiles[y + 1][x] == TILE_WALL)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Place doors at corridor-room junctions
|
||||
// DISABLED: Door placement removed per user request
|
||||
static void place_doors(Map *map, Room *rooms, int room_count) {
|
||||
(void)map;
|
||||
(void)rooms;
|
||||
(void)room_count;
|
||||
// No-op: doors disabled
|
||||
}
|
||||
|
||||
// Connect all rooms with corridors
|
||||
static void connect_rooms(Map *map, Room *rooms, int room_count) {
|
||||
for (int i = 0; i < room_count - 1; i++) {
|
||||
|
|
@ -125,6 +152,9 @@ static void connect_rooms(Map *map, Room *rooms, int room_count) {
|
|||
carve_h_corridor(map, cx1, cx2, cy2);
|
||||
}
|
||||
}
|
||||
|
||||
// Place doors after all corridors are carved
|
||||
place_doors(map, rooms, room_count);
|
||||
}
|
||||
|
||||
// Place stairs in the last room (furthest from start)
|
||||
|
|
@ -134,7 +164,38 @@ static void place_stairs(Map *map, Room *rooms, int room_count) {
|
|||
int cx, cy;
|
||||
get_room_center(last_room, &cx, &cy);
|
||||
|
||||
// Place stairs at center of last room
|
||||
// Ensure stairs are placed on a floor tile, not a wall
|
||||
if (in_bounds(cx, cy, MAP_WIDTH, MAP_HEIGHT) && map->tiles[cy][cx] == TILE_FLOOR) {
|
||||
map->tiles[cy][cx] = TILE_STAIRS;
|
||||
return;
|
||||
}
|
||||
|
||||
// 3x3 fallback
|
||||
for (int dy = -1; dy <= 1; dy++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
int nx = cx + dx;
|
||||
int ny = cy + dy;
|
||||
if (in_bounds(nx, ny, MAP_WIDTH, MAP_HEIGHT) && map->tiles[ny][nx] == TILE_FLOOR) {
|
||||
map->tiles[ny][nx] = TILE_STAIRS;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Expanded fallback: scan the room for any floor tile
|
||||
for (int dy = 0; dy < last_room->h; dy++) {
|
||||
for (int dx = 0; dx < last_room->w; dx++) {
|
||||
int nx = last_room->x + dx;
|
||||
int ny = last_room->y + dy;
|
||||
if (in_bounds(nx, ny, MAP_WIDTH, MAP_HEIGHT) && map->tiles[ny][nx] == TILE_FLOOR) {
|
||||
map->tiles[ny][nx] = TILE_STAIRS;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Final fallback: force the center tile to stairs regardless of type
|
||||
fprintf(stderr, "Warning: No floor tile found for stairs at room center (%d, %d). Forcing stairs placement.\n", cx, cy);
|
||||
if (in_bounds(cx, cy, MAP_WIDTH, MAP_HEIGHT)) {
|
||||
map->tiles[cy][cx] = TILE_STAIRS;
|
||||
}
|
||||
|
|
|
|||
122
libs/tileset/tileset.c
Normal file
122
libs/tileset/tileset.c
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
#include "tileset.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int tileset_init(Tileset *ts, int tile_w, int tile_h) {
|
||||
if (ts == NULL)
|
||||
return 0;
|
||||
if (tile_w <= 0 || tile_h <= 0)
|
||||
return 0;
|
||||
|
||||
memset(ts, 0, sizeof(Tileset));
|
||||
|
||||
ts->tile_w = tile_w;
|
||||
ts->tile_h = tile_h;
|
||||
|
||||
// Compute grid dimensions to fit MAX_TILE_ID tiles
|
||||
ts->atlas_cols = 4; // 4 columns
|
||||
ts->atlas_rows = (MAX_TILE_ID + ts->atlas_cols - 1) / ts->atlas_cols; // round up
|
||||
|
||||
int atlas_w = ts->atlas_cols * tile_w;
|
||||
int atlas_h = ts->atlas_rows * tile_h;
|
||||
|
||||
// Validate atlas dimensions are reasonable
|
||||
if (atlas_w <= 0 || atlas_h <= 0 || atlas_w > 4096 || atlas_h > 4096)
|
||||
return 0;
|
||||
|
||||
ts->render_target = LoadRenderTexture(atlas_w, atlas_h);
|
||||
if (ts->render_target.id == 0)
|
||||
return 0;
|
||||
|
||||
// Clear to transparent so unpainted regions don't show artifacts
|
||||
BeginTextureMode(ts->render_target);
|
||||
ClearBackground(BLANK);
|
||||
EndTextureMode();
|
||||
|
||||
ts->finalized = 0;
|
||||
ts->tile_count = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tileset_register(Tileset *ts, int id) {
|
||||
if (ts == NULL)
|
||||
return 0;
|
||||
if (id < 0 || id >= MAX_TILE_ID)
|
||||
return 0;
|
||||
if (ts->render_target.id == 0)
|
||||
return 0;
|
||||
if (ts->finalized)
|
||||
return 0;
|
||||
if (ts->regions[id].width != 0)
|
||||
return 0; // already registered
|
||||
|
||||
int col = id % ts->atlas_cols;
|
||||
int row = id / ts->atlas_cols;
|
||||
|
||||
ts->regions[id] = (Rectangle){
|
||||
(float)(col * ts->tile_w),
|
||||
(float)(row * ts->tile_h),
|
||||
(float)ts->tile_w,
|
||||
(float)ts->tile_h
|
||||
};
|
||||
ts->tile_count++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tileset_finalize(Tileset *ts) {
|
||||
if (ts == NULL)
|
||||
return 0;
|
||||
if (ts->render_target.id == 0)
|
||||
return 0;
|
||||
if (ts->finalized)
|
||||
return 1; // already finalized
|
||||
|
||||
// Convert RenderTexture to regular Texture2D
|
||||
// RenderTexture textures are flipped vertically in raylib, so we need to handle that
|
||||
Texture2D old_texture = ts->render_target.texture;
|
||||
|
||||
// Create a new texture from the render texture data
|
||||
Image img = LoadImageFromTexture(old_texture);
|
||||
if (img.data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Flip image vertically because RenderTexture is upside-down
|
||||
ImageFlipVertical(&img);
|
||||
|
||||
Texture2D new_tex = LoadTextureFromImage(img);
|
||||
UnloadImage(img);
|
||||
|
||||
if (new_tex.id == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Unload the old render texture and replace with the new regular texture
|
||||
UnloadRenderTexture(ts->render_target);
|
||||
ts->render_target.id = 0;
|
||||
ts->atlas = new_tex;
|
||||
ts->finalized = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Rectangle tileset_get_region(const Tileset *ts, int id) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return (Rectangle){0, 0, 0, 0};
|
||||
if (!ts->finalized)
|
||||
return (Rectangle){0, 0, 0, 0};
|
||||
return ts->regions[id];
|
||||
}
|
||||
|
||||
void tileset_destroy(Tileset *ts) {
|
||||
if (ts == NULL)
|
||||
return;
|
||||
if (ts->finalized) {
|
||||
if (ts->atlas.id != 0)
|
||||
UnloadTexture(ts->atlas);
|
||||
} else {
|
||||
if (ts->render_target.id != 0)
|
||||
UnloadRenderTexture(ts->render_target);
|
||||
}
|
||||
memset(ts, 0, sizeof(Tileset));
|
||||
}
|
||||
91
libs/tileset/tileset.h
Normal file
91
libs/tileset/tileset.h
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#ifndef TILESET_H
|
||||
#define TILESET_H
|
||||
|
||||
#include "settings.h"
|
||||
#include <raylib.h>
|
||||
|
||||
// Maximum number of tiles that can be registered in a single atlas
|
||||
#define MAX_TILE_ID 32
|
||||
|
||||
// Tile IDs for map tiles (variants for visual variety)
|
||||
#define TILE_WALL_0 0
|
||||
#define TILE_WALL_1 1
|
||||
#define TILE_FLOOR_0 2
|
||||
#define TILE_FLOOR_1 3
|
||||
#define TILE_FLOOR_2 4
|
||||
#define TILE_FLOOR_3 5
|
||||
#define TILE_STAIRS 6
|
||||
|
||||
// Sprite IDs for entities
|
||||
#define SPRITE_PLAYER 7
|
||||
#define SPRITE_PLAYER_WALK_0 8
|
||||
#define SPRITE_PLAYER_WALK_1 9
|
||||
#define SPRITE_PLAYER_ATTACK 10
|
||||
#define SPRITE_ENEMY_GOBLIN 11
|
||||
#define SPRITE_ENEMY_GOBLIN_WALK_0 12
|
||||
#define SPRITE_ENEMY_GOBLIN_WALK_1 13
|
||||
#define SPRITE_ENEMY_GOBLIN_ATTACK 14
|
||||
#define SPRITE_ENEMY_SKELETON 15
|
||||
#define SPRITE_ENEMY_SKELETON_WALK_0 16
|
||||
#define SPRITE_ENEMY_SKELETON_WALK_1 17
|
||||
#define SPRITE_ENEMY_SKELETON_ATTACK 18
|
||||
#define SPRITE_ENEMY_ORC 19
|
||||
#define SPRITE_ENEMY_ORC_WALK_0 20
|
||||
#define SPRITE_ENEMY_ORC_WALK_1 21
|
||||
#define SPRITE_ENEMY_ORC_ATTACK 22
|
||||
#define SPRITE_ITEM_POTION 23
|
||||
#define SPRITE_ITEM_WEAPON 24
|
||||
#define SPRITE_ITEM_ARMOR 25
|
||||
|
||||
// Door tiles
|
||||
#define TILE_DOOR_CLOSED_SPRITE 26
|
||||
#define TILE_DOOR_OPEN_SPRITE 27
|
||||
|
||||
// Effect/status sprites
|
||||
#define SPRITE_EFFECT_BURN 28
|
||||
#define SPRITE_EFFECT_POISON 29
|
||||
#define SPRITE_EFFECT_BLOCK 30
|
||||
#define SPRITE_SLASH_EFFECT 31
|
||||
|
||||
// Total count of defined tiles
|
||||
#define NUM_TILE_IDS 32
|
||||
|
||||
// Tileset encapsulates a GPU texture atlas with sub-rectangle regions per tile ID.
|
||||
// The atlas is built at startup by painting into a RenderTexture, then finalized
|
||||
// into a regular Texture2D for efficient drawing via DrawTexturePro.
|
||||
typedef struct {
|
||||
RenderTexture2D render_target; // RenderTexture for painting (valid before finalize)
|
||||
Texture2D atlas; // GPU texture (valid after finalize)
|
||||
int tile_w; // width of each tile in pixels
|
||||
int tile_h; // height of each tile in pixels
|
||||
Rectangle regions[MAX_TILE_ID]; // sub-rectangles within atlas for each tile ID
|
||||
int tile_count; // number of registered tiles
|
||||
int atlas_cols; // number of columns in the atlas grid
|
||||
int atlas_rows; // number of rows in the atlas grid
|
||||
int finalized; // 1 after tileset_finalize called, 0 otherwise
|
||||
} Tileset;
|
||||
|
||||
// Initialize a tileset with the given tile dimensions.
|
||||
// Computes atlas grid size based on MAX_TILE_ID and allocates a RenderTexture.
|
||||
// Returns 0 on failure (e.g., RenderTexture allocation failed), non-zero on success.
|
||||
int tileset_init(Tileset *ts, int tile_w, int tile_h);
|
||||
|
||||
// Register a tile ID with its atlas region.
|
||||
// The region is computed automatically based on tile_w/tile_h and the ID index.
|
||||
// Returns 0 if the ID is out of bounds or already registered, non-zero on success.
|
||||
int tileset_register(Tileset *ts, int id);
|
||||
|
||||
// Finalize the tileset: converts the internal RenderTexture into a regular Texture2D
|
||||
// suitable for DrawTexturePro. After this call, painting functions must not be used.
|
||||
// Returns 0 on failure, non-zero on success.
|
||||
int tileset_finalize(Tileset *ts);
|
||||
|
||||
// Get the atlas sub-rectangle for a given tile ID.
|
||||
// Returns a zeroed Rectangle if the ID is invalid or not registered.
|
||||
Rectangle tileset_get_region(const Tileset *ts, int id);
|
||||
|
||||
// Destroy a tileset, unloading the atlas texture and zeroing the struct.
|
||||
// Safe to call on a zero-initialized or already-destroyed tileset.
|
||||
void tileset_destroy(Tileset *ts);
|
||||
|
||||
#endif // TILESET_H
|
||||
854
libs/tileset/tileset_paint.c
Normal file
854
libs/tileset/tileset_paint.c
Normal file
|
|
@ -0,0 +1,854 @@
|
|||
#include "tileset_paint.h"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Simple LCG for deterministic noise (seeded by position)
|
||||
static unsigned int lcg_seed = 0;
|
||||
static void lcg_srand(unsigned int seed) { lcg_seed = seed; }
|
||||
static unsigned int lcg_rand(void) {
|
||||
lcg_seed = lcg_seed * 1103515245 + 12345;
|
||||
return lcg_seed;
|
||||
}
|
||||
|
||||
static int lcg_rand_range(int min, int max) {
|
||||
return min + (int)(lcg_rand() % (unsigned int)(max - min + 1));
|
||||
}
|
||||
|
||||
// Helper: get the RenderTexture target for painting a specific tile ID
|
||||
static RenderTexture2D get_target(Tileset *ts) {
|
||||
return ts->render_target;
|
||||
}
|
||||
|
||||
// Helper: compute screen offset for a tile ID within the atlas
|
||||
static Vector2 get_paint_offset(Tileset *ts, int id) {
|
||||
int col = id % ts->atlas_cols;
|
||||
int row = id / ts->atlas_cols;
|
||||
return (Vector2){(float)(col * ts->tile_w), (float)(row * ts->tile_h)};
|
||||
}
|
||||
|
||||
void paint_wall_tile(Tileset *ts, int id, int variant) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int w = ts->tile_w;
|
||||
int h = ts->tile_h;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Base color: much darker for better contrast against floor
|
||||
Color base = variant == 0 ? (Color){45, 42, 38, 255} : (Color){35, 32, 28, 255};
|
||||
DrawRectangle((int)off.x, (int)off.y, w, h, base);
|
||||
|
||||
// Brick pattern
|
||||
int brick_h = h / 3;
|
||||
int brick_w = w / 2;
|
||||
Color mortar = (Color){25, 22, 18, 255};
|
||||
Color brick_light = variant == 0 ? (Color){70, 65, 60, 255} : (Color){50, 47, 43, 255};
|
||||
Color brick_dark = variant == 0 ? (Color){40, 37, 33, 255} : (Color){30, 27, 24, 255};
|
||||
|
||||
for (int row = 0; row < 3; row++) {
|
||||
int y = (int)off.y + row * brick_h;
|
||||
int offset_x = (row % 2 == 0) ? 0 : brick_w / 2;
|
||||
for (int col = -1; col < 3; col++) {
|
||||
int x = (int)off.x + offset_x + col * brick_w;
|
||||
if (x >= (int)off.x + w)
|
||||
break;
|
||||
if (x + brick_w <= (int)off.x)
|
||||
continue;
|
||||
|
||||
// Clip to tile bounds
|
||||
int draw_x = x < (int)off.x ? (int)off.x : x;
|
||||
int draw_w = brick_w;
|
||||
if (draw_x + draw_w > (int)off.x + w)
|
||||
draw_w = (int)off.x + w - draw_x;
|
||||
|
||||
Color c = ((col + row) % 2 == 0) ? brick_light : brick_dark;
|
||||
DrawRectangle(draw_x, y, draw_w, brick_h - 1, c);
|
||||
}
|
||||
}
|
||||
|
||||
// Mortar lines
|
||||
for (int row = 1; row < 3; row++) {
|
||||
int y = (int)off.y + row * brick_h;
|
||||
DrawLine((int)off.x, y, (int)off.x + w - 1, y, mortar);
|
||||
}
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_floor_tile(Tileset *ts, int id, int variant) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int w = ts->tile_w;
|
||||
int h = ts->tile_h;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Base stone color - lighter than walls for contrast
|
||||
Color base = (Color){75, 72, 68, 255};
|
||||
DrawRectangle((int)off.x, (int)off.y, w, h, base);
|
||||
|
||||
// Seeded noise based on variant
|
||||
lcg_srand((unsigned int)(variant * 7919 + id * 104729));
|
||||
|
||||
// Dithered noise dots - lighter shades
|
||||
int num_dots = 8 + variant * 4;
|
||||
for (int i = 0; i < num_dots; i++) {
|
||||
int px = (int)off.x + lcg_rand_range(1, w - 2);
|
||||
int py = (int)off.y + lcg_rand_range(1, h - 2);
|
||||
int shade = lcg_rand_range(0, 3);
|
||||
Color c;
|
||||
if (shade == 0)
|
||||
c = (Color){85, 82, 78, 255};
|
||||
else if (shade == 1)
|
||||
c = (Color){65, 62, 58, 255};
|
||||
else
|
||||
c = (Color){90, 87, 83, 255};
|
||||
DrawPixel(px, py, c);
|
||||
}
|
||||
|
||||
// Occasional crack line
|
||||
if (variant >= 2) {
|
||||
int crack_x = (int)off.x + lcg_rand_range(2, w - 3);
|
||||
int crack_y = (int)off.y + lcg_rand_range(2, h - 3);
|
||||
int crack_len = lcg_rand_range(2, 4);
|
||||
int crack_dir = lcg_rand_range(0, 1); // 0 = horizontal, 1 = vertical
|
||||
Color crack_color = (Color){55, 52, 48, 255};
|
||||
for (int i = 0; i < crack_len; i++) {
|
||||
if (crack_dir == 0)
|
||||
DrawPixel(crack_x + i, crack_y, crack_color);
|
||||
else
|
||||
DrawPixel(crack_x, crack_y + i, crack_color);
|
||||
}
|
||||
}
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_stairs_tile(Tileset *ts, int id) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int w = ts->tile_w;
|
||||
int h = ts->tile_h;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Dark stone background
|
||||
DrawRectangle((int)off.x, (int)off.y, w, h, (Color){40, 38, 35, 255});
|
||||
|
||||
// Stair steps (3 steps)
|
||||
int step_h = h / 4;
|
||||
Color step_light = (Color){100, 95, 90, 255};
|
||||
Color step_dark = (Color){60, 57, 53, 255};
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int y = (int)off.y + h - (i + 1) * step_h;
|
||||
int inset = i * 2;
|
||||
int x = (int)off.x + inset;
|
||||
DrawRectangle(x, y, w - inset * 2, step_h - 1, step_light);
|
||||
DrawLine(x, y + step_h - 1, x + w - inset * 2 - 1, y + step_h - 1, step_dark);
|
||||
}
|
||||
|
||||
// ">" symbol on top step
|
||||
int top_y = (int)off.y + 2;
|
||||
int cx = (int)off.x + w / 2;
|
||||
Color arrow = (Color){180, 175, 170, 255};
|
||||
DrawPixel(cx, top_y, arrow);
|
||||
DrawPixel(cx - 1, top_y + 1, arrow);
|
||||
DrawPixel(cx + 1, top_y + 1, arrow);
|
||||
DrawPixel(cx - 2, top_y + 2, arrow);
|
||||
DrawPixel(cx + 2, top_y + 2, arrow);
|
||||
DrawPixel(cx, top_y + 3, arrow);
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
static void draw_player_base(Tileset *ts, int id, int leg_offset_left, int leg_offset_right, int arm_offset_left, int arm_offset_right) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int w = ts->tile_w;
|
||||
int h = ts->tile_h;
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Clear to transparent
|
||||
DrawRectangle(ox, oy, w, h, BLANK);
|
||||
|
||||
// Simple adventurer silhouette (16x16)
|
||||
Color skin = (Color){230, 200, 160, 255};
|
||||
Color tunic = (Color){60, 100, 180, 255};
|
||||
Color pants = (Color){80, 60, 40, 255};
|
||||
Color boots = (Color){50, 40, 30, 255};
|
||||
Color hair = (Color){120, 80, 40, 255};
|
||||
|
||||
// Head (3x3)
|
||||
DrawRectangle(ox + 6, oy + 2, 4, 3, skin);
|
||||
// Hair
|
||||
DrawRectangle(ox + 6, oy + 1, 4, 1, hair);
|
||||
DrawPixel(ox + 5, oy + 2, hair);
|
||||
DrawPixel(ox + 10, oy + 2, hair);
|
||||
|
||||
// Body/tunic (4x5)
|
||||
DrawRectangle(ox + 5, oy + 5, 6, 5, tunic);
|
||||
// Belt
|
||||
DrawRectangle(ox + 5, oy + 9, 6, 1, (Color){120, 80, 30, 255});
|
||||
|
||||
// Legs with offset for walking animation
|
||||
DrawRectangle(ox + 6 + leg_offset_left, oy + 10, 2, 4, pants);
|
||||
DrawRectangle(ox + 8 + leg_offset_right, oy + 10, 2, 4, pants);
|
||||
|
||||
// Boots with offset
|
||||
DrawRectangle(ox + 6 + leg_offset_left, oy + 14, 2, 2, boots);
|
||||
DrawRectangle(ox + 8 + leg_offset_right, oy + 14, 2, 2, boots);
|
||||
|
||||
// Arms with offset
|
||||
DrawRectangle(ox + 3 + arm_offset_left, oy + 6, 2, 3, skin);
|
||||
DrawRectangle(ox + 11 + arm_offset_right, oy + 6, 2, 3, skin);
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_player_tile(Tileset *ts, int id) {
|
||||
// Idle pose - no offsets
|
||||
draw_player_base(ts, id, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void paint_player_walk_tile(Tileset *ts, int id, int frame) {
|
||||
// Frame 0: left leg forward, right leg back
|
||||
// Frame 1: right leg forward, left leg back
|
||||
int leg_left = (frame == 0) ? -1 : 1;
|
||||
int leg_right = (frame == 0) ? 1 : -1;
|
||||
int arm_left = (frame == 0) ? 1 : -1;
|
||||
int arm_right = (frame == 0) ? -1 : 1;
|
||||
draw_player_base(ts, id, leg_left, leg_right, arm_left, arm_right);
|
||||
}
|
||||
|
||||
void paint_player_attack_tile(Tileset *ts, int id) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int w = ts->tile_w;
|
||||
int h = ts->tile_h;
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Clear to transparent
|
||||
DrawRectangle(ox, oy, w, h, BLANK);
|
||||
|
||||
// Attack pose - lunging forward with sword arm extended
|
||||
Color skin = (Color){230, 200, 160, 255};
|
||||
Color tunic = (Color){60, 100, 180, 255};
|
||||
Color pants = (Color){80, 60, 40, 255};
|
||||
Color boots = (Color){50, 40, 30, 255};
|
||||
Color hair = (Color){120, 80, 40, 255};
|
||||
Color steel = (Color){180, 180, 190, 255};
|
||||
|
||||
// Head (3x3)
|
||||
DrawRectangle(ox + 7, oy + 2, 4, 3, skin);
|
||||
// Hair
|
||||
DrawRectangle(ox + 7, oy + 1, 4, 1, hair);
|
||||
DrawPixel(ox + 6, oy + 2, hair);
|
||||
DrawPixel(ox + 11, oy + 2, hair);
|
||||
|
||||
// Body/tunic (4x5) - shifted right for lunge
|
||||
DrawRectangle(ox + 6, oy + 5, 6, 5, tunic);
|
||||
// Belt
|
||||
DrawRectangle(ox + 6, oy + 9, 6, 1, (Color){120, 80, 30, 255});
|
||||
|
||||
// Legs - left forward, right back
|
||||
DrawRectangle(ox + 5, oy + 10, 2, 4, pants);
|
||||
DrawRectangle(ox + 9, oy + 10, 2, 4, pants);
|
||||
|
||||
// Boots
|
||||
DrawRectangle(ox + 5, oy + 14, 2, 2, boots);
|
||||
DrawRectangle(ox + 9, oy + 14, 2, 2, boots);
|
||||
|
||||
// Left arm (back)
|
||||
DrawRectangle(ox + 4, oy + 6, 2, 3, skin);
|
||||
|
||||
// Right arm extended forward with sword
|
||||
DrawRectangle(ox + 12, oy + 6, 3, 2, skin);
|
||||
// Sword blade
|
||||
DrawRectangle(ox + 14, oy + 4, 1, 6, steel);
|
||||
// Sword hilt
|
||||
DrawRectangle(ox + 13, oy + 7, 3, 1, (Color){100, 80, 40, 255});
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
// Helper: draw goblin base with configurable leg/arm offsets
|
||||
static void draw_goblin_base(Tileset *ts, int id, int leg_left, int leg_right, int arm_left, int arm_right) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
Color skin = (Color){80, 140, 60, 255};
|
||||
Color dark = (Color){50, 90, 35, 255};
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
DrawRectangle(ox, oy, ts->tile_w, ts->tile_h, BLANK);
|
||||
|
||||
// Head (large, hunched forward)
|
||||
DrawRectangle(ox + 4, oy + 3, 8, 6, skin);
|
||||
// Eyes (angry)
|
||||
DrawPixel(ox + 5, oy + 5, (Color){200, 50, 50, 255});
|
||||
DrawPixel(ox + 10, oy + 5, (Color){200, 50, 50, 255});
|
||||
// Ears (pointy)
|
||||
DrawPixel(ox + 3, oy + 4, skin);
|
||||
DrawPixel(ox + 12, oy + 4, skin);
|
||||
// Body (small, hunched)
|
||||
DrawRectangle(ox + 5, oy + 9, 6, 4, dark);
|
||||
// Legs with offsets
|
||||
DrawRectangle(ox + 5 + leg_left, oy + 13, 2, 3, skin);
|
||||
DrawRectangle(ox + 9 + leg_right, oy + 13, 2, 3, skin);
|
||||
// Arms with offsets
|
||||
DrawRectangle(ox + 3 + arm_left, oy + 10, 2, 2, skin);
|
||||
DrawRectangle(ox + 11 + arm_right, oy + 10, 2, 2, skin);
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
// Helper: draw skeleton base with configurable leg/arm offsets
|
||||
static void draw_skeleton_base(Tileset *ts, int id, int leg_left, int leg_right, int arm_left, int arm_right) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
Color bone = (Color){220, 220, 210, 255};
|
||||
Color dark_bone = (Color){180, 180, 170, 255};
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
DrawRectangle(ox, oy, ts->tile_w, ts->tile_h, BLANK);
|
||||
|
||||
// Skull
|
||||
DrawRectangle(ox + 5, oy + 2, 6, 5, bone);
|
||||
// Eye sockets
|
||||
DrawPixel(ox + 6, oy + 4, (Color){20, 20, 20, 255});
|
||||
DrawPixel(ox + 9, oy + 4, (Color){20, 20, 20, 255});
|
||||
// Ribs
|
||||
for (int i = 0; i < 3; i++) {
|
||||
DrawRectangle(ox + 4, oy + 8 + i * 2, 8, 1, bone);
|
||||
}
|
||||
// Spine
|
||||
DrawRectangle(ox + 7, oy + 7, 2, 6, dark_bone);
|
||||
// Legs with offsets
|
||||
DrawRectangle(ox + 5 + leg_left, oy + 13, 2, 3, bone);
|
||||
DrawRectangle(ox + 9 + leg_right, oy + 13, 2, 3, bone);
|
||||
// Arms with offsets
|
||||
DrawRectangle(ox + 3 + arm_left, oy + 8, 2, 3, bone);
|
||||
DrawRectangle(ox + 11 + arm_right, oy + 8, 2, 3, bone);
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
// Helper: draw orc base with configurable leg/arm offsets
|
||||
static void draw_orc_base(Tileset *ts, int id, int leg_left, int leg_right, int arm_left, int arm_right) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
Color skin = (Color){60, 100, 45, 255};
|
||||
Color dark = (Color){40, 70, 30, 255};
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
DrawRectangle(ox, oy, ts->tile_w, ts->tile_h, BLANK);
|
||||
|
||||
// Large head
|
||||
DrawRectangle(ox + 3, oy + 2, 10, 7, skin);
|
||||
// Small angry eyes
|
||||
DrawPixel(ox + 5, oy + 5, (Color){250, 250, 50, 255});
|
||||
DrawPixel(ox + 10, oy + 5, (Color){250, 250, 50, 255});
|
||||
// Tusks
|
||||
DrawPixel(ox + 6, oy + 7, (Color){240, 240, 220, 255});
|
||||
DrawPixel(ox + 9, oy + 7, (Color){240, 240, 220, 255});
|
||||
// Broad body
|
||||
DrawRectangle(ox + 3, oy + 9, 10, 5, dark);
|
||||
// Thick legs with offsets
|
||||
DrawRectangle(ox + 4 + leg_left, oy + 14, 3, 2, skin);
|
||||
DrawRectangle(ox + 9 + leg_right, oy + 14, 3, 2, skin);
|
||||
// Thick arms with offsets
|
||||
DrawRectangle(ox + 1 + arm_left, oy + 10, 3, 3, skin);
|
||||
DrawRectangle(ox + 12 + arm_right, oy + 10, 3, 3, skin);
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_enemy_tile(Tileset *ts, int id, int enemy_type) {
|
||||
// Idle pose - no offsets
|
||||
switch (enemy_type) {
|
||||
case 0: draw_goblin_base(ts, id, 0, 0, 0, 0); break;
|
||||
case 1: draw_skeleton_base(ts, id, 0, 0, 0, 0); break;
|
||||
case 2: draw_orc_base(ts, id, 0, 0, 0, 0); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void paint_enemy_walk_tile(Tileset *ts, int id, int enemy_type, int frame) {
|
||||
// Frame 0: left leg forward, right leg back
|
||||
// Frame 1: right leg forward, left leg back
|
||||
int leg_left = (frame == 0) ? -1 : 1;
|
||||
int leg_right = (frame == 0) ? 1 : -1;
|
||||
int arm_left = (frame == 0) ? 1 : -1;
|
||||
int arm_right = (frame == 0) ? -1 : 1;
|
||||
|
||||
switch (enemy_type) {
|
||||
case 0: draw_goblin_base(ts, id, leg_left, leg_right, arm_left, arm_right); break;
|
||||
case 1: draw_skeleton_base(ts, id, leg_left, leg_right, arm_left, arm_right); break;
|
||||
case 2: draw_orc_base(ts, id, leg_left, leg_right, arm_left, arm_right); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void paint_enemy_attack_tile(Tileset *ts, int id, int enemy_type) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
DrawRectangle(ox, oy, ts->tile_w, ts->tile_h, BLANK);
|
||||
|
||||
switch (enemy_type) {
|
||||
case 0: {
|
||||
// Goblin attack - lunging with dagger
|
||||
Color skin = (Color){80, 140, 60, 255};
|
||||
Color dark = (Color){50, 90, 35, 255};
|
||||
Color steel = (Color){180, 180, 190, 255};
|
||||
// Head (leaning forward)
|
||||
DrawRectangle(ox + 6, oy + 3, 8, 6, skin);
|
||||
DrawPixel(ox + 7, oy + 5, (Color){200, 50, 50, 255});
|
||||
DrawPixel(ox + 12, oy + 5, (Color){200, 50, 50, 255});
|
||||
// Body
|
||||
DrawRectangle(ox + 7, oy + 9, 6, 4, dark);
|
||||
// Left leg back
|
||||
DrawRectangle(ox + 5, oy + 13, 2, 3, skin);
|
||||
// Right leg forward
|
||||
DrawRectangle(ox + 11, oy + 13, 2, 3, skin);
|
||||
// Left arm back
|
||||
DrawRectangle(ox + 4, oy + 10, 2, 2, skin);
|
||||
// Right arm extended with dagger
|
||||
DrawRectangle(ox + 14, oy + 9, 2, 2, skin);
|
||||
DrawRectangle(ox + 15, oy + 7, 1, 4, steel);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
// Skeleton attack - swinging sword
|
||||
Color bone = (Color){220, 220, 210, 255};
|
||||
Color dark_bone = (Color){180, 180, 170, 255};
|
||||
Color steel = (Color){180, 180, 190, 255};
|
||||
// Skull
|
||||
DrawRectangle(ox + 6, oy + 2, 6, 5, bone);
|
||||
DrawPixel(ox + 7, oy + 4, (Color){20, 20, 20, 255});
|
||||
DrawPixel(ox + 10, oy + 4, (Color){20, 20, 20, 255});
|
||||
// Ribs
|
||||
for (int i = 0; i < 3; i++) {
|
||||
DrawRectangle(ox + 5, oy + 8 + i * 2, 8, 1, bone);
|
||||
}
|
||||
// Spine
|
||||
DrawRectangle(ox + 8, oy + 7, 2, 6, dark_bone);
|
||||
// Legs
|
||||
DrawRectangle(ox + 6, oy + 13, 2, 3, bone);
|
||||
DrawRectangle(ox + 10, oy + 13, 2, 3, bone);
|
||||
// Left arm back
|
||||
DrawRectangle(ox + 4, oy + 8, 2, 3, bone);
|
||||
// Right arm extended with sword
|
||||
DrawRectangle(ox + 13, oy + 7, 3, 2, bone);
|
||||
DrawRectangle(ox + 15, oy + 5, 1, 6, steel);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
// Orc attack - overhead smash
|
||||
Color skin = (Color){60, 100, 45, 255};
|
||||
Color dark = (Color){40, 70, 30, 255};
|
||||
Color steel = (Color){180, 180, 190, 255};
|
||||
// Head
|
||||
DrawRectangle(ox + 4, oy + 2, 10, 7, skin);
|
||||
DrawPixel(ox + 6, oy + 5, (Color){250, 250, 50, 255});
|
||||
DrawPixel(ox + 11, oy + 5, (Color){250, 250, 50, 255});
|
||||
// Tusks
|
||||
DrawPixel(ox + 7, oy + 7, (Color){240, 240, 220, 255});
|
||||
DrawPixel(ox + 10, oy + 7, (Color){240, 240, 220, 255});
|
||||
// Body
|
||||
DrawRectangle(ox + 4, oy + 9, 10, 5, dark);
|
||||
// Legs
|
||||
DrawRectangle(ox + 5, oy + 14, 3, 2, skin);
|
||||
DrawRectangle(ox + 10, oy + 14, 3, 2, skin);
|
||||
// Left arm back
|
||||
DrawRectangle(ox + 2, oy + 10, 3, 3, skin);
|
||||
// Right arm raised with club
|
||||
DrawRectangle(ox + 13, oy + 4, 3, 3, skin);
|
||||
DrawRectangle(ox + 14, oy + 1, 2, 5, steel);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_item_tile(Tileset *ts, int id, int item_type) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int w = ts->tile_w;
|
||||
int h = ts->tile_h;
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
DrawRectangle(ox, oy, w, h, BLANK);
|
||||
|
||||
switch (item_type) {
|
||||
case 0: {
|
||||
// Flask shape
|
||||
Color glass = (Color){200, 60, 60, 255};
|
||||
Color liquid = (Color){255, 80, 80, 255};
|
||||
Color highlight = (Color){255, 150, 150, 255};
|
||||
// Neck
|
||||
DrawRectangle(ox + 6, oy + 2, 4, 3, glass);
|
||||
// Body
|
||||
DrawRectangle(ox + 4, oy + 5, 8, 8, liquid);
|
||||
// Cork
|
||||
DrawRectangle(ox + 6, oy + 1, 4, 1, (Color){160, 120, 60, 255});
|
||||
// Highlight
|
||||
DrawPixel(ox + 5, oy + 6, highlight);
|
||||
DrawPixel(ox + 5, oy + 7, highlight);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
// Sword
|
||||
Color blade = (Color){220, 220, 230, 255};
|
||||
Color hilt = (Color){160, 120, 40, 255};
|
||||
Color guard = (Color){140, 140, 150, 255};
|
||||
// Blade
|
||||
DrawRectangle(ox + 7, oy + 2, 2, 9, blade);
|
||||
// Tip
|
||||
DrawPixel(ox + 7, oy + 1, blade);
|
||||
DrawPixel(ox + 8, oy + 1, blade);
|
||||
// Guard
|
||||
DrawRectangle(ox + 5, oy + 11, 6, 1, guard);
|
||||
// Hilt
|
||||
DrawRectangle(ox + 7, oy + 12, 2, 3, hilt);
|
||||
// Pommel
|
||||
DrawPixel(ox + 7, oy + 15, guard);
|
||||
DrawPixel(ox + 8, oy + 15, guard);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
// Chestplate
|
||||
Color metal = (Color){100, 120, 160, 255};
|
||||
Color dark_metal = (Color){70, 85, 115, 255};
|
||||
Color highlight = (Color){140, 160, 200, 255};
|
||||
// Main plate
|
||||
DrawRectangle(ox + 4, oy + 3, 8, 9, metal);
|
||||
// Collar
|
||||
DrawRectangle(ox + 5, oy + 2, 6, 1, dark_metal);
|
||||
// Vertical ridge
|
||||
DrawRectangle(ox + 7, oy + 3, 2, 9, highlight);
|
||||
// Bottom trim
|
||||
DrawRectangle(ox + 4, oy + 11, 8, 1, dark_metal);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_door_closed_tile(Tileset *ts, int id) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
int w = ts->tile_w;
|
||||
int h = ts->tile_h;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Wooden door frame
|
||||
Color wood_dark = (Color){100, 70, 40, 255};
|
||||
Color wood_light = (Color){140, 100, 60, 255};
|
||||
Color wood_mid = (Color){120, 85, 50, 255};
|
||||
|
||||
// Frame
|
||||
DrawRectangle(ox, oy, w, h, wood_dark);
|
||||
// Panels
|
||||
DrawRectangle(ox + 2, oy + 2, w - 4, h - 4, wood_mid);
|
||||
// Inner panel
|
||||
DrawRectangle(ox + 4, oy + 4, w - 8, h - 8, wood_light);
|
||||
// Cross pattern
|
||||
DrawRectangle(ox + 7, oy + 2, 2, h - 4, wood_dark);
|
||||
DrawRectangle(ox + 2, oy + 7, w - 4, 2, wood_dark);
|
||||
// Handle
|
||||
DrawPixel(ox + 12, oy + 8, (Color){200, 180, 50, 255});
|
||||
DrawPixel(ox + 12, oy + 9, (Color){200, 180, 50, 255});
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_door_open_tile(Tileset *ts, int id) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
int w = ts->tile_w;
|
||||
int h = ts->tile_h;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Open door - shows floor with door frame on sides
|
||||
Color floor = (Color){75, 72, 68, 255};
|
||||
Color wood_dark = (Color){100, 70, 40, 255};
|
||||
|
||||
// Floor
|
||||
DrawRectangle(ox, oy, w, h, floor);
|
||||
// Door frame on left side (open)
|
||||
DrawRectangle(ox, oy, 3, h, wood_dark);
|
||||
// Hinges
|
||||
DrawPixel(ox + 1, oy + 4, (Color){80, 80, 80, 255});
|
||||
DrawPixel(ox + 1, oy + 12, (Color){80, 80, 80, 255});
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_effect_burn_tile(Tileset *ts, int id) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
DrawRectangle(ox, oy, ts->tile_w, ts->tile_h, BLANK);
|
||||
|
||||
// Fire effect - orange/red flames
|
||||
Color flame1 = (Color){255, 100, 20, 255};
|
||||
Color flame2 = (Color){255, 180, 40, 255};
|
||||
Color flame3 = (Color){255, 60, 10, 255};
|
||||
|
||||
// Flame shapes
|
||||
DrawRectangle(ox + 4, oy + 8, 2, 6, flame1);
|
||||
DrawRectangle(ox + 7, oy + 6, 2, 8, flame2);
|
||||
DrawRectangle(ox + 10, oy + 9, 2, 5, flame3);
|
||||
DrawPixel(ox + 5, oy + 5, flame2);
|
||||
DrawPixel(ox + 8, oy + 4, flame1);
|
||||
DrawPixel(ox + 11, oy + 7, flame2);
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_effect_poison_tile(Tileset *ts, int id) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
DrawRectangle(ox, oy, ts->tile_w, ts->tile_h, BLANK);
|
||||
|
||||
// Poison effect - green bubbles/drops
|
||||
Color poison1 = (Color){50, 200, 50, 255};
|
||||
Color poison2 = (Color){30, 150, 30, 255};
|
||||
Color poison3 = (Color){80, 255, 80, 255};
|
||||
|
||||
// Bubbles
|
||||
DrawRectangle(ox + 5, oy + 4, 3, 3, poison1);
|
||||
DrawRectangle(ox + 9, oy + 7, 2, 2, poison2);
|
||||
DrawRectangle(ox + 4, oy + 10, 2, 2, poison3);
|
||||
DrawRectangle(ox + 8, oy + 11, 3, 2, poison1);
|
||||
DrawPixel(ox + 11, oy + 5, poison3);
|
||||
DrawPixel(ox + 6, oy + 13, poison2);
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_effect_block_tile(Tileset *ts, int id) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
DrawRectangle(ox, oy, ts->tile_w, ts->tile_h, BLANK);
|
||||
|
||||
// Block/shield effect - blue shield shape
|
||||
Color shield = (Color){80, 130, 220, 255};
|
||||
Color shield_light = (Color){120, 170, 255, 255};
|
||||
Color shield_dark = (Color){50, 90, 180, 255};
|
||||
|
||||
// Shield outline
|
||||
DrawRectangle(ox + 4, oy + 2, 8, 12, shield);
|
||||
// Inner highlight
|
||||
DrawRectangle(ox + 6, oy + 4, 4, 8, shield_light);
|
||||
// Border
|
||||
DrawRectangle(ox + 4, oy + 2, 8, 1, shield_dark);
|
||||
DrawRectangle(ox + 4, oy + 13, 8, 1, shield_dark);
|
||||
DrawRectangle(ox + 4, oy + 2, 1, 12, shield_dark);
|
||||
DrawRectangle(ox + 11, oy + 2, 1, 12, shield_dark);
|
||||
// Cross in center
|
||||
DrawRectangle(ox + 7, oy + 6, 2, 4, shield_dark);
|
||||
DrawRectangle(ox + 6, oy + 7, 4, 2, shield_dark);
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void paint_slash_effect_tile(Tileset *ts, int id) {
|
||||
if (ts == NULL || id < 0 || id >= MAX_TILE_ID)
|
||||
return;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return;
|
||||
|
||||
Vector2 off = get_paint_offset(ts, id);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
|
||||
BeginTextureMode(ts->render_target);
|
||||
DrawRectangle(ox, oy, ts->tile_w, ts->tile_h, BLANK);
|
||||
|
||||
// Slash effect - white/gray diagonal slash
|
||||
Color slash = (Color){255, 255, 255, 255};
|
||||
Color slash_trail = (Color){200, 200, 220, 255};
|
||||
|
||||
// Main slash line (diagonal)
|
||||
DrawRectangle(ox + 2, oy + 12, 3, 2, slash);
|
||||
DrawRectangle(ox + 4, oy + 10, 3, 2, slash);
|
||||
DrawRectangle(ox + 6, oy + 8, 3, 2, slash);
|
||||
DrawRectangle(ox + 8, oy + 6, 3, 2, slash);
|
||||
DrawRectangle(ox + 10, oy + 4, 3, 2, slash);
|
||||
DrawRectangle(ox + 12, oy + 2, 2, 2, slash);
|
||||
// Trail
|
||||
DrawPixel(ox + 3, oy + 11, slash_trail);
|
||||
DrawPixel(ox + 5, oy + 9, slash_trail);
|
||||
DrawPixel(ox + 7, oy + 7, slash_trail);
|
||||
DrawPixel(ox + 9, oy + 5, slash_trail);
|
||||
DrawPixel(ox + 11, oy + 3, slash_trail);
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
int tileset_paint_all(Tileset *ts) {
|
||||
if (ts == NULL)
|
||||
return 0;
|
||||
if (ts->render_target.id == 0 || ts->finalized)
|
||||
return 0;
|
||||
|
||||
// Register all tile IDs first
|
||||
for (int id = 0; id < NUM_TILE_IDS; id++) {
|
||||
if (!tileset_register(ts, id))
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Paint map tiles
|
||||
paint_wall_tile(ts, TILE_WALL_0, 0);
|
||||
paint_wall_tile(ts, TILE_WALL_1, 1);
|
||||
paint_floor_tile(ts, TILE_FLOOR_0, 0);
|
||||
paint_floor_tile(ts, TILE_FLOOR_1, 1);
|
||||
paint_floor_tile(ts, TILE_FLOOR_2, 2);
|
||||
paint_floor_tile(ts, TILE_FLOOR_3, 3);
|
||||
paint_stairs_tile(ts, TILE_STAIRS);
|
||||
|
||||
// Paint entity sprites
|
||||
paint_player_tile(ts, SPRITE_PLAYER);
|
||||
paint_player_walk_tile(ts, SPRITE_PLAYER_WALK_0, 0);
|
||||
paint_player_walk_tile(ts, SPRITE_PLAYER_WALK_1, 1);
|
||||
paint_player_attack_tile(ts, SPRITE_PLAYER_ATTACK);
|
||||
|
||||
// Enemy goblin sprites
|
||||
paint_enemy_tile(ts, SPRITE_ENEMY_GOBLIN, 0);
|
||||
paint_enemy_walk_tile(ts, SPRITE_ENEMY_GOBLIN_WALK_0, 0, 0);
|
||||
paint_enemy_walk_tile(ts, SPRITE_ENEMY_GOBLIN_WALK_1, 0, 1);
|
||||
paint_enemy_attack_tile(ts, SPRITE_ENEMY_GOBLIN_ATTACK, 0);
|
||||
|
||||
// Enemy skeleton sprites
|
||||
paint_enemy_tile(ts, SPRITE_ENEMY_SKELETON, 1);
|
||||
paint_enemy_walk_tile(ts, SPRITE_ENEMY_SKELETON_WALK_0, 1, 0);
|
||||
paint_enemy_walk_tile(ts, SPRITE_ENEMY_SKELETON_WALK_1, 1, 1);
|
||||
paint_enemy_attack_tile(ts, SPRITE_ENEMY_SKELETON_ATTACK, 1);
|
||||
|
||||
// Enemy orc sprites
|
||||
paint_enemy_tile(ts, SPRITE_ENEMY_ORC, 2);
|
||||
paint_enemy_walk_tile(ts, SPRITE_ENEMY_ORC_WALK_0, 2, 0);
|
||||
paint_enemy_walk_tile(ts, SPRITE_ENEMY_ORC_WALK_1, 2, 1);
|
||||
paint_enemy_attack_tile(ts, SPRITE_ENEMY_ORC_ATTACK, 2);
|
||||
|
||||
paint_item_tile(ts, SPRITE_ITEM_POTION, 0);
|
||||
paint_item_tile(ts, SPRITE_ITEM_WEAPON, 1);
|
||||
paint_item_tile(ts, SPRITE_ITEM_ARMOR, 2);
|
||||
|
||||
// Door tiles
|
||||
paint_door_closed_tile(ts, TILE_DOOR_CLOSED_SPRITE);
|
||||
paint_door_open_tile(ts, TILE_DOOR_OPEN_SPRITE);
|
||||
|
||||
// Effect sprites
|
||||
paint_effect_burn_tile(ts, SPRITE_EFFECT_BURN);
|
||||
paint_effect_poison_tile(ts, SPRITE_EFFECT_POISON);
|
||||
paint_effect_block_tile(ts, SPRITE_EFFECT_BLOCK);
|
||||
paint_slash_effect_tile(ts, SPRITE_SLASH_EFFECT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
66
libs/tileset/tileset_paint.h
Normal file
66
libs/tileset/tileset_paint.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#ifndef TILESET_PAINT_H
|
||||
#define TILESET_PAINT_H
|
||||
|
||||
#include "tileset.h"
|
||||
|
||||
// Forward declarations for types used in painting (avoid including common.h which conflicts with tileset.h macros)
|
||||
typedef enum { ENEMY_GOBLIN_FWD, ENEMY_SKELETON_FWD, ENEMY_ORC_FWD } EnemyType_Paint;
|
||||
typedef enum { ITEM_POTION_FWD, ITEM_WEAPON_FWD, ITEM_ARMOR_FWD } ItemType_Paint;
|
||||
|
||||
// Paint a wall tile with brick-like pattern.
|
||||
// variant: 0 or 1 for shade variation.
|
||||
void paint_wall_tile(Tileset *ts, int id, int variant);
|
||||
|
||||
// Paint a floor tile with stone/dithered pattern.
|
||||
// variant: 0-3 for different noise patterns.
|
||||
void paint_floor_tile(Tileset *ts, int id, int variant);
|
||||
|
||||
// Paint a stairs tile with depth illusion.
|
||||
void paint_stairs_tile(Tileset *ts, int id);
|
||||
|
||||
// Paint the player sprite (adventurer silhouette).
|
||||
void paint_player_tile(Tileset *ts, int id);
|
||||
|
||||
// Paint a player walking animation frame.
|
||||
// frame: 0 or 1 for the two walk frames.
|
||||
void paint_player_walk_tile(Tileset *ts, int id, int frame);
|
||||
|
||||
// Paint a player attacking animation frame.
|
||||
void paint_player_attack_tile(Tileset *ts, int id);
|
||||
|
||||
// Paint an enemy sprite based on type.
|
||||
void paint_enemy_tile(Tileset *ts, int id, int enemy_type);
|
||||
|
||||
// Paint an enemy walking animation frame.
|
||||
// frame: 0 or 1 for the two walk frames.
|
||||
void paint_enemy_walk_tile(Tileset *ts, int id, int enemy_type, int frame);
|
||||
|
||||
// Paint an enemy attacking animation frame.
|
||||
void paint_enemy_attack_tile(Tileset *ts, int id, int enemy_type);
|
||||
|
||||
// Paint an item sprite based on type.
|
||||
void paint_item_tile(Tileset *ts, int id, int item_type);
|
||||
|
||||
// Paint a closed door tile.
|
||||
void paint_door_closed_tile(Tileset *ts, int id);
|
||||
|
||||
// Paint an open door tile.
|
||||
void paint_door_open_tile(Tileset *ts, int id);
|
||||
|
||||
// Paint a burning/fire effect sprite.
|
||||
void paint_effect_burn_tile(Tileset *ts, int id);
|
||||
|
||||
// Paint a poison effect sprite.
|
||||
void paint_effect_poison_tile(Tileset *ts, int id);
|
||||
|
||||
// Paint a block/shield effect sprite.
|
||||
void paint_effect_block_tile(Tileset *ts, int id);
|
||||
|
||||
// Paint a slash attack effect sprite.
|
||||
void paint_slash_effect_tile(Tileset *ts, int id);
|
||||
|
||||
// Convenience: paint and register all tiles in one call.
|
||||
// Returns 0 on failure, non-zero on success.
|
||||
int tileset_paint_all(Tileset *ts);
|
||||
|
||||
#endif // TILESET_PAINT_H
|
||||
98
src/common.h
98
src/common.h
|
|
@ -9,7 +9,7 @@ typedef struct {
|
|||
} Vec2;
|
||||
|
||||
// Tile types
|
||||
typedef enum { TILE_WALL, TILE_FLOOR, TILE_STAIRS } TileType;
|
||||
typedef enum { TILE_WALL, TILE_FLOOR, TILE_STAIRS, TILE_DOOR_CLOSED, TILE_DOOR_OPEN, TILE_DOOR_RUINED } TileType;
|
||||
|
||||
// Status effect types
|
||||
typedef enum { EFFECT_NONE, EFFECT_POISON, EFFECT_STUN, EFFECT_BLEED, EFFECT_WEAKEN, EFFECT_BURN } StatusEffectType;
|
||||
|
|
@ -49,69 +49,165 @@ typedef struct {
|
|||
typedef enum { ITEM_POTION, ITEM_WEAPON, ITEM_ARMOR } ItemType;
|
||||
|
||||
// Item
|
||||
|
||||
typedef struct {
|
||||
int x, y;
|
||||
|
||||
ItemType type;
|
||||
|
||||
int power;
|
||||
|
||||
int floor;
|
||||
|
||||
int picked_up;
|
||||
|
||||
DamageClass dmg_class;
|
||||
|
||||
int crit_chance;
|
||||
|
||||
int crit_multiplier;
|
||||
|
||||
int status_chance;
|
||||
|
||||
// rendering
|
||||
|
||||
int sprite_tile_id; // tile ID for rendering
|
||||
|
||||
} Item;
|
||||
|
||||
// Player animation states
|
||||
typedef enum { PLAYER_ANIM_IDLE, PLAYER_ANIM_WALK, PLAYER_ANIM_ATTACK } PlayerAnimState;
|
||||
|
||||
// Player
|
||||
|
||||
typedef struct {
|
||||
Vec2 position;
|
||||
|
||||
int hp, max_hp;
|
||||
|
||||
int attack;
|
||||
|
||||
int defense;
|
||||
|
||||
int floor;
|
||||
|
||||
int step_count;
|
||||
|
||||
int speed; // actions per 100 ticks (100 = 1 action per turn)
|
||||
|
||||
int cooldown; // countdown to next action (0 = can act)
|
||||
|
||||
int dodge; // dodge chance percentage
|
||||
|
||||
int block; // flat damage reduction on successful block roll
|
||||
|
||||
Item equipped_weapon;
|
||||
|
||||
int has_weapon;
|
||||
|
||||
Item equipped_armor;
|
||||
|
||||
int has_armor;
|
||||
|
||||
Item inventory[MAX_INVENTORY];
|
||||
|
||||
int inventory_count;
|
||||
|
||||
// status effects
|
||||
|
||||
StatusEffect effects[MAX_EFFECTS];
|
||||
|
||||
int effect_count;
|
||||
|
||||
// animation
|
||||
|
||||
PlayerAnimState anim_state;
|
||||
|
||||
int anim_frame; // current animation frame
|
||||
|
||||
int anim_timer; // frames until next frame
|
||||
|
||||
int facing_right; // 1 = facing right, 0 = facing left
|
||||
|
||||
// rendering
|
||||
|
||||
int sprite_tile_id; // tile ID for rendering
|
||||
|
||||
// visual effects
|
||||
|
||||
int flash_timer; // damage flash frames remaining
|
||||
|
||||
} Player;
|
||||
|
||||
// Enemy types
|
||||
typedef enum { ENEMY_GOBLIN, ENEMY_SKELETON, ENEMY_ORC } EnemyType;
|
||||
|
||||
// Enemy animation states
|
||||
typedef enum { ENEMY_ANIM_IDLE, ENEMY_ANIM_WALK, ENEMY_ANIM_ATTACK } EnemyAnimState;
|
||||
|
||||
// Enemy
|
||||
|
||||
typedef struct {
|
||||
Vec2 position;
|
||||
|
||||
int hp;
|
||||
|
||||
int max_hp;
|
||||
|
||||
int attack;
|
||||
|
||||
int alive;
|
||||
|
||||
EnemyType type;
|
||||
|
||||
int speed; // actions per 100 ticks
|
||||
|
||||
int cooldown; // countdown to next action
|
||||
|
||||
int dodge; // dodge chance percentage
|
||||
|
||||
int block; // flat damage reduction
|
||||
|
||||
int resistance[NUM_DMG_CLASSES];
|
||||
|
||||
DamageClass dmg_class;
|
||||
|
||||
int status_chance;
|
||||
|
||||
int crit_chance; // crit chance percentage (0-100)
|
||||
|
||||
int crit_mult; // crit damage multiplier percentage (e.g. 150 = 1.5x)
|
||||
|
||||
// vision
|
||||
|
||||
int vision_range;
|
||||
|
||||
int alert; // 1 = aware of player, searching
|
||||
|
||||
int last_known_x; // last position where enemy saw player
|
||||
|
||||
int last_known_y;
|
||||
|
||||
// status effects
|
||||
|
||||
StatusEffect effects[MAX_EFFECTS];
|
||||
|
||||
int effect_count;
|
||||
|
||||
// animation
|
||||
|
||||
EnemyAnimState anim_state;
|
||||
|
||||
int anim_frame; // current animation frame
|
||||
|
||||
int anim_timer; // frames until next frame
|
||||
|
||||
int facing_right; // 1 = facing right, 0 = facing left
|
||||
|
||||
// rendering
|
||||
|
||||
int sprite_tile_id; // tile ID for rendering
|
||||
|
||||
} Enemy;
|
||||
|
||||
|
||||
|
|
|
|||
64
src/enemy.c
64
src/enemy.c
|
|
@ -5,6 +5,7 @@
|
|||
#include "movement.h"
|
||||
#include "rng/rng.h"
|
||||
#include "settings.h"
|
||||
#include "tileset/tileset.h"
|
||||
#include <string.h>
|
||||
|
||||
// Forward declaration
|
||||
|
|
@ -25,6 +26,12 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
|||
if (floor >= 4)
|
||||
max_type = 3;
|
||||
|
||||
// Get the player's starting room (first room) to exclude from enemy spawn
|
||||
Room *start_room = NULL;
|
||||
if (map->room_count > 0) {
|
||||
start_room = &map->rooms[0];
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_enemies; i++) {
|
||||
// Find random floor position
|
||||
int ex, ey;
|
||||
|
|
@ -35,6 +42,14 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Don't spawn in the starting room
|
||||
if (start_room != NULL) {
|
||||
if (ex >= start_room->x && ex < start_room->x + start_room->w && ey >= start_room->y &&
|
||||
ey < start_room->y + start_room->h) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't spawn on other enemies
|
||||
if (is_enemy_at(enemies, *count, ex, ey)) {
|
||||
continue;
|
||||
|
|
@ -125,6 +140,27 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
|||
}
|
||||
e.cooldown = e.speed;
|
||||
|
||||
// Initialize animation state
|
||||
e.anim_state = ENEMY_ANIM_IDLE;
|
||||
e.anim_frame = 0;
|
||||
e.anim_timer = 0;
|
||||
e.facing_right = (e.position.x < p->position.x) ? 1 : 0;
|
||||
// Set sprite tile ID based on enemy type
|
||||
switch (e.type) {
|
||||
case ENEMY_GOBLIN:
|
||||
e.sprite_tile_id = SPRITE_ENEMY_GOBLIN;
|
||||
break;
|
||||
case ENEMY_SKELETON:
|
||||
e.sprite_tile_id = SPRITE_ENEMY_SKELETON;
|
||||
break;
|
||||
case ENEMY_ORC:
|
||||
e.sprite_tile_id = SPRITE_ENEMY_ORC;
|
||||
break;
|
||||
default:
|
||||
e.sprite_tile_id = SPRITE_ENEMY_GOBLIN;
|
||||
break;
|
||||
}
|
||||
|
||||
enemies[i] = e;
|
||||
(*count)++;
|
||||
}
|
||||
|
|
@ -275,6 +311,9 @@ void enemy_act(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_coun
|
|||
|
||||
// Attack if adjacent to player
|
||||
if (can_see && can_see_entity(map, e->position.x, e->position.y, p->position.x, p->position.y, 1)) {
|
||||
e->anim_state = ENEMY_ANIM_ATTACK;
|
||||
e->anim_timer = 12;
|
||||
e->facing_right = (e->position.x < p->position.x) ? 1 : 0;
|
||||
combat_enemy_attack(e, p);
|
||||
propagate_alert(e, all_enemies, enemy_count);
|
||||
return;
|
||||
|
|
@ -282,14 +321,28 @@ void enemy_act(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_coun
|
|||
|
||||
// Move toward player if visible
|
||||
if (can_see) {
|
||||
int old_x = e->position.x;
|
||||
int old_y = e->position.y;
|
||||
enemy_move_toward_player(e, p, map, all_enemies, enemy_count);
|
||||
if (e->position.x != old_x || e->position.y != old_y) {
|
||||
e->anim_state = ENEMY_ANIM_WALK;
|
||||
e->anim_timer = 8;
|
||||
e->facing_right = (e->position.x < p->position.x) ? 1 : 0;
|
||||
}
|
||||
propagate_alert(e, all_enemies, enemy_count);
|
||||
return;
|
||||
}
|
||||
|
||||
// If alert but can't see player, move toward last known position
|
||||
if (e->alert) {
|
||||
int old_x = e->position.x;
|
||||
int old_y = e->position.y;
|
||||
enemy_move_to_last_known(e, map, all_enemies, enemy_count);
|
||||
if (e->position.x != old_x || e->position.y != old_y) {
|
||||
e->anim_state = ENEMY_ANIM_WALK;
|
||||
e->anim_timer = 8;
|
||||
e->facing_right = (e->position.x < old_x) ? 0 : 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -304,6 +357,17 @@ void enemy_update_all(Enemy enemies[], int count, Player *p, Map *map) {
|
|||
if (!e->alive)
|
||||
continue;
|
||||
|
||||
// Update animation timer
|
||||
if (e->anim_timer > 0) {
|
||||
e->anim_timer--;
|
||||
if (e->anim_timer <= 0) {
|
||||
e->anim_state = ENEMY_ANIM_IDLE;
|
||||
e->anim_frame = 0;
|
||||
} else if (e->anim_state == ENEMY_ANIM_WALK) {
|
||||
e->anim_frame = (e->anim_timer / 4) % 2;
|
||||
}
|
||||
}
|
||||
|
||||
e->cooldown -= e->speed;
|
||||
if (e->cooldown <= 0) {
|
||||
enemy_act(e, p, map, enemies, count);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define GAME_STATE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "tileset/tileset.h"
|
||||
#include <raylib.h>
|
||||
|
||||
// Floating damage text
|
||||
|
|
@ -65,6 +66,12 @@ typedef struct {
|
|||
int final_score;
|
||||
// Seed for this run
|
||||
unsigned int run_seed;
|
||||
// Tileset atlas for rendering
|
||||
Tileset tileset;
|
||||
// Slash effect timer for attack animations
|
||||
int slash_timer; // frames remaining for slash effect
|
||||
int slash_x, slash_y; // position of slash effect
|
||||
DamageClass slash_dmg_class; // damage type for slash visual
|
||||
} GameState;
|
||||
|
||||
#endif // GAME_STATE_H
|
||||
|
|
|
|||
17
src/items.c
17
src/items.c
|
|
@ -2,6 +2,7 @@
|
|||
#include "map/map.h"
|
||||
#include "rng/rng.h"
|
||||
#include "settings.h"
|
||||
#include "tileset/tileset.h"
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -77,6 +78,22 @@ void item_spawn(Item items[], int *count, Map *map, int floor) {
|
|||
item.power = 1 + rng_int(0, floor / 2);
|
||||
}
|
||||
|
||||
// Set sprite tile ID based on item type
|
||||
switch (item.type) {
|
||||
case ITEM_POTION:
|
||||
item.sprite_tile_id = SPRITE_ITEM_POTION;
|
||||
break;
|
||||
case ITEM_WEAPON:
|
||||
item.sprite_tile_id = SPRITE_ITEM_WEAPON;
|
||||
break;
|
||||
case ITEM_ARMOR:
|
||||
item.sprite_tile_id = SPRITE_ITEM_ARMOR;
|
||||
break;
|
||||
default:
|
||||
item.sprite_tile_id = SPRITE_ITEM_POTION;
|
||||
break;
|
||||
}
|
||||
|
||||
items[*count] = item;
|
||||
(*count)++;
|
||||
}
|
||||
|
|
|
|||
104
src/main.c
104
src/main.c
|
|
@ -4,11 +4,14 @@
|
|||
#include "enemy.h"
|
||||
#include "items.h"
|
||||
#include "map/map.h"
|
||||
#include "map/utils.h"
|
||||
#include "movement.h"
|
||||
#include "player.h"
|
||||
#include "render.h"
|
||||
#include "rng/rng.h"
|
||||
#include "settings.h"
|
||||
#include "tileset/tileset.h"
|
||||
#include "tileset/tileset_paint.h"
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -182,19 +185,18 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
|||
if (gs->game_over)
|
||||
return;
|
||||
|
||||
// Check if stepped on stairs
|
||||
if (gs->map.tiles[gs->player.position.y][gs->player.position.x] == TILE_STAIRS) {
|
||||
gs->awaiting_descend = 1;
|
||||
gs->last_message = "Descend to next floor? (Y/N)";
|
||||
gs->message_timer = 120;
|
||||
return;
|
||||
}
|
||||
|
||||
// combat feedback - player attacked an enemy this turn
|
||||
if (attacked_enemy != NULL) {
|
||||
int ex = attacked_enemy->position.x * TILE_SIZE + 8;
|
||||
int ey = attacked_enemy->position.y * TILE_SIZE;
|
||||
|
||||
// Trigger slash effect
|
||||
gs->slash_timer = 8;
|
||||
gs->slash_x = attacked_enemy->position.x;
|
||||
gs->slash_y = attacked_enemy->position.y;
|
||||
// Use player's equipped weapon damage class, or default to slash
|
||||
gs->slash_dmg_class = gs->player.has_weapon ? gs->player.equipped_weapon.dmg_class : DMG_SLASH;
|
||||
|
||||
if (combat_was_dodged()) {
|
||||
spawn_floating_label(gs, ex, ey, LABEL_DODGE, EFFECT_NONE);
|
||||
audio_play_dodge(gs);
|
||||
|
|
@ -237,6 +239,7 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
|||
gs->screen_shake = SHAKE_PLAYER_DAMAGE_DURATION;
|
||||
gs->damage_taken += combat_get_last_damage();
|
||||
gs->times_hit++;
|
||||
gs->player.flash_timer = 4; // Trigger damage flash
|
||||
spawn_floating_text(gs, gs->player.position.x * TILE_SIZE + 8, gs->player.position.y * TILE_SIZE,
|
||||
combat_get_last_damage(), combat_was_critical());
|
||||
}
|
||||
|
|
@ -247,6 +250,13 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
|||
|
||||
if (gs->player.hp <= 0)
|
||||
gs->game_over = 1;
|
||||
|
||||
// Check if stepped on stairs AFTER enemy turns
|
||||
if (gs->map.tiles[gs->player.position.y][gs->player.position.x] == TILE_STAIRS) {
|
||||
gs->awaiting_descend = 1;
|
||||
gs->last_message = "Descend to next floor? (Y/N)";
|
||||
gs->message_timer = 120;
|
||||
}
|
||||
}
|
||||
|
||||
// If player is stunned, wait for any key then consume the turn
|
||||
|
|
@ -457,11 +467,27 @@ static int handle_movement_input(GameState *gs) {
|
|||
try_move_entity(&gs->player.position, direction, &gs->map, &gs->player, gs->enemies, gs->enemy_count, true);
|
||||
if (result == MOVE_RESULT_MOVED) {
|
||||
player_on_move(&gs->player);
|
||||
// Set walk animation
|
||||
gs->player.anim_state = PLAYER_ANIM_WALK;
|
||||
gs->player.anim_frame = 0;
|
||||
gs->player.anim_timer = 8; // frames to show each walk frame
|
||||
// Update facing direction
|
||||
if (direction.x != 0)
|
||||
gs->player.facing_right = (direction.x > 0);
|
||||
action = 1;
|
||||
} else if (result == MOVE_RESULT_BLOCKED_ENEMY) {
|
||||
target = player_find_enemy_at(gs->enemies, gs->enemy_count, new_x, new_y);
|
||||
if (target != NULL) {
|
||||
player_attack(&gs->player, target);
|
||||
// Set attack animation
|
||||
gs->player.anim_state = PLAYER_ANIM_ATTACK;
|
||||
gs->player.anim_frame = 0;
|
||||
gs->player.anim_timer = 12; // frames to show attack
|
||||
// Face the enemy
|
||||
if (target->position.x > gs->player.position.x)
|
||||
gs->player.facing_right = 1;
|
||||
else if (target->position.x < gs->player.position.x)
|
||||
gs->player.facing_right = 0;
|
||||
action = 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -526,13 +552,32 @@ static void game_loop(unsigned int run_seed, FontManager *fm) {
|
|||
load_audio_assets(&gs);
|
||||
// font
|
||||
init_fonts(fm);
|
||||
// Initialize tileset atlas
|
||||
if (!tileset_init(&gs.tileset, TILE_SIZE, TILE_SIZE)) {
|
||||
fprintf(stderr, "Failed to initialize tileset\n");
|
||||
return;
|
||||
}
|
||||
if (!tileset_paint_all(&gs.tileset)) {
|
||||
fprintf(stderr, "Failed to paint tiles\n");
|
||||
tileset_destroy(&gs.tileset);
|
||||
return;
|
||||
}
|
||||
if (!tileset_finalize(&gs.tileset)) {
|
||||
fprintf(stderr, "Failed to finalize tileset\n");
|
||||
tileset_destroy(&gs.tileset);
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize first floor
|
||||
init_floor(&gs, 1);
|
||||
|
||||
// Disable esc to exit
|
||||
SetExitKey(0);
|
||||
|
||||
int frame_counter = 0;
|
||||
while (!WindowShouldClose()) {
|
||||
frame_counter++;
|
||||
|
||||
// Handle input
|
||||
if (!gs.game_over) {
|
||||
// Tick status effects at the start of each frame where input is checked
|
||||
|
|
@ -552,6 +597,12 @@ static void game_loop(unsigned int run_seed, FontManager *fm) {
|
|||
gs.game_won = 0;
|
||||
load_audio_assets(&gs);
|
||||
init_fonts(fm);
|
||||
// Re-initialize tileset for new run
|
||||
if (!tileset_init(&gs.tileset, TILE_SIZE, TILE_SIZE) || !tileset_paint_all(&gs.tileset) ||
|
||||
!tileset_finalize(&gs.tileset)) {
|
||||
fprintf(stderr, "Failed to re-initialize tileset\n");
|
||||
break;
|
||||
}
|
||||
init_floor(&gs, 1);
|
||||
// Update window title with new seed
|
||||
char title[128];
|
||||
|
|
@ -567,6 +618,27 @@ static void game_loop(unsigned int run_seed, FontManager *fm) {
|
|||
// Update effects
|
||||
update_effects(&gs);
|
||||
|
||||
// Update slash effect timer
|
||||
if (gs.slash_timer > 0)
|
||||
gs.slash_timer--;
|
||||
|
||||
// Update player animation
|
||||
if (gs.player.anim_timer > 0) {
|
||||
gs.player.anim_timer--;
|
||||
if (gs.player.anim_timer <= 0) {
|
||||
// Animation finished, return to idle
|
||||
gs.player.anim_state = PLAYER_ANIM_IDLE;
|
||||
gs.player.anim_frame = 0;
|
||||
} else if (gs.player.anim_state == PLAYER_ANIM_WALK) {
|
||||
// Toggle walk frame every 4 frames
|
||||
gs.player.anim_frame = (gs.player.anim_timer / 4) % 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Update player damage flash
|
||||
if (gs.player.flash_timer > 0)
|
||||
gs.player.flash_timer--;
|
||||
|
||||
// Render
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
|
@ -576,15 +648,19 @@ static void game_loop(unsigned int run_seed, FontManager *fm) {
|
|||
cam.zoom = 1.0f;
|
||||
cam.offset = (Vector2){(float)gs.shake_x, (float)gs.shake_y};
|
||||
BeginMode2D(cam);
|
||||
render_map(&gs.map);
|
||||
render_items(gs.items, gs.item_count, gs.map.visible);
|
||||
render_enemies(gs.enemies, gs.enemy_count, gs.map.visible);
|
||||
render_player(&gs.player);
|
||||
render_map(&gs.map, &gs.tileset);
|
||||
render_items(gs.items, gs.item_count, gs.map.visible, &gs.tileset);
|
||||
render_enemies(gs.enemies, gs.enemy_count, gs.map.visible, &gs.tileset, frame_counter);
|
||||
render_player(&gs.player, &gs.tileset, frame_counter);
|
||||
// Draw slash effect on top of entities
|
||||
if (gs.slash_timer > 0) {
|
||||
render_slash_effect(gs.slash_x, gs.slash_y, gs.slash_dmg_class, gs.slash_timer);
|
||||
}
|
||||
EndMode2D();
|
||||
|
||||
// Floating texts follow world shake
|
||||
render_floating_texts(gs.floating_texts, gs.floating_count, gs.shake_x, gs.shake_y);
|
||||
render_ui(&gs.player, fm);
|
||||
render_floating_texts(gs.floating_texts, gs.floating_count, gs.shake_x, gs.shake_y, fm);
|
||||
render_ui(&gs.player, &gs.tileset, fm);
|
||||
|
||||
// Draw action log
|
||||
render_action_log(gs.action_log, gs.log_count, gs.log_head, fm);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "common.h"
|
||||
#include "items.h"
|
||||
#include "settings.h"
|
||||
#include "tileset/tileset.h"
|
||||
#include <string.h>
|
||||
|
||||
void player_init(Player *p, int x, int y) {
|
||||
|
|
@ -28,6 +29,13 @@ void player_init(Player *p, int x, int y) {
|
|||
p->effect_count = 0;
|
||||
memset(p->effects, 0, sizeof(p->effects));
|
||||
|
||||
// Initialize animation state
|
||||
p->anim_state = PLAYER_ANIM_IDLE;
|
||||
p->anim_frame = 0;
|
||||
p->anim_timer = 0;
|
||||
p->facing_right = 1;
|
||||
p->sprite_tile_id = SPRITE_PLAYER;
|
||||
|
||||
// Initialize inventory to empty
|
||||
for (int i = 0; i < MAX_INVENTORY; i++) {
|
||||
p->inventory[i].picked_up = 1; // mark as invalid
|
||||
|
|
|
|||
358
src/render.c
358
src/render.c
|
|
@ -1,6 +1,8 @@
|
|||
#include "render.h"
|
||||
#include "items.h"
|
||||
#include "settings.h"
|
||||
#include "map/utils.h"
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
|
@ -63,75 +65,289 @@ static void draw_text_body(Font f, const char *text, float x, float y, int size,
|
|||
DrawTextEx(f, text, (Vector2){x, y}, (float)size, spacing, c);
|
||||
}
|
||||
|
||||
void render_map(const Map *map) {
|
||||
void render_map(const Map *map, const Tileset *tileset) {
|
||||
for (int y = 0; y < MAP_HEIGHT; y++) {
|
||||
for (int x = 0; x < MAP_WIDTH; x++) {
|
||||
Rectangle rect = {(float)(x * TILE_SIZE), (float)(y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE};
|
||||
Rectangle dst = {(float)(x * TILE_SIZE), (float)(y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE};
|
||||
int visible = map->visible[y][x];
|
||||
int remembered = map->remembered[y][x];
|
||||
|
||||
if (!visible && !remembered) {
|
||||
DrawRectangleRec(rect, (Color){5, 5, 10, 255});
|
||||
DrawRectangleRec(dst, (Color){5, 5, 10, 255});
|
||||
continue;
|
||||
}
|
||||
|
||||
int tile_id = -1;
|
||||
switch (map->tiles[y][x]) {
|
||||
case TILE_WALL:
|
||||
tile_id = TILE_WALL_0 + ((x * 7 + y * 13) % 2);
|
||||
break;
|
||||
case TILE_FLOOR:
|
||||
tile_id = TILE_FLOOR_0 + ((x * 7 + y * 13) % 4);
|
||||
break;
|
||||
case TILE_STAIRS:
|
||||
tile_id = TILE_STAIRS;
|
||||
break;
|
||||
case TILE_DOOR_CLOSED:
|
||||
tile_id = TILE_DOOR_CLOSED_SPRITE;
|
||||
break;
|
||||
case TILE_DOOR_OPEN:
|
||||
tile_id = TILE_DOOR_OPEN_SPRITE;
|
||||
break;
|
||||
case TILE_DOOR_RUINED:
|
||||
tile_id = TILE_DOOR_OPEN_SPRITE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (tile_id >= 0 && tileset != NULL && tileset->finalized) {
|
||||
Rectangle src = tileset_get_region(tileset, tile_id);
|
||||
if (src.width > 0) {
|
||||
Color tint = WHITE;
|
||||
if (!visible) {
|
||||
// Dim remembered tiles
|
||||
tint = (Color){128, 128, 128, 255};
|
||||
}
|
||||
DrawTexturePro(tileset->atlas, src, dst, (Vector2){0, 0}, 0.0f, tint);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to solid colors if tileset not available
|
||||
Color wall_color = visible ? DARKGRAY : (Color){25, 25, 30, 255};
|
||||
Color floor_color = visible ? BLACK : (Color){15, 15, 20, 255};
|
||||
Color stairs_color = visible ? (Color){100, 100, 100, 255} : (Color){40, 40, 45, 255};
|
||||
Color stairs_color = visible ? (Color){180, 160, 100, 255} : (Color){60, 55, 50, 255};
|
||||
Color door_color = visible ? (Color){139, 119, 89, 255} : (Color){60, 55, 50, 255};
|
||||
|
||||
switch (map->tiles[y][x]) {
|
||||
case TILE_WALL:
|
||||
DrawRectangleRec(rect, wall_color);
|
||||
DrawRectangleRec(dst, wall_color);
|
||||
break;
|
||||
case TILE_FLOOR:
|
||||
DrawRectangleRec(rect, floor_color);
|
||||
DrawRectangleRec(dst, floor_color);
|
||||
// Torch flicker: warm tint on floor tiles adjacent to stairs
|
||||
{
|
||||
int is_adjacent_to_stairs = 0;
|
||||
for (int dy = -1; dy <= 1 && !is_adjacent_to_stairs; dy++) {
|
||||
for (int dx = -1; dx <= 1 && !is_adjacent_to_stairs; dx++) {
|
||||
int nx = x + dx;
|
||||
int ny = y + dy;
|
||||
if (in_bounds(nx, ny, MAP_WIDTH, MAP_HEIGHT) && map->tiles[ny][nx] == TILE_STAIRS) {
|
||||
is_adjacent_to_stairs = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_adjacent_to_stairs && visible) {
|
||||
int flicker = (int)(sinf(GetTime() * 5.0f) * 15.0f);
|
||||
DrawRectangleRec(dst, (Color){40 + flicker, 25, 10, 60});
|
||||
}
|
||||
}
|
||||
// Grid lines
|
||||
if (DRAW_GRID_LINES && visible) {
|
||||
DrawRectangleLines((int)dst.x, (int)dst.y, (int)dst.width, (int)dst.height, (Color){20, 20, 20, 80});
|
||||
}
|
||||
break;
|
||||
case TILE_STAIRS:
|
||||
DrawRectangleRec(rect, stairs_color);
|
||||
DrawRectangleRec(dst, stairs_color);
|
||||
// Make stairs very visible with bright symbol and bounce
|
||||
{
|
||||
int bounce = (int)(sinf(GetTime() * 3.0f) * 1.5f);
|
||||
if (visible)
|
||||
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 2, NORM_FONT, WHITE);
|
||||
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 1 + bounce, NORM_FONT + 2, (Color){255, 255, 200, 255});
|
||||
else
|
||||
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 2, NORM_FONT, (Color){60, 60, 65, 255});
|
||||
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 1 + bounce, NORM_FONT + 2, (Color){100, 90, 70, 255});
|
||||
}
|
||||
break;
|
||||
case TILE_DOOR_CLOSED:
|
||||
DrawRectangleRec(dst, door_color);
|
||||
if (visible) {
|
||||
DrawRectangle(x * TILE_SIZE + 2, y * TILE_SIZE + 2, TILE_SIZE - 4, TILE_SIZE - 4, (Color){100, 80, 60, 255});
|
||||
DrawRectangleLines(x * TILE_SIZE + 2, y * TILE_SIZE + 2, TILE_SIZE - 4, TILE_SIZE - 4,
|
||||
(Color){60, 50, 40, 255});
|
||||
DrawText("+", x * TILE_SIZE + 5, y * TILE_SIZE + 1, NORM_FONT, WHITE);
|
||||
}
|
||||
break;
|
||||
case TILE_DOOR_OPEN:
|
||||
DrawRectangleRec(dst, floor_color);
|
||||
if (visible) {
|
||||
DrawRectangle(x * TILE_SIZE + 2, y * TILE_SIZE + 2, TILE_SIZE - 4, TILE_SIZE - 4, (Color){80, 70, 50, 180});
|
||||
DrawRectangleLines(x * TILE_SIZE + 2, y * TILE_SIZE + 2, TILE_SIZE - 4, TILE_SIZE - 4,
|
||||
(Color){60, 50, 40, 200});
|
||||
DrawText("'", x * TILE_SIZE + 6, y * TILE_SIZE + 2, NORM_FONT, (Color){150, 140, 120, 255});
|
||||
}
|
||||
break;
|
||||
case TILE_DOOR_RUINED:
|
||||
DrawRectangleRec(dst, (Color){60, 45, 30, 255});
|
||||
if (visible) {
|
||||
DrawRectangle(x * TILE_SIZE + 1, y * TILE_SIZE + 1, TILE_SIZE - 2, TILE_SIZE - 2, (Color){80, 60, 40, 200});
|
||||
DrawLine(x * TILE_SIZE + 2, y * TILE_SIZE + 2, x * TILE_SIZE + TILE_SIZE - 2, y * TILE_SIZE + TILE_SIZE - 2,
|
||||
(Color){120, 90, 60, 255});
|
||||
DrawLine(x * TILE_SIZE + TILE_SIZE - 2, y * TILE_SIZE + 2, x * TILE_SIZE + 2, y * TILE_SIZE + TILE_SIZE - 2,
|
||||
(Color){120, 90, 60, 255});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void render_player(const Player *p) {
|
||||
Rectangle rect = {(float)(p->position.x * TILE_SIZE), (float)(p->position.y * TILE_SIZE), (float)TILE_SIZE,
|
||||
void render_player(const Player *p, const Tileset *tileset, int frame_counter) {
|
||||
Rectangle dst = {(float)(p->position.x * TILE_SIZE), (float)(p->position.y * TILE_SIZE), (float)TILE_SIZE,
|
||||
(float)TILE_SIZE};
|
||||
DrawRectangleRec(rect, BLUE);
|
||||
|
||||
if (tileset != NULL && tileset->finalized) {
|
||||
int tile_id = p->sprite_tile_id;
|
||||
switch (p->anim_state) {
|
||||
case PLAYER_ANIM_WALK:
|
||||
tile_id = (p->anim_frame == 0) ? SPRITE_PLAYER_WALK_0 : SPRITE_PLAYER_WALK_1;
|
||||
break;
|
||||
case PLAYER_ANIM_ATTACK:
|
||||
tile_id = SPRITE_PLAYER_ATTACK;
|
||||
break;
|
||||
default:
|
||||
// Idle breathing: subtle bob every 60 frames
|
||||
if ((frame_counter / 30) % 2 == 0) {
|
||||
dst.y -= 1;
|
||||
}
|
||||
tile_id = p->sprite_tile_id;
|
||||
break;
|
||||
}
|
||||
|
||||
Rectangle src = tileset_get_region(tileset, tile_id);
|
||||
if (src.width > 0) {
|
||||
// Flip horizontally if facing left
|
||||
if (!p->facing_right) {
|
||||
src.width = -src.width;
|
||||
}
|
||||
DrawTexturePro(tileset->atlas, src, dst, (Vector2){0, 0}, 0.0f, WHITE);
|
||||
|
||||
// Draw status effect overlays
|
||||
for (int e = 0; e < p->effect_count && e < MAX_EFFECTS; e++) {
|
||||
if (p->effects[e].duration > 0) {
|
||||
int effect_tile = -1;
|
||||
switch (p->effects[e].type) {
|
||||
case EFFECT_BURN:
|
||||
effect_tile = SPRITE_EFFECT_BURN;
|
||||
break;
|
||||
case EFFECT_POISON:
|
||||
effect_tile = SPRITE_EFFECT_POISON;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (effect_tile >= 0) {
|
||||
Rectangle eff_src = tileset_get_region(tileset, effect_tile);
|
||||
if (eff_src.width > 0) {
|
||||
Rectangle eff_dst = {dst.x + 8, dst.y + 8, 8, 8};
|
||||
DrawTexturePro(tileset->atlas, eff_src, eff_dst, (Vector2){0, 0}, 0.0f, (Color){255, 255, 255, 180});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Damage flash overlay
|
||||
if (p->flash_timer > 0) {
|
||||
DrawRectangleRec(dst, (Color){255, 0, 0, 128});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to solid color
|
||||
DrawRectangleRec(dst, BLUE);
|
||||
if (p->flash_timer > 0) {
|
||||
DrawRectangleRec(dst, (Color){255, 0, 0, 128});
|
||||
}
|
||||
}
|
||||
|
||||
void render_enemies(const Enemy *enemies, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]) {
|
||||
void render_enemies(const Enemy *enemies, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH],
|
||||
const Tileset *tileset, int frame_counter) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!enemies[i].alive)
|
||||
continue;
|
||||
if (!visible[enemies[i].position.y][enemies[i].position.x])
|
||||
continue;
|
||||
|
||||
Rectangle rect = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE),
|
||||
Rectangle dst = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE),
|
||||
(float)TILE_SIZE, (float)TILE_SIZE};
|
||||
|
||||
// Different colors based on enemy type
|
||||
// Select animation frame based on sprite_tile_id base
|
||||
int base_tile = enemies[i].sprite_tile_id;
|
||||
int tile_id;
|
||||
if (enemies[i].anim_state == ENEMY_ANIM_WALK) {
|
||||
tile_id = (enemies[i].anim_frame == 0) ? base_tile + 1 : base_tile + 2;
|
||||
} else if (enemies[i].anim_state == ENEMY_ANIM_ATTACK) {
|
||||
tile_id = base_tile + 3;
|
||||
} else if (enemies[i].anim_state == ENEMY_ANIM_IDLE) {
|
||||
// Idle breathing: subtle bob every 60 frames
|
||||
if ((frame_counter / 30) % 2 == 0) {
|
||||
dst.y -= 1;
|
||||
}
|
||||
tile_id = base_tile;
|
||||
} else {
|
||||
tile_id = base_tile;
|
||||
}
|
||||
|
||||
if (tile_id >= 0 && tileset != NULL && tileset->finalized) {
|
||||
Rectangle src = tileset_get_region(tileset, tile_id);
|
||||
if (src.width > 0) {
|
||||
// Flip horizontally if facing left
|
||||
if (!enemies[i].facing_right) {
|
||||
src.width = -src.width;
|
||||
}
|
||||
DrawTexturePro(tileset->atlas, src, dst, (Vector2){0, 0}, 0.0f, WHITE);
|
||||
|
||||
// Draw status effect overlays
|
||||
for (int e = 0; e < enemies[i].effect_count && e < MAX_EFFECTS; e++) {
|
||||
if (enemies[i].effects[e].duration > 0) {
|
||||
int effect_tile = -1;
|
||||
switch (enemies[i].effects[e].type) {
|
||||
case EFFECT_BURN:
|
||||
effect_tile = SPRITE_EFFECT_BURN;
|
||||
break;
|
||||
case EFFECT_POISON:
|
||||
effect_tile = SPRITE_EFFECT_POISON;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (effect_tile >= 0) {
|
||||
Rectangle eff_src = tileset_get_region(tileset, effect_tile);
|
||||
if (eff_src.width > 0) {
|
||||
Rectangle eff_dst = {dst.x + 8, dst.y + 8, 8, 8};
|
||||
DrawTexturePro(tileset->atlas, eff_src, eff_dst, (Vector2){0, 0}, 0.0f, (Color){255, 255, 255, 180});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enemy alert overlay (yellow tint when alert)
|
||||
if (enemies[i].alert) {
|
||||
DrawRectangleRec(dst, (Color){255, 255, 0, 30});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Fallback to solid colors
|
||||
Color enemy_color;
|
||||
switch (enemies[i].type) {
|
||||
case ENEMY_GOBLIN:
|
||||
enemy_color = COLOR_ENEMY_GOBLIN; // dark red
|
||||
enemy_color = COLOR_ENEMY_GOBLIN;
|
||||
break;
|
||||
case ENEMY_SKELETON:
|
||||
enemy_color = COLOR_ENEMY_SKELETON; // light gray
|
||||
enemy_color = COLOR_ENEMY_SKELETON;
|
||||
break;
|
||||
case ENEMY_ORC:
|
||||
enemy_color = COLOR_ENEMY_ORC; // dark green
|
||||
enemy_color = COLOR_ENEMY_ORC;
|
||||
break;
|
||||
default:
|
||||
enemy_color = RED;
|
||||
break;
|
||||
}
|
||||
|
||||
DrawRectangleRec(rect, enemy_color);
|
||||
DrawRectangleRec(dst, enemy_color);
|
||||
if (enemies[i].alert) {
|
||||
DrawRectangleRec(dst, (Color){255, 255, 0, 30});
|
||||
}
|
||||
}
|
||||
|
||||
// Draw hp bar above enemy, color-coded by health remaining
|
||||
int hp_pixels = (enemies[i].hp * TILE_SIZE) / enemies[i].max_hp;
|
||||
|
|
@ -151,38 +367,47 @@ void render_enemies(const Enemy *enemies, int count, const unsigned char visible
|
|||
}
|
||||
}
|
||||
|
||||
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]) {
|
||||
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH],
|
||||
const Tileset *tileset) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (items[i].picked_up)
|
||||
continue;
|
||||
if (!visible[items[i].y][items[i].x])
|
||||
continue;
|
||||
|
||||
Rectangle rect = {(float)(items[i].x * TILE_SIZE), (float)(items[i].y * TILE_SIZE), (float)TILE_SIZE,
|
||||
Rectangle dst = {(float)(items[i].x * TILE_SIZE), (float)(items[i].y * TILE_SIZE), (float)TILE_SIZE,
|
||||
(float)TILE_SIZE};
|
||||
|
||||
// Different colors based on item type
|
||||
int tile_id = items[i].sprite_tile_id;
|
||||
|
||||
if (tile_id >= 0 && tileset != NULL && tileset->finalized) {
|
||||
Rectangle src = tileset_get_region(tileset, tile_id);
|
||||
if (src.width > 0) {
|
||||
DrawTexturePro(tileset->atlas, src, dst, (Vector2){0, 0}, 0.0f, WHITE);
|
||||
}
|
||||
} else {
|
||||
// Fallback to solid colors
|
||||
Color item_color;
|
||||
switch (items[i].type) {
|
||||
case ITEM_POTION:
|
||||
item_color = COLOR_ITEM_POTION; // red/pink
|
||||
item_color = COLOR_ITEM_POTION;
|
||||
break;
|
||||
case ITEM_WEAPON:
|
||||
item_color = COLOR_ITEM_WEAPON; // yellow
|
||||
item_color = COLOR_ITEM_WEAPON;
|
||||
break;
|
||||
case ITEM_ARMOR:
|
||||
item_color = COLOR_ITEM_ARMOR; // blue
|
||||
item_color = COLOR_ITEM_ARMOR;
|
||||
break;
|
||||
default:
|
||||
item_color = GREEN;
|
||||
break;
|
||||
}
|
||||
|
||||
DrawRectangleRec(rect, item_color);
|
||||
DrawRectangleRec(dst, item_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void render_ui(const Player *p, const FontManager *fm) {
|
||||
void render_ui(const Player *p, const Tileset *tileset, const FontManager *fm) {
|
||||
// HUD Panel
|
||||
const int hud_y = MAP_HEIGHT * TILE_SIZE;
|
||||
const int hud_height = 60;
|
||||
|
|
@ -213,10 +438,18 @@ void render_ui(const Player *p, const FontManager *fm) {
|
|||
int portrait_y = hud_y + 8;
|
||||
int portrait_size = 44;
|
||||
|
||||
// FIXME: for now this is just a blue square indicating the player. Once we
|
||||
// model the player, add classes, sprites, etc. this will need to be revisited.
|
||||
DrawRectangle(portrait_x, portrait_y, portrait_size, portrait_size, (Color){30, 30, 45, 255});
|
||||
DrawRectangle(portrait_x + 2, portrait_y + 2, portrait_size - 4, portrait_size - 4, BLUE);
|
||||
// Draw player sprite in portrait
|
||||
if (tileset != NULL && tileset->finalized) {
|
||||
Rectangle src = tileset_get_region(tileset, SPRITE_PLAYER);
|
||||
if (src.width > 0) {
|
||||
Rectangle dst = {(float)portrait_x, (float)portrait_y, (float)portrait_size, (float)portrait_size};
|
||||
DrawTexturePro(tileset->atlas, src, dst, (Vector2){0, 0}, 0.0f, WHITE);
|
||||
} else {
|
||||
DrawRectangle(portrait_x, portrait_y, portrait_size, portrait_size, BLUE);
|
||||
}
|
||||
} else {
|
||||
DrawRectangle(portrait_x, portrait_y, portrait_size, portrait_size, BLUE);
|
||||
}
|
||||
DrawRectangleLines(portrait_x, portrait_y, portrait_size, portrait_size, (Color){139, 119, 89, 255});
|
||||
|
||||
// HP Bar, to the right of portrait
|
||||
|
|
@ -552,7 +785,54 @@ static int label_font_size(FloatingLabel label) {
|
|||
return (label == LABEL_CRIT) ? FONT_SIZE_FLOAT_CRIT : FONT_SIZE_FLOAT_LABEL;
|
||||
}
|
||||
|
||||
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y) {
|
||||
void render_slash_effect(int x, int y, DamageClass dmg_class, int timer) {
|
||||
if (timer <= 0)
|
||||
return;
|
||||
|
||||
float alpha = (float)timer / 8.0f;
|
||||
if (alpha > 1.0f)
|
||||
alpha = 1.0f;
|
||||
int a = (int)(255 * alpha);
|
||||
int px = x * TILE_SIZE;
|
||||
int py = y * TILE_SIZE;
|
||||
|
||||
switch (dmg_class) {
|
||||
case DMG_SLASH:
|
||||
// Red diagonal slash
|
||||
DrawLine(px + 2, py + 2, px + TILE_SIZE - 2, py + TILE_SIZE - 2, (Color){255, 80, 80, a});
|
||||
DrawLine(px + 4, py + 2, px + TILE_SIZE - 2, py + TILE_SIZE - 4, (Color){255, 120, 120, a});
|
||||
break;
|
||||
case DMG_IMPACT:
|
||||
// Orange burst (star pattern)
|
||||
DrawLine(px + TILE_SIZE / 2, py + 2, px + TILE_SIZE / 2, py + TILE_SIZE - 2, (Color){255, 180, 60, a});
|
||||
DrawLine(px + 2, py + TILE_SIZE / 2, px + TILE_SIZE - 2, py + TILE_SIZE / 2, (Color){255, 180, 60, a});
|
||||
DrawLine(px + 4, py + 4, px + TILE_SIZE - 4, py + TILE_SIZE - 4, (Color){255, 200, 100, a});
|
||||
DrawLine(px + 4, py + TILE_SIZE - 4, px + TILE_SIZE - 4, py + 4, (Color){255, 200, 100, a});
|
||||
break;
|
||||
case DMG_PIERCE:
|
||||
// Yellow horizontal streak
|
||||
DrawLine(px + 2, py + TILE_SIZE / 2, px + TILE_SIZE - 2, py + TILE_SIZE / 2, (Color){255, 255, 100, a});
|
||||
DrawLine(px + 2, py + TILE_SIZE / 2 - 2, px + TILE_SIZE - 2, py + TILE_SIZE / 2 - 2, (Color){255, 255, 150, a});
|
||||
DrawLine(px + 2, py + TILE_SIZE / 2 + 2, px + TILE_SIZE - 2, py + TILE_SIZE / 2 + 2, (Color){255, 255, 150, a});
|
||||
break;
|
||||
case DMG_FIRE:
|
||||
// Red-orange flame burst
|
||||
DrawLine(px + TILE_SIZE / 2, py + TILE_SIZE - 2, px + TILE_SIZE / 2, py + 4, (Color){255, 100, 30, a});
|
||||
DrawLine(px + TILE_SIZE / 2 - 3, py + TILE_SIZE - 4, px + TILE_SIZE / 2 - 1, py + 6, (Color){255, 150, 50, a});
|
||||
DrawLine(px + TILE_SIZE / 2 + 3, py + TILE_SIZE - 4, px + TILE_SIZE / 2 + 1, py + 6, (Color){255, 150, 50, a});
|
||||
break;
|
||||
case DMG_POISON:
|
||||
// Green splash
|
||||
DrawLine(px + 4, py + 4, px + TILE_SIZE - 4, py + TILE_SIZE - 4, (Color){50, 255, 100, a});
|
||||
DrawLine(px + TILE_SIZE - 4, py + 4, px + 4, py + TILE_SIZE - 4, (Color){80, 255, 120, a});
|
||||
DrawCircle(px + TILE_SIZE / 2, py + TILE_SIZE / 2, 3.0f, (Color){100, 255, 150, a / 2});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y, const FontManager *fm) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (texts[i].lifetime <= 0)
|
||||
continue;
|
||||
|
|
@ -568,15 +848,17 @@ void render_floating_texts(FloatingText *texts, int count, int shake_x, int shak
|
|||
int font_size = label_font_size(texts[i].label);
|
||||
Color color = label_color(&texts[i], a);
|
||||
const char *text = label_text(texts[i].label);
|
||||
int text_w = MeasureText(text, font_size);
|
||||
DrawText(text, x - text_w / 2, y, font_size, color);
|
||||
Vector2 text_size = MeasureTextEx(fm->body_font, text, (float)font_size, NORM_CHAR_SPACE);
|
||||
draw_text_body(fm->body_font, text, (float)(x - (int)text_size.x / 2), (float)y, font_size, NORM_CHAR_SPACE,
|
||||
color);
|
||||
} else {
|
||||
// Numeric damage
|
||||
Color color = texts[i].is_critical ? (Color){255, 200, 50, a} : (Color){255, 100, 100, a};
|
||||
char text[16];
|
||||
snprintf(text, sizeof(text), "%d", texts[i].value);
|
||||
int text_w = MeasureText(text, FONT_SIZE_FLOAT_DMG);
|
||||
DrawText(text, x - text_w / 2, y, FONT_SIZE_FLOAT_DMG, color);
|
||||
Vector2 text_size = MeasureTextEx(fm->body_font, text, (float)FONT_SIZE_FLOAT_DMG, NORM_CHAR_SPACE);
|
||||
draw_text_body(fm->body_font, text, (float)(x - (int)text_size.x / 2), (float)y, FONT_SIZE_FLOAT_DMG,
|
||||
NORM_CHAR_SPACE, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
src/render.h
27
src/render.h
|
|
@ -99,20 +99,24 @@ int init_fonts(FontManager *fm);
|
|||
// Unload all fonts held by a FontManager
|
||||
void destroy_fonts(FontManager *fm);
|
||||
|
||||
// Render the map tiles
|
||||
void render_map(const Map *map);
|
||||
// Render the map tiles using tileset atlas
|
||||
void render_map(const Map *map, const Tileset *tileset);
|
||||
|
||||
// Render the player
|
||||
void render_player(const Player *p);
|
||||
// Render the player using tileset atlas
|
||||
// frame_counter is used for idle breathing animation
|
||||
void render_player(const Player *p, const Tileset *tileset, int frame_counter);
|
||||
|
||||
// Render all enemies
|
||||
void render_enemies(const Enemy *enemies, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]);
|
||||
// Render all enemies using tileset atlas
|
||||
// frame_counter is used for idle breathing animation
|
||||
void render_enemies(const Enemy *enemies, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH],
|
||||
const Tileset *tileset, int frame_counter);
|
||||
|
||||
// Render all items
|
||||
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]);
|
||||
// Render all items using tileset atlas
|
||||
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH],
|
||||
const Tileset *tileset);
|
||||
|
||||
// Render UI overlay
|
||||
void render_ui(const Player *p, const FontManager *fm);
|
||||
void render_ui(const Player *p, const Tileset *tileset, const FontManager *fm);
|
||||
|
||||
// Render action log (bottom left corner)
|
||||
void render_action_log(const char log[5][128], int count, int head, const FontManager *fm);
|
||||
|
|
@ -121,7 +125,10 @@ void render_action_log(const char log[5][128], int count, int head, const FontMa
|
|||
void render_inventory_overlay(const Player *p, int selected, const FontManager *fm);
|
||||
|
||||
// Render floating damage text
|
||||
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y);
|
||||
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y, const FontManager *fm);
|
||||
|
||||
// Render slash effect during attacks
|
||||
void render_slash_effect(int x, int y, DamageClass dmg_class, int timer);
|
||||
|
||||
// Render end screen (victory or death) with stats breakdown
|
||||
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
||||
|
|
|
|||
|
|
@ -83,4 +83,7 @@
|
|||
#define ENEMY_VIEW_RANGE 6
|
||||
#define ENEMY_PATROL_MOVE_CHANCE 30
|
||||
|
||||
// Visual polish
|
||||
#define DRAW_GRID_LINES 1
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue