Started inventory rendering.

This commit is contained in:
mibi88 2024-08-01 23:09:04 +02:00
parent 4d2eb2e8de
commit d555c5be6f
18 changed files with 182 additions and 88 deletions

View file

@ -34,6 +34,7 @@ set(SOURCES
src/npc.c src/npc.c
src/events.c src/events.c
src/animation.c src/animation.c
src/inventory.c
# ... # ...
) )
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets # Shared assets, fx-9860G-only assets and fx-CG-50-only assets
@ -56,6 +57,8 @@ set(ASSETS
set(ASSETS_cg set(ASSETS_cg
assets-cg/player_male.png assets-cg/player_male.png
assets-cg/player_female.png assets-cg/player_female.png
assets-cg/player_male_inv.png
assets-cg/player_female_inv.png
assets-cg/npc/char/npc_male.png assets-cg/npc/char/npc_male.png
assets-cg/npc/char/npc_female.png assets-cg/npc/char/npc_female.png
assets-cg/npc/char/npc_milkman.png assets-cg/npc/char/npc_milkman.png
@ -69,6 +72,8 @@ set(ASSETS_cg
assets-cg/INFO_Icon.png assets-cg/INFO_Icon.png
assets-cg/player_face.png assets-cg/player_face.png
assets-cg/font.png assets-cg/font.png
assets-cg/inventory.png
assets-cg/items.png
) )
set(ASSETS_cg_EGA64 set(ASSETS_cg_EGA64
@ -98,6 +103,8 @@ set(ASSETS_fx_1b
assets-fx/1b/npc/face/npc_milkman.png assets-fx/1b/npc/face/npc_milkman.png
assets-fx/1b/npc/face/npc_police.png assets-fx/1b/npc/face/npc_police.png
assets-fx/1b/INFO_Icon.png assets-fx/1b/INFO_Icon.png
assets-fx/1b/inventory.png
assets-fx/1b/items.png
# ... # ...
) )
@ -112,7 +119,9 @@ set(ASSETS_fx_2b
assets-fx/2b/npc/face/npc_female.png assets-fx/2b/npc/face/npc_female.png
assets-fx/2b/npc/face/npc_milkman.png assets-fx/2b/npc/face/npc_milkman.png
assets-fx/2b/npc/face/npc_police.png assets-fx/2b/npc/face/npc_police.png
assets-fx/1b/INFO_Icon.png assets-fx/2b/INFO_Icon.png
assets-fx/2b/inventory.png
assets-fx/2b/items.png
# ... # ...
) )

BIN
assets-cg/base_slot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
assets-cg/items.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

BIN
assets-cg/selected.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

BIN
assets-cg/selection.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

View file

@ -5,3 +5,7 @@ INFO_Icon.png:
inventory.png: inventory.png:
type: bopti-image type: bopti-image
name: inventory_img name: inventory_img
items.png:
type: bopti-image
name: items_img

BIN
assets-fx/1b/items.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

View file

@ -5,3 +5,7 @@ INFO_Icon.png:
inventory.png: inventory.png:
type: bopti-image type: bopti-image
name: inventory_img name: inventory_img
items.png:
type: bopti-image
name: items_img

BIN
assets-fx/2b/items.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

BIN
assets-fx/selected.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

BIN
assets-fx/selection.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

View file

@ -13,6 +13,7 @@
#endif #endif
#define SLOT_NUM 9 #define SLOT_NUM 9
#define SLOT_COLUMNS 3
#if GINT_RENDER_RGB #if GINT_RENDER_RGB
/* The tile size */ /* The tile size */

View file

@ -1,6 +1,7 @@
#include "game.h" #include "game.h"
#include "config.h" #include "config.h"
#include "inventory.h"
#include "map.h" #include "map.h"
#include "mapdata.h" #include "mapdata.h"
#include "npc.h" #include "npc.h"
@ -135,6 +136,7 @@ void game_draw(Game *game) {
dprint(8, 8, C_BLACK, "npc_count: %d", npc_count); dprint(8, 8, C_BLACK, "npc_count: %d", npc_count);
dprint(8, 16, C_BLACK, "Mana: %d", game->mana); dprint(8, 16, C_BLACK, "Mana: %d", game->mana);
dprint(8, 24, C_BLACK, "X: %d Y: %d", game->player.x, game->player.y); dprint(8, 24, C_BLACK, "X: %d Y: %d", game->player.x, game->player.y);
inventory_draw(game, &game->inventory);
} }
/* Key management */ /* Key management */
@ -149,7 +151,17 @@ void game_get_inputs(Game *game) {
if(keydown(KEY_EXIT)) if(keydown(KEY_EXIT))
game->exittoOS = true; game->exittoOS = true;
/* Player actions - Prototypes in player.h and implementation in player.c */ /* Inventory */
if(keydown(KEY_ALPHA)) {
game->inventory.open = !game->inventory.open;
/* TODO: Make something cleaner */
while(keydown(KEY_ALPHA)) {
clearevents();
sleep();
}
} else {
/* Player actions - Prototypes in player.h and implementation in
* player.c */
if(keydown(KEY_LEFT)) if(keydown(KEY_LEFT))
player_move(game, D_LEFT); player_move(game, D_LEFT);
if(keydown(KEY_RIGHT)) if(keydown(KEY_RIGHT))
@ -180,8 +192,10 @@ void game_get_inputs(Game *game) {
Portal *dest_portal = (Portal *)portal->portal; Portal *dest_portal = (Portal *)portal->portal;
Collider dest_collider = dest_portal->collider; Collider dest_collider = dest_portal->collider;
Map *dest_map = (Map *)portal->map; Map *dest_map = (Map *)portal->map;
player->x = (dest_collider.x1 + dest_collider.x2) / 2 * PXSIZE; player->x =
player->y = (dest_collider.y1 + dest_collider.y2) / 2 * PXSIZE; (dest_collider.x1 + dest_collider.x2) / 2 * PXSIZE;
player->y =
(dest_collider.y1 + dest_collider.y2) / 2 * PXSIZE;
game->map_level = dest_map; game->map_level = dest_map;
/* TODO: Make something cleaner */ /* TODO: Make something cleaner */
while(keydown(KEY_SHIFT)) { while(keydown(KEY_SHIFT)) {
@ -230,6 +244,7 @@ void game_get_inputs(Game *game) {
#endif // USB_FEATURE #endif // USB_FEATURE
} }
}
void game_update_animations(Game *game, unsigned char ms) { void game_update_animations(Game *game, unsigned char ms) {
animation_update(&game->npc_animation, ms); animation_update(&game->npc_animation, ms);

View file

@ -25,6 +25,7 @@ typedef enum {
I_NONE, I_NONE,
I_ARMOR, I_ARMOR,
I_GLOVE, I_GLOVE,
I_SWORD,
I_BEER, I_BEER,
I_MILK, I_MILK,
I_TALISMAN, I_TALISMAN,
@ -38,6 +39,10 @@ typedef struct {
typedef struct { typedef struct {
Slot slots[SLOT_NUM]; Slot slots[SLOT_NUM];
Slot talisman;
Slot armor;
Slot weapon;
char open : 1;
} Inventory; } Inventory;
typedef struct { typedef struct {
@ -204,6 +209,7 @@ typedef struct {
bool debug_extra; bool debug_extra;
Animation npc_animation; Animation npc_animation;
Inventory inventory;
int mana; /* Only for testing events TODO: Remove this! */ int mana; /* Only for testing events TODO: Remove this! */
} Game; } Game;

View file

@ -1 +1,51 @@
#include "inventory.h" #include "inventory.h"
#include <gint/display.h>
extern bopti_image_t inventory_img;
extern bopti_image_t items_img;
extern bopti_image_t player_male_inv_img;
extern bopti_image_t player_female_inv_img;
void inventory_draw(Game *game, Inventory *inventory) {
size_t i;
/* TODO: Cleanup! */
inventory->slots[5].i = I_GLOVE;
inventory->armor.i = I_ARMOR;
inventory->talisman.i = I_TALISMAN;
inventory->weapon.i = I_SWORD;
if(inventory->open) {
dimage(0, 0, &inventory_img);
for(i=0;i<SLOT_NUM;i++){
#if GINT_RENDER_RGB
dsubimage(272+(i%SLOT_COLUMNS)*32, 87+(i/SLOT_COLUMNS)*32,
&items_img, inventory->slots[i].i*28, 0, 28, 27,
DIMAGE_NONE);
#else
dsubimage(88+(i%SLOT_COLUMNS)*12, 24+(i/SLOT_COLUMNS)*12,
&items_img, inventory->slots[i].i*8, 0, 8, 8,
DIMAGE_NONE);
#endif
}
#if GINT_RENDER_RGB
dsubimage(222, 87, &items_img, inventory->talisman.i*28, 0, 28, 27,
DIMAGE_NONE);
dsubimage(222, 87+32, &items_img, inventory->armor.i*28, 0, 28, 27,
DIMAGE_NONE);
dsubimage(222, 87+64, &items_img, inventory->weapon.i*28, 0, 28, 27,
DIMAGE_NONE);
#else
dsubimage(72, 24, &items_img, inventory->talisman.i*8, 0, 8, 8,
DIMAGE_NONE);
dsubimage(72, 24+12, &items_img, inventory->armor.i*8, 0, 8, 8,
DIMAGE_NONE);
dsubimage(72, 24+24, &items_img, inventory->weapon.i*8, 0, 8, 8,
DIMAGE_NONE);
#endif
#if GINT_RENDER_RGB
dimage(183, 20,
game->player.is_male ? &player_male_inv_img
: &player_female_inv_img);
#endif
}
}

View file

@ -4,4 +4,6 @@
/* The structs related to the inventory are defined in game.h */ /* The structs related to the inventory are defined in game.h */
#include "game.h" #include "game.h"
void inventory_draw(Game *game, Inventory *inventory);
#endif #endif

View file

@ -32,7 +32,8 @@
extern Map *worldRPG[]; extern Map *worldRPG[];
/* Game data (defined in "game.h")*/ /* Game data (defined in "game.h")*/
Game game = {NULL, Game game = {
NULL,
{12 * PXSIZE, {12 * PXSIZE,
36 * PXSIZE, 36 * PXSIZE,
0, 0,
@ -56,7 +57,9 @@ Game game = {NULL,
false, false,
false, false,
{}, {},
100}; {},
100,
};
/* screen capture management code. TODO: Clean this up! */ /* screen capture management code. TODO: Clean this up! */