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,86 +151,99 @@ 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_LEFT)) if(keydown(KEY_ALPHA)) {
player_move(game, D_LEFT); game->inventory.open = !game->inventory.open;
if(keydown(KEY_RIGHT))
player_move(game, D_RIGHT);
if(keydown(KEY_UP))
player_move(game, D_UP);
if(keydown(KEY_DOWN))
player_move(game, D_DOWN);
if(keydown(KEY_SHIFT))
player_action(game);
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_ALPHA)) {
clearevents(); clearevents();
sleep(); sleep();
} }
} } else {
Player *player = &game->player; /* Player actions - Prototypes in player.h and implementation in
if(keydown(KEY_SHIFT)) { * player.c */
uint32_t i; if(keydown(KEY_LEFT))
for(i = 0; i < game->map_level->nbPortal; i++) { player_move(game, D_LEFT);
Portal *portal = &game->map_level->portals[i]; if(keydown(KEY_RIGHT))
if(player->x >= (int)portal->collider.x1 * PXSIZE && player_move(game, D_RIGHT);
player->x < (int)portal->collider.x2 * PXSIZE && if(keydown(KEY_UP))
player->y >= (int)portal->collider.y1 * PXSIZE && player_move(game, D_UP);
player->y < (int)portal->collider.y2 * PXSIZE) { if(keydown(KEY_DOWN))
Portal *dest_portal = (Portal *)portal->portal; player_move(game, D_DOWN);
Collider dest_collider = dest_portal->collider; if(keydown(KEY_SHIFT))
Map *dest_map = (Map *)portal->map; player_action(game);
player->x = (dest_collider.x1 + dest_collider.x2) / 2 * PXSIZE; if(keydown(KEY_OPTN)) {
player->y = (dest_collider.y1 + dest_collider.y2) / 2 * PXSIZE; game->player.is_male = !game->player.is_male;
game->map_level = dest_map; /* TODO: Make something cleaner */
/* TODO: Make something cleaner */ while(keydown(KEY_OPTN)) {
while(keydown(KEY_SHIFT)) { clearevents();
clearevents(); sleep();
sleep(); }
}
Player *player = &game->player;
if(keydown(KEY_SHIFT)) {
uint32_t i;
for(i = 0; i < game->map_level->nbPortal; i++) {
Portal *portal = &game->map_level->portals[i];
if(player->x >= (int)portal->collider.x1 * PXSIZE &&
player->x < (int)portal->collider.x2 * PXSIZE &&
player->y >= (int)portal->collider.y1 * PXSIZE &&
player->y < (int)portal->collider.y2 * PXSIZE) {
Portal *dest_portal = (Portal *)portal->portal;
Collider dest_collider = dest_portal->collider;
Map *dest_map = (Map *)portal->map;
player->x =
(dest_collider.x1 + dest_collider.x2) / 2 * PXSIZE;
player->y =
(dest_collider.y1 + dest_collider.y2) / 2 * PXSIZE;
game->map_level = dest_map;
/* TODO: Make something cleaner */
while(keydown(KEY_SHIFT)) {
clearevents();
sleep();
}
} }
} }
} }
}
/*Temp debug*/ /*Temp debug*/
if(keydown(KEY_F1)) { if(keydown(KEY_F1)) {
NPC *mynpc = npc_create(); NPC *mynpc = npc_create();
if(mynpc) { if(mynpc) {
mynpc->curx = (player->x << PRECISION) / PXSIZE; mynpc->curx = (player->x << PRECISION) / PXSIZE;
mynpc->cury = (player->y << PRECISION) / PXSIZE; mynpc->cury = (player->y << PRECISION) / PXSIZE;
mynpc->x = player->x; mynpc->x = player->x;
mynpc->y = player->x; mynpc->y = player->x;
mynpc->hasPath = 0; mynpc->hasPath = 0;
mynpc->face = 0; mynpc->face = 0;
mynpc->paused = 0; mynpc->paused = 0;
mynpc->has_dialog = 0; mynpc->has_dialog = 0;
}
} }
}
/* Display Debug Information on screen */ /* Display Debug Information on screen */
#if DEBUGMODE #if DEBUGMODE
if(keydown(KEY_F1)) { if(keydown(KEY_F1)) {
game->debug_map = !game->debug_map; game->debug_map = !game->debug_map;
} }
if(keydown(KEY_F2)) { if(keydown(KEY_F2)) {
game->debug_player = !game->debug_player; game->debug_player = !game->debug_player;
} }
if(keydown(KEY_F3)) { if(keydown(KEY_F3)) {
game->debug_extra = !game->debug_extra; game->debug_extra = !game->debug_extra;
} }
#endif #endif
/* if USB is enabled - keybinding for screencapture */ /* if USB is enabled - keybinding for screencapture */
#if USB_FEATURE #if USB_FEATURE
if(keydown(KEY_7)) if(keydown(KEY_7))
game->screenshot = true; game->screenshot = true;
if(keydown(KEY_8)) if(keydown(KEY_8))
game->record = !game->record; game->record = !game->record;
#endif // USB_FEATURE #endif // USB_FEATURE
}
} }
void game_update_animations(Game *game, unsigned char ms) { void game_update_animations(Game *game, unsigned char 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,31 +32,34 @@
extern Map *worldRPG[]; extern Map *worldRPG[];
/* Game data (defined in "game.h")*/ /* Game data (defined in "game.h")*/
Game game = {NULL, Game game = {
{12 * PXSIZE, NULL,
36 * PXSIZE, {12 * PXSIZE,
0, 36 * PXSIZE,
0, 0,
100, 0,
SPEED, 100,
false, SPEED,
0, false,
false, 0,
false, false,
true, false,
{}}, true,
{{}, {}, 0}, {}},
false, {{}, {}, 0},
false, false,
false, false,
0, false,
0,
/* debug variables*/ /* debug variables*/
false, false,
false, false,
false, false,
{}, {},
100}; {},
100,
};
/* screen capture management code. TODO: Clean this up! */ /* screen capture management code. TODO: Clean this up! */