#include "render.h" #include "common.h" #include "items.h" #include "raylib.h" #include "settings.h" #include #include void render_map(const Map *map) { 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}; switch (map->tiles[y][x]) { case TILE_WALL: DrawRectangleRec(rect, DARKGRAY); break; case TILE_FLOOR: DrawRectangleRec(rect, BLACK); break; case TILE_STAIRS: DrawRectangleRec(rect, (Color){100, 100, 100, 255}); // Draw stairs marker DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 2, 12, WHITE); break; } } } } void render_player(const Player *p) { Rectangle rect = {(float)(p->x * TILE_SIZE), (float)(p->y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE}; DrawRectangleRec(rect, BLUE); } void render_enemies(const Enemy *enemies, int count) { for (int i = 0; i < count; i++) { if (!enemies[i].alive) continue; Rectangle rect = {(float)(enemies[i].x * TILE_SIZE), (float)(enemies[i].y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE}; // Different colors based on enemy type Color enemy_color; switch (enemies[i].type) { case ENEMY_GOBLIN: enemy_color = (Color){150, 50, 50, 255}; // dark red break; case ENEMY_SKELETON: enemy_color = (Color){200, 200, 200, 255}; // light gray break; case ENEMY_ORC: enemy_color = (Color){50, 150, 50, 255}; // dark green break; default: enemy_color = RED; break; } DrawRectangleRec(rect, enemy_color); // Draw hp bar above enemy int hp_percent = (enemies[i].hp * TILE_SIZE) / enemies[i].max_hp; if (hp_percent > 0) { Rectangle hp_bar = {(float)(enemies[i].x * TILE_SIZE), (float)(enemies[i].y * TILE_SIZE - 4), (float)hp_percent, 3}; DrawRectangleRec(hp_bar, GREEN); } } } void render_items(const Item *items, int count) { for (int i = 0; i < count; i++) { if (items[i].picked_up) continue; Rectangle rect = {(float)(items[i].x * TILE_SIZE), (float)(items[i].y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE}; // Different colors based on item type Color item_color; switch (items[i].type) { case ITEM_POTION: item_color = (Color){255, 100, 100, 255}; // red/pink break; case ITEM_WEAPON: item_color = (Color){255, 255, 100, 255}; // yellow break; case ITEM_ARMOR: item_color = (Color){100, 100, 255, 255}; // blue break; default: item_color = GREEN; break; } DrawRectangleRec(rect, item_color); } } void render_ui(const Player *p) { // UI background bar at bottom of screen Rectangle ui_bg = {0, (float)(MAP_HEIGHT * TILE_SIZE), (float)SCREEN_WIDTH, 60}; DrawRectangleRec(ui_bg, (Color){30, 30, 30, 255}); // Draw dividing line DrawLine(0, MAP_HEIGHT * TILE_SIZE, SCREEN_WIDTH, MAP_HEIGHT * TILE_SIZE, GRAY); // Player hp char hp_text[32]; snprintf(hp_text, sizeof(hp_text), "HP: %d/%d", p->hp, p->max_hp); DrawText(hp_text, 10, MAP_HEIGHT * TILE_SIZE + 10, 20, RED); // Player attack char atk_text[32]; snprintf(atk_text, sizeof(atk_text), "ATK: %d", p->attack); DrawText(atk_text, 120, MAP_HEIGHT * TILE_SIZE + 10, 20, YELLOW); // Floor number char floor_text[32]; snprintf(floor_text, sizeof(floor_text), "Floor: %d", p->floor); DrawText(floor_text, 220, MAP_HEIGHT * TILE_SIZE + 10, 20, WHITE); // Defense stat char def_text[32]; snprintf(def_text, sizeof(def_text), "DEF: %d", p->defense); DrawText(def_text, 340, MAP_HEIGHT * TILE_SIZE + 10, 20, BLUE); // Inventory count char inv_text[32]; snprintf(inv_text, sizeof(inv_text), "Inv: %d/%d", p->inventory_count, MAX_INVENTORY); DrawText(inv_text, 440, MAP_HEIGHT * TILE_SIZE + 10, 16, GREEN); // Equipment display - second row int eq_y = MAP_HEIGHT * TILE_SIZE + 10; // Weapon slot if (p->has_weapon) { char weapon_text[48]; snprintf(weapon_text, sizeof(weapon_text), "Wpn:[%s +%d]", item_get_name(&p->equipped_weapon), p->equipped_weapon.power); DrawText(weapon_text, 10, eq_y + 25, 14, YELLOW); } else { DrawText("Wpn:---", 10, eq_y + 25, 14, DARKGRAY); } // Armor slot if (p->has_armor) { char armor_text[48]; snprintf(armor_text, sizeof(armor_text), "Arm:[%s +%d]", item_get_name(&p->equipped_armor), p->equipped_armor.power); DrawText(armor_text, 170, eq_y + 25, 14, BLUE); } else { DrawText("Arm:---", 170, eq_y + 25, 14, DARKGRAY); } // Controls hint DrawText("WASD:Move G:Pickup I:Inventory U:Use E:Equip Q:Quit", 330, eq_y + 25, 12, GRAY); } void render_inventory_overlay(const Player *p, int selected) { // Semi-transparent overlay Rectangle overlay = {(float)(SCREEN_WIDTH / 2 - 200), 80, 400, 320}; DrawRectangleRec(overlay, (Color){20, 20, 20, 240}); DrawRectangleLines((int)overlay.x, (int)overlay.y, (int)overlay.width, (int)overlay.height, GOLD); // Title const char *title = "INVENTORY"; int title_w = MeasureText(title, 20); DrawText(title, overlay.x + (overlay.width - title_w) / 2, overlay.y + 15, 20, GOLD); // Column headers DrawText("# Item", overlay.x + 20, overlay.y + 50, 14, GRAY); DrawText("Type", overlay.x + 130, overlay.y + 50, 14, GRAY); DrawText("Power", overlay.x + 210, overlay.y + 50, 14, GRAY); DrawText("Action", overlay.x + 280, overlay.y + 50, 14, GRAY); // Draw each inventory slot char slot_text[64]; for (int i = 0; i < MAX_INVENTORY; i++) { int y_pos = overlay.y + 75 + (i * 22); if (i < p->inventory_count && !p->inventory[i].picked_up) { // Occupied slot const Item *item = &p->inventory[i]; // Highlight selected if (i == selected) { DrawRectangle((int)overlay.x + 10, y_pos - 2, (int)overlay.width - 20, 20, (Color){60, 60, 60, 255}); } // Slot number snprintf(slot_text, sizeof(slot_text), "%d.", i + 1); DrawText(slot_text, overlay.x + 20, y_pos, 14, WHITE); // Item name const char *name = item_get_name(item); DrawText(name, overlay.x + 50, y_pos, 14, WHITE); // Type const char *type = (item->type == ITEM_POTION) ? "Potion" : (item->type == ITEM_WEAPON) ? "Weapon" : "Armor"; Color type_color = (item->type == ITEM_POTION) ? PINK : (item->type == ITEM_WEAPON) ? YELLOW : BLUE; DrawText(type, overlay.x + 130, y_pos, 14, type_color); // Power snprintf(slot_text, sizeof(slot_text), "+%d", item->power); DrawText(slot_text, overlay.x + 210, y_pos, 14, YELLOW); // Action hint if (item->type == ITEM_POTION) { DrawText("[U]se", overlay.x + 280, y_pos, 14, GREEN); } else { DrawText("[E]quip", overlay.x + 280, y_pos, 14, GOLD); } } else { // Empty slot snprintf(slot_text, sizeof(slot_text), "%d.", i + 1); DrawText(slot_text, overlay.x + 20, y_pos, 14, (Color){60, 60, 60, 255}); } } // Instructions const char *hint = "WASD: Select | ENTER/U: Use | E: Equip | ESC: Close"; int hint_w = MeasureText(hint, 12); DrawText(hint, overlay.x + (overlay.width - hint_w) / 2, overlay.y + 290, 12, GRAY); } void render_game_over(void) { // Semi-transparent overlay Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT}; DrawRectangleRec(overlay, (Color){0, 0, 0, 200}); // Game over text const char *title = "GAME OVER"; int title_width = MeasureText(title, 60); DrawText(title, (SCREEN_WIDTH - title_width) / 2, SCREEN_HEIGHT / 2 - 30, 60, RED); const char *subtitle = "Press R to restart or Q to quit"; int sub_width = MeasureText(subtitle, 20); DrawText(subtitle, (SCREEN_WIDTH - sub_width) / 2, SCREEN_HEIGHT / 2 + 40, 20, WHITE); } void render_message(const char *message) { if (message == NULL) return; // Draw message box Rectangle msg_bg = {(float)(SCREEN_WIDTH / 2 - 150), (float)(SCREEN_HEIGHT / 2 - 30), 300, 60}; DrawRectangleRec(msg_bg, (Color){50, 50, 50, 230}); DrawRectangleLines((int)msg_bg.x, (int)msg_bg.y, (int)msg_bg.width, (int)msg_bg.height, WHITE); int msg_width = MeasureText(message, 20); DrawText(message, (SCREEN_WIDTH - msg_width) / 2, SCREEN_HEIGHT / 2 - 10, 20, WHITE); }