visual work on inventory

pull/2/head
bgiraudr 4 months ago
parent c45f31bd33
commit b3612845fe
  1. 3
      CMakeLists.txt
  2. BIN
      assets-cg/battle_ui.png
  3. 5
      assets-cg/fxconv-metadata.txt
  4. BIN
      assets-cg/inventory.png
  5. BIN
      assets-cg/items/item.png
  6. BIN
      assets-cg/items/item2.png
  7. 3
      include/inventory.h
  8. 6
      src/battle.c
  9. 34
      src/inventory.c

@ -22,6 +22,7 @@ add_custom_command(
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/assets-cg/maps/
DEPENDS assets-cg/maps/testCarte.tmx
assets-cg/maps/1.tmx
assets-cg/maps/2.tmx
assets-cg/tileset.png
assets-cg/maps/tileset.tsx
assets-cg/maps/inside/tileset_in.tsx
@ -53,6 +54,7 @@ set(SOURCES
set(ASSETS_cg
assets-cg/tileset.png
assets-cg/inventory.png
assets-cg/categories.png
assets-cg/dialogue.png
assets-cg/capacite.png
@ -60,6 +62,7 @@ set(ASSETS_cg
assets-cg/maps/inside/tileset_in.png
assets-cg/maps/testCarte.json
assets-cg/maps/1.json
assets-cg/maps/2.json
assets-cg/maps/inside/1.json
assets-cg/maps/inside/2.json
assets-cg/spritesheet.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

@ -34,6 +34,11 @@ battle_ui.png:
type: bopti-image
name: img_battle
profile: p8
inventory.png:
type: bopti-image
name: img_inventory
profile: p8
player_moves.txt:
custom-type: player_moves

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 B

After

Width:  |  Height:  |  Size: 121 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 B

After

Width:  |  Height:  |  Size: 121 B

@ -12,4 +12,5 @@ struct Inventory {
bool add_item_to_inventory(struct Game *game, struct Inventory *inventory, struct Item *item);
int get_first_free_space(struct Inventory *inventory);
void display_inventory(struct Inventory *inventory);
int open_inventory(struct Game *game, struct Inventory *inventory, char* context, bool keep_open);
int open_inventory(struct Game *game, struct Inventory *inventory, char* context, bool keep_open);
int get_nb_items(struct Inventory *inventory);

@ -185,6 +185,7 @@ void draw_battle(struct Player *player, struct Monster *monster) {
if(monster->stats->pv < 0) monster->stats->pv = 0;
dclear(C_RGB(25,25,25));
drect(323, 120, DWIDTH, 125, getTypeFromName(player->stats.type).color);
dimage(0,0,&img_battle);
int posHP = (float)player->stats.pv / player->stats.max_pv * WIDTH_HP;
drect(290,138,290+WIDTH_HP,142,C_WHITE);
@ -198,8 +199,7 @@ void draw_battle(struct Player *player, struct Monster *monster) {
drect(290,138,290+posHP,142,pcolor);
dprint(333,124,C_BLACK,"%d",player->stats.level);
dprint(246,124,C_BLACK,"%d/%d", player->stats.pv, player->stats.max_pv);
dtext(340,115,C_BLUE, player->stats.type);
dprint(256,122,C_BLACK,"%d/%d", player->stats.pv, player->stats.max_pv);
int posHPmonster = (float)monster->stats->pv / monster->stats->max_pv * WIDTH_HP;
dprint(2,8,C_BLACK,"%s",monster->name);
@ -214,7 +214,7 @@ void draw_battle(struct Player *player, struct Monster *monster) {
drect(48,23,48+posHPmonster,27,mcolor);
dprint(90,9,C_BLACK,"%d",monster->stats->level);
dprint(127,11,C_BLACK,"%d/%d", monster->stats->pv, monster->stats->max_pv);
dtext(92,0,C_BLUE, monster->stats->type);
drect(0,0,84,4,getTypeFromName(monster->stats->type).color);
dimage(265,10,monster->sprite);
}

@ -22,6 +22,16 @@ int get_first_free_space(struct Inventory *inventory) {
return NB_PLAYER_ITEMS;
}
int get_nb_items(struct Inventory *inventory) {
int ret = 0;
for(int i = 0; i < NB_PLAYER_ITEMS; i++) {
if(inventory->items[i] != NULL) {
ret++;
}
}
return ret;
}
bool add_item_to_inventory(struct Game *game, struct Inventory *inventory, struct Item *item) {
int index = get_first_free_space(inventory);
@ -47,23 +57,29 @@ bool add_item_to_inventory(struct Game *game, struct Inventory *inventory, struc
}
void display_inventory(struct Inventory *inventory) {
const int x_inventory = 30;
const int y_inventory = 56;
for(int i = 0 ; i < NB_PLAYER_ITEMS ; i++) {
int x = i%10;
int y = i/10;
if(inventory->items[i] != NULL) {
dimage(18*x+50,25*y+50,inventory->items[i]->sprite);
dimage(34*x+x_inventory, 41*y+y_inventory, inventory->items[i]->sprite);
} else {
drect(18*x+50,25*y+50,18*x+65,25*y+65,C_BLACK);
drect(34*x+x_inventory, 41*y+y_inventory, 34*x+x_inventory+31, 41*y+y_inventory+31, C_BLACK);
}
}
}
int open_inventory(struct Game *game, struct Inventory *inventory, char* context, bool keep_open) {
extern bopti_image_t img_inventory;
int buffer = keydown(KEY_SHIFT);
struct Vec2 cursor = VEC2(0,0);
int pos = 0;
int suppression = 0;
const int x_inventory = 30;
const int y_inventory = 56;
while(1) {
clearevents();
@ -77,15 +93,17 @@ int open_inventory(struct Game *game, struct Inventory *inventory, char* context
pos = cursor.x + cursor.y*10;
dclear(C_WHITE);
dtext(130,15,C_BLACK,context);
drect(18*cursor.x+48, 25*cursor.y+48, 18*cursor.x+67, 25*cursor.y+67,suppression ? C_RED : C_GREEN);
if(suppression) dtext(130,35,C_RED,"Suppression");
dclear(C_RGB(25,25,25));
dimage(0, 0, &img_inventory);
dtext(5,2,C_BLACK,context);
drect(34*cursor.x+x_inventory-2, 41*cursor.y+y_inventory-2, 34*cursor.x+x_inventory+33, 41*cursor.y+y_inventory+33, suppression ? C_RED : C_GREEN);
if(suppression) dtext(5,16,C_RED,"Suppression");
dprint(5, 185, C_BLACK, "%d/%d", get_nb_items(inventory), NB_PLAYER_ITEMS);
display_inventory(inventory);
if(inventory->items[pos] != NULL) {
dprint(10, DHEIGHT-30, C_BLACK, "nom : %s", inventory->items[pos]->name);
dprint(10, DHEIGHT-15, C_BLACK, "desc : %s", inventory->items[pos]->description);
dtext(5, 30, C_BLACK, inventory->items[pos]->name);
dtext(104, 30, C_BLACK, inventory->items[pos]->description);
}
dupdate();

Loading…
Cancel
Save