mirror of https://github.com/bgiraudr/Adoranda.git
inventory now can store items. Of course.
This commit is contained in:
parent
3d3361151b
commit
f71c203ae1
|
@ -45,6 +45,7 @@ set(SOURCES
|
|||
src/capacite.c
|
||||
src/monster.c
|
||||
src/event.c
|
||||
src/inventory.c
|
||||
)
|
||||
|
||||
set(ASSETS_cg
|
||||
|
@ -65,6 +66,9 @@ set(ASSETS_cg
|
|||
assets-cg/monsters/test2.png
|
||||
assets-cg/monsters/monsters.txt
|
||||
assets-cg/player_moves.txt
|
||||
assets-cg/items/items.txt
|
||||
assets-cg/items/item.png
|
||||
assets-cg/items/item2.png
|
||||
)
|
||||
|
||||
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
|
||||
|
|
|
@ -311,6 +311,7 @@ def convert_items(input, output, params, target):
|
|||
|
||||
item += fxconv.string(data["name"])
|
||||
item += fxconv.u32(data["id"])
|
||||
item += fxconv.ptr(f"img_{data['sprite']}")
|
||||
items += fxconv.ptr(item)
|
||||
|
||||
fxconv.elf(items, output, "_" + params["name"], **target)
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"name":"Test1",
|
||||
"id":1
|
||||
"id":1,
|
||||
"sprite":"item"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"name":"Obj2",
|
||||
"id":2
|
||||
"id":2,
|
||||
"sprite":"item2"
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
*.png:
|
||||
type: bopti-image
|
||||
name_regex: (.*)\.png img_\1
|
||||
|
||||
items.txt:
|
||||
custom-type: items
|
||||
name: items
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 150 B |
Binary file not shown.
After Width: | Height: | Size: 152 B |
|
@ -4,4 +4,5 @@
|
|||
|
||||
#define NB_INTERIORS 2
|
||||
|
||||
#define NB_PLAYER_MOVES 3
|
||||
#define NB_PLAYER_MOVES 3
|
||||
#define NB_PLAYER_ITEMS 10
|
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
#include "define.h"
|
||||
#include <gint/display.h>
|
||||
|
||||
struct Item {
|
||||
char *name;
|
||||
int id;
|
||||
bopti_image_t *sprite;
|
||||
char *description;
|
||||
};
|
||||
|
||||
struct Items {
|
||||
int nbItems;
|
||||
struct Item *items[];
|
||||
};
|
||||
|
||||
struct Inventory {
|
||||
int nbItems;
|
||||
struct Item *items[NB_PLAYER_ITEMS];
|
||||
};
|
||||
|
||||
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);
|
|
@ -4,6 +4,7 @@
|
|||
#include "vec2.h"
|
||||
#include "stats.h"
|
||||
#include "capacite.h"
|
||||
#include "inventory.h"
|
||||
#include "define.h"
|
||||
|
||||
struct Player {
|
||||
|
@ -15,6 +16,7 @@ struct Player {
|
|||
const struct Stats base_stats;
|
||||
struct Stats stats;
|
||||
struct Move *moves[NB_PLAYER_MOVES];
|
||||
struct Inventory inventory;
|
||||
/*player mid - offset pixels*/
|
||||
int x_mid, y_mid;
|
||||
/*the direction the player facing to*/
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "battle.h"
|
||||
#include "capacite.h"
|
||||
#include "util.h"
|
||||
#include "inventory.h"
|
||||
|
||||
/*draw the current state of the game*/
|
||||
void engine_draw(struct Game const *game) {
|
||||
|
@ -124,8 +125,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));
|
||||
/*game->player->sprint = game->player->sprint ? 0 : 1;
|
||||
add_move(game->player, get_move_id(3));*/
|
||||
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);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "game.h"
|
||||
#include "event.h"
|
||||
#include "player.h"
|
||||
#include "capacite.h"
|
||||
|
||||
bool handle_event(struct Game *game, char const *event)
|
||||
{
|
||||
|
@ -20,6 +21,11 @@ bool handle_event(struct Game *game, char const *event)
|
|||
add_xp(game->player, atoi(event));
|
||||
return true;
|
||||
}
|
||||
else if(!strncmp(event, "move:", 5)) {
|
||||
event += 5;
|
||||
add_move(game->player, get_move_id(atoi(event)));
|
||||
return true;
|
||||
}
|
||||
else if(!strcmp(event, "test:test")) {
|
||||
// etc, n'importe quoi de compliqué
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "inventory.h"
|
||||
#include "util.h"
|
||||
#include "define.h"
|
||||
|
||||
extern struct Items items;
|
||||
|
||||
struct Item *get_item_id(int id) {
|
||||
for(int i = 0; i < items.nbItems; i++) {
|
||||
if(items.items[i]->id == id) return items.items[i];
|
||||
}
|
||||
return items.items[0];
|
||||
}
|
||||
|
||||
int get_first_free_space(struct Inventory *inventory) {
|
||||
for(int i = 0; i < NB_PLAYER_ITEMS; i++) {
|
||||
if(inventory->items[i] == NULL) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return NB_PLAYER_ITEMS;
|
||||
}
|
||||
|
||||
bool add_item_to_inventory(struct Inventory *inventory, struct Item *item) {
|
||||
int index = get_first_free_space(inventory);
|
||||
if(index < NB_PLAYER_ITEMS) {
|
||||
inventory->items[index] = item;
|
||||
inventory->nbItems++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void remove_item_pos(struct Inventory *inventory, int pos) {
|
||||
inventory->items[pos] = NULL;
|
||||
inventory->nbItems--;
|
||||
}
|
||||
|
||||
void display_inventory(struct Inventory *inventory) {
|
||||
dclear(C_WHITE);
|
||||
for(int i = 0 ; i < NB_PLAYER_ITEMS ; i++) {
|
||||
if(inventory->items[i] != NULL) {
|
||||
dimage(0,18*i,inventory->items[i]->sprite);
|
||||
}
|
||||
}
|
||||
dupdate();
|
||||
wait_for_input(KEY_SHIFT);
|
||||
}
|
|
@ -28,11 +28,16 @@ struct Player init_player(void) {
|
|||
.xp = 0
|
||||
};
|
||||
|
||||
struct Inventory inventory = {
|
||||
.nbItems = 0
|
||||
};
|
||||
|
||||
struct Player player = {
|
||||
.pos = VEC2(32, 30),
|
||||
.pos_visual = VEC2F(32*TILE_SIZE, 30*TILE_SIZE),
|
||||
.base_stats = bstats,
|
||||
.stats = stats,
|
||||
.inventory = inventory,
|
||||
.x_mid = 6,
|
||||
.y_mid = 1,
|
||||
.show_x = 12,
|
||||
|
|
Loading…
Reference in New Issue