Mateusz Kin

Members
  • Content count

    2
  • Joined

  • Last visited

Community Reputation

159 Neutral

About Mateusz Kin

  • Rank
    Newbie
  1. In Zombienation (my project) class Bullet : public sf::RectangleShape { public: Bullet(float speed,sf::Vector2f direct,sf::Vector2f pos); bool update(float dt); double getDistance() { return distanceTraveled; } private: float speed; sf::Vector2f direction; double distanceTraveled; // if distance is to long then delete bullet from memory sf::Vector2f position, startingPosition; }; bool Weapon::shot(sf::Vector2f pos, sf::Vector2f direction) { if((roundsIn > 0) && canShot) { isShooting = true; for(unsigned int x = 0; x < bulletCont.size(); x++) { if(bulletCont[x] == nullptr) // when one is empty fill it with new bullet { bulletCont[x] = new Bullet(1600,direction,pos); canShot = false; // each weapon have different fire rate roundsIn--; return true; break; } } bulletCont.push_back(new Bullet(1600,direction,pos)); canShot = false; roundsIn--; } else { isShooting = false; // weapon is empty or have to wait for new bullet return false; } if(roundsIn == 0) { reloadingCall = true; } } where bulletCont is a vector of Bullet's pointers. Simple.   And direction void CCharacter::shot() { sf::Vector2f tempDirect(aim); // aim store where mouse is recoil(&tempDirect); if(actual->shot(pos,tempDirect)) // player tried too shot { crosshair->pushSize(1.1); } } void CCharacter::updateDirection() { direct.x = (aim.x-400); direct.y = (aim.y-300); double len = sqrtf(direct.x*direct.x+direct.y*direct.y); direct.x/=len; direct.y/=len; } If you want I could send you all files (cpp + hpp of those 3 classes)
  2. As well you can create your own drawable class.   http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php