mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2025-05-28 22:45:20 +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, (int *)&game->player.life, "life");
|
||||||
events_bind_variable(&game->handler, &game->mana, "mana");
|
events_bind_variable(&game->handler, &game->mana, "mana");
|
||||||
inventory_init(&game->inventory);
|
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);
|
// reload_npc(&game);
|
||||||
}
|
}
|
||||||
|
@ -191,16 +195,27 @@ void game_get_inputs(Game *game) {
|
||||||
clearevents();
|
clearevents();
|
||||||
sleep();
|
sleep();
|
||||||
}
|
}
|
||||||
if(keydown(KEY_SHIFT))
|
if(keydown(KEY_OPTN))
|
||||||
game->inventory.selected = game->inventory.selection;
|
inventory_move_from_selected(&game->inventory);
|
||||||
if(keydown(KEY_OPTN)) {
|
|
||||||
game->player.is_male = !game->player.is_male;
|
|
||||||
/* TODO: Make something cleaner */
|
/* TODO: Make something cleaner */
|
||||||
while(keydown(KEY_OPTN)) {
|
while(keydown(KEY_OPTN)) {
|
||||||
clearevents();
|
clearevents();
|
||||||
sleep();
|
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 {
|
} else {
|
||||||
/* Player actions - Prototypes in player.h and implementation in
|
/* Player actions - Prototypes in player.h and implementation in
|
||||||
* player.c */
|
* player.c */
|
||||||
|
|
|
@ -32,6 +32,15 @@ typedef enum {
|
||||||
I_AMOUNT
|
I_AMOUNT
|
||||||
} Item;
|
} Item;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
IT_NONE,
|
||||||
|
IT_TALISMAN,
|
||||||
|
IT_ARMOR,
|
||||||
|
IT_WEAPON,
|
||||||
|
IT_FOOD,
|
||||||
|
IT_AMOUNT
|
||||||
|
} ItemType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Item i : 4;
|
Item i : 4;
|
||||||
unsigned char durability;
|
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_male_inv_img;
|
||||||
extern bopti_image_t player_female_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) {
|
void inventory_init(Inventory *inventory) {
|
||||||
inventory->open = 0;
|
inventory->open = 0;
|
||||||
memset(inventory->slots, 0, sizeof(Slot)*SLOT_NUM);
|
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);
|
player->is_male ? &player_male_inv_img : &player_female_inv_img);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
/* TODO: Stats. */
|
||||||
}
|
}
|
||||||
|
|
||||||
char inventory_add(Inventory *inventory, Item item) {
|
char inventory_add(Inventory *inventory, Item item) {
|
||||||
|
@ -63,6 +74,59 @@ char inventory_add(Inventory *inventory, Item item) {
|
||||||
return 1;
|
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) {
|
void inventory_move_selection(Inventory *inventory, Direction direction) {
|
||||||
switch(direction) {
|
switch(direction) {
|
||||||
case D_UP:
|
case D_UP:
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
void inventory_init(Inventory *inventory);
|
void inventory_init(Inventory *inventory);
|
||||||
void inventory_draw(Inventory *inventory, Player *player);
|
void inventory_draw(Inventory *inventory, Player *player);
|
||||||
char inventory_add(Inventory *inventory, Item item);
|
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);
|
void inventory_move_selection(Inventory *inventory, Direction direction);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue