Example #1
0
void Stage::perform(double dt, Unit* hero)
{

  for(int i = 0; i < units.size(); i++)
    {
      if(!isOffScreen(units[i]))
	{
	  units[i]->increment(dt); //if it's on screen draw it
	}
      else
	{
	  if(units[i]->isBullet())
	    {
	      units[i]->setHealth(0); //if a bullet goes off screen don't draw it
	    }
	}
      if (units[i]->getHealth() <= 0)
	{
	  removeUnit(units[i]);
	  i--;
	}
      //checkCollisions(units[i],dt);
      checkCollisions(units[i]);
    }
  adjustUnits();
  xoffset = -hero->getx() + SCREEN_WIDTH/2;
  yoffset = -hero->gety() + SCREEN_HEIGHT/2;
}
Example #2
0
/* monster can be removed if they are off-screen
 * or if they are dead
 */
bool monster::canBeRemoved()
{
	if (isOffScreen(SCREEN_WIDTH, SCREEN_HEIGHT)) //JG TODO fix this hack
	{
		return true;
	}

	if ((currentState == RS_DEAD) &&
			(sprites[MAIN_SPRITE].getAnimationState() == AS_DEAD))
	{
		return true;
	}

	return false;
}
Example #3
0
/* bullets can be removed if they are off screen or
 * if they have been "killed"
 */
bool Bullet::canBeRemoved()
{
	if (isOffScreen(SCREEN_WIDTH, SCREEN_HEIGHT)) //JG TODO fix this hack
	{
		return true;
	}

	if ((currentState == RS_DEAD) &&
			(sprites[BULLET_RED_SPRITE_INDEX].getAnimationState() == AS_DEAD))
	{
		return true;
	}

	return false;
}
Example #4
0
void Stage::adjustUnits()
{
  bool topleft,topright,botleft,botright;
  
  for(int i = 0; i<units.size(); i++)
    {
      //      cout << "Needing to adjust unit" << endl;
      if(units[i]->isBullet())
	{
	  if(!isInBounds(units[i]->getx(), units[i]->gety()))
	    {

		  
		  //		  cout << "subtracting from hero's current bullets" << endl;
	      units[i]->setHealth(0);
	      continue;
	    }
	  else if(isOffScreen(units[i]))
	    {
	      units[i]->setHealth(0);
	      continue;
	    }
	}
      else
	{
	  topleft = topright = botleft = botright = 1;
	  //if topleft is in bounds
	  //if top right is in bounds
	  //if bottom left is in bounds
	  //if bottom right is in bounds
	  
	  for(int j =0; j<sqrt(((units[i]->getx()*units[i]->getx())+(units[i]->gety()*units[i]->gety())));j++)
	    {
	     
	      if(isInBounds(units[i]->getx(),units[i]->gety()))
		topleft = 0;
	      if(isInBounds(units[i]->getx()+SPRWIDTH,units[i]->gety()))
		topright = 0;
	      if(isInBounds(units[i]->getx(),units[i]->gety()+SPRLENGTH))
		botleft = 0;
	      if(isInBounds(units[i]->getx()+SPRWIDTH,units[i]->gety()+SPRLENGTH))
		botright = 0;
	      
	      if(topright || botright || botleft || topleft)
		{
		  if(topright)
		    {
		      if(botright)
			{
			  units[i]->setx(units[i]->getx()-1);
			}
		      if(topleft)
			{
			  units[i]->sety(units[i]->gety()+1);
			}
		      if(!botright && !topleft)
			{
			  units[i]->setx(units[i]->getx()-1);
			  units[i]->sety(units[i]->gety()+1);
			}
		    }
		  else if(topleft)
		    {
		      if(botleft)
			{
			  units[i]->setx(units[i]->getx()+1); 
			}
		      else
			{
			  units[i]->setx(units[i]->getx()+1);
			  units[i]->sety(units[i]->gety()+1);
			}
		    }
		  else if(botright)
		    {
		      if(botleft)
			{
			  units[i]->sety(units[i]->gety()-1);
			}
		      else
			{
			  units[i]->sety(units[i]->gety()-1);
			  units[i]->setx(units[i]->getx()-1);
			}
		    }
		  else
		    {
		      units[i]->sety(units[i]->gety()-1);
		      units[i]->setx(units[i]->getx()+1);
		    }
		}
	      else
		break;
	    }
	}      
    }
}