ads-game:: resource expiration

This commit is contained in:
Zeno Rogue 2022-09-18 17:29:01 +02:00
parent a1a65ac612
commit 567ef8e7e6
3 changed files with 16 additions and 4 deletions

View File

@ -85,6 +85,11 @@ void draw_game_cell(cell *c, ads_matrix V, ld plev) {
for(auto& r: ci.rocks) {
auto& rock = *r;
if(!paused) {
if(rock.type == oRock && rock.expire < pdata.score) { rock.resource = rtNone; rock.col = rock_color[rtNone]; rock.expire = 999999; }
if(rock.type == oResource && rock.expire < pdata.score) { rock.resource = rtNone; rock.col = rsrc_color[rtNone]; rock.shape = rsrc_shape[rtNone]; rock.expire = 999999; }
}
hybrid::in_actual([&]{
dynamicval<eGeometry> b(geometry, gRotSpace);

View File

@ -10,6 +10,7 @@ struct ads_object {
cell *owner;
ads_matrix at;
color_t col;
int expire;
vector<ld>* shape;
ld life_start, life_end;
@ -24,6 +25,10 @@ struct ads_object {
enum eWalltype { wtNone, wtDestructible, wtSolid, wtGate };
int gen_expire() {
return 20 / randd() - 15;
}
struct shipstate {
ads_matrix at;
ld start;
@ -122,6 +127,7 @@ void add_rock(cell *c, cellinfo& ci, const ads_matrix& T) {
eResourceType rt = eResourceType(rand() % 6);
auto r = std::make_unique<ads_object> (oRock, c, T, rock_color[rt]);
r->resource = rt;
r->expire = gen_expire();
r->shape = &(rand() % 2 ? shape_rock2 : shape_rock);
if(geometry != gRotSpace) { println(hlog, "wrong geometry detected in gen_rocks 2!"); exit(1); }
int q = 0;
@ -192,13 +198,14 @@ void gen_particles(int qty, cell *c, shiftmatrix from, color_t col, ld spd, ld t
}
}
void gen_resource(cell *c, shiftmatrix from, eResourceType rsrc) {
void gen_resource(cell *c, shiftmatrix from, eResourceType rsrc, int expire) {
if(!rsrc) return;
auto r = std::make_unique<ads_object>(oResource, c, from, rsrc_color[rsrc]);
r->shape = rsrc_shape[rsrc];
r->life_end = HUGE_VAL;
r->life_start = 0;
r->resource = rsrc;
r->expire = expire;
ci_at[c].rocks.emplace_back(std::move(r));
}
@ -248,7 +255,7 @@ void handle_crashes() {
hybrid::in_actual([&] {
gen_particles(rpoisson(crash_particle_qty), m->owner, m->at * ads_matrix(Id, m->life_end), missile_color, crash_particle_rapidity, crash_particle_life);
gen_particles(rpoisson(crash_particle_qty), r->owner, r->at * ads_matrix(Id, r->life_end), r->col, crash_particle_rapidity, crash_particle_life);
gen_resource(r->owner, r->at * ads_matrix(Id, r->life_end), r->resource);
gen_resource(r->owner, r->at * ads_matrix(Id, r->life_end), r->resource, r->expire);
});
}
}

View File

@ -5,9 +5,9 @@ namespace ads_game {
enum eResourceType { rtNone, rtHull, rtGold, rtAmmo, rtFuel, rtOxygen };
color_t rock_color[6] = { 0x703800FF, 0xC0A080FF, 0xC08010FF, 0xC04000FF, 0x408000FF, 0x8040A0FF, };
color_t rsrc_color[6] = {0, 0xC0C0C0FF, 0xFFD500FF, 0xFF0000FF, 0x00FF00FF, 0x0000FFFF };
color_t rsrc_color[6] = { 0x404040FF, 0xC0C0C0FF, 0xFFD500FF, 0xFF0000FF, 0x00FF00FF, 0x0000FFFF };
vector<ld>* rsrc_shape[6] = { nullptr, &shape_heart, &shape_gold, &shape_weapon, &shape_fuel, &shape_airtank };
vector<ld>* rsrc_shape[6] = { &shape_particle, &shape_heart, &shape_gold, &shape_weapon, &shape_fuel, &shape_airtank };
void rsrc_config() {
max_pdata.hitpoints = 3;