summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cpp15
-rw-r--r--src/game/interface.cpp11
2 files changed, 21 insertions, 5 deletions
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;
}