summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-10-14 15:34:53 +0200
committerPaweł Redman <pawel.redman@gmail.com>2017-10-14 15:34:53 +0200
commitbb0a7bfe31714ff56ce1c1ce428cdf240804db14 (patch)
treeb5c5137f80443343e9d46bda3c7b96c777142181 /src/game.cpp
parentb0edfd3fa2ad078677d43b743fdb78e5af52e99a (diff)
Oriented sprites and the human sprite.
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp61
1 files changed, 46 insertions, 15 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 396d26a..bb04ee7 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -2,17 +2,37 @@
namespace game {
-
class unit_t : public world::entity_t {
-
};
-static render::animated_texture_t test;
+struct {
+ struct {
+ render::oriented_sprite_4M_t head_idle, body_idle;
+ render::oriented_sprite_4M2_t legs_idle, legs_walking;
+ } human;
+} assets;
+
+bool load_assets(void)
+{
+ assets.human.head_idle.load("assets/units/human/head_idle", 1, 1, 1);
+ assets.human.body_idle.load("assets/units/human/body_idle", 2, 2, 2);
+ assets.human.legs_idle.load("assets/units/human/legs_idle", 2, 2);
+ assets.human.legs_walking.load("assets/units/human/legs_walking", 2, 2);
+ return true;
+}
class human_t : public unit_t {
- void render(render::state_t *render)
+
+public:
+ float angle = 0.0f;
+ bool walking = false;
+
+ void render_to(render::state_t *render)
{
- render->render(&test, bounds);
+ render->render((walking ? &assets.human.legs_walking :
+ &assets.human.legs_idle), bounds, angle);
+ render->render(&assets.human.body_idle, bounds, angle);
+ render->render(&assets.human.head_idle, bounds, angle);
}
};
@@ -20,22 +40,33 @@ static human_t *human;
void state_t::start(void)
{
- test.load("assets/test_", 4);
-
human = new human_t;
- human->bounds.left = -0.2f;
- human->bounds.top = -0.2f;
- human->bounds.width = 3.0f;
- human->bounds.height = 3.0f;
+ human->bounds.left = 0.33f;
+ human->bounds.top = 0.0f;
+ human->bounds.width = 0.66f;
+ human->bounds.height = 1.0f;
human->link(&world);
}
void state_t::tick(void)
{
- human->unlink();
- human->bounds.left += 0.05f;
- human->bounds.top += 0.05f;
- human->link(&world);
+ static float stalin = 2.0f;
+
+ stalin -= ((float)rand() / RAND_MAX) * 0.1f;
+
+ human->walking = false;
+
+ if (stalin < 0) {
+ human->walking = true;
+ human->angle += (rand() & 2 ? 0.2f : -0.2f);
+ human->unlink();
+ human->bounds.left += cos(human->angle) * 0.04;
+ human->bounds.top += sin(human->angle) * 0.04;
+ human->link(&world);
+ }
+
+ if (stalin < -4.0f)
+ stalin = 2.0f;
}
} //namespace game