Collectibles can be collected

This commit is contained in:
Pyrex 2024-02-28 17:36:06 -08:00
parent 7649a2dc7e
commit df1d1450e7
6 changed files with 77 additions and 59 deletions

View File

@ -8,6 +8,16 @@
sys_i32 game_collectible_next = 0; sys_i32 game_collectible_next = 0;
game_collectible game_collectibles[GAME_COLLECTIBLES_N]; game_collectible game_collectibles[GAME_COLLECTIBLES_N];
struct {
sys_i32 x;
sys_i32 y;
sys_i32 r;
} game_collectible_bubble = {
.x = 0,
.y = 0,
.r = 0
};
sys_i32 game_collectible_wobb_frame = 0; sys_i32 game_collectible_wobb_frame = 0;
void game_collectibles_preinit() { void game_collectibles_preinit() {
@ -25,17 +35,64 @@ void game_collectibles_init() {
} }
sys_i32 game_collectible_wobb() {
return game_wobb3(game_collectible_wobb_frame & 0xff);
}
void game_collectibles_update() { void game_collectibles_update() {
game_collectible_wobb_frame += 1; game_collectible_wobb_frame += 1;
game_collectible_bubble.r = game_collectible_bubble.r * 7 / 8;
if (game_collectible_bubble.r < PIXEL_SZ_MICROPIXEL / 2) { game_collectible_bubble.r = 0; }
// check collision with player
sys_i32 player_x, player_y;
game_player_get_center(&player_x, &player_y);
for (sys_i32 i = 0; i < game_collectible_next; i++) {
sys_i32 r;
game_collectible* c = &game_collectibles[i];
if (c->collected) { continue; }
switch (c->type) {
case GAME_COLLECTIBLE_TYPE_CAKE: r = 16; break;
default: r = 8; break;
}
// convert to micropixels
// add approx radius of player
sys_i32 r_distcheck = (r + 5) * PIXEL_SZ_MICROPIXEL;
int64_t dx = player_x - c->x;
int64_t dy = player_y - c->y;
if (dx * dx + dy * dy <= r_distcheck * r_distcheck) {
c->collected = true;
// TODO: Spawn effect
game_collectible_bubble.x=c->x / PIXEL_SZ_MICROPIXEL;
game_collectible_bubble.y=c->y / PIXEL_SZ_MICROPIXEL + game_collectible_wobb();
game_collectible_bubble.r=r * PIXEL_SZ_MICROPIXEL;
}
}
} }
void game_collectibles_draw() { void game_collectibles_draw() {
if (game_collectible_bubble.r > 0) {
sys_circ_fill(
game_collectible_bubble.x,
game_collectible_bubble.y,
game_collectible_bubble.r / PIXEL_SZ_MICROPIXEL,
7
);
}
for (sys_i32 i = 0; i < game_collectible_next; i++) { for (sys_i32 i = 0; i < game_collectible_next; i++) {
game_collectible c = game_collectibles[i]; game_collectible* c = &game_collectibles[i];
sys_i32 x = c.x / PIXEL_SZ_MICROPIXEL;
sys_i32 y = c.y / PIXEL_SZ_MICROPIXEL; if (c->collected) { continue; }
y += game_wobb3(game_collectible_wobb_frame & 0xff);
switch(c.type) { sys_i32 x = c->x / PIXEL_SZ_MICROPIXEL;
sys_i32 y = c->y / PIXEL_SZ_MICROPIXEL + game_collectible_wobb();
switch(c->type) {
case GAME_COLLECTIBLE_TYPE_CAKE: case GAME_COLLECTIBLE_TYPE_CAKE:
sys_sprite_draw_ext( sys_sprite_draw_ext(
spr_game_collectibles,0,x-16,y-16,4,4,false,false); spr_game_collectibles,0,x-16,y-16,4,4,false,false);

View File

@ -14,6 +14,7 @@ typedef struct {
sys_i32 x; sys_i32 x;
sys_i32 y; sys_i32 y;
game_collectible_type type; game_collectible_type type;
bool collected;
} game_collectible; } game_collectible;
void game_collectibles_preinit(); void game_collectibles_preinit();

View File

@ -180,3 +180,11 @@ void game_player_anim_add_progress(uint8_t amt) {
(uint32_t) amt (uint32_t) amt
) & 0xff; ) & 0xff;
} }
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;
}

View File

@ -6,4 +6,6 @@ void game_player_update();
void game_player_set_camera(); void game_player_set_camera();
void game_player_draw(); void game_player_draw();
void game_player_get_center(sys_i32* x, sys_i32* y);
#endif // GAME_PLAYER_H #endif // GAME_PLAYER_H

View File

@ -3520,7 +3520,7 @@
"savedSelections": [], "savedSelections": [],
"cachedPixelData": { "cachedPixelData": {
"opaqueTiles": "000000011000011000000000", "opaqueTiles": "000000011000011000000000",
"averageColors": "4feededddcaa4fedbbcbbacadddcfb89fa69dcbbbbbabbbbdbbcf27af269dbbbbedcbedc4edddedddfee4feebdcabdcb" "averageColors": "4feededdddbb4fedbbcbbacadddcfb89fa69dcbbbbbabbbbdbbcf27af269dbbbbedcbedc4edddedddfee4feebdcabdcb"
} }
}, },
{ {
@ -3949,54 +3949,6 @@
"fieldInstances": [], "fieldInstances": [],
"__worldX": 376, "__worldX": 376,
"__worldY": 488 "__worldY": 488
},
{
"__identifier": "collectible_cake",
"__grid": [25,3],
"__pivot": [0,0],
"__tags": [],
"__tile": { "tilesetUid": 118, "x": 0, "y": 0, "w": 32, "h": 32 },
"__smartColor": "#D77643",
"iid": "4b368ea0-b0a0-11ee-9688-0d7f1bfe0da2",
"width": 32,
"height": 32,
"defUid": 117,
"px": [200,24],
"fieldInstances": [],
"__worldX": 456,
"__worldY": 456
},
{
"__identifier": "collectible_money_big",
"__grid": [24,8],
"__pivot": [0,0],
"__tags": [],
"__tile": { "tilesetUid": 118, "x": 32, "y": 0, "w": 16, "h": 16 },
"__smartColor": "#EAD4AA",
"iid": "4c5d0d40-b0a0-11ee-9688-cf7a0e35c759",
"width": 16,
"height": 16,
"defUid": 120,
"px": [192,64],
"fieldInstances": [],
"__worldX": 448,
"__worldY": 496
},
{
"__identifier": "collectible_money_small",
"__grid": [28,8],
"__pivot": [0,0],
"__tags": [],
"__tile": { "tilesetUid": 118, "x": 32, "y": 16, "w": 16, "h": 16 },
"__smartColor": "#EAD4AA",
"iid": "4d9d2e60-b0a0-11ee-9688-8f806f225ae3",
"width": 16,
"height": 16,
"defUid": 121,
"px": [224,64],
"fieldInstances": [],
"__worldX": 480,
"__worldY": 496
} }
] ]
} }

View File

@ -166,11 +166,9 @@ void sys_oval_draw_ext(
int64_t bb8 = 8 * b * b; int64_t bb8 = 8 * b * b;
do { do {
if (!fill) { // draw the points at the edge of the line no matter what
// draw the points at the edge of the line
sys_scanline_internal_set(x0, x1, y0, c, false); sys_scanline_internal_set(x0, x1, y0, c, false);
sys_scanline_internal_set(x0, x1, y1, c, false); sys_scanline_internal_set(x0, x1, y1, c, false);
}
int64_t e2 = 2 * err; int64_t e2 = 2 * err;
if (e2 <= dy) { if (e2 <= dy) {
if (fill) { if (fill) {