Beispiel #1
0
Hero::Hero(const char* a_TextureName, int a_Sprite_W, int a_Sprite_H, float a_Position_X, float a_Position_Y, float a_Velocity_X, float a_Velocity_Y, int a_Health)
{

	Init(a_TextureName, a_Sprite_W,  a_Sprite_H, a_Position_X, a_Position_Y);
	m_SpriteID = CreateSprite( m_TextureName, m_Sprite_W, m_Sprite_H, true );
	m_HeroHealth = a_Health;
	IsAlive = true;
	m_SpriteType = 'H';
	Vector2D Velocity (a_Velocity_X, a_Velocity_Y);
	//HeroBullet = Bullet("./images/Bullet.png",4, 4, 10, 10, 0, 0,'H');
	Vector2D tempPosition(200,300);
	//HeroBullet.SetPosition(tempPosition);
	//std::list<Bullet>HeroBullets(20, Bullet("./images/Bullet.png",4, 4, 10, 10, 0, 0,'H'));
	for( i=0; i < 20; i++)
	{
		Bullet HeroBullet("./images/Bullet.png",4, 4, 10, 10, 0, 0,'H');
		HBullets.push_back(HeroBullet);
	}
}
Beispiel #2
0
//------------------------------------------------------------------------------------------------------
//function that determines point on line segment that is closest to position passed 
//------------------------------------------------------------------------------------------------------
glm::vec3 Line3D::PointOnLine(float positionX, float positionY, float positionZ) const
{

	//variable to store normalized portion of line segment that point uses up
	float lineSegmentPortion;

	//first calculate distance vector between line segment's start and end point
	//also create a position vector out of the position X, Y and Z values passed
	glm::vec3 distance = m_endPoint - m_startPoint;
	glm::vec3 tempPosition(positionX, positionY, positionZ);

	//calculate the line segment portion using a dot
	//product formula and distance vector created above
	lineSegmentPortion = glm::dot(distance, (tempPosition - m_startPoint)) /
		                 glm::dot(distance, distance);

	//if the line segment portion is zero or less the
	//point closest to the sphere is the line's start point
	if (lineSegmentPortion <= 0.0f)
	{
		return m_startPoint;
	}

	//if the line segment portion is one or more the
	//point closest to the sphere is the line's end point
	else if (lineSegmentPortion >= 1.0f)
	{
		return m_endPoint;
	}

	//otherwise the line segment portion is a value between 0 and 1 
	//meaning that the point closest to the sphere is on the line 
	//somewhere, so use another formula to calculate that point exactly
	else
	{
		return (m_startPoint + lineSegmentPortion * distance);
	}

}
Beispiel #3
0
Leader::Leader(float x, float y, int N, std::string whichPattern, bool yestofollowers, bool tracersYorN, bool slowmo) {
  // Some constants
  displayx = x;
  displayy = y;
  numberofleaders = N;
  conv = 3.141592 / 180.0; 
  centerMass = 500.0;
  center = sf::Vector2f(displayx/2.0, displayy/2.0);
  radius = 2.0;
  pattern = whichPattern;
  putinFollowers = yestofollowers;
  tracersONorOFF = tracersYorN;
  slowdown = slowmo;
  if( slowdown ) {
    centerMass = 100;
  }
  
  // Initialize leader properties
  circles.setRadius(radius);
  circles.setFillColor(sf::Color::Cyan);
  sf::FloatRect origin = circles.getLocalBounds();
  circles.setOrigin( 0.5*origin.width, 0.5*origin.height );
  
  // Tracers
  R_knot = 500;
  if( putinFollowers && tracersONorOFF ) {
    m_lifetime = sf::Time(sf::seconds(1));
  }
  else{
    m_lifetime = sf::Time(sf::seconds(10));
  }
  tracertemplate.setRadius(radius);
  tracertemplate.setFillColor(sf::Color::Cyan);
  origin = tracertemplate.getLocalBounds();
  tracertemplate.setOrigin( 0.5*origin.width, 0.5*origin.height );

  tracertemplateF.setRadius(radius);
  tracertemplateF.setFillColor(sf::Color::Blue);
  origin = tracertemplateF.getLocalBounds();
  tracertemplateF.setOrigin( 0.5*origin.width, 0.5*origin.height );

  srand(time(NULL));
  
  // This routine handles starting locations, velocities, and angles
  // for a variety of setups.
  if( pattern    == "spiral"        || pattern == "circle" 
      || pattern == "flower"        || pattern == "flower_spiral" 
      || pattern == "double circle" || pattern == "puzzle piece center" 
      || pattern == "bulls eye"     || pattern == "crazy folds" ){
    for( int i=0; i<numberofleaders; i++ ){
      
      float tempAngle = 360 / numberofleaders;
    
      sf::Vector2f tempPosition( -R_knot*sin( conv*tempAngle*i ), R_knot*cos( conv*tempAngle*i ) );
      sf::Vector2f place = center + tempPosition;
      circles.setPosition(place);    

      sf::Vector2f centertoleader = place - center;
      float mag = sqrt(pow(centertoleader.x,2)+pow(centertoleader.y,2));
      sf::Vector2f center_hat = centertoleader / mag;

      // Counter Clockwise
      sf::Vector2f vel_hat( center_hat.y, -center_hat.x );
      // Clockwise
      sf::Vector2f vel_hat1( -center_hat.y, center_hat.x );
      float vx,vy;

      if( pattern == "puzzle piece center" ) {
	centerMass = 10000;
      }      
      if( pattern == "flower" || pattern == "flower_spiral" || pattern == "bulls eye" ) { 
	if( pattern == "bulls eye" ) {
	  centerMass = 10000;
	}
	vx = sqrt(centerMass / R_knot );
	vy = sqrt(centerMass / R_knot );
      }
      if (pattern == "crazy folds" ){
	vx = 10;
	vy = 0.5;
      }
      else{
	// note: 16 and 16 basically give  a perfect circle
	vx = 10;
	vy = 10;
      }
     
      sf::Vector2f velocity_knot( vel_hat.x*vx, vel_hat.y*vy );
      float m = 10;
      ParticleAdd(circles, velocity_knot, tempAngle, m);
      
      if( pattern == "double circle" ) {
	float tempR = R_knot / 20;
	tempPosition = sf::Vector2f( -tempR*sin( conv*tempAngle*i ), tempR*cos( conv*tempAngle*i ) );
	place = center + tempPosition;
	circles.setPosition(place);  
	centertoleader = place - center;
	mag = sqrt(pow(centertoleader.x,2)+pow(centertoleader.y,2));
	center_hat = centertoleader / mag;
	vel_hat = sf::Vector2f( center_hat.y, -center_hat.x );
	
	vx = 10;
	vy = 10;
	
	velocity_knot = sf::Vector2f( vel_hat.x*vx, vel_hat.y*vy );
       	ParticleAdd(circles, velocity_knot, tempAngle, m);
      }
    }
    
    if( pattern == "random" ){
      // Randomly place the leaders with random velocity vectors:
      float tempX = rand() % ( int (displayx) - 2*int(radius) ) + int(radius);
      float tempY = rand() % ( int (displayy) - 2*int(radius) ) + int(radius);
      float tempAngle = rand() % 360;;  
      circles.setPosition( tempX, tempY );
      float vx = (rand() % 40) / 10.0;
      float vy = (rand() % 40) / 10.0;
      sf::Vector2f velocity_knot( -vx*sin( conv*tempAngle ), vy*cos( conv*tempAngle) );   
      float m = 10;
      ParticleAdd(circles, velocity_knot, tempAngle, m);
    }
  }
  if(    pattern == "boxTL"       || pattern == "boxC" 
      || pattern == "boxTL folds" || pattern == "boxC folds" ){
    
    numberofleaders = 10000;
    // squareD might need to be tweaked
    float squareD = center.y - 100;
    sf::Vector2f topLeft = center - sf::Vector2f(squareD,squareD);
    int particles_per_row = 0; 
    if( numberofleaders % 100 == 0) {
      particles_per_row = sqrt( numberofleaders );
    }
    else {
      std::cerr << "error, check box routine" << std::endl;
    }
    float spacing = squareD / particles_per_row;
    // i = rows
    // j = columns
    for( int i=0; i<particles_per_row; i++ ) {
      for( int j=0; j<particles_per_row; j++ ) {
	sf::Vector2f temp(0,0);
		
	if( pattern == "boxC" || pattern == "boxC folds" ) {
	  temp = topLeft + sf::Vector2f(i*2*spacing,j*2*spacing);
	}
	
	if( pattern == "boxTL" || pattern == "boxTL folds" ) {
	  temp = topLeft + sf::Vector2f(i*spacing,j*spacing);
	}
	
	circles.setPosition( temp );

	sf::Vector2f velocity_knot(0,0);
	if( pattern == "boxTL folds" || pattern == "boxC folds" ) { 
	  velocity_knot = sf::Vector2f( 3,3 );
	}
	
	float m = 10;
	ParticleAdd(circles,velocity_knot,0.0,m);
      }
    }
  }
  if( putinFollowers ) {
    for( int i=0; i<numberofleaders; i++ ){
      // Randomly place the followers with random velocity vectors:
      float tempX = rand() % ( int (displayx) - 2*int(radius) ) + int(radius);
      float tempY = rand() % ( int (displayy) - 2*int(radius) ) + int(radius);
      circles.setPosition( tempX, tempY );
      circles.setFillColor( sf::Color::Blue );
      float tempAngle = rand() % 360;
    
      float vx = (rand() % 90) / 10.0;
      float vy = (rand() % 90) / 10.0;
      sf::Vector2f velocity_knot( -vx*sin( conv*tempAngle ), vy*cos( conv*tempAngle) );
      FollowerAdd(circles, velocity_knot, tempAngle);
    }
  }
}