mirror of https://github.com/bgiraudr/Adoranda.git
Display of inventory + delete item + replace item
This commit is contained in:
parent
f71c203ae1
commit
c594ed0d44
|
@ -172,7 +172,7 @@ def parseTeleporter(layer):
|
|||
raise Exception("parseTeleporter() : Un téléporteur est mal configuré")
|
||||
if len(i["properties"]) == 2:
|
||||
print("parseTeleporter() : passage automatique idMap = -1 sur téléporteur x = " + str(i["properties"][0]["value"]) + ", y = " + str(i["properties"][1]["value"]))
|
||||
teleporter += fxconv.u32(-1);
|
||||
teleporter += fxconv.u32(-1)
|
||||
for j in i["properties"]:
|
||||
teleporter += fxconv.u32(j["value"])
|
||||
except KeyError :
|
||||
|
@ -308,10 +308,13 @@ def convert_items(input, output, params, target):
|
|||
file = open(f,"r")
|
||||
data = json.load(file)
|
||||
item = fxconv.Structure()
|
||||
|
||||
item += fxconv.string(data["name"])
|
||||
item += fxconv.u32(data["id"])
|
||||
item += fxconv.ptr(f"img_{data['sprite']}")
|
||||
items += fxconv.ptr(item)
|
||||
try:
|
||||
item += fxconv.string(data["name"])
|
||||
item += fxconv.u32(data["id"])
|
||||
item += fxconv.string(data["description"])
|
||||
item += fxconv.ptr(f"img_{data['sprite']}")
|
||||
items += fxconv.ptr(item)
|
||||
except KeyError:
|
||||
raise Exception(f"convert_items() : L'item {data['name']} est mal configuré")
|
||||
|
||||
fxconv.elf(items, output, "_" + params["name"], **target)
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name":"Test1",
|
||||
"id":1,
|
||||
"sprite":"item"
|
||||
"sprite":"item",
|
||||
"description":"test1"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name":"Obj2",
|
||||
"id":2,
|
||||
"sprite":"item2"
|
||||
"sprite":"item2",
|
||||
"description":"test2"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="100" height="38" tilewidth="16" tileheight="16" infinite="0" nextlayerid="14" nextobjectid="62">
|
||||
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="100" height="38" tilewidth="16" tileheight="16" infinite="0" nextlayerid="14" nextobjectid="63">
|
||||
<editorsettings>
|
||||
<export target="testCarte.json" format="json"/>
|
||||
</editorsettings>
|
||||
|
@ -185,6 +185,12 @@
|
|||
<property name="text" value="De quoi bien commencer l'aventure !;~move:3;De rien :)"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object id="62" gid="267" x="448" y="432" width="16" height="16">
|
||||
<properties>
|
||||
<property name="name" value="Pancarte"/>
|
||||
<property name="text" value="Cadeau;~give:1"/>
|
||||
</properties>
|
||||
</object>
|
||||
</objectgroup>
|
||||
<objectgroup id="11" name="teleporter">
|
||||
<object id="50" gid="238" x="448" y="528" width="16" height="16">
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
#define NB_INTERIORS 2
|
||||
|
||||
#define NB_PLAYER_MOVES 3
|
||||
#define NB_PLAYER_ITEMS 10
|
||||
#define NB_PLAYER_ITEMS 30
|
|
@ -13,14 +13,15 @@ struct Game {
|
|||
};
|
||||
|
||||
enum action {
|
||||
DIR_DOWN = 0,
|
||||
DIR_LEFT = 1,
|
||||
DIR_UP = 2,
|
||||
DIR_RIGHT = 3,
|
||||
ACTION_SHIFT = 4,
|
||||
ACTION_ALPHA = 5,
|
||||
ACTION_F1 = 6,
|
||||
ACTION_OPTN = 7
|
||||
DIR_DOWN,
|
||||
DIR_LEFT,
|
||||
DIR_UP,
|
||||
DIR_RIGHT,
|
||||
ACTION_SHIFT,
|
||||
ACTION_ALPHA,
|
||||
ACTION_OPTN,
|
||||
ACTION_F1,
|
||||
ACTION_F2,
|
||||
};
|
||||
|
||||
/*get the input with a timeout*/
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
struct Item {
|
||||
char *name;
|
||||
int id;
|
||||
bopti_image_t *sprite;
|
||||
char *description;
|
||||
bopti_image_t *sprite;
|
||||
};
|
||||
|
||||
struct Items {
|
||||
|
@ -23,4 +23,5 @@ struct Item *get_item_id(int id);
|
|||
bool add_item_to_inventory(struct Inventory *inventory, struct Item *item);
|
||||
int get_first_free_space(struct Inventory *inventory);
|
||||
void remove_item_pos(struct Inventory *inventory, int pos);
|
||||
void display_inventory(struct Inventory *inventory);
|
||||
void display_inventory(struct Inventory *inventory);
|
||||
int open_inventory(struct Inventory *inventory, char* context);
|
|
@ -127,8 +127,10 @@ void engine_action(struct Game *game, int action) {
|
|||
if(action == ACTION_F1) {
|
||||
/*game->player->sprint = game->player->sprint ? 0 : 1;
|
||||
add_move(game->player, get_move_id(3));*/
|
||||
open_inventory(&game->player->inventory, "Consultation");
|
||||
}
|
||||
if(action == ACTION_F2) {
|
||||
add_item_to_inventory(&game->player->inventory, get_item_id(1));
|
||||
display_inventory(&game->player->inventory);
|
||||
}
|
||||
if(action == ACTION_OPTN) {
|
||||
draw_stats(game->player->stats);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "event.h"
|
||||
#include "player.h"
|
||||
#include "capacite.h"
|
||||
#include "inventory.h"
|
||||
|
||||
bool handle_event(struct Game *game, char const *event)
|
||||
{
|
||||
|
@ -14,6 +15,7 @@ bool handle_event(struct Game *game, char const *event)
|
|||
int len=strlen(event), qty=1;
|
||||
char *star = strchr(event, '*');
|
||||
if(star) len=star-event, qty=atoi(star+1);
|
||||
add_item_to_inventory(&game->player->inventory,get_item_id(2));
|
||||
return true;
|
||||
}
|
||||
else if(!strncmp(event, "xp:", 3)) {
|
||||
|
|
|
@ -38,7 +38,8 @@ int get_inputs(void) {
|
|||
/*action key*/
|
||||
if(key == KEY_SHIFT) return ACTION_SHIFT;
|
||||
if(key == KEY_ALPHA) return ACTION_ALPHA;
|
||||
if(key == KEY_F1) return ACTION_F1;
|
||||
if(key == KEY_OPTN) return ACTION_OPTN;
|
||||
if(key == KEY_F1) return ACTION_F1;
|
||||
if(key == KEY_F2) return ACTION_F2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "inventory.h"
|
||||
#include "util.h"
|
||||
#include "define.h"
|
||||
#include "vec2.h"
|
||||
|
||||
extern struct Items items;
|
||||
|
||||
|
@ -26,26 +27,94 @@ int get_first_free_space(struct Inventory *inventory) {
|
|||
|
||||
bool add_item_to_inventory(struct Inventory *inventory, struct Item *item) {
|
||||
int index = get_first_free_space(inventory);
|
||||
|
||||
extern bopti_image_t img_dialogue;
|
||||
dimage(42,DHEIGHT-75,&img_dialogue);
|
||||
|
||||
if(index < NB_PLAYER_ITEMS) {
|
||||
dprint(50,DHEIGHT-47,C_BLACK,"Vous ajoutez %s à votre inventaire !", item->name);
|
||||
dupdate();
|
||||
wait_for_input(KEY_SHIFT);
|
||||
inventory->items[index] = item;
|
||||
inventory->nbItems++;
|
||||
return true;
|
||||
} else {
|
||||
dprint(50,DHEIGHT-47,C_BLACK,"Plus de place pour ajouter %s à votre inventaire !", item->name);
|
||||
dupdate();
|
||||
wait_for_input(KEY_SHIFT);
|
||||
int pos = open_inventory(inventory, "Remplacer");
|
||||
if(pos != -1) {
|
||||
inventory->items[pos] = item;
|
||||
inventory->nbItems++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void remove_item_pos(struct Inventory *inventory, int pos) {
|
||||
inventory->items[pos] = NULL;
|
||||
inventory->items[pos] = NULL;
|
||||
inventory->nbItems--;
|
||||
}
|
||||
|
||||
void display_inventory(struct Inventory *inventory) {
|
||||
dclear(C_WHITE);
|
||||
for(int i = 0 ; i < NB_PLAYER_ITEMS ; i++) {
|
||||
int x = i%10;
|
||||
int y = i/10;
|
||||
if(inventory->items[i] != NULL) {
|
||||
dimage(0,18*i,inventory->items[i]->sprite);
|
||||
dimage(18*x+50,25*y+50,inventory->items[i]->sprite);
|
||||
} else {
|
||||
drect(18*x+50,25*y+50,18*x+65,25*y+65,C_BLACK);
|
||||
}
|
||||
}
|
||||
dupdate();
|
||||
wait_for_input(KEY_SHIFT);
|
||||
}
|
||||
|
||||
int open_inventory(struct Inventory *inventory, char* context) {
|
||||
int buffer = keydown(KEY_SHIFT);
|
||||
struct Vec2 cursor = VEC2(0,0);
|
||||
int pos = 0;
|
||||
int suppression = 0;
|
||||
|
||||
while(1) {
|
||||
clearevents();
|
||||
|
||||
cursor.x += keydown(KEY_RIGHT) - keydown(KEY_LEFT);
|
||||
cursor.y += keydown(KEY_DOWN) - keydown(KEY_UP);
|
||||
|
||||
if(cursor.x > 9) cursor.x = 9;
|
||||
if(cursor.x < 0) cursor.x = 0;
|
||||
if(cursor.y > 2) cursor.y = 2;
|
||||
if(cursor.y < 0) cursor.y = 0;
|
||||
|
||||
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");
|
||||
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);
|
||||
}
|
||||
dupdate();
|
||||
|
||||
if(keydown(KEY_SHIFT)) {
|
||||
if(buffer) buffer = 0;
|
||||
else if(inventory->items[pos] != NULL) {
|
||||
if(!suppression) break;
|
||||
else remove_item_pos(inventory, pos);
|
||||
}
|
||||
}
|
||||
if(keydown(KEY_OPTN)) {
|
||||
suppression = suppression ? 0 : 1;
|
||||
}
|
||||
if(keydown(KEY_EXIT)) {
|
||||
pos = -1;
|
||||
break;
|
||||
}
|
||||
while(keydown_any(KEY_RIGHT, KEY_LEFT, KEY_DOWN, KEY_UP, KEY_SHIFT, KEY_OPTN, 0)) clearevents();
|
||||
}
|
||||
return pos;
|
||||
}
|
Loading…
Reference in New Issue