Added rudimentary Inventory display, however we must have some way to keep track of the selected item in inventory offset. Perhaps through a global variable or, if it must be done, through a new Inventory struct that contains pertinent information. It should likely be the latter, so the same system can be expanded to chests and the like. Also added the ITEM type in general.
parent
57a1b46db4
commit
4b7e0db3e0
5
game.c
5
game.c
|
@ -20,10 +20,15 @@ int gameInit() {
|
|||
player = newTile(PLAYER, 0, 2, 2);
|
||||
player->tid = 1;
|
||||
player->id = 12;
|
||||
((struct PlayerTile*)player->data)->inventory = newTile(ITEM, 1, 0, 0);
|
||||
|
||||
//gameMoveTile(newTile(ITEM, 0, 4, 4), 4, 4);
|
||||
|
||||
current_context = &walkContext;
|
||||
allocateMap(¤t_map, 64, 64);
|
||||
floodMap(¤t_map, TILE_REPLACE, FLOOR, STONE);
|
||||
gameMoveTile(player, 2, 2);
|
||||
appendTile(&(current_map->matrix[4][4]), ITEM, 0);
|
||||
|
||||
drawPath(¤t_map, TILE_APPEND, WALL, STONE, 6, 1, 8, 12);
|
||||
drawPath(¤t_map, TILE_APPEND, WALL, STONE, 12, 4, 7, 13);
|
||||
|
|
|
@ -202,6 +202,7 @@ void interfaceSetScale(float scale_x, float scale_y) {
|
|||
|
||||
void scaleTiles(float scale_x, float scale_y) {
|
||||
setSpritesheetScale(&player_sprites, scale_x, scale_y);
|
||||
setSpritesheetScale(&item_sprites, scale_x, scale_y);
|
||||
setSpritesheetScale(&shadow_sprites, scale_x, scale_y);
|
||||
setSpritesheetScale(&door_sprites, scale_x, scale_y);
|
||||
setSpritesheetScale(&npc_sprites, scale_x, scale_y);
|
||||
|
@ -249,6 +250,7 @@ int interfaceInit() {
|
|||
ui_spritesheet = IMG_Load_RW(SDL_RWFromMem(&ui_images, ui_images_length), 1);
|
||||
|
||||
loadSpritesheetFromMemory(&player_sprites, player_images, player_images_length, 16, 32, TOTAL_CLASSES);
|
||||
loadSpritesheetFromMemory(&item_sprites, item_images, item_images_length, 16, 32, 16);
|
||||
loadSpritesheetFromMemory(&shadow_sprites, shadow_images, shadow_images_length, 16, 32, TOTAL_CLASSES);
|
||||
loadSpritesheetFromMemory(&door_sprites, door_images, door_images_length, 16, 32, 16);
|
||||
loadSpritesheetFromMemory(&npc_sprites, npc_images, npc_images_length, 16, 32, 16);
|
||||
|
@ -371,6 +373,9 @@ void cameraDraw() {
|
|||
drawScaledSprite(&shadow_sprites, 0, camera_surface, (step_x*shadow_sprites.s_width)-camera_offset_x, (step_y*shadow_sprites.s_height/2)-camera_offset_y);
|
||||
drawScaledSprite(&player_sprites, current_tile->id, camera_surface, (step_x*player_sprites.s_width)-camera_offset_x, (step_y*player_sprites.s_height/2)-camera_offset_y);
|
||||
break;
|
||||
case ITEM:
|
||||
drawScaledSprite(&item_sprites, current_tile->id, camera_surface, (step_x*item_sprites.s_width)-camera_offset_x, (step_y*item_sprites.s_height/2)-camera_offset_y);
|
||||
break;
|
||||
}
|
||||
current_tile = current_tile->next;
|
||||
}
|
||||
|
@ -499,6 +504,12 @@ void interfaceDrawInventory() {
|
|||
SDL_Surface *new_surface = SDL_CreateRGBSurface(screen->flags, (screen->w/6), screen->h/2, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
|
||||
SDL_Rect render_area = { screen->w-(screen->w/6), screen->h/8, screen->w/6, screen->h/2 };
|
||||
SDL_FillRect(new_surface, NULL, SDL_MapRGB(new_surface->format, 196, 164, 64));
|
||||
struct Tile *current_item = ((struct PlayerTile*)player->data)->inventory;
|
||||
while (current_item) {
|
||||
drawScaledSprite(&item_sprites, current_item->id, new_surface, 0, 0);
|
||||
current_item = current_item->next;
|
||||
}
|
||||
//drawScaledSprite(&player_sprites, 0, new_surface, 0, 0);
|
||||
SDL_SetAlpha(new_surface, SDL_SRCALPHA, 128);
|
||||
SDL_BlitSurface(new_surface, NULL, screen, &render_area);
|
||||
SDL_FreeSurface(new_surface);
|
||||
|
|
|
@ -37,6 +37,7 @@ struct Spritesheet {
|
|||
SDL_Surface *s_spritesheet;
|
||||
};
|
||||
struct Spritesheet player_sprites;
|
||||
struct Spritesheet item_sprites;
|
||||
struct Spritesheet shadow_sprites;
|
||||
struct Spritesheet npc_sprites;
|
||||
struct Spritesheet door_sprites;
|
||||
|
|
|
@ -34,6 +34,7 @@ int main(int argc, char **argv) {
|
|||
convert("tiles/font_mini.png", "font_mini_images");
|
||||
convert("tiles/ui.png", "ui_images");
|
||||
convert("tiles/players.png", "player_images");
|
||||
convert("tiles/items.png", "item_images");
|
||||
convert("tiles/npcs.png", "npc_images");
|
||||
convert("tiles/walls.png", "wall_images");
|
||||
convert("tiles/floors.png", "floor_images");
|
||||
|
|
9
tile.c
9
tile.c
|
@ -59,6 +59,10 @@ struct Tile *newTile(unsigned int type_id, short id, short x, short y) {
|
|||
new_tile->data = (struct NpcTile *) malloc(sizeof(struct NpcTile));
|
||||
memcpy(new_tile->data, &npcs[id], sizeof(struct NpcTile));
|
||||
break;
|
||||
case ITEM:
|
||||
new_tile->data = (struct ItemTile *) malloc(sizeof(struct ItemTile));
|
||||
memcpy(new_tile->data, &items[id], sizeof(struct ItemTile));
|
||||
break;
|
||||
default:
|
||||
new_tile->data = (struct BasicTile *) malloc(sizeof(struct BasicTile));
|
||||
memcpy(new_tile->data, &walls[id], sizeof(struct BasicTile));
|
||||
|
@ -111,3 +115,8 @@ struct PlayerTile players[] = {
|
|||
struct NpcTile npcs[] = {
|
||||
{ NO_PASS, "nupi", 4, BEHAVE_WANDER, 0, 0}
|
||||
};
|
||||
|
||||
struct ItemTile items[] = {
|
||||
{ 0, "small macana", 1, "P1d4" },
|
||||
{ 0, "large macana", 1, "P1d8" }
|
||||
};
|
||||
|
|
9
tile.h
9
tile.h
|
@ -62,6 +62,15 @@ struct NpcTile {
|
|||
struct Tile *target;
|
||||
};
|
||||
extern struct NpcTile npcs[];
|
||||
|
||||
struct ItemTile {
|
||||
int collision;
|
||||
char name[16];
|
||||
int type; // 0 = generic item, 1 = weapons, 2 = armour
|
||||
char stats[31]; // instead of having each stat a separate property, a string is used. e.g., "P1d8F1d2I1d4" = physical 1d8, fire 1d2, ice 1d4
|
||||
};
|
||||
extern struct ItemTile items[];
|
||||
|
||||
/*
|
||||
interface used for creating new Tile
|
||||
*/
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 466 B |
|
@ -19,6 +19,11 @@ unsigned char player_images[] = {
|
|||
};
|
||||
unsigned int player_images_length = 2099;
|
||||
|
||||
unsigned char item_images[] = {
|
||||
0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x08,0x06,0x00,0x00,0x00,0x5c,0x72,0xa8,0x66,0x00,0x00,0x01,0x99,0x49,0x44,0x41,0x54,0x78,0x9c,0xed,0xd7,0xb1,0x0d,0x02,0x31,0x10,0x04,0xc0,0x13,0x75,0x10,0xb8,0x80,0x0b,0x68,0x81,0x80,0x82,0xe8,0x95,0x42,0xe8,0xc0,0x64,0x16,0x7a,0x7d,0xf2,0xf8,0x25,0x63,0x79,0x26,0xb7,0xec,0x64,0xd7,0x77,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x35,0x22,0x6a,0x66,0xd6,0xd1,0x0f,0x81,0xd5,0x5d,0x46,0x5c,0x9a,0x99,0xf1,0x78,0xbf,0x42,0x09,0xc0,0x62,0x32,0xb3,0x3e,0xaf,0x6d,0x02,0x50,0x00,0x30,0x89,0x5a,0x4a,0xa9,0xb7,0xfb,0xef,0xa1,0xdd,0x09,0xbf,0x02,0x80,0x09,0xb4,0xf0,0x97,0x52,0x8e,0x86,0xb6,0x7e,0x9f,0x37,0xf6,0xc3,0x64,0x36,0xe1,0x3f,0x5c,0x00,0x1d,0xe5,0x01,0x8c,0xd4,0x19,0xfe,0xee,0xf3,0xc0,0x18,0xdd,0x3f,0xf7,0x4e,0xf8,0x15,0x00,0x4c,0xe0,0xb4,0x9d,0xdf,0xd8,0x0f,0x93,0xb1,0xf3,0xc3,0xba,0xda,0x0f,0x1e,0x76,0x7e,0x58,0x4e,0x4f,0x70,0xb7,0xe5,0xa1,0x00,0x60,0x22,0xbd,0x81,0x15,0x7a,0x98,0xd4,0x19,0xe1,0x07,0x16,0x24,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xea,0x03,0xd8,0x20,0x6f,0x9c,0x42,0xdb,0x1e,0xc4,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82,
|
||||
};
|
||||
unsigned int item_images_length = 466;
|
||||
|
||||
unsigned char npc_images[] = {
|
||||
0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x08,0x06,0x00,0x00,0x00,0x5c,0x72,0xa8,0x66,0x00,0x00,0x01,0xc1,0x49,0x44,0x41,0x54,0x78,0x9c,0xed,0xd9,0xb1,0x11,0x82,0x30,0x14,0x06,0x60,0x74,0x02,0x5b,0x3a,0x06,0x60,0x09,0x46,0xa0,0x70,0x5e,0x07,0xa1,0x61,0x08,0xfa,0x67,0x81,0x7a,0x18,0x89,0x56,0x82,0xe6,0xbe,0xaf,0xc9,0x91,0x0b,0x77,0xaf,0xf9,0x5f,0x12,0xa8,0x2a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0xb7,0xf5,0x7d,0x1f,0x4d,0xd3,0xc4,0xde,0x75,0x00,0xdf,0x75,0x4c,0x27,0xda,0xb6,0x8d,0x69,0x9a,0xf6,0xa8,0x05,0xd8,0xd8,0x4b,0x03,0xa8,0xeb,0xba,0x1a,0x86,0xa1,0x1a,0xc7,0xf1,0xb0,0x47,0x41,0xc0,0x8e,0x92,0xa3,0x7f,0x24,0x23,0x50,0x90,0xa7,0x13,0xc0,0x4a,0xf8,0x0f,0x8b,0x11,0x28,0x4c,0x1a,0xec,0x58,0xcc,0xc7,0x9b,0x75,0x40,0x01,0x5e,0xbe,0x01,0xdc,0x44,0xc4,0x9c,0xff,0x73,0x9c,0xb7,0xab,0x06,0xd8,0xd4,0xea,0xce,0xde,0xdd,0x76,0xff,0x4b,0x7e,0x9d,0x6b,0x01,0x14,0x20,0x1b,0xe2,0x6e,0x71,0x05,0x48,0x1a,0x81,0xf0,0x43,0x21,0xde,0x06,0x39,0xd3,0x04,0x3e,0xbe,0x07,0xfc,0x87,0xdc,0x37,0x80,0x27,0x97,0x39,0xf0,0xf7,0xd0,0x0b,0x3f,0x14,0x22,0xdb,0x00,0xba,0xf5,0x7f,0xff,0xc2,0x0f,0x05,0xc9,0xfe,0x05,0x98,0x8f,0xfc,0xa7,0xc7,0xf3,0x16,0xc5,0x00,0xbf,0x21,0x0d,0xbc,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0xaf,0xae,0x60,0xa0,0x2a,0x6f,0x17,0x2b,0x1d,0xf4,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82,
|
||||
};
|
||||
|
|
|
@ -15,6 +15,9 @@ extern unsigned int ui_images_length;
|
|||
extern unsigned char player_images[];
|
||||
extern unsigned int player_images_length;
|
||||
|
||||
extern unsigned char item_images[];
|
||||
extern unsigned int item_images_length;
|
||||
|
||||
extern unsigned char npc_images[];
|
||||
extern unsigned int npc_images_length;
|
||||
|
||||
|
|
Loading…
Reference in New Issue