diff --git a/CMakeLists.txt b/CMakeLists.txt index e646b91..ae1e57a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ set(SOURCES src/npc.c src/events.c src/animation.c + src/inventory.c # ... ) # Shared assets, fx-9860G-only assets and fx-CG-50-only assets @@ -56,6 +57,8 @@ set(ASSETS set(ASSETS_cg assets-cg/player_male.png assets-cg/player_female.png + assets-cg/player_male_inv.png + assets-cg/player_female_inv.png assets-cg/npc/char/npc_male.png assets-cg/npc/char/npc_female.png assets-cg/npc/char/npc_milkman.png @@ -69,6 +72,8 @@ set(ASSETS_cg assets-cg/INFO_Icon.png assets-cg/player_face.png assets-cg/font.png + assets-cg/inventory.png + assets-cg/items.png ) set(ASSETS_cg_EGA64 @@ -98,6 +103,8 @@ set(ASSETS_fx_1b assets-fx/1b/npc/face/npc_milkman.png assets-fx/1b/npc/face/npc_police.png assets-fx/1b/INFO_Icon.png + assets-fx/1b/inventory.png + assets-fx/1b/items.png # ... ) @@ -112,7 +119,9 @@ set(ASSETS_fx_2b assets-fx/2b/npc/face/npc_female.png assets-fx/2b/npc/face/npc_milkman.png assets-fx/2b/npc/face/npc_police.png - assets-fx/1b/INFO_Icon.png + assets-fx/2b/INFO_Icon.png + assets-fx/2b/inventory.png + assets-fx/2b/items.png # ... ) diff --git a/assets-cg/base_slot.png b/assets-cg/base_slot.png new file mode 100644 index 0000000..8a45491 Binary files /dev/null and b/assets-cg/base_slot.png differ diff --git a/assets-cg/inventory.png b/assets-cg/inventory.png index a56f56a..c7030a0 100644 Binary files a/assets-cg/inventory.png and b/assets-cg/inventory.png differ diff --git a/assets-cg/items.png b/assets-cg/items.png new file mode 100644 index 0000000..3730ee2 Binary files /dev/null and b/assets-cg/items.png differ diff --git a/assets-cg/selected.png b/assets-cg/selected.png new file mode 100644 index 0000000..ae7cb57 Binary files /dev/null and b/assets-cg/selected.png differ diff --git a/assets-cg/selection.png b/assets-cg/selection.png new file mode 100644 index 0000000..5348c4c Binary files /dev/null and b/assets-cg/selection.png differ diff --git a/assets-fx/1b/fxconv-metadata.txt b/assets-fx/1b/fxconv-metadata.txt index 400e93b..881385f 100644 --- a/assets-fx/1b/fxconv-metadata.txt +++ b/assets-fx/1b/fxconv-metadata.txt @@ -5,3 +5,7 @@ INFO_Icon.png: inventory.png: type: bopti-image name: inventory_img + +items.png: + type: bopti-image + name: items_img diff --git a/assets-fx/1b/items.png b/assets-fx/1b/items.png new file mode 100644 index 0000000..eeb6dbf Binary files /dev/null and b/assets-fx/1b/items.png differ diff --git a/assets-fx/2b/fxconv-metadata.txt b/assets-fx/2b/fxconv-metadata.txt index 400e93b..881385f 100644 --- a/assets-fx/2b/fxconv-metadata.txt +++ b/assets-fx/2b/fxconv-metadata.txt @@ -5,3 +5,7 @@ INFO_Icon.png: inventory.png: type: bopti-image name: inventory_img + +items.png: + type: bopti-image + name: items_img diff --git a/assets-fx/2b/items.png b/assets-fx/2b/items.png new file mode 100644 index 0000000..eeb6dbf Binary files /dev/null and b/assets-fx/2b/items.png differ diff --git a/assets-fx/selected.png b/assets-fx/selected.png new file mode 100644 index 0000000..bd155be Binary files /dev/null and b/assets-fx/selected.png differ diff --git a/assets-fx/selection.png b/assets-fx/selection.png new file mode 100644 index 0000000..7092037 Binary files /dev/null and b/assets-fx/selection.png differ diff --git a/src/config.h b/src/config.h index 87598ae..67e0b3a 100644 --- a/src/config.h +++ b/src/config.h @@ -13,6 +13,7 @@ #endif #define SLOT_NUM 9 +#define SLOT_COLUMNS 3 #if GINT_RENDER_RGB /* The tile size */ diff --git a/src/game.c b/src/game.c index 25b94eb..0b5306e 100644 --- a/src/game.c +++ b/src/game.c @@ -1,6 +1,7 @@ #include "game.h" #include "config.h" +#include "inventory.h" #include "map.h" #include "mapdata.h" #include "npc.h" @@ -135,6 +136,7 @@ void game_draw(Game *game) { dprint(8, 8, C_BLACK, "npc_count: %d", npc_count); dprint(8, 16, C_BLACK, "Mana: %d", game->mana); dprint(8, 24, C_BLACK, "X: %d Y: %d", game->player.x, game->player.y); + inventory_draw(game, &game->inventory); } /* Key management */ @@ -149,86 +151,99 @@ void game_get_inputs(Game *game) { if(keydown(KEY_EXIT)) game->exittoOS = true; - /* Player actions - Prototypes in player.h and implementation in player.c */ - if(keydown(KEY_LEFT)) - player_move(game, D_LEFT); - if(keydown(KEY_RIGHT)) - player_move(game, D_RIGHT); - if(keydown(KEY_UP)) - player_move(game, D_UP); - if(keydown(KEY_DOWN)) - player_move(game, D_DOWN); - if(keydown(KEY_SHIFT)) - player_action(game); - if(keydown(KEY_OPTN)) { - game->player.is_male = !game->player.is_male; + /* Inventory */ + if(keydown(KEY_ALPHA)) { + game->inventory.open = !game->inventory.open; /* TODO: Make something cleaner */ - while(keydown(KEY_OPTN)) { + while(keydown(KEY_ALPHA)) { clearevents(); sleep(); } - } - Player *player = &game->player; - if(keydown(KEY_SHIFT)) { - uint32_t i; - for(i = 0; i < game->map_level->nbPortal; i++) { - Portal *portal = &game->map_level->portals[i]; - if(player->x >= (int)portal->collider.x1 * PXSIZE && - player->x < (int)portal->collider.x2 * PXSIZE && - player->y >= (int)portal->collider.y1 * PXSIZE && - player->y < (int)portal->collider.y2 * PXSIZE) { - Portal *dest_portal = (Portal *)portal->portal; - Collider dest_collider = dest_portal->collider; - Map *dest_map = (Map *)portal->map; - player->x = (dest_collider.x1 + dest_collider.x2) / 2 * PXSIZE; - player->y = (dest_collider.y1 + dest_collider.y2) / 2 * PXSIZE; - game->map_level = dest_map; - /* TODO: Make something cleaner */ - while(keydown(KEY_SHIFT)) { - clearevents(); - sleep(); + } else { + /* Player actions - Prototypes in player.h and implementation in + * player.c */ + if(keydown(KEY_LEFT)) + player_move(game, D_LEFT); + if(keydown(KEY_RIGHT)) + player_move(game, D_RIGHT); + if(keydown(KEY_UP)) + player_move(game, D_UP); + if(keydown(KEY_DOWN)) + player_move(game, D_DOWN); + if(keydown(KEY_SHIFT)) + player_action(game); + if(keydown(KEY_OPTN)) { + game->player.is_male = !game->player.is_male; + /* TODO: Make something cleaner */ + while(keydown(KEY_OPTN)) { + clearevents(); + sleep(); + } + } + Player *player = &game->player; + if(keydown(KEY_SHIFT)) { + uint32_t i; + for(i = 0; i < game->map_level->nbPortal; i++) { + Portal *portal = &game->map_level->portals[i]; + if(player->x >= (int)portal->collider.x1 * PXSIZE && + player->x < (int)portal->collider.x2 * PXSIZE && + player->y >= (int)portal->collider.y1 * PXSIZE && + player->y < (int)portal->collider.y2 * PXSIZE) { + Portal *dest_portal = (Portal *)portal->portal; + Collider dest_collider = dest_portal->collider; + Map *dest_map = (Map *)portal->map; + player->x = + (dest_collider.x1 + dest_collider.x2) / 2 * PXSIZE; + player->y = + (dest_collider.y1 + dest_collider.y2) / 2 * PXSIZE; + game->map_level = dest_map; + /* TODO: Make something cleaner */ + while(keydown(KEY_SHIFT)) { + clearevents(); + sleep(); + } } } } - } - /*Temp debug*/ - if(keydown(KEY_F1)) { - NPC *mynpc = npc_create(); - if(mynpc) { - mynpc->curx = (player->x << PRECISION) / PXSIZE; - mynpc->cury = (player->y << PRECISION) / PXSIZE; - mynpc->x = player->x; - mynpc->y = player->x; - mynpc->hasPath = 0; - mynpc->face = 0; - mynpc->paused = 0; - mynpc->has_dialog = 0; + /*Temp debug*/ + if(keydown(KEY_F1)) { + NPC *mynpc = npc_create(); + if(mynpc) { + mynpc->curx = (player->x << PRECISION) / PXSIZE; + mynpc->cury = (player->y << PRECISION) / PXSIZE; + mynpc->x = player->x; + mynpc->y = player->x; + mynpc->hasPath = 0; + mynpc->face = 0; + mynpc->paused = 0; + mynpc->has_dialog = 0; + } } - } - /* Display Debug Information on screen */ + /* Display Debug Information on screen */ #if DEBUGMODE - if(keydown(KEY_F1)) { - game->debug_map = !game->debug_map; - } - if(keydown(KEY_F2)) { - game->debug_player = !game->debug_player; - } - if(keydown(KEY_F3)) { - game->debug_extra = !game->debug_extra; - } + if(keydown(KEY_F1)) { + game->debug_map = !game->debug_map; + } + if(keydown(KEY_F2)) { + game->debug_player = !game->debug_player; + } + if(keydown(KEY_F3)) { + game->debug_extra = !game->debug_extra; + } #endif - /* if USB is enabled - keybinding for screencapture */ + /* if USB is enabled - keybinding for screencapture */ #if USB_FEATURE - if(keydown(KEY_7)) - game->screenshot = true; - if(keydown(KEY_8)) - game->record = !game->record; + if(keydown(KEY_7)) + game->screenshot = true; + if(keydown(KEY_8)) + game->record = !game->record; #endif // USB_FEATURE + } } void game_update_animations(Game *game, unsigned char ms) { diff --git a/src/game.h b/src/game.h index f82c51b..a58a438 100644 --- a/src/game.h +++ b/src/game.h @@ -25,6 +25,7 @@ typedef enum { I_NONE, I_ARMOR, I_GLOVE, + I_SWORD, I_BEER, I_MILK, I_TALISMAN, @@ -38,6 +39,10 @@ typedef struct { typedef struct { Slot slots[SLOT_NUM]; + Slot talisman; + Slot armor; + Slot weapon; + char open : 1; } Inventory; typedef struct { @@ -204,6 +209,7 @@ typedef struct { bool debug_extra; Animation npc_animation; + Inventory inventory; int mana; /* Only for testing events TODO: Remove this! */ } Game; diff --git a/src/inventory.c b/src/inventory.c index 91f36e5..511bf51 100644 --- a/src/inventory.c +++ b/src/inventory.c @@ -1 +1,51 @@ #include "inventory.h" + +#include + +extern bopti_image_t inventory_img; +extern bopti_image_t items_img; +extern bopti_image_t player_male_inv_img; +extern bopti_image_t player_female_inv_img; + +void inventory_draw(Game *game, Inventory *inventory) { + size_t i; + /* TODO: Cleanup! */ + inventory->slots[5].i = I_GLOVE; + inventory->armor.i = I_ARMOR; + inventory->talisman.i = I_TALISMAN; + inventory->weapon.i = I_SWORD; + if(inventory->open) { + dimage(0, 0, &inventory_img); + for(i=0;islots[i].i*28, 0, 28, 27, + DIMAGE_NONE); +#else + dsubimage(88+(i%SLOT_COLUMNS)*12, 24+(i/SLOT_COLUMNS)*12, + &items_img, inventory->slots[i].i*8, 0, 8, 8, + DIMAGE_NONE); +#endif + } +#if GINT_RENDER_RGB + dsubimage(222, 87, &items_img, inventory->talisman.i*28, 0, 28, 27, + DIMAGE_NONE); + dsubimage(222, 87+32, &items_img, inventory->armor.i*28, 0, 28, 27, + DIMAGE_NONE); + dsubimage(222, 87+64, &items_img, inventory->weapon.i*28, 0, 28, 27, + DIMAGE_NONE); +#else + dsubimage(72, 24, &items_img, inventory->talisman.i*8, 0, 8, 8, + DIMAGE_NONE); + dsubimage(72, 24+12, &items_img, inventory->armor.i*8, 0, 8, 8, + DIMAGE_NONE); + dsubimage(72, 24+24, &items_img, inventory->weapon.i*8, 0, 8, 8, + DIMAGE_NONE); +#endif +#if GINT_RENDER_RGB + dimage(183, 20, + game->player.is_male ? &player_male_inv_img + : &player_female_inv_img); +#endif + } +} diff --git a/src/inventory.h b/src/inventory.h index 2c41b82..b8a0368 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -4,4 +4,6 @@ /* The structs related to the inventory are defined in game.h */ #include "game.h" +void inventory_draw(Game *game, Inventory *inventory); + #endif diff --git a/src/main.c b/src/main.c index 986e4ea..e9762af 100644 --- a/src/main.c +++ b/src/main.c @@ -32,31 +32,34 @@ extern Map *worldRPG[]; /* Game data (defined in "game.h")*/ -Game game = {NULL, - {12 * PXSIZE, - 36 * PXSIZE, - 0, - 0, - 100, - SPEED, - false, - 0, - false, - false, - true, - {}}, - {{}, {}, 0}, - false, - false, - false, - 0, +Game game = { + NULL, + {12 * PXSIZE, + 36 * PXSIZE, + 0, + 0, + 100, + SPEED, + false, + 0, + false, + false, + true, + {}}, + {{}, {}, 0}, + false, + false, + false, + 0, - /* debug variables*/ - false, - false, - false, - {}, - 100}; + /* debug variables*/ + false, + false, + false, + {}, + {}, + 100, +}; /* screen capture management code. TODO: Clean this up! */