Deliver cake to NPCs

This commit is contained in:
Pyrex 2024-02-29 12:08:50 -08:00
parent 60e1a4ed43
commit 1a89e4f3b6
10 changed files with 131 additions and 9 deletions

View File

@ -5,6 +5,7 @@ cc_library(
name = "game", name = "game",
srcs = glob(["*.c"]) + [ srcs = glob(["*.c"]) + [
"art/game_collectibles.c", "art/game_collectibles.c",
"art/game_hud.c",
"art/game_npcs.c", "art/game_npcs.c",
"art/game_player.c", "art/game_player.c",
"art/game_tiles.c", "art/game_tiles.c",
@ -17,6 +18,7 @@ cc_library(
) )
add_sprites(name="game_collectibles", n=24) add_sprites(name="game_collectibles", n=24)
add_sprites(name="game_hud", n=2)
add_sprites(name="game_player", n=96) add_sprites(name="game_player", n=96)
add_sprites(name="game_npcs", n=64) add_sprites(name="game_npcs", n=64)
add_sprites(name="game_tiles", n=120) add_sprites(name="game_tiles", n=120)

BIN
game/art/game_hud.aseprite Normal file

Binary file not shown.

8
game/art/game_hud.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef GAME_HUD_H
#define GAME_HUD_H
#include "sys/sys.h"
extern sys_spritesheet spr_game_hud;
#endif // ART_GAME_HUD_H

BIN
game/art/game_hud.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

View File

@ -51,4 +51,5 @@ void game_draw() {
sys_camera_reset(); sys_camera_reset();
game_dialogue_draw(); game_dialogue_draw();
game_player_draw_hud();
} }

View File

@ -66,6 +66,12 @@ void game_collectibles_update() {
game_collectible_bubble.x=c->x / PIXEL_SZ_MICROPIXEL; game_collectible_bubble.x=c->x / PIXEL_SZ_MICROPIXEL;
game_collectible_bubble.y=c->y / PIXEL_SZ_MICROPIXEL + game_collectible_wobb(); game_collectible_bubble.y=c->y / PIXEL_SZ_MICROPIXEL + game_collectible_wobb();
game_collectible_bubble.r=r * PIXEL_SZ_MICROPIXEL; game_collectible_bubble.r=r * PIXEL_SZ_MICROPIXEL;
switch (c->type) {
case GAME_COLLECTIBLE_TYPE_CAKE: game_player_collectibles.n_cake += 16; break;
case GAME_COLLECTIBLE_TYPE_MONEY_BIG: game_player_collectibles.n_dollars += 5; break;
case GAME_COLLECTIBLE_TYPE_MONEY_SMALL: game_player_collectibles.n_dollars += 1; break;
}
} }
} }
} }

View File

@ -1,4 +1,5 @@
#include <assert.h> #include <assert.h>
#include "art/game_hud.h"
#include "art/game_npcs.h" #include "art/game_npcs.h"
#include "device/device.h" #include "device/device.h"
#include "sys/sys.h" #include "sys/sys.h"
@ -46,6 +47,7 @@ game_npc* game_npc_create(sys_i32 x, sys_i32 y) {
.present = true, .present = true,
.n_dialogues_seen = 0, .n_dialogues_seen = 0,
.received_cake = false,
}; };
game_npcs[id] = npc; game_npcs[id] = npc;
return &game_npcs[id]; return &game_npcs[id];
@ -85,7 +87,12 @@ void game_npc_trigger_dialogue(sys_i32 npc_id) {
// TODO: Make it possible for the player to have the cake // TODO: Make it possible for the player to have the cake
game_npc* npc = &game_npcs[npc_id]; game_npc* npc = &game_npcs[npc_id];
if (npc->no_cake_dialogue != NULL) {
if (
!npc->received_cake &&
game_player_collectibles.n_cake == 0 &&
npc->no_cake_dialogue != NULL
) {
dialogue = npc->no_cake_dialogue; dialogue = npc->no_cake_dialogue;
} else if (npc->n_dialogues_seen < npc->n_dialogues) { } else if (npc->n_dialogues_seen < npc->n_dialogues) {
dialogue = npc->dialogues[npc->n_dialogues_seen++]; dialogue = npc->dialogues[npc->n_dialogues_seen++];
@ -96,6 +103,12 @@ void game_npc_trigger_dialogue(sys_i32 npc_id) {
return; return;
} }
// give the NPC cake if possible
if (!npc->received_cake && game_player_collectibles.n_cake > 0) {
npc->received_cake = true;
game_player_collectibles.n_cake -= 1;
}
game_dialogue_display(dialogue); game_dialogue_display(dialogue);
} }
@ -106,7 +119,20 @@ void game_npcs_draw() {
if (!n->present) { continue; } if (!n->present) { continue; }
game_npc_palette palette = game_npc_palette palette =
game_npc_palettes[game_npcs[i].palette_id % GAME_NPC_N_PALETTES]; game_npc_palettes[n->palette_id % GAME_NPC_N_PALETTES];
if (n->received_cake) {
sys_sprite_draw_ext(
spr_game_hud,
0,
n->x / PIXEL_SZ_MICROPIXEL - 4,
n->y / PIXEL_SZ_MICROPIXEL - 18,
1,
1,
!n->face_left,
false
);
}
sys_dpal_set(14, palette.main); sys_dpal_set(14, palette.main);
sys_dpal_set(12, palette.alt0_0); sys_dpal_set(12, palette.alt0_0);

View File

@ -21,6 +21,7 @@ typedef struct {
bool present; bool present;
uint8_t n_dialogues_seen; uint8_t n_dialogues_seen;
bool received_cake;
} game_npc; } game_npc;
// pointer goes to data section and will be valid forever // pointer goes to data section and will be valid forever

View File

@ -1,3 +1,5 @@
#include <assert.h>
#include "art/game_hud.h"
#include "art/game_player.h" #include "art/game_player.h"
#include "art/game_tiles.h" #include "art/game_tiles.h"
#include "device/device.h" #include "device/device.h"
@ -20,6 +22,11 @@ sys_i32 game_player_dx = 0;
sys_i32 game_player_dy = 0; sys_i32 game_player_dy = 0;
bool game_player_faceleft = false; bool game_player_faceleft = false;
game_player_collectibles_t game_player_collectibles = {
.n_cake=0,
.n_dollars=0
};
typedef enum { typedef enum {
GAME_PLAYER_ANIM_STANDING, GAME_PLAYER_ANIM_STANDING,
GAME_PLAYER_ANIM_WALKING, GAME_PLAYER_ANIM_WALKING,
@ -129,6 +136,14 @@ void game_player_update(bool* allow_input) {
} }
} }
void game_player_get_center(sys_i32* x, sys_i32* y) {
*x = game_player_bbox.x;
// center on me, not on feet
*y = game_player_bbox.y - 8 * PIXEL_SZ_MICROPIXEL;
}
void game_player_set_camera() { void game_player_set_camera() {
sys_i32 x = game_player_bbox.x; sys_i32 x = game_player_bbox.x;
sys_i32 y = game_player_bbox.y; sys_i32 y = game_player_bbox.y;
@ -182,9 +197,65 @@ void game_player_anim_add_progress(uint8_t amt) {
} }
void game_player_get_center(sys_i32* x, sys_i32* y) { void game_player_draw_hud_number(sys_i32 number, sys_i32 x, sys_i32 y);
*x = game_player_bbox.x; void game_player_draw_hud() {
sys_i32 y = 4;
if (game_player_collectibles.n_dollars > 0) {
sys_sprite_draw_ext(
spr_game_hud,
1,
4, y,
1, 1,
false, false
);
game_player_draw_hud_number(game_player_collectibles.n_dollars, 16, y);
y += 10;
}
if (game_player_collectibles.n_cake > 0) {
sys_sprite_draw_ext(
spr_game_hud,
0,
4, y - 1,
1, 1,
false, false
);
game_player_draw_hud_number(game_player_collectibles.n_cake, 16, y);
y += 10;
}
}
// center on me, not on feet void game_player_draw_hud_number1(sys_i32 number, sys_i32 x, sys_i32 y, uint8_t color) {
*y = game_player_bbox.y - 8 * PIXEL_SZ_MICROPIXEL; number = sys_min_i32(sys_max_i32(number, 0), 255);
char s[2];
s[1] = 0;
if (number >= 100) {
sys_i32 top_digit = number / 100;
assert(0 <= top_digit && top_digit < 10);
s[0] = '0' + top_digit;
number = number % 100;
sys_print(s, x, y, color);
x += 8;
}
if (number >= 10) {
sys_i32 top_digit = number / 10;
assert(0 <= top_digit && top_digit < 10);
s[0] = '0' + top_digit;
number = number % 10;
sys_print(s, x, y, color);
x += 8;
}
sys_i32 top_digit = number;
assert(0 <= top_digit && top_digit < 10);
s[0] = '0' + top_digit;
sys_print(s, x, y, color);
}
void game_player_draw_hud_number(sys_i32 number, sys_i32 x_start, sys_i32 y_start) {
for (sys_i32 dy = -1; dy <= 1; dy++) {
for (sys_i32 dx = -1; dx <= 1; dx++) {
game_player_draw_hud_number1(number, x_start+dx, y_start+dy, 0);
}
}
game_player_draw_hud_number1(number, x_start, y_start, 7);
} }

View File

@ -1,11 +1,18 @@
#ifndef GAME_PLAYER_H #ifndef GAME_PLAYER_H
#define GAME_PLAYER_H #define GAME_PLAYER_H
typedef struct {
sys_i32 n_cake;
sys_i32 n_dollars;
} game_player_collectibles_t;
extern game_player_collectibles_t game_player_collectibles;
void game_player_init(); void game_player_init();
void game_player_update(bool* allow_input); void game_player_update(bool* allow_input);
void game_player_set_camera();
void game_player_draw();
void game_player_get_center(sys_i32* x, sys_i32* y); void game_player_get_center(sys_i32* x, sys_i32* y);
void game_player_set_camera();
void game_player_draw();
void game_player_draw_hud();
#endif // GAME_PLAYER_H #endif // GAME_PLAYER_H