示例#1
0
文件: hero.cpp 项目: renmaoting/616
void Hero::update(Uint32 ticks) { 
  if ( explosion ) {
    explosion->update(ticks);
    if ( explosion->chunkCount() == 0 ) {
      delete explosion;
      explosion = NULL;
    }
    return;
  }

  if(special != NULL)
  {
    special->advanceFrame(ticks);
    special->setPosition(this->getPosition()-Vector2f(20,50));
  }
  advanceFrame(ticks);
  Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
  setPosition(getPosition() + incr);
  if ( Y() <= 0) {
    velocityY( abs( velocityY() ) );
  }
  if ( Y() >= worldHeight-frameHeight) {
    velocityY( -abs( velocityY() ) );
  }

  if ( X() <= 0) {
    velocityX( abs( velocityX() ) );
    right = true;
  }
  if ( X() >= worldWidth-frameWidth) {
    velocityX( -abs( velocityX() ) );
    right = false;
  }  
}
示例#2
0
inline void Rayman::jumpFunction(){
  float spd = 700;
  if(!currentLandPosSet) {
      currentLandPos = Y();
      currentLandPosSet = true;
  }
    
  if(faceDirection== -1)
    frames = FrameFactory::getInstance().getFrames(frameName, "jumpLeft");
  if(faceDirection== 1)
    frames = FrameFactory::getInstance().getFrames(frameName, "jumpRight");

  if( abs(currentLandPos - Y()) > 300 ){
    velocityY(spd);
    isReachTop = true;
  }
  else{
    if(!isReachTop)
      velocityY(-spd);
  }

  if( Y() > currentLandPos ){
    //std::cout<<"finish jump"<<std::endl;
    setIsJump(false);
    isReachTop = false;
    currentLandPosSet = false;
    Y(currentLandPos);
    velocityY(0);
  }
}
void TWRotateMultiSprite::update(Uint32 ticks) { 
  advanceFrame(ticks);

  Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
  setPosition(getPosition() + incr);
  
  setAngle(getAngle() + getAngleInc() );

  if ( Y() < 0) {
    velocityY( abs( velocityY() ) );
    
  }
  if ( Y() > worldHeight-frameHeight) {
    velocityY( -abs( velocityY() ) );
  }

  if ( X() < 0) {
    velocityX( abs( velocityX() ) );
    flag = true;	
  }
  if ( X() > worldWidth-frameWidth) {
    velocityX( -abs( velocityX() ) );
	flag = false;
  }  

}
void Sprite::update(Uint32 ticks) { 
  float incr = velocityY() * static_cast<float>(ticks) * 0.001;
  Y( Y()+incr );
  float height = static_cast<float>(frame->getHeight());
  if ( Y() < 0) {
    velocityY( abs( velocityY() ) );
  }
  if  (Y() > Gamedata::getInstance()->getXmlInt("worldHeight")-height)  {
    velocityY( -abs( velocityY() ) );
  }

  incr = velocityX() * static_cast<float>(ticks) * 0.001;
  if (name == "aibullet") {
    X( X()+incr );}
  else X( X()+incr );
  float width = static_cast<float>(frame->getWidth());
  if (name == "aibullet"){
    velocityX( -abs( velocityX() ) );
  }
  else {

  if ( X() < 0) {
    velocityX( abs( velocityX() ) );
  }
  if (( X() > Gamedata::getInstance()->getXmlInt("worldWidth")-width) && name != "bullet") {
    velocityX( -abs( velocityX() ) );
  }  
}
}
void TwoWaySprite::update(Uint32 ticks) { 
  if(explosion){
    explosion->update(ticks);
    if(explosion->chunkCount()==0){
      delete explosion;
      explosion = NULL;
    }
    return;
  }
  Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
  setPosition(getPosition() + incr);

  advanceFrame(ticks);
  if ( Y() < 0) {
    velocityY( abs( velocityY() ) );
  }
  if ( Y() > worldHeight-frameHeight) {
    velocityY( -abs( velocityY() ) );
  }

  if ( X() < 0) {
    velocityX( abs( velocityX() ) );
  }
  if ( X() > worldWidth-frameWidth) {
    velocityX( -abs( velocityX() ) );
  } 
}
示例#6
0
void TwoWaySprite::update(Uint32 ticks) { 
  advanceFrame(ticks);

  Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
  setPosition(getPosition() + incr);

  if ( Y() < 0) {
    velocityY( abs( velocityY() ) );
      
  }
  if ( Y() > worldHeight-frameHeight) {
    velocityY( -abs( velocityY() ) );
     
  }

  if ( X() < 0) {
    velocityX( abs( velocityX() ) );
      flipX = 1;
  }
  
  if ( X() > worldWidth-frameWidth) {
    velocityX( -abs( velocityX() ) );
       flipX = -1;
  }  

}
示例#7
0
void Sprite::update(Uint32 ticks) {

  const static float speedLoss = JSONGamedata::getInstance().getFloat("sprite.speedLoss");

  updateVelocity(ticks);
  Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001 * scale;
  setPosition(getPosition() + incr);

  if ( Y() < 0) {
    velocityY( abs( velocityY() * speedLoss) );
  }
  if ( Y() > worldHeight-frameHeight) {
    velocityY( -abs( velocityY() * speedLoss) );
  }

  if ( X() < 0) {
    velocityX( abs( velocityX() * speedLoss) );
  }
  if ( X() > worldWidth-frameWidth) {
    velocityX( -abs( velocityX() * speedLoss) );
  }

  if(Planets::getInstance().checkForCollision(this)){
    //velocityY( -velocityY() * speedLoss );
    //velocityX( -velocityX() * speedLoss );
  }
}
示例#8
0
void Jets::update(Uint32 ticks) { 

  int deviation = getRandomFactorBetween(0,200);
  int length = sqrt((playerX+deviation - X())*(playerX+deviation-X()) + (playerY+deviation-Y())*(playerY+deviation-Y()));
  velocityX(throttleX*(playerX - X())/length);
  velocityY(throttleY*(playerY - Y())/length);
   int delta_x = playerX - X();
   int delta_y = playerY - Y();
   angle = -(atan2(delta_y, delta_x)*180.0000)/3.142 ;
  
   Vector2f incr = getVelocity() *  static_cast<float>(ticks) * 0.001;
   setPosition(getPosition() + incr);

  if(getRotate()) 
   angle += getRotationSpeed() % 360;
  if ( Y() < 0) {
    velocityY( abs( velocityY() ) );
  }
  if ( Y() > worldHeight-frameHeight) {
    velocityY( -abs( velocityY() ) );
  }

  if ( X() < 0) {
    velocityX( abs( velocityX() ) );
  }
  if ( X() > worldWidth-frameWidth) {
    velocityX( -abs( velocityX() ) );
  }  
}
示例#9
0
文件: cat.cpp 项目: epompeii/tipiCat
void Cat::update(Uint32 ticks) { 
   //std::cout << ticks << std::endl;
  advanceFrame(ticks);
  
  if(t >= 0){
    jump(ticks) ;
  }
  else if( t2 >= 0){
    fall(ticks) ;
  }
  else{
    Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
      setPosition(getPosition() + incr);

      if ( Y() < 0) {
        velocityY( abs( velocityY() ) );
      }
      if ( Y() > worldHeight-frameHeight) {
        velocityY( -abs( velocityY() ) );
      }

      if ( X() < 0) {
        velocityX( abs( velocityX() ) );
      }
      if ( X() > worldWidth-frameWidth) {
        velocityX( -abs( velocityX() ) );
      }  
  }
}
示例#10
0
文件: player.cpp 项目: amitn7/2D-game
void Player::down(){
  keyPressedY = true;
  if(Y() < worldHeight - playerHeight && !flipPlayerUp) {
    velocityY(speedY);
  }
  else if(Y() < worldHeight - playerWidth && flipPlayerUp){
    velocityY(speedY);
  }
}
示例#11
0
Scaledsprite::Scaledsprite(const std::string& name): TwoWaySprite(name,
                                                   Gamedata::getInstance().getXmlInt("world/width")*(rand()*1.0/RAND_MAX),
                                                   Gamedata::getInstance().getXmlInt("world/height")*(rand()*1.0/RAND_MAX),
                                                                  Gamedata::getInstance().getXmlInt(name+"/speedX")*(rand()%2?-1:+1),
                                                   Gamedata::getInstance().getXmlInt(name+"/speedY")*(rand()%2?-1:+1),
                                                                  Gamedata::getInstance().getRandFloat(Gamedata::getInstance().getXmlFloat(name+"/scale/min"),
                                                                                                             Gamedata::getInstance().getXmlFloat(name+"/scale/max"))
                                                   ),
reDisplay(true)
{
    velocityX(velocityX()*getScale());
    velocityY(velocityY()*getScale());
}
示例#12
0
void Meteor::update(Uint32 ticks) {
  if ( explosion ) {
    explosion->update(ticks);
    if ( explosion->chunkCount() == 0 ) {
      delete explosion;
      explosion = NULL;
    }
    return;
  }
 
  Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
  setPosition(getPosition() + incr);

  if ( X() < 0) {
    velocityX( abs( velocityY() ) );
  }
  if ( X() > worldWidth-frameWidth) {
    velocityX( -abs( velocityX() ) );
  }

  if ( Y() > worldHeight-frameHeight) {
    Y(0); //wraparound on X-axis
    X( Gamedata::getInstance().getRandInRange(0, worldWidth-frameWidth) );
  }  
}
示例#13
0
/*void ExplodingSprite::makeChunks(unsigned int n) { 
  // Break the SDL_Surface into n*n squares; where each square
  // has width and height of frameWidth/n and frameHeight/n
  unsigned int chunk_width = std::max(1u, getFrame()->getWidth()/n);
  unsigned int chunk_height = std::max(1u, getFrame()->getHeight()/n);
  int speedx = static_cast<int>(velocityX()); // Wanna test for zero...
  int speedy = static_cast<int>(velocityY()); // Make sure it's an int.
  if (speedx == 0) speedx = 1; // Make sure it's not 0;
  if (speedy == 0) speedy = 1; // Make sure it's not 0;

  // Get the SDL_Surface so we can chunk it:
  SDL_Surface* spriteSurface(getFrame()->getSurface()); 
  Sint16 source_y = getFrame()->getSourceY();
  while  (source_y < getFrame()->getHeight() ) {
    Sint16 source_x = getFrame()->getSourceX();
    while ( source_x < getFrame()->getWidth() ) {
      // Give each chunk it's own speed/direction:
      float sx = (rand() % speedx + 40) * (rand()%2?-1:1); // 'cause %0 is 
      float sy = (rand() % speedy + 40) * (rand()%2?-1:1); // float except
      Frame* frame = 
            new Frame(spriteSurface, chunk_width, chunk_height,
                  source_x, source_y
                );
      Chunk chunk(
                Vector2f(X()+source_x,   // x coord of destination 
                         Y()+source_y), // y coord of destination
                Vector2f(sx, sy),
                getName()+"/chunk",
                frame);
      // chunks uses value semantics, as does frames, but there's
      // a big difference:
      chunks.push_back(chunk);
      frames.push_back(frame);
      source_x += chunk_width;
    }
    source_y += chunk_height;
  }
}

*/
void ExplodingSprite::makeChunks(unsigned int n) { 
  const Frame* frame = getFrame();
  unsigned int chunk_width = frame->getWidth()/n;
  unsigned int chunk_height = frame->getHeight()/n;
  Sint16 source_x = frame->getSourceX();
  Sint16 source_y = frame->getSourceY();

  int speedx = static_cast<int>(velocityX()); // Wanna test for zero...
  int speedy = static_cast<int>(velocityY()); // Make sure it's an int.
  if (speedx == 0) speedx = 1; // Make sure it's not 0;
  if (speedy == 0) speedy = 1; // Make sure it's not 0;

  // Get the SDL_Surface so we can chunk it:
  SDL_Surface* spriteSurface(frame->getSurface()); 
  for (unsigned int i = 0; i < n; ++i) {
    for (unsigned int j = 0; j < n; ++j) {
      float sx = (rand() % speedx + 40) * (rand()%2?-1:1); // 'cause %0 is 
      float sy = (rand() % speedy + 40) * (rand()%2?-1:1); // float except
      
      frames.push_back(
                new Frame(spriteSurface, chunk_width, chunk_height,
                  source_x+i*chunk_width,  // x coord of surface
                  source_y+j*chunk_height) // y coord of surface
      );
      Chunk chunk(
                Vector2f(X()+i*chunk_width,   // x coord of destination 
                         Y()+j*chunk_height), // y coord of destination
                Vector2f(sx, sy),
                getName()+"/chunk",
                frames.back()
                );
      chunks.push_back(chunk);
    }
  }
}
示例#14
0
void ExplodingSprite::makeChunks_multi(unsigned int n) { 
  unsigned int chunk_width = getFrame()->getWidth()/n;
  unsigned int chunk_height = getFrame()->getHeight()/n;
  Sint16 source_x = getFrame()->getSourceX();
  Sint16 source_y = getFrame()->getSourceY();
  int speedx = static_cast<int>(velocityX())+1; // Make sure it's not 0;
  int speedy = static_cast<int>(velocityY())+1; // Make sure it's an int.
  SDL_Surface* spriteSurface(getFrame()->getSurface()); 
  for (unsigned int i = 0; i < n; ++i) {
    for (unsigned int j = 0; j < n; ++j) {
      float sx = (rand() % speedx + rand()%80+20) * (rand()%2?-1:1); // 'cause %0 is 
      float sy = (rand() % speedy + rand()%80+40) * (rand()%2?-1:1); // float except
      Frame* frame = 
            new Frame(spriteSurface, chunk_width, chunk_height,
                  source_x+i*chunk_width,  // x coord of surface
                  source_y+j*chunk_height // y coord of surface
                );
      Chunk chunk(
                Vector2f(X()+i*chunk_width,   // x coord of destination 
                         Y()+j*chunk_height), // y coord of destination
                Vector2f(sx, sy),
               getName()+"Chunk",
               // getName(),
                frame);
      chunks.push_back(chunk);
      frames.push_back(frame);
    }
  }
}
示例#15
0
文件: player.cpp 项目: amitn7/2D-game
void Player::up(){
  keyPressedY = true;
  if( Y() > 0) {
    velocityY(-speedY);
    
 }
}
示例#16
0
void Explosion::update(Uint32 ticks) { 
  float yincr = velocityY() * static_cast<float>(ticks) * 0.001;
  Y( Y()- yincr );
  float xincr = velocityX() * static_cast<float>(ticks) * 0.001;
  X( X()- xincr );
  distance += ( hypot(xincr, yincr) );
}
void EnemyBullet::set(Vector2f pos, Vector2f vel)
{
  setPosition(pos);
  setVelocity(vel);
  Y(Y()+60);
  velocityY(0);
}
示例#18
0
void Sprite::update(Uint32 ticks) {
    Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
    setPosition(getPosition() + incr);

    if (Y() < 0)
        velocityY(std::abs(velocityY()));

    if (Y() > worldHeight - frameHeight)
        velocityY(-std::abs(velocityY()));

    if (X() < 0)
        velocityX(std::abs(velocityX()));

    if (X() > worldWidth - frameWidth)
        velocityX(-std::abs(velocityX()));
}
示例#19
0
void Chunk::update(Uint32 ticks) { 
  float yincr = velocityY() * static_cast<float>(ticks) * 0.001;
  Y( Y()- yincr );
  float xincr = velocityX() * static_cast<float>(ticks) * 0.001;
  X( X()- xincr );
  distance += ( hypot(xincr, yincr) );
  if (distance > maxDistance) tooFar = true;
}
示例#20
0
void MultiSprite::move(Uint32 ticks) {
	Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
	setPosition(getPosition() + incr);

	if (Y() < 0) {
		velocityY(abs(velocityY()));
	}
	if (Y() > worldHeight - frameHeight) {
		velocityY(-abs(velocityY()));
	}

	if (X() < 0) {
		velocityX(abs(velocityX()));
	}
	if (X() > worldWidth - frameWidth) {
		velocityX(-abs(velocityX()));
	}
}
示例#21
0
void Bullet::setOrientation(int x, int y,float playerX,float playerY,int a){
 int length = sqrt((x-playerX)*(x-playerX) + (y-playerY)*(y-playerY));
 velocityX((x-playerX)/length);
 velocityY((y-playerY)/length);
 angle = a+270;
 
 X(playerX+60/scale);
 Y(playerY+60/scale);
 }
示例#22
0
文件: player.cpp 项目: amitn7/2D-game
void Player::update(Uint32 ticks) { 
  timeSinceLastBullet += ticks;
  bullets.update(ticks);
  if ( explodingPlayer ) {
    explodingPlayer->update(ticks);
    if ( explodingPlayer->chunkCount() == 0 ) {
      delete explodingPlayer;
      explodingPlayer = NULL;
      exploded =true;
    }
    return;
  }
  if(exploded) return ;
  if(keyPressedX == false ){
      velocityX( 0 );
  }
  if(keyPressedY == false ){
      velocityY( 0 );
  }
  Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
  setPosition(getPosition() + incr);
  if(Y() < 0 ){
    velocityY(speedY);
     if(!flipPlayerUp)flipPlayer=0;
  }
  if(Y() > worldHeight - playerHeight){
    velocityY(-speedY);
    if(!flipPlayerUp) flipPlayer=0;
  }
  if(X() < 0){
    velocityX(speedX);
    if(!flipPlayerUp) flipPlayer=0;
  }
  if(X() > worldWidth - playerWidth){
    velocityX(-speedX);
     if(!flipPlayerUp) flipPlayer=1;
  }
  keyPressedX = false;
  keyPressedY = false;
  
}
示例#23
0
void Sprite::updateVelocity(Uint32 ticks){

  Planets &planets = Planets::getInstance();

  acceleration = planets.accelerationFromPlanets(getPosition());

  // std::cout << "Sprite Accel: " << acceleration << std::endl;

  float inc = acceleration[0] * 0.001 * static_cast<float>(ticks);
  velocityX( velocityX() + inc );

  inc = acceleration[1] * 0.001 * static_cast<float>(ticks);
  velocityY( velocityY() + inc );

  if(maxSpeeds[0] != -99){
    if(velocityX() > maxSpeeds[0]) {
      velocityX( maxSpeeds[0] );
    } else if(velocityX() < -maxSpeeds[0]){
      velocityX( -maxSpeeds[0]);
    }
  }

  if(maxSpeeds[1] != -99){
    if(velocityY() > maxSpeeds[1]) {
      velocityY( maxSpeeds[1] );
    } else if(velocityY() < -maxSpeeds[1]){
      velocityY( -maxSpeeds[1]);
    }
  }
}
示例#24
0
void TwowaySprite::update(Uint32 ticks) { 
  advanceFrame(ticks);
  Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
  setPosition(getPosition() + incr);

  if ( Y() < 0) {
    velocityY( abs( velocityY() ) );
	direction = 4; //Go down
  }
  if ( Y() > worldHeight-frameHeight) {
    velocityY( -abs( velocityY() ) );
	direction = 3; //Go up
  }

  if ( X() < 0) {
    velocityX( abs( velocityX() ) );
	direction = 1; //Go right
  }
  if ( X() > worldWidth-frameWidth) {
    velocityX( -abs( velocityX() ) );
	direction = 2; //Go left
  }  
}
void MultiBullets::update(Uint32 ticks) { 
  Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
  setPosition(getPosition() + incr);

  if ( Y() < 0) {
    velocityY( abs( velocityY() ) );
    done = true;
  }
  if ( Y() > worldHeight-frameHeight) {
    velocityY( -abs( velocityY() ) );
    done = true;
    //setPosition(Vector2f(rand() % (6400 - 100 + 1) + 1, 
    //                rand() % 100));
  }

  if ( X() < 0) {
    velocityX( abs( velocityX() ) );
    done = true;
  }
  if ( X() > worldWidth-frameWidth) {
    velocityX( -abs( velocityX() ) );
    done = true;
  }  
}
示例#26
0
void Player::move(Uint32 ticks) {
	//check explode
	Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
	setPosition(getPosition() + incr);

	if (Y() < 0) {
		velocityY(0);
	}
	if (Y() > worldHeight - frameHeight) {
		velocityY(0);
	}

	if (X() < 0) {
		velocityX(abs(velocityX()));
		this->X(0);
		//this->dirChanged = true;

	}
	if (X() > worldWidth - frameWidth) {
		velocityX(-abs(velocityX()));
		this->X(worldWidth - frameWidth);
		//this->dirChanged = true;
	}
}
示例#27
0
void Player::reset(){
	
	
	forward=false;
	back=false;
	up=false;
	down=false;
	flag=false;
	physics = true;
	count=2;
	score=0;
	X(Gamedata::getInstance().getXmlInt("fire/Loc/X")); 
	Y(Gamedata::getInstance().getXmlInt("fire/Loc/Y"));
	velocityX(Gamedata::getInstance().getXmlInt("fire/SpeedX"));
	velocityY(Gamedata::getInstance().getXmlInt("fire/SpeedY"));
	flagStop=true;
	
	}
EnemyBullet::EnemyBullet(const string& name, Vector2f position, Vector2f velocity,  
               const std::list<Drawable*>& sprites, Player * tr):
  Drawable(name, position, velocity),
  frame(FrameFactory::getInstance().getFrame(name)),
  target(tr),
  targets(sprites),
  strategy(new PerPixelCollisionStrategy()),
  tooFar(false),
  lock(false),
  ticksSinceLastFrame(0),
  frameWidth(frame->getWidth()),
  frameHeight(frame->getHeight()),
  worldWidth(Gamedata::getInstance().getXmlInt("world/width")),
  worldHeight(Gamedata::getInstance().getXmlInt("world/height"))
{
 Y(Y()+60);
 velocityY(0);
}
示例#29
0
void ExplodingSprite::makeChunks(unsigned int n) {
//	std::cout << n << std::endl;
	// Break the SDL_Surface into n*n squares; where each square
	// has width and height of frameWidth/n and frameHeight/n
	unsigned int chunk_width = std::max(1u, getFrame()->getWidth() / n);
	unsigned int chunk_height = std::max(1u, getFrame()->getHeight() / n);
	int speedx = static_cast<int>(velocityX()); // Wanna test for zero...
	int speedy = static_cast<int>(velocityY()); // Make sure it's an int.
	if (speedx == 0)
		speedx = 1; // Make sure it's not 0;
	if (speedy == 0)
		speedy = 1; // Make sure it's not 0;

	// Get the SDL_Surface so we can chunk it:
	SDL_Surface* spriteSurface(getFrame()->getSurface());
	Sint16 source_y = getFrame()->getSourceY();
	while (source_y < getFrame()->getHeight()) {
		Sint16 source_x = getFrame()->getSourceX();
		while (source_x < getFrame()->getWidth()) {
//			std::cout << source_x << ", " << source_y << std::endl;
			// Give each chunk it's own speed/direction:
//			float sx = (rand() % speedx + 40) * (rand() % 2 ? -1 : 1); // 'cause %0 is
//			float sy = (rand() % speedy + 40) * (rand() % 2 ? -1 : 1); // float except

			float sx = (Gamedata::getInstance().getRandInRange(10, 40)) * (rand() % 2 ? -1 : 1); // 'cause %0 is
			float sy = (Gamedata::getInstance().getRandInRange(10, 40)) * (rand() % 2 ? -1 : 1); // float except
//			std::cout << sx << ", " << sy << std::endl;
			Frame* frame = new Frame(spriteSurface, chunk_width, chunk_height,
					source_x, source_y);
			Chunk chunk(Vector2f(X() + source_x,   // x coord of destination
			Y() + source_y), // y coord of destination
			Vector2f(sx, sy), getName() + "/chunk", frame);
			// chunks uses value semantics, as does frames, but there's
			// a big difference:
			chunks.push_back(chunk);
			frames.push_back(frame);
			source_x += chunk_width;
		}
		source_y += chunk_height;
	}
}
void ExplodingSprite::makeChunks(unsigned int n) { 
  // Break the SDL_Surface into n*n squares; where each square
  // has width and height of frameWidth/n and frameHeight/n
  unsigned int chunk_width = frame->getWidth()/n;
  unsigned int chunk_height = frame->getHeight()/n;
  Sint16 source_x = frame->getSourceX();
  Sint16 source_y = frame->getSourceY();
  int speedx = static_cast<int>(velocityX()); // Wanna test for zero...
  int speedy = static_cast<int>(velocityY()); // Make sure it's an int.
  if (speedx == 0) speedx = 1; // Make sure it's not 0;
  if (speedy == 0) speedy = 1; // Make sure it's not 0;

  // Get the SDL_Surface so we can chunk it:
  SDL_Surface* spriteSurface(frame->getSurface()); 
  // i tracks the width, j tracks the height:
  for (unsigned int i = 0; i < n; ++i) {
    for (unsigned int j = 0; j < n; ++j) {
      // Give each chunk it's own speed/direction:
      float sx = (rand() % speedx + 40) * (rand()%2?-1:1); // 'cause %0 is 
      float sy = (rand() % speedy + 40) * (rand()%2?-1:1); // float except
      Frame* frame = 
            new Frame(spriteSurface, chunk_width, chunk_height,
                  source_x+i*chunk_width,  // x coord of surface
                  source_y+j*chunk_height // y coord of surface
                );
      Chunk chunk(
                Vector2f(X()+i*chunk_width,   // x coord of destination 
                         Y()+j*chunk_height), // y coord of destination
                Vector2f(sx, sy),
                getName()+"Chunk",
                frame);
      // chunks uses value semantics, as does frames, but there's
      // a big difference:
      chunks.push_back(chunk);
      frames.push_back(frame);
    }
  }


}