X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FCharacter.cc;h=a29e63d792fd50d17935f6dc1d3bb82067cc2903;hp=ffecfd5b8c5db2c2c82c3e4cc478c00d718f3fed;hb=bc2bc12125d6c223d2935557e01926fe21166e38;hpb=fcb40aa40c6a13ca0e0962b35973ac4574779574 diff --git a/src/Character.cc b/src/Character.cc index ffecfd5..a29e63d 100644 --- a/src/Character.cc +++ b/src/Character.cc @@ -56,23 +56,27 @@ private: Mf::Vector2 location; }; -struct WindResistenceForce +struct ResistanceForce { + explicit ResistanceForce(Mf::Scalar scale = 1.0) : + k(scale) {} + const Mf::Vector2& operator () (const Mf::LinearState<2>& state) { - force = -2.0 * state.velocity; + force = -k * state.velocity; return force; } private: - Mf::Vector2 force; + Mf::Vector2 force; + Mf::Scalar k; }; Character::Character(const std::string& name) : - tilemap_(name), - animation_(name) + tilemap(name), + animation(name) { current.init(); @@ -82,7 +86,7 @@ Character::Character(const std::string& name) : // gravity current.force = Mf::Vector2(0.0, 000.0); current.forces.push_back(SpringForce(Mf::Vector2(500.0, 200.0))); - current.forces.push_back(WindResistenceForce()); + current.forces.push_back(ResistanceForce(4.0)); current.forces.push_back(Mf::LinearState<2>::GravityForce(-2000.0)); // starting position @@ -114,11 +118,8 @@ void Character::update(Mf::Scalar t, Mf::Scalar dt) //Mf::euler(current, t, dt); - //current.force = Mf::Vector2(0.0, -2000.0); - current.force = userForce; current.integrate(t, dt); - - animation_.update(t, dt); + animation.update(t, dt); } @@ -127,16 +128,16 @@ void Character::draw(Mf::Scalar alpha) const Mf::Vector2 position = cml::lerp(previous.position, current.position, alpha); //glColor3f(1.0f, 1.0f, 1.0f); - tilemap_.bind(); + tilemap.bind(); - Mf::Tilemap::Index frame = animation_.getFrame(); + Tilemap::Index frame = animation.getFrame(); - Mf::Tilemap::Orientation orientation = Mf::Tilemap::NORMAL; + Tilemap::Orientation orientation = Tilemap::NORMAL; - if (current.velocity[0] < 0.0) orientation = Mf::Tilemap::REVERSE; + if (current.velocity[0] < 0.0) orientation = Tilemap::REVERSE; Mf::Scalar coords[8]; - tilemap_.getTileCoords(frame, coords, orientation); + tilemap.getTileCoords(frame, coords, orientation); Mf::Scalar s = 16.0; @@ -164,16 +165,5 @@ void Character::draw(Mf::Scalar alpha) const } -Mf::Tilemap& Character::getTilemap() -{ - return tilemap_; -} - -Mf::Animation& Character::getAnimation() -{ - return animation_; -} - - /** vim: set ts=4 sw=4 tw=80: *************************************************/