]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
gravity?
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 27 Mar 2017 23:22:49 +0000 (19:22 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 27 Mar 2017 23:22:49 +0000 (19:22 -0400)
include/components.hpp
include/player.hpp
src/attack.cpp
src/components.cpp
src/inventory.cpp
src/player.cpp

index fe56a8812523e0d6c310a07deb316ca7c38e98dd..20a1419c395fdc614231cbace845077a8e83328f 100644 (file)
@@ -98,7 +98,7 @@ struct Physics : public Component {
         * Constructor that sets the gravity constant, if not specified it becomes 0.
         * @param g The non default gravity constant.
         */
-       Physics(float g = 1.0f): g(g) {}
+       Physics(float g = 0.2f): g(g) {}
        Physics(XMLElement* imp, XMLElement* def) {
                fromXML(imp, def);
        }
@@ -108,7 +108,7 @@ struct Physics : public Component {
        void fromXML(XMLElement* imp, XMLElement* def) final {
                if (imp->QueryFloatAttribute("gravity", &g) != XML_NO_ERROR) {
                        if (def->QueryFloatAttribute("value", &g) != XML_NO_ERROR)
-                               g = 1.0f;
+                               g = 0.2f;
                }
        }
 };
index 2c65717c4ec75cc4fd67167d5ff3834c9c6961ce..efac984995a9ee0bd10a568241a337c55223a47d 100644 (file)
@@ -15,7 +15,7 @@
 /**
  * The constant velocity the player is given when moved with the arrow keys.
  */
-constexpr const float PLAYER_SPEED_CONSTANT = 0.15f;
+constexpr const float PLAYER_SPEED_CONSTANT = 0.03f;
 
 /**
  * @class PlayerSystem
index 550b8492e38d0a1aca61381d0bfa9befef3d9220..3dc159452aa74e21ebee5defb42dc56f86892367 100644 (file)
@@ -3,8 +3,8 @@
 #include <engine.hpp>
 #include <particle.hpp>
 
-constexpr int shortSlashLength = 100;
-constexpr int longSlashLength = 200;
+constexpr int shortSlashLength = 20;
+constexpr int longSlashLength = 40;
 
 // math helpers because we don't trust stdlib
 template<typename T>
@@ -41,7 +41,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
                                        if (e.has_component<Player>())
                                                return;
 
-                                       if (inrange(a.pos.x, pos.x, pos.x + dim.width, shortSlashLength)) {
+                                       if (inrange(a.pos.x, pos.x, pos.x + dim.width, HLINES(shortSlashLength))) {
                                                h.health -= a.power;
                                                game::engine.getSystem<ParticleSystem>()->addMultiple(15, ParticleType::DownSlash,
                                                        [&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7);
@@ -56,7 +56,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
                                        if (e.has_component<Player>())
                                                return;
 
-                                       if (inrange(a.pos.x, pos.x, pos.x + dim.width, shortSlashLength)) {
+                                       if (inrange(a.pos.x, pos.x, pos.x + dim.width, 0)) {
                                                h.health -= a.power;
                                                game::engine.getSystem<ParticleSystem>()->addMultiple(15, ParticleType::SmallBlast,
                                                        [&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7);
index 732e21f8305b5310f188edb869e16e60d8416dae..dee56a62d75f3f962e74a4c2f0922d412c9a83d5 100644 (file)
@@ -27,8 +27,8 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
 
        (void)ev;
        en.each<Position, Direction>([&](entityx::Entity entity, Position &position, Direction &direction) {
-               position.x += direction.x * dt;
-               position.y += direction.y * dt;
+               position.x += HLINES(direction.x) * dt;
+               position.y += HLINES(direction.y) * dt;
 
                if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
                        auto animate = entity.component<Animate>();
@@ -38,7 +38,7 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                                animate->updateAnimation(1, sprite->sprite, dt);
                        else
                                animate->firstFrame(1, sprite->sprite);
-                       }
+               }
                if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) {
                        direction.x = 0;
                } else {
@@ -60,7 +60,7 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                                                h = 0;
                                        }
                                } else
-                                       direction.x = (ppos.x > position.x) ? .05 : -.05;
+                                       direction.x = (ppos.x > position.x) ? .01 : -.01;
                        } else if (entity.has_component<Wander>()) {
                                auto& countdown = entity.component<Wander>()->countdown;
 
@@ -68,7 +68,7 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                                        countdown--;
                                } else {
                                        countdown = 5000 + randGet() % 10 * 100;
-                                       direction.x = (randGet() % 3 - 1) * 0.02f;
+                                       direction.x = (randGet() % 3 - 1) * 0.004f;
                                }
                        }
                }
index 3e7104effed427bb67aba16dec53b82dfc17e832..664d8a64cf2ca5f01ee0a7766c75e2eb7a563ca2 100644 (file)
@@ -211,7 +211,7 @@ void InventorySystem::receive(const MouseReleaseEvent &mre)
 
                auto e = game::entities.create();
                e.assign<Position>(mre.position.x, mre.position.y);
-               e.assign<Direction>(0, 1);
+               e.assign<Direction>(0, 0.4f);
                e.assign<ItemDrop>(items[movingItem]);
                e.assign<Sprite>();
                e.component<Sprite>()->addSpriteSegment(
index d9a4a9890638cda55f6000fd13fa44aee85fbaa5..711ddae3d117d073655fec296d1ef42e502c75e1 100644 (file)
@@ -75,7 +75,7 @@ void PlayerSystem::create(void)
        player.assign<Position>(0.0f, 100.0f);
        player.assign<Direction>(0.0f, 0.0f);
        //player.assign<Physics>(-0.001f);
-       player.assign<Physics>(1);
+       player.assign<Physics>();
        player.assign<Visible>(-0.2f);
        player.assign<Health>(100);
        auto sprite = player.assign<Sprite>();
@@ -154,7 +154,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
 
        if ((kc == SDLK_SPACE) && game::canJump && ((vel.y > -0.01) & (vel.y < 0.01))) {
                loc.y += HLINES(2);
-               vel.y = .4;
+               vel.y = 0.05f;
                vel.grounded = false;
        } else if (!ui::dialogBoxExists || ui::dialogPassive) {
                if (kc == getControl(0)) {
@@ -229,7 +229,7 @@ void PlayerSystem::receive(const UseItemEvent& uie)
                                e.assign<Position>(pos.x, pos.y + 10);
 
                                auto angle = std::atan2(uie.curs.y - pos.y, uie.curs.x - pos.x);
-                               e.assign<Direction>(1 * std::cos(angle), 1 * std::sin(angle));
+                               e.assign<Direction>(0.25f * std::cos(angle), 0.25f * std::sin(angle));
 
                                e.assign<Visible>(-5);
                                e.assign<Physics>();