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/events.c
src/animation.c
src/inventory.c
# ...
)
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
@ -56,6 +57,8 @@ set(ASSETS
set(ASSETS_cg
assets-cg/player_male.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_female.png
assets-cg/npc/char/npc_milkman.png
@ -69,6 +72,8 @@ set(ASSETS_cg
assets-cg/INFO_Icon.png
assets-cg/player_face.png
assets-cg/font.png
assets-cg/inventory.png
assets-cg/items.png
)
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_police.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_milkman.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:
type: bopti-image
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:
type: bopti-image
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
#define SLOT_NUM 9
#define SLOT_COLUMNS 3
#if GINT_RENDER_RGB
/* The tile size */

View file

@ -1,6 +1,7 @@
#include "game.h"
#include "config.h"
#include "inventory.h"
#include "map.h"
#include "mapdata.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, 16, C_BLACK, "Mana: %d", game->mana);
dprint(8, 24, C_BLACK, "X: %d Y: %d", game->player.x, game->player.y);
inventory_draw(game, &game->inventory);
}
/* Key management */
@ -149,86 +151,99 @@ void game_get_inputs(Game *game) {
if(keydown(KEY_EXIT))
game->exittoOS = true;
/* Player actions - Prototypes in player.h and implementation in player.c */
if(keydown(KEY_LEFT))
player_move(game, D_LEFT);
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;
/* Inventory */
if(keydown(KEY_ALPHA)) {
game->inventory.open = !game->inventory.open;
/* TODO: Make something cleaner */
while(keydown(KEY_OPTN)) {
while(keydown(KEY_ALPHA)) {
clearevents();
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();
} else {
/* Player actions - Prototypes in player.h and implementation in
* player.c */
if(keydown(KEY_LEFT))
player_move(game, D_LEFT);
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 */
while(keydown(KEY_OPTN)) {
clearevents();
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*/
if(keydown(KEY_F1)) {
NPC *mynpc = npc_create();
if(mynpc) {
mynpc->curx = (player->x << PRECISION) / PXSIZE;
mynpc->cury = (player->y << PRECISION) / PXSIZE;
mynpc->x = player->x;
mynpc->y = player->x;
mynpc->hasPath = 0;
mynpc->face = 0;
mynpc->paused = 0;
mynpc->has_dialog = 0;
/*Temp debug*/
if(keydown(KEY_F1)) {
NPC *mynpc = npc_create();
if(mynpc) {
mynpc->curx = (player->x << PRECISION) / PXSIZE;
mynpc->cury = (player->y << PRECISION) / PXSIZE;
mynpc->x = player->x;
mynpc->y = player->x;
mynpc->hasPath = 0;
mynpc->face = 0;
mynpc->paused = 0;
mynpc->has_dialog = 0;
}
}
}
/* Display Debug Information on screen */
/* Display Debug Information on screen */
#if DEBUGMODE
if(keydown(KEY_F1)) {
game->debug_map = !game->debug_map;
}
if(keydown(KEY_F2)) {
game->debug_player = !game->debug_player;
}
if(keydown(KEY_F3)) {
game->debug_extra = !game->debug_extra;
}
if(keydown(KEY_F1)) {
game->debug_map = !game->debug_map;
}
if(keydown(KEY_F2)) {
game->debug_player = !game->debug_player;
}
if(keydown(KEY_F3)) {
game->debug_extra = !game->debug_extra;
}
#endif
/* if USB is enabled - keybinding for screencapture */
/* if USB is enabled - keybinding for screencapture */
#if USB_FEATURE
if(keydown(KEY_7))
game->screenshot = true;
if(keydown(KEY_8))
game->record = !game->record;
if(keydown(KEY_7))
game->screenshot = true;
if(keydown(KEY_8))
game->record = !game->record;
#endif // USB_FEATURE
}
}
void game_update_animations(Game *game, unsigned char ms) {

View file

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

View file

@ -1 +1,51 @@
#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 */
#include "game.h"
void inventory_draw(Game *game, Inventory *inventory);
#endif

View file

@ -32,31 +32,34 @@
extern Map *worldRPG[];
/* Game data (defined in "game.h")*/
Game game = {NULL,
{12 * PXSIZE,
36 * PXSIZE,
0,
0,
100,
SPEED,
false,
0,
false,
false,
true,
{}},
{{}, {}, 0},
false,
false,
false,
0,
Game game = {
NULL,
{12 * PXSIZE,
36 * PXSIZE,
0,
0,
100,
SPEED,
false,
0,
false,
false,
true,
{}},
{{}, {}, 0},
false,
false,
false,
0,
/* debug variables*/
false,
false,
false,
{},
100};
/* debug variables*/
false,
false,
false,
{},
{},
100,
};
/* screen capture management code. TODO: Clean this up! */