From 567ef8e7e6f0ed8954ae1ca12dc6e0446549d910 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 18 Sep 2022 17:29:01 +0200 Subject: [PATCH] ads-game:: resource expiration --- rogueviz/ads/display.cpp | 5 +++++ rogueviz/ads/map.cpp | 11 +++++++++-- rogueviz/ads/resources.cpp | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/rogueviz/ads/display.cpp b/rogueviz/ads/display.cpp index 4b2b648b..028c8485 100644 --- a/rogueviz/ads/display.cpp +++ b/rogueviz/ads/display.cpp @@ -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 b(geometry, gRotSpace); diff --git a/rogueviz/ads/map.cpp b/rogueviz/ads/map.cpp index ea0ec1d4..a4217f26 100644 --- a/rogueviz/ads/map.cpp +++ b/rogueviz/ads/map.cpp @@ -10,6 +10,7 @@ struct ads_object { cell *owner; ads_matrix at; color_t col; + int expire; vector* 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 (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(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); }); } } diff --git a/rogueviz/ads/resources.cpp b/rogueviz/ads/resources.cpp index f9b98290..7fbfd426 100644 --- a/rogueviz/ads/resources.cpp +++ b/rogueviz/ads/resources.cpp @@ -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* rsrc_shape[6] = { nullptr, &shape_heart, &shape_gold, &shape_weapon, &shape_fuel, &shape_airtank }; +vector* rsrc_shape[6] = { &shape_particle, &shape_heart, &shape_gold, &shape_weapon, &shape_fuel, &shape_airtank }; void rsrc_config() { max_pdata.hitpoints = 3;