summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-12-19 21:08:24 +0100
committerPaweł Redman <pawel.redman@gmail.com>2017-12-19 21:08:24 +0100
commit6dc7ae4f49931f721ad072cc72038cada78b147e (patch)
treed289fbce21085ddfa8a948b6b8004acde87a2433
parent1e702f4e99858d297607a7c1fde7d2df661ae324 (diff)
Add a button for spawning more soldiers.
-rw-r--r--src/common.hpp1
-rw-r--r--src/game/game.cpp15
-rw-r--r--src/game/interface.cpp11
3 files changed, 22 insertions, 5 deletions
diff --git a/src/common.hpp b/src/common.hpp
index c249db4..f623f09 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -235,6 +235,7 @@ namespace game {
// These are called by the interface.
void select(rectf_t rect);
void command(v2f_t x);
+ void spawn_soldier(v2f_t x);
size_t roll(die_t die);
};
diff --git a/src/game/game.cpp b/src/game/game.cpp
index d086cb6..3f64e0c 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -136,6 +136,21 @@ void state_t::command(v2f_t x)
}
}
+void state_t::spawn_soldier(v2f_t x)
+{
+ unit_soldier_t *soldier;
+ world::cmodel_t cmodel;
+
+ soldier = new unit_soldier_t(this);
+ soldier->place(&world, x);
+
+ cmodel.bounds = soldier->cmodel.bounds;
+ cmodel.cflags = soldier->move.cflags;
+
+ if (world.test_rect(&cmodel, soldier))
+ soldier->destroy();
+}
+
void state_t::tick(double now_, double dt_)
{
union {
diff --git a/src/game/interface.cpp b/src/game/interface.cpp
index 0ffdbab..0c2125b 100644
--- a/src/game/interface.cpp
+++ b/src/game/interface.cpp
@@ -62,6 +62,8 @@ void state_t::tick(double dt)
window->setView(sf::View(view_center, view_size));
+ wmouse = window->mapPixelToCoords(sf::Mouse::getPosition(*window));
+
while (window->pollEvent(event)) {
// FIXME: refactor this nested switch clusterfuck
switch (event.type) {
@@ -70,8 +72,6 @@ void state_t::tick(double dt)
return;
case sf::Event::MouseButtonPressed:
- wmouse = window->mapPixelToCoords(sf::Vector2i(event.mouseButton.x, event.mouseButton.y));
-
switch (event.mouseButton.button) {
case sf::Mouse::Button::Left:
select.selecting = true;
@@ -140,6 +140,10 @@ void state_t::tick(double dt)
}
break;
+ case sf::Keyboard::Key::H:
+ game->spawn_soldier(wmouse);
+ break;
+
case sf::Keyboard::Key::F1:
debug_draw_cmodels ^= 1;
print("debug_draw_cmodels = " + std::to_string(debug_draw_cmodels));
@@ -165,9 +169,6 @@ void state_t::tick(double dt)
}
}
- // Compute this _after_ the setView above.
- wmouse = window->mapPixelToCoords(sf::Mouse::getPosition(*window));
-
if (select.selecting)
select.rect[1] = wmouse;
}