aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy <drumsetmonkey@gmail.com>2016-10-26 09:27:40 -0400
committerAndy <drumsetmonkey@gmail.com>2016-10-26 09:27:40 -0400
commit0fa2320e978926db6781a2bdcdf5a9b6f0317e93 (patch)
tree61576fdff5ae8434c2299486690f4b411d6b79d3 /src
parente0f353be4c21f38978bef83e9651ef9eda886da4 (diff)
Physics and world collide
Diffstat (limited to 'src')
-rw-r--r--src/player.cpp4
-rw-r--r--src/world.cpp41
2 files changed, 38 insertions, 7 deletions
diff --git a/src/player.cpp b/src/player.cpp
index 59274b3..37a958d 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -12,7 +12,9 @@ void PlayerSystem::create(void)
player = game::entities.create();
player.assign<Position>(0.0f, 100.0f);
player.assign<Direction>(0.0f, 0.0f);
- player.assign<Physics>(-0.001f);
+ // The new g value is a multiplier for the gravity constant. This allows for air resistance simulation.
+ //player.assign<Physics>(-0.001f);
+ player.assign<Physics>(1);
player.assign<Visible>(-0.2f);
auto sprite = player.assign<Sprite>();
diff --git a/src/world.cpp b/src/world.cpp
index 365345d..8e2d60b 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -370,6 +370,31 @@ void WorldSystem::load(const std::string& file)
float cdat[2] = {dim.x, dim.y};
entity.assign<Solid>(cdat[0], cdat[1]);
+ } else if (tname == "Direction") {
+ vec2 dir;
+
+ if (wxml->Attribute("direction") != nullptr) {
+ dir = str2coord(wxml->StrAttribute("direction"));
+ } else if (wxml->Attribute("value") != nullptr) {
+ dir = str2coord(wxml->StrAttribute("value"));
+ } else {
+ dir = vec2(0,0);
+ }
+
+ float cdat[2] = {dir.x, dir.y};
+ entity.assign<Direction>(cdat[0], cdat[1]);
+ } else if (tname == "Physics") {
+ float g;
+
+ if (wxml->Attribute("gravity") != nullptr) {
+ g = wxml->FloatAttribute("gravity");
+ } else if (wxml->Attribute("value") != nullptr) {
+ g = wxml->FloatAttribute("value");
+ } else {
+ g = 1.0f;
+ }
+
+ entity.assign<Physics>(g);
}
abcd = abcd->NextSiblingElement();
@@ -1013,10 +1038,18 @@ void WorldSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
void WorldSystem::detect(entityx::TimeDelta dt)
{
+ game::entities.each<Direction, Physics>(
+ [&](entityx::Entity e, Direction &vel, Physics &phys) {
+ (void)e;
+ // handle gravity
+ if (vel.y > -2.0f) {
+ vel.y -= (GRAVITY_CONSTANT * phys.g) * dt;
+ }
+ });
+
game::entities.each<Position, Direction, Solid>(
[&](entityx::Entity e, Position &loc, Direction &vel, Solid &dim) {
(void)e;
-
//if (health.health <= 0)
// UserError("die mofo");
@@ -1039,11 +1072,7 @@ void WorldSystem::detect(entityx::TimeDelta dt)
// TODO ground flag
}
}
-
- // handle gravity
- else if (vel.y > -2.0f) {
- vel.y -= GRAVITY_CONSTANT * dt;
- }
+
// insure that the entity doesn't fall off either edge of the world.
if (loc.x < world.startX) {