mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2025-05-27 14:05:16 +02:00
Inventory management.
This commit is contained in:
parent
b26cf53e91
commit
fe824d7340
4 changed files with 95 additions and 4 deletions
23
src/game.c
23
src/game.c
|
@ -37,6 +37,10 @@ void game_init(Game *game) {
|
|||
events_bind_variable(&game->handler, (int *)&game->player.life, "life");
|
||||
events_bind_variable(&game->handler, &game->mana, "mana");
|
||||
inventory_init(&game->inventory);
|
||||
/* For debugging */
|
||||
game->inventory.slots[5].i = I_GLOVE;
|
||||
game->inventory.slots[1].i = I_ARMOR;
|
||||
game->inventory.slots[8].i = I_TALISMAN;
|
||||
|
||||
// reload_npc(&game);
|
||||
}
|
||||
|
@ -191,16 +195,27 @@ void game_get_inputs(Game *game) {
|
|||
clearevents();
|
||||
sleep();
|
||||
}
|
||||
if(keydown(KEY_SHIFT))
|
||||
game->inventory.selected = game->inventory.selection;
|
||||
if(keydown(KEY_OPTN)) {
|
||||
game->player.is_male = !game->player.is_male;
|
||||
if(keydown(KEY_OPTN))
|
||||
inventory_move_from_selected(&game->inventory);
|
||||
/* TODO: Make something cleaner */
|
||||
while(keydown(KEY_OPTN)) {
|
||||
clearevents();
|
||||
sleep();
|
||||
}
|
||||
if(keydown(KEY_SQUARE)) {
|
||||
inventory_use(&game->inventory, &game->player);
|
||||
}
|
||||
if(keydown(KEY_F1)) {
|
||||
inventory_unequip(&game->inventory, IT_TALISMAN);
|
||||
}
|
||||
if(keydown(KEY_F2)) {
|
||||
inventory_unequip(&game->inventory, IT_ARMOR);
|
||||
}
|
||||
if(keydown(KEY_F3)) {
|
||||
inventory_unequip(&game->inventory, IT_WEAPON);
|
||||
}
|
||||
if(keydown(KEY_SHIFT))
|
||||
game->inventory.selected = game->inventory.selection;
|
||||
} else {
|
||||
/* Player actions - Prototypes in player.h and implementation in
|
||||
* player.c */
|
||||
|
|
|
@ -32,6 +32,15 @@ typedef enum {
|
|||
I_AMOUNT
|
||||
} Item;
|
||||
|
||||
typedef enum {
|
||||
IT_NONE,
|
||||
IT_TALISMAN,
|
||||
IT_ARMOR,
|
||||
IT_WEAPON,
|
||||
IT_FOOD,
|
||||
IT_AMOUNT
|
||||
} ItemType;
|
||||
|
||||
typedef struct {
|
||||
Item i : 4;
|
||||
unsigned char durability;
|
||||
|
|
|
@ -10,6 +10,16 @@ extern bopti_image_t selected_img;
|
|||
extern bopti_image_t player_male_inv_img;
|
||||
extern bopti_image_t player_female_inv_img;
|
||||
|
||||
char item_types[I_AMOUNT] = {
|
||||
IT_NONE,
|
||||
IT_ARMOR,
|
||||
IT_WEAPON,
|
||||
IT_WEAPON,
|
||||
IT_FOOD,
|
||||
IT_FOOD,
|
||||
IT_TALISMAN
|
||||
};
|
||||
|
||||
void inventory_init(Inventory *inventory) {
|
||||
inventory->open = 0;
|
||||
memset(inventory->slots, 0, sizeof(Slot)*SLOT_NUM);
|
||||
|
@ -49,6 +59,7 @@ void inventory_draw(Inventory *inventory, Player *player) {
|
|||
player->is_male ? &player_male_inv_img : &player_female_inv_img);
|
||||
#endif
|
||||
}
|
||||
/* TODO: Stats. */
|
||||
}
|
||||
|
||||
char inventory_add(Inventory *inventory, Item item) {
|
||||
|
@ -63,6 +74,59 @@ char inventory_add(Inventory *inventory, Item item) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
void inventory_move_from_selected(Inventory *inventory) {
|
||||
if(inventory->selected < 0) return;
|
||||
Slot current = inventory->slots[inventory->selection];
|
||||
Slot new = inventory->slots[inventory->selected];
|
||||
inventory->slots[inventory->selection] = new;
|
||||
inventory->slots[inventory->selected] = current;
|
||||
}
|
||||
|
||||
void inventory_use(Inventory *inventory, Player *player) {
|
||||
Item item = inventory->slots[inventory->selection].i;
|
||||
switch(item_types[item]){
|
||||
case IT_TALISMAN:
|
||||
inventory->equipped[0] = inventory->slots[inventory->selection];
|
||||
break;
|
||||
case IT_ARMOR:
|
||||
inventory->equipped[1] = inventory->slots[inventory->selection];
|
||||
break;
|
||||
case IT_WEAPON:
|
||||
inventory->equipped[2] = inventory->slots[inventory->selection];
|
||||
break;
|
||||
case IT_FOOD:
|
||||
/* TODO */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
inventory->slots[inventory->selection].i = I_NONE;
|
||||
inventory->slots[inventory->selection].durability = 255;
|
||||
}
|
||||
|
||||
void inventory_unequip(Inventory *inventory, ItemType type) {
|
||||
if(inventory->slots[inventory->selection].i) return;
|
||||
switch(type){
|
||||
case IT_TALISMAN:
|
||||
inventory->slots[inventory->selection] = inventory->equipped[0];
|
||||
inventory->equipped[0].i = I_NONE;
|
||||
inventory->equipped[0].durability = 255;
|
||||
break;
|
||||
case IT_ARMOR:
|
||||
inventory->slots[inventory->selection] = inventory->equipped[1];
|
||||
inventory->equipped[1].i = I_NONE;
|
||||
inventory->equipped[1].durability = 255;
|
||||
break;
|
||||
case IT_WEAPON:
|
||||
inventory->slots[inventory->selection] = inventory->equipped[2];
|
||||
inventory->equipped[2].i = I_NONE;
|
||||
inventory->equipped[2].durability = 255;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void inventory_move_selection(Inventory *inventory, Direction direction) {
|
||||
switch(direction) {
|
||||
case D_UP:
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
void inventory_init(Inventory *inventory);
|
||||
void inventory_draw(Inventory *inventory, Player *player);
|
||||
char inventory_add(Inventory *inventory, Item item);
|
||||
void inventory_move_from_selected(Inventory *inventory);
|
||||
void inventory_use(Inventory *inventory, Player *player);
|
||||
void inventory_unequip(Inventory *inventory, ItemType type);
|
||||
void inventory_move_selection(Inventory *inventory, Direction direction);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue