Implement collecting chests

Internal Changelog:
- Set chest limit to 65535
- Handle (de-)spawning chest on coin counter
- Add coin increment to chest collision with player
scene_man
En Yi 2023-09-21 22:08:02 +08:00
parent e1a0c6e4e0
commit a8e0d99870
2 changed files with 20 additions and 1 deletions

View File

@ -451,6 +451,10 @@ static void level_scene_render_func(Scene_t* scene)
static char mempool_stats[512];
print_mempool_stats(mempool_stats);
DrawText(mempool_stats, gui_x, gui_y, 12, BLACK);
gui_y += 300;
sprintf(buffer, "Chests: %u / %u", data->coins.current, data->coins.total);
DrawText(buffer, gui_x, gui_y, 24, BLACK);
EndDrawing();
}
@ -591,7 +595,11 @@ static void toggle_block_system(Scene_t* scene)
}
break;
case SPAWN_CHEST:
spawn_chest(scene, tile_idx);
if (data->coins.total < 65535)
{
spawn_chest(scene, tile_idx);
data->coins.total++;
}
break;
}
change_a_tile(&tilemap, tile_idx, new_type);
@ -612,6 +620,13 @@ static void toggle_block_system(Scene_t* scene)
sc_map_foreach(&tilemap.tiles[tile_idx].entities_set, m_id, ent)
{
if (ent->m_tag == PLAYER_ENT_TAG) continue;
if (!ent->m_alive) continue;
if (ent->m_tag == CHEST_ENT_TAG)
{
data->coins.total--;
}
CTileCoord_t* p_tilecoord = get_component(
ent, CTILECOORD_COMP_T
);

View File

@ -1501,6 +1501,10 @@ void hitbox_update_system(Scene_t* scene)
{
// Need to remove immediately, otherwise will interfere with bomb spawning
remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_other_ent);
if (p_other_ent->m_tag == CHEST_ENT_TAG)
{
data->coins.current++;
}
}
}