summaryrefslogtreecommitdiff
path: root/src/game/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r--src/game/game.cpp48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 71d24ac..b9a46db 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -16,8 +16,7 @@ void state_t::start(void)
units.insert(human);
alien = new alien_t;
- alien->place(&world, v2f_t(5.5, 5.5));
- units.insert(alien);
+ alien->place(&world, v2f_t(15.5, -2.5));
}
void state_t::stop(void)
@@ -41,6 +40,10 @@ void state_t::select(rectf_t x)
continue;
unit = (unit_t*)ent;
+
+ if (unit->type != unit_t::UNIT_HUMAN)
+ continue;
+
unit->selected = selection_cookie;
selected_units.insert(unit);
}
@@ -62,8 +65,45 @@ void state_t::tick(double now_, double dt_)
now = now_;
dt = dt_;
- for (unit_t *unit : units)
- unit->keep_moving(now, dt);
+ for (unit_t *unit : units) {
+ rectf_t wake_range;
+
+ wake_range[0] = unit->x - v2f_t(10, 10);
+ wake_range[1] = unit->x + v2f_t(10, 10);
+
+ for (world::entity_t *ent : world.get_entities(wake_range, -1)) {
+ unit_t *enemy;
+
+ if (ent->type != ET_UNIT)
+ continue;
+
+ enemy = (unit_t*)ent;
+ enemy->wake_time = now;
+
+ if (enemy->awake)
+ continue;
+
+ if (enemy->type == unit_t::UNIT_HUMAN)
+ continue;
+
+ enemy->awake = true;
+ awake_units.insert(enemy);
+ enemy->wake(now, unit);
+ }
+
+ unit->think(now, dt);
+ }
+
+ for (auto i = std::begin(awake_units); i != std::end(awake_units);) {
+ if (now - (*i)->wake_time >= 5.0) {
+ (*i)->awake = false;
+ (*i)->sleep(now);
+ i = awake_units.erase(i);
+ } else {
+ (*i)->think(now, dt);
+ i++;
+ }
+ }
}
bool load_assets(void)