示例#1
0
void GameActivity::enemyOnEnemyCollisionCheck()
{
	//looping through all the enemies updating their positons and checking for collisions
	for (int i = 0; i < enemies.size(); i++)
	{
		//#####   NEED TO INSERT CHECK iF THE ENEMY IS IN A GIVEN RADIOUS OF THE PLAYER FIRST TO IMPROVE EFFIENCY
		for (int j = i + 1; j < enemies.size(); j++)
		{
			if (enemies[i].checkForCollision(enemies[j].boundingBox))
				enemies[i].update(time2, playerX, playerY);
			if (boss_flag == true)
			{
				if (boss.checkForCollision(enemies[i].boundingBox))
					boss.update(time2, playerX, playerY);
			}

		}
		if (enemies[i].checkForCollision(hero.boundingBox) || boss.checkForCollision(hero.boundingBox))
		{
			hero.setCollisionFlag(true);
		}
		else
		{
			hero.setCollisionFlag(false);
		}
		enemies[i].update(time2, playerX, playerY);

	}
}
void Game::ResetGame()
{
  std::vector<std::string> enemies;
  enemies.push_back("Enemy1");
  enemies.push_back("Enemy2");
  enemies.push_back("Enemy3");

  for(unsigned int i = 0; i < enemies.size(); i++)
  {
  AIShip* enemy = dynamic_cast<AIShip*>(Game::GetGameObjectManager().Get(enemies[i]));
	assert(NULL != enemy);
	
	enemy->setElapsedTime(0);
  }
  WeaponPowerUp* weapon = dynamic_cast<WeaponPowerUp*>(Game::GetGameObjectManager().Get("WeaponPowerUp"));
  assert(NULL != weapon);
  weapon->setPowerUpLevel(1);
  weapon->setElapsedTime(20.f);
  weapon->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);
  
  ShieldPowerUp* shield = dynamic_cast<ShieldPowerUp*>(Game::GetGameObjectManager().Get("ShieldPowerUp"));
  assert(NULL != weapon);
  shield->setElapsedTime(10.f);
  shield->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);
  _score = 0;

  Boss* boss = dynamic_cast<Boss*>(Game::GetGameObjectManager().Get("Boss"));
  assert(NULL != boss);
  boss->setElapsedTime(0.f);

   AILaser* laser1 = dynamic_cast<AILaser*>(Game::GetGameObjectManager().Get("AILaser1"));
  assert(NULL != laser1);
  laser1->setElapsedTime(0.f);
  laser1->setSpeed(0.f);
  laser1->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);

  AILaser2* laser2 = dynamic_cast<AILaser2*>(Game::GetGameObjectManager().Get("AILaser2"));
  assert(NULL != laser2);
  laser2->setElapsedTime(0.f);
  laser2->setSpeed(0.f);
  laser2->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);

  AILaser3* laser3 = dynamic_cast<AILaser3*>(Game::GetGameObjectManager().Get("AILaser3"));
  assert(NULL != laser3);
  laser3->setElapsedTime(0.f);
  laser3->setSpeed(0.f);
  laser3->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);

  BossLaser* blaser = dynamic_cast<BossLaser*>(Game::GetGameObjectManager().Get("BossLaser"));
  assert(NULL != blaser);
  blaser->setElapsedTime(0.f);
  blaser->setSpeed(0.f,0.f);
  blaser->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);




  
}
int main()
{
	Boss * boss = new Boss;
	boss->Doing();
	
	delete boss;
	return 0;
}
void Game::Start(void)
{
  if(_gameState != Uninitialized)
    return;

  _mainWindow.Create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32),"Paint Wars!");

  SFMLSoundProvider soundProvider;
  ServiceLocator::RegisterAudioService(&soundProvider);

  ServiceLocator::GetAudio()->PlaySong("assets/NewSoundtrack.ogg",true);

  PlayerShip *player1 = new PlayerShip();
  player1->SetPosition(SCREEN_WIDTH/2, _gameField.Bottom - 40);
  _gameObjectManager.Add("Ship1", player1);
  Laser *laser1 = new Laser();
  laser1->SetPosition(Game::SCREEN_WIDTH / 2, Game::SCREEN_HEIGHT + 100);
  _gameObjectManager.Add("Laser1", laser1);
   AIShip *enemy1 = new AIShip();
   enemy1->SetPosition(SCREEN_WIDTH/2, _gameField.Top);
   _gameObjectManager.Add("Enemy1", enemy1);
   AIShip *enemy2 = new AIShip();
   enemy2->SetPosition(SCREEN_WIDTH/2, _gameField.Top);
   _gameObjectManager.Add("Enemy2", enemy2);
   AIShip *enemy3 = new AIShip();
   enemy3->SetPosition(SCREEN_WIDTH/2, _gameField.Top);
   _gameObjectManager.Add("Enemy3", enemy3);
   AILaser *ailaser1 = new AILaser();
   ailaser1->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);
   _gameObjectManager.Add("AILaser1", ailaser1);
   AILaser2 *ailaser2 = new AILaser2();
   ailaser2->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);
   _gameObjectManager.Add("AILaser2", ailaser2);
   AILaser3 *ailaser3 = new AILaser3();
   ailaser3->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);
   _gameObjectManager.Add("AILaser3", ailaser3);
   Boss *boss = new Boss();
   boss->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);
   _gameObjectManager.Add("Boss", boss);
   BossLaser *bosslaser = new BossLaser();
   bosslaser->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);
   _gameObjectManager.Add("BossLaser",bosslaser);
   WeaponPowerUp *weaponpowerup = new WeaponPowerUp();
    weaponpowerup->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);
   _gameObjectManager.Add("WeaponPowerUp",weaponpowerup);
    ShieldPowerUp *shieldpowerup = new ShieldPowerUp();
    shieldpowerup->SetPosition(SCREEN_WIDTH/2, _gameField.Top - 100);
   _gameObjectManager.Add("ShieldPowerUp",shieldpowerup);
   
   _gameState = Game::ShowingSplash;

  while(!IsExiting())
  {
    GameLoop();
  }

  _mainWindow.Close();
}
示例#5
0
void collisionDetection() {
	//Check if any bullets hit
	for (std::vector<Projectile>::iterator projectile = projectiles.begin(); projectile != projectiles.end();) {
		bool broken = false;
		for (std::vector<Enemy>::iterator enemy = enemies.begin(); enemy != enemies.end();) {
			if (isHit((*projectile).getBoundingBox(), (*enemy).getBoundingBox())) {
				enemy = enemies.erase(enemy);
				projectile = projectiles.erase(projectile);
				broken = true;
				break;
			}
			else {
				++enemy;
			}
		}
		if (!broken && isHit((*projectile).getBoundingBox(), boss.getBoundingBox())) {
			boss.hit();
			projectile = projectiles.erase(projectile);
			broken = true;
		}
		if (!broken) {
			projectile++;
		}
	}

	//Check if anything went outside the viewport
	for (std::vector<Enemy>::iterator enemy = enemies.begin(); enemy != enemies.end();) {
		if ((*enemy).getBoundingBox()[1][0] < topLeft[0]) {
			enemy = enemies.erase(enemy);
		}
		else {
			++enemy;
		}
	}
	Entity viewport = Entity();
	viewport.height = H_fen;
	viewport.width = W_fen;
	for (std::vector<Projectile>::iterator projectile = projectiles.begin(); projectile != projectiles.end();) {
		if (!isHit((*projectile).getBoundingBox(), viewport.getBoundingBox())) {
			projectile = projectiles.erase(projectile);
		}
		else {
			++projectile;
		}
	}

	//Check if the player didn't hit an enemy
	for (std::vector<Enemy>::iterator enemy = enemies.begin(); enemy != enemies.end();) {
		if (isHit(character.getBoundingBox(), (*enemy).getBoundingBox())) {
			enemy = enemies.erase(enemy);
			// Do some logic here
		}
		else {
			++enemy;
		}
	}
}
示例#6
0
//take keyboard input into account
void keyboard(unsigned char key, int x, int y)
{
    //printf("Keydown %d, cursor pos (%d,%d)\n",key,x,y);
    //fflush(stdout);
    keyPressed[key] = true;

	if ((key>='1')&&(key<='9'))
	{
		DisplayMode= (DisplayModeType) (key-'0');
		return;
	}
    
    updateCharacterMovementDirection();
    
	switch (key)
    {
    case 'm': {
        if (MouseMode == MOUSE_MODE_SHOOTING) {
            MouseMode = MOUSE_MODE_CAMERA;
        }
        else if (MouseMode == MOUSE_MODE_CAMERA) {
            MouseMode = MOUSE_MODE_SHOOTING;
        }
        break;
    }
	case 27:     // touche ESC
        exit(0);
	case 'L':
		//turn lighting on
		glEnable(GL_LIGHTING);
		break;
	case 'l':
		//turn lighting off
		glDisable(GL_LIGHTING);
		break;
	case 'b':
		spawnBoss(0);
		break;
	case 'j':
		if (boss.position[0] <= 0)
			boss.setDestination(Vec3Df(-2, -1, -0.5), 1);
		else
			boss.setDestination(Vec3Df(0, -1, -1), 1);
		break;
	case 'k':
		if (boss.position[0] >= 0)
			boss.setDestination(Vec3Df(2, -1, 0), 1);
		else
			boss.setDestination(Vec3Df(0, -1, 0.5), 1);
		break;
	case '+':
		meshIndex = ++meshIndex % meshes.size();
		break;
    }
}
示例#7
0
/// Computes lighting for the entire scene
void computeLighting()
{
    for (auto &ridge : mountains)
    {
        for (int i=0; i < ridge.meshVertices.size(); i = i+3)
        {
            // Compute for our (single) light
            Vec3Df vertexpos = Vec3Df(ridge.meshVertices[i],
                                      ridge.meshVertices[i+1],
                                      ridge.meshVertices[i+2]);
            Vec3Df normal = Vec3Df(ridge.meshNormals[i],
                                   ridge.meshNormals[i+1],
                                   ridge.meshNormals[i+2]);
            Vec3Df lighting = computeLighting(vertexpos, normal, DIFFUSE_LIGHTING);
            
            // Pass computed values to Ridge
            ridge.meshColors[i] = lighting[0];
            ridge.meshColors[i+1] = lighting[1];
            ridge.meshColors[i+2] = lighting[2];
        }
    }
	
	if (toggleBoss) {
		std::vector<Vertex> vertices = boss.getMesh().vertices;
		std::vector<Vec3Df> meshColors = std::vector<Vec3Df>(vertices.size());

		auto rotMat = matrixMultiplication(
			rotateMatrixY(boss.angleHeadY*M_PI / 180),
			rotateMatrixX(boss.angleHeadZ*M_PI / 180)
			);

		for (int i = 0; i < vertices.size(); i++)
		{
			// Compute for our (single) light
			Vertex vertex = vertices[i];
			Vec3Df vec = vertex.p;
			vec = calculateMatrix(rotMat, vec);
			vec = vec + boss.translation;
			vec = vec * boss.scale;
			vec = vec + boss.position;

			Vec3Df nor = vertex.n;
			nor = calculateMatrix(rotMat, nor);
			nor = nor + boss.translation;
			nor = nor * boss.scale;
			nor = nor + boss.position;

			Vec3Df lighting = computeLighting(vec, nor, PHONG_LIGHTNING);

			meshColors[i] = lighting;
		}
		boss.getMesh().meshColor = meshColors;
	}
}
示例#8
0
文件: Boss.cpp 项目: zsn6493/EATFUZI
Boss* Boss::create(Sprite* sprite, int ps)
{
	Boss *boss = new Boss();
	boss->m_Ps = (PowerEnumStatus)ps;                 //怪物类型
	if (boss && boss->initWithFile(sprite))
	{
		boss->autorelease();
		return boss;
	}
	CC_SAFE_DELETE(boss);
	return NULL;
}
示例#9
0
文件: boss.cpp 项目: lindianyin/sgbj
int bossMgr::combatResult(chessCombat* pCombat)    //boss战斗结束
{
    if (NULL == pCombat)
    {
        ERR();
        return HC_ERROR;
    }
    Boss* pb = getBoss(pCombat->m_data_id).get();
    if (NULL == pb)
    {
        ERR();
        return HC_ERROR;
    }
    return pb->combatResult(pCombat);
}
示例#10
0
int main(int argc, char* argv[])
{
	Boss* b = new Boss("胡汉三回来了");
	StockObserver* so = new StockObserver("张博",b);
	NBAObserver* no = new NBAObserver("赵书淇",b);

	b->Attach(so);
	b->Attach(no);

	b->Notify();

	cin.ignore();

	return 0;
}
示例#11
0
int main()
{
	Enemy enemy;
	Boss boss;

	cout << "Enemy: " << endl;
	enemy.Attack();

	cout << endl;
	
	cout << "Boss: " << endl;
	boss.Attack();
	boss.MegaAttack();

	return 0;
}
示例#12
0
int main(int argc, char const *argv[])
{
	Boss* huhansan = new Boss();

	StockObserver* tongshi1 = new StockObserver("aaa",huhansan);
	StockObserver* tongshi2 = new StockObserver("bbb",huhansan);

	huhansan->Attach(tongshi1);
	huhansan->Attach(tongshi2);

	huhansan->Detach(tongshi1);

	huhansan->setSubjectState("我胡汉三回来了");
	huhansan->Notify();
	return 0;
}
示例#13
0
void GameActivity::render()
{
	
	glClear(GL_COLOR_BUFFER_BIT);
	
	glLoadIdentity();									
	// Use the negated camera position as a translation; effectively we move the world and the camera so that the camera is at 0,0,0
	glTranslated(-camX, -camY, 0.0);

	// Render the  background
	
		drawTiles();
	
	
	//hero.boundingBox.draw();
	hero.draw(playerTextureID);
	
	//drawing Collectables
	for each (Collectable  c in collectables)
	{
		if (c.type == Collectable::Type::GUN)
		{
			c.draw(2);
		}
		else
		{
			c.draw(1);
		}
	}
	
	//drawing each player bullet  
	for (int i = 0; i < hero.bullets.size(); i++)
	{
		//hero.bullets[i].boundingBox.draw();
		hero.bullets[i].draw(bullet1ID,0.1);
	}
	//drawing each enemy in the vector
	for (int i = 0; i < enemies.size(); i++)
	{
		//enemies[i].boundingBox.draw();
		enemies[i].draw();
	}
	if (boss_flag==true)
	{
		
		boss.draw();
	}
	for (int i = 0; i < enemies.size(); i++)
	{
		for (int j = 0; j < enemies[i].bullets.size(); j++)
		{
			//enemies[i].bullets[j].boundingBox.draw();
			enemies[i].bullets[j].draw(bullet2ID, 0.3);
		}
	}
	renderHUD();
	glFlush();

}
示例#14
0
文件: main.cpp 项目: JustinMorritt/C-
int main()
{
	Enemy e;
	e.Attack();

	Boss b;

	b.Attack();

	std::cout << std::endl;
	b.SpecialAttack();

	b.Taunt();

	std::cout << std::endl;
	

	std::cin.get();
	return 0;
}
示例#15
0
void Logic::create_enemy(float t){//生产敌机的逻辑
	t*=50;
	int flag=(int)t;
	if(flag%100==0 && flag<=1500){
		EnemyPlane1* temp = new EnemyPlane1(*enemy_type[0]);
		EnemyPlane1* temp1 = new EnemyPlane1(*enemy_type[0]);
		temp->set_pos(Position(-temp->getwidth()/2,-temp->getheight()/2));
		temp1->set_pos(Position(win_width+temp1->getwidth()/2,-temp->getheight()/2));
		enemy.push_back(temp);
		enemy.push_back(temp1);
	}

	if(flag%400==0 && flag>400 && flag<=3200){
		EnemyPlane2* temp = new EnemyPlane2(*enemy_type[1]);
		EnemyPlane2* temp1 = new EnemyPlane2(*enemy_type[1]);
		EnemyPlane2* temp2 = new EnemyPlane2(*enemy_type[1]);
		temp->set_pos(Position(win_width/2,-temp->getheight()/2));
		temp1->set_pos(Position(win_width/4,-temp->getheight()/2));
		temp2->set_pos(Position(win_width*3/4,-temp->getheight()/2));
		enemy.push_back(temp);
		enemy.push_back(temp1);
		enemy.push_back(temp2);
	}

	if(flag%100==0&&flag>1000 && flag<=3600){
		EnemyPlane3* temp1 = new EnemyPlane3(*enemy_type[2]);
		EnemyPlane3* temp2 = new EnemyPlane3(*enemy_type[2]);
		int range = int(win_width - temp1->getwidth());
		float start = temp1->getwidth()/2;
		temp1->set_pos(Position(start+rand()%range,-temp1->getheight()/2));
		temp2->set_pos(Position(start+rand()%range,-temp2->getheight()/2));
		enemy.push_back(temp1);
		enemy.push_back(temp2);
	}

	if(flag == 3600){
		Boss* temp = new Boss(*enemy_type[3]);
		temp->set_pos(Position(win_width/2,-temp->getheight()/2));
		enemy.push_back(temp);
	}
}
示例#16
0
void display( )
{
	switch( DisplayMode )
	{
	case GAME:
	{
		glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
		drawLightPosition();
		//drawCoordinateSystem();

		// Note that drawing order has consequences for 'transparancy'
		background->draw();
		for (int i = 0; i < numberOfRidges; i++)
		{
			mountains[i].draw();
		}
		groundfloor->draw();
		
		if (toggleBoss)
			boss.draw();

		glDisable(GL_DEPTH_TEST);
		for (auto &projectile : projectiles) {
			projectile.draw();
		}
		glEnable(GL_DEPTH_TEST);

        character.draw();
		for (auto &enemy : enemies) {
			enemy.draw();
		}
		break;
	}
    case MESH:
    {
        glEnable(GL_LIGHTING);
        glPushMatrix();
		//David:
        //glRotatef(-90.0f, 0.0f, 0.0f, 1.0f);
        //glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);
		//hoofd
		//glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
		//glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
        meshes[meshIndex].drawSmooth();
        glPopMatrix();
        glDisable(GL_LIGHTING);
        break;
    }
	default:
		break;
	}
}
示例#17
0
/**
 * Animation function, only put animation code here!
 * That is to say, code that updates positioning of drawables.
 */
void animate( )
{
	int currentTime = glutGet(GLUT_ELAPSED_TIME);
	int deltaTime = currentTime - glutElapsedTime;
	glutElapsedTime = currentTime;


    LightPos[0] += 0.002;
    
	for (int i = 0; i < numberOfRidges; i++)
	{
		mountains[i].move(deltaTime);
	}
	background->move(deltaTime);
	groundfloor->move(deltaTime);


	for (auto &enemy : enemies) {
		enemy.animate(deltaTime);
	}
	for (auto &projectile : projectiles) {
		projectile.animate(deltaTime);
	}

	character.animate(deltaTime);
	character.position[0] = std::fmax(character.position[0], topLeft[0] + (character.width / 2.0f) * character.scale);
	character.position[0] = std::fmin(character.position[0], bottomRight[0] - (character.width / 2.0f) * character.scale);

	character.position[1] = std::fmin(character.position[1], topLeft[1] - (character.height / 2.0f) * character.scale);
	character.position[1] = std::fmax(character.position[1], bottomRight[1] + (character.height / 2.0f) * character.scale + 1.0);

	if (toggleBoss)
		boss.animate(deltaTime);

	collisionDetection();

    // After everything has moved, lighting should be recalculated
    computeLighting();
}
示例#18
0
文件: Boss.cpp 项目: joyfish/PlaneWar
Boss * Boss::create(const BossConfig * pConfig) {
    Boss * ret = NEW Boss(pConfig);
    ret->autorelease();
    
    return ret;
}
示例#19
0
void spawnBoss(int unusedValue)
{
	//boss = Boss(Vec3Df(6, -1, -2), -1, 0.5);
	boss.setTarget(&character.position);
	toggleBoss = true;
}
示例#20
0
Boss::Boss(const Boss &boss)
  :Employee(boss.getFirstName(), boss.getSecondName())
{
  this->setWeeklySalary(boss.getWeeklySalary());
}
示例#21
0
void drawBlobHealthShieldInfo()
{
	float healthPercent;
	float healthBar, shieldBar, oxygenBar;
	int fade;
	int y, bossX;
	String s;
	GLColor c;
	Texture *t;
	
	static GLColor darkRed = GLColor::red.darker();
	static GLColor darkYellow = GLColor::yellow.darker();
	static GLColor darkCyan = GLColor::cyan.darker();
	static GLColor darkGreen = GLColor::green.darker();
	
	y = 20;
	
	bool flashBar = ((((int)graphics->getAnimTimer()) % 100) < 50);
	bool showDanger;
	
	for (Unit *unit = (Unit*)entityManager->blobList.getFirstElement() ; unit != NULL ; unit = (Unit*)unit->next)
	{
		if ((unit->health <= -100) || (unit->definition->type == BLOB_MIA) || (!unit->showHealthData))
		{
			continue;
		}
		
		switch (unit->definition->type)
		{
			case BLOB_MIA:
			case BLOB_ASSIMILATING:
			case BLOB_SOLDIER:
				continue;
				break;
					
			default:
				break;
		}
		
		showDanger = false;
		
		fade = 35;
		
		if (unit->maxShield > 0)
		{
			fade = 40;
		}
		
		if (unit->oxygen < MAX_OXYGEN_IND)
		{
			fade = 45;
		}
		
		graphics->fade(0.5, 30, y - 5, 210, fade);
		
		s.setText("str_%s", unit->getName());
		
		if ((t = textureManager->getTexture(s.getText())) == NULL)
		{
			t = graphics->getGLString("%s", unit->getName());
			textureManager->addTexture(s.getText(), t);
		}
		
		glColor3f(1.0, 1.0, 1.0);
		graphics->blit(t, 35, y, false);
		
		healthPercent = unit->getHealthPercent();
		
		healthBar = 200;
		shieldBar = 200;
		oxygenBar = 200;
		
		healthBar /= unit->maxHealth;
		shieldBar /= unit->maxShield;
		oxygenBar /= MAX_OXYGEN;
		
		healthBar *= unit->health;
		shieldBar *= unit->shield;
		oxygenBar *= unit->oxygen;
		
		y += 16;
		
		if (healthPercent >= 75)
		{
			c = darkGreen;
		}
		else if (healthPercent >= 25)
		{
			c = darkYellow;
		}
		else
		{
			c = darkRed;
		}
		
		graphics->drawRect(35, y, 200, 8, c, true);
		
		if (unit == player)
		{
			glColor4f(1.0, 1.0, 1.0, (!game->autoLockTarget) ? 1.0 : 0.15);
			graphics->blit(textureManager->getTexture("textures/game/noTarget.png"), 120, y - 18, false);
		}
		else
		{
			glColor4f(1.0, 1.0, 1.0, 1.0);
		
			if (unit->currentCrumb != NULL)
			{
				graphics->blit(textureManager->getTexture("gfx/game/crumbFollowing.png"), 120, y - 18, false);
			}
		
			if (unit->crumbLost)
			{
				graphics->blit(textureManager->getTexture("gfx/game/crumbLost.png"), 136, y - 18, false);
			}
		}
		
		if ((unit->health > 0) && (healthPercent < 25))
		{
			if (flashBar)
			{
				graphics->drawRect(35, y, (int)healthBar, 8, c, true);
			}
			
			showDanger = true;
		}
		else if (unit->health > 0)
		{
			graphics->drawRect(35, y, (int)healthBar, 8, c, true);
		}
		
		if ((unit->flags & EF_WRAPPED) || (unit->flags & EF_ONFIRE) || (unit->flags & EF_FROZEN))
		{
			showDanger = true;
		}
		
		if (showDanger)
		{
			glColor4f(1.0, 1.0, 1.0, (flashBar) ? 1.0 : 0.5);
			graphics->blit(textureManager->getTexture("textures/game/danger.png"), 185, y - 18, false);
		}
		
		y += 10;
		
		if (unit->maxShield > 0)
		{
			graphics->drawRect(35, y, 200, 4, darkCyan, true);
			
			if (unit->shield > 0)
			{
				graphics->drawRect(35, y, (int)shieldBar, 4, GLColor::cyan, true);
			}
		}
		
		y += 6;
		
		if (unit->oxygen < MAX_OXYGEN)
		{
			graphics->drawRect(35, y, 200, 4, darkYellow, true);
			
			if (unit->oxygen > 0)
			{
				graphics->drawRect(35, y, (int)oxygenBar, 4, GLColor::yellow, true);
			}
		}
		else if (unit->oxygen != MAX_OXYGEN_IND)
		{
			graphics->drawRect(35, y, 200, 4, GLColor::yellow, true);
		}
		
		if ((unit != player) && (unit->flags & EF_VANISHED))
		{
			graphics->fade(0.75, 30, y - 37, 210, fade);
		}
		
		y += 20;
	}
	
	y = 20;
	
	for (Boss *boss = (Boss*)entityManager->bossList.getFirstElement() ; boss != NULL ; boss = (Boss*)boss->next)
	{
		if ((boss->health <= 0) || (!boss->showHealthData))
		{
			continue;
		}
		
		bossX = graphics->screen->w - 240;
		
		graphics->fade(0.5, bossX, y - 5, 210, 40);
		
		s.setText("str_%s", boss->getName());
		
		if ((t = textureManager->getTexture(s.getText())) == NULL)
		{
			t = graphics->getGLString("%s", boss->getName());
			textureManager->addTexture(s.getText(), t);
		}
		
		glColor3f(1.0, 1.0, 1.0);
		graphics->blit(t, bossX + 5, y, false);
		
		healthPercent = boss->getHealthPercent();
		
		healthBar = 200;
		shieldBar = 200;
		
		healthBar /= boss->maxHealth;
		shieldBar /= boss->maxShield;
		
		healthBar *= boss->health;
		shieldBar *= boss->shield;
		
		y += 16;
		
		if (healthPercent >= 75)
		{
			c = darkGreen;
		}
		else if (healthPercent >= 25)
		{
			c = darkYellow;
		}
		else
		{
			c = darkRed;
		}
		
		graphics->drawRect(bossX + 5, y, 200, 8, c, true);
		
		if (boss->health > 0)
		{
			graphics->drawRect(bossX + 5, y, (int)healthBar, 8, c, true);
		}
		
		y += 10;
		
		if (boss->maxShield > 0)
		{
			graphics->drawRect(bossX + 5, y, 200, 4, darkCyan, true);
			
			if (boss->shield > 0)
			{
				graphics->drawRect(bossX + 5, y, (int)shieldBar, 4, GLColor::cyan, true);
			}
		}
		
		y += 26;
	}
}
示例#22
0
void doExplosion(Vector position, int size, Entity *owner)
{
	audio->playSound(SND_GRENADE_EXPLODE, CH_EXPLODE, camera->getSoundDistance(position));
	
	addExplosionParticles(size, position);
	addExplosionMark(position, size * 2);
	
	if (game->cutsceneType != CUTSCENE_NONE)
	{
		return;
	}
	
	float distance;
	
	for (Unit *unit = (Unit*)entityManager->enemyList.getFirstElement() ; unit != NULL ; unit = (Unit*)unit->next)
	{
		if (!unit->canBeDamaged())
		{
			continue;
		}
		
		distance = Math::getDistance(unit->position, position);
		
		if (distance > (size * 4))
		{
			continue;
		}
		
		explosionHarmUnit(unit, size, (int)distance, position, owner);
	}
	
	for (Unit *unit = (Unit*)entityManager->blobList.getFirstElement() ; unit != NULL ; unit = (Unit*)unit->next)
	{
		if (!unit->canBeDamaged())
		{
			continue;
		}
		
		distance = Math::getDistance(unit->position, position);
		
		if (distance > (size * 4))
		{
			continue;
		}
		
		explosionHarmUnit(unit, size, (int)distance, position, owner);
	}
	
	float damage;
	
	for (Entity *entity = (Entity*)entityManager->structureList.getFirstElement() ; entity != NULL ; entity = (Entity*)entity->next)
	{
		if (!(entity->flags & EF_IMMORTAL))
		{
			distance = Math::getDistance(entity->position, position);
			
			damage = (size * 4);
			
			if (distance > (size * 4))
			{
				continue;
			}
			
			if (distance > (damage / 10))
			{
				for (int i = (size * 4) ; i < distance ; i++)
				{
					damage *= 0.95;
				}
			}
			
			if (damage < 1)
			{
				continue;
			}
			
			entity->health -= damage;
			
			debug(("Structure (%s) took %.2f damage from explosion\n", (entity->name != "" ? entity->getName() : "unnamed"), damage));
		}
	}
	
	Entity *oldSelf;
	
	for (Boss *boss = (Boss*)entityManager->bossList.getFirstElement() ; boss != NULL ; boss = (Boss*)boss->next)
	{
		if (boss == owner)
		{
			continue;
		}
		
		if (boss->flags & (EF_IMMORTAL|EF_VANISHED))
		{
			continue;
		}
		
		distance = Math::getDistance(boss->position, position);
		
		damage = (size * 4);
		
		if (distance > (size * 4))
		{
			continue;
		}
		
		if (distance > (damage / 10))
		{
			for (int i = (size * 4) ; i < distance ; i++)
			{
				damage *= 0.95;
			}
		}
		
		if (damage < 1)
		{
			continue;
		}
		
		oldSelf = self;
		self = boss;
		boss->reactToDamage(owner, damage);
		self = oldSelf;
		
		debug(("%s took %.2f damage from explosion\n", boss->getName(), damage));
	}
}
示例#23
0
Scene* SceneManager::generateLevel(int levelIndex, int score)
{
	if (levelIndex == 0) {
		Director* director = Director::getInstance();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create start scene
		ParallaxBackground* bckMenu = new ParallaxBackground();
		bckMenu->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckMenu->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckMenu->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0), true);
		bckMenu->scheduleUpdate();

		auto startScene = IntermediaryScene::create(IntermediaryScene::MENU);
		startScene->setBackground(bckMenu);

		// Create dummy player
		auto dummy = DummyPlayer::create();
		dummy->setPosition(Vec2(width / 2, 130));
		startScene->setPlayer(dummy);

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level0.mp3", true);

		Label* playButtonLabel = Label::createWithTTF("Play", "font.ttf", 35);
		MenuItem* playButton = MenuItemLabel::create(playButtonLabel, [&](Ref* sender){SceneManager::getInstance().fillStack();});

		Label* optionsButtonLabel = Label::createWithTTF("Options", "font.ttf", 35);
		MenuItem* optionsButton = MenuItemLabel::create(optionsButtonLabel);

		Label* exitButtonLabel = Label::createWithTTF("Exit", "font.ttf", 35);
		MenuItem* exitButton = MenuItemLabel::create(exitButtonLabel, [&](Ref* sender){Director::getInstance()->end(); });

		startScene->addMenuItem(playButton);
		startScene->addMenuItem(optionsButton);
		startScene->addMenuItem(exitButton);
		startScene->createMenu();

		return startScene;
	}
	if (levelIndex == 1) {
		Director* director = Director::getInstance();

		// Create a new GameLayer
		GameLayer* firstLevelLayer = GameLayer::create();

		// Create a background
		ParallaxBackground* bckFirstLevel = new ParallaxBackground();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create animations and bullets
		bckFirstLevel->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckFirstLevel->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckFirstLevel->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0),true);
		bckFirstLevel->scheduleUpdate();

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level1.mp3", true);

		// Create player
		Player* hero = Player::create();
		hero->setPosition(Vec2(width / 2, 130));
		hero->setTag(PLAYER_TAG);
		hero->setScore(score);

		// Create boss
		Boss* boss = Boss::create(OBJECT_FIRSTBOSS);

		BossCannon* cannon1 = BossCannon::create(OBJECT_FIRSTBOSS_CANNON_1, OBJECT_FIRSTBOSS_CANNON_1_D, OBJECT_BOSSBULLET_LASER);
		cannon1->setPosition(Vec2(123, 105));
		cannon1->setFireMethod(1, 10, 50);

		BossCannon* cannon2 = BossCannon::create(OBJECT_FIRSTBOSS_CANNON_2, OBJECT_FIRSTBOSS_CANNON_2_D, OBJECT_BOSSBULLET_SPIKEBALL);
		cannon2->setPosition(Vec2(150, 183));
		cannon2->setFireMethod(2, 10, 50);

		BossCannon* cannon3 = BossCannon::create(OBJECT_FIRSTBOSS_CANNON_3, OBJECT_FIRSTBOSS_CANNON_3_D, OBJECT_BOSSBULLET_BALL);
		cannon3->setPosition(Vec2(59, 148));
		cannon3->setFireMethod(3, 3, 50);

		boss->addCannon(1, cannon2);
		boss->addCannon(2, cannon1);
		boss->addCannon(3, cannon3);

		// Create Interactive object factory
		InteractiveObjectFactory* mailboxFactory = InteractiveObjectFactory::create(OBJECT_MAILBOX, director->getWinSize().height * 1.6 / 800, false, MAILBOX_COLLISION_BITMASK, true, false, true);
		mailboxFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		mailboxFactory->setSpawnFrequency(5);
		mailboxFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		InteractiveObjectFactory* rocketFactory = InteractiveObjectFactory::create(OBJECT_ROCKET, director->getWinSize().height * 1.6 / 800, false, ROCKET_COLLISION_BITMASK, true, false, false);
		rocketFactory->setPositionInterval(Vec2(100, height));
		rocketFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 25.0 / 800), 0));
		rocketFactory->setSpawnFrequency(20);

		InteractiveObjectFactory* spikesFactory = InteractiveObjectFactory::create(OBJECT_SPIKES, director->getWinSize().height * 0.5 / 800, false, SPIKES_COLLISION_BITMASK, false, true, true);
		spikesFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		spikesFactory->setSpawnFrequency(5);
		spikesFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));


		firstLevelLayer->setBackground(bckFirstLevel);
		firstLevelLayer->setPlayer(hero);
		firstLevelLayer->setBoss(boss);
		firstLevelLayer->setDistanceToBoss(1000);
		firstLevelLayer->addObjectFactory(mailboxFactory);
		firstLevelLayer->addObjectFactory(rocketFactory);
		firstLevelLayer->addObjectFactory(spikesFactory);

		//Create Scene
		GameLevel* firstLevel = GameLevel::create(firstLevelLayer);

		return firstLevel;
	}
	if (levelIndex == 2)
	{
		Director* director = Director::getInstance();

		// Create a new GameLayer
		GameLayer* secondLevelLayer = GameLayer::create();

		// Create a background
		ParallaxBackground* bckSecondLevel = new ParallaxBackground();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create animations and bullets
		bckSecondLevel->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckSecondLevel->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckSecondLevel->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0), true);
		bckSecondLevel->scheduleUpdate();

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level2.mp3", true);

		// Create player
		Player* hero = Player::create();
		hero->setPosition(Vec2(width / 2, 130));
		hero->setTag(PLAYER_TAG);
		hero->setScore(score);

		// Create boss
		Boss* boss = Boss::create(OBJECT_SECONDBOSS,true);

		BossCannon* cannon1 = BossCannon::create(OBJECT_SECONDBOSS_CANNON_1, OBJECT_SECONDBOSS_CANNON_1_D, OBJECT_BOSSBULLET_ENERGYBALL);
		cannon1->setPosition(Vec2(85, 38));
		cannon1->setFireMethod(1, 10, 50);

		BossCannon* cannon2 = BossCannon::create(OBJECT_SECONDBOSS_CANNON_2, OBJECT_SECONDBOSS_CANNON_2_D, OBJECT_BOSSBULLET_SAWBLADE);
		cannon2->setPosition(Vec2(34, 137));
		cannon2->setFireMethod(2, 10, 50);

		BossCannon* cannon3 = BossCannon::create(OBJECT_SECONDBOSS_CANNON_3, OBJECT_SECONDBOSS_CANNON_3_D, OBJECT_BOSSBULLET_FLAMEBALL);
		cannon3->setPosition(Vec2(20, 135));
		cannon3->setFireMethod(3, 3, 50);

		boss->addCannon(1, cannon1);
		boss->addCannon(2, cannon2);
		boss->addCannon(3, cannon3);

		// Create Interactive object factory
		InteractiveObjectFactory* mailboxFactory = InteractiveObjectFactory::create(OBJECT_MAILBOX, director->getWinSize().height * 1.6 / 800, false, MAILBOX_COLLISION_BITMASK, true, false, true);
		mailboxFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		mailboxFactory->setSpawnFrequency(5);
		mailboxFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		InteractiveObjectFactory* rocketFactory = InteractiveObjectFactory::create(OBJECT_ROCKET, director->getWinSize().height * 1.6 / 800, false, ROCKET_COLLISION_BITMASK, true, false, false);
		rocketFactory->setPositionInterval(Vec2(100, height));
		rocketFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 25.0 / 800), 0));
		rocketFactory->setSpawnFrequency(20);

		InteractiveObjectFactory* spikesFactory = InteractiveObjectFactory::create(OBJECT_SPIKES, director->getWinSize().height * 0.5 / 800, false, SPIKES_COLLISION_BITMASK, false, true, true);
		spikesFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		spikesFactory->setSpawnFrequency(5);
		spikesFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));


		secondLevelLayer->setBackground(bckSecondLevel);
		secondLevelLayer->setPlayer(hero);
		secondLevelLayer->setBoss(boss);
		secondLevelLayer->setDistanceToBoss(100);
		secondLevelLayer->addObjectFactory(mailboxFactory);
		secondLevelLayer->addObjectFactory(rocketFactory);
		secondLevelLayer->addObjectFactory(spikesFactory);

		//Create Scene
		GameLevel* firstLevel = GameLevel::create(secondLevelLayer);

		return firstLevel;
	}
	if (levelIndex == 3)
	{
		Director* director = Director::getInstance();

		// Create a new GameLayer
		GameLayer* thirdLevelLayer = GameLayer::create();

		// Create a background
		ParallaxBackground* bckThirdLevel = new ParallaxBackground();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create animations and bullets
		bckThirdLevel->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckThirdLevel->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckThirdLevel->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0), true);
		bckThirdLevel->scheduleUpdate();

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level3.mp3", true);

		// Create player
		Player* hero = Player::create();
		hero->setPosition(Vec2(width / 2, 130));
		hero->setTag(PLAYER_TAG);
		hero->setScore(score);

		// Create boss
		Boss* boss = Boss::create(OBJECT_THIRDBOSS);

		BossCannon* cannon1 = BossCannon::create(OBJECT_THIRDBOSS_CANNON_1, OBJECT_THIRDBOSS_CANNON_1_D, OBJECT_BOSSBULLET_BOMB);
		cannon1->setPosition(Vec2(68, 218));
		cannon1->setFireMethod(2, 10, 10);

		BossCannon* cannon2 = BossCannon::create(OBJECT_THIRDBOSS_CANNON_2, OBJECT_THIRDBOSS_CANNON_2_D, OBJECT_BOSSBULLET_RASENGAN);
		cannon2->setPosition(Vec2(28, 148));
		cannon2->setFireMethod(3, 1, 10);

		boss->addCannon(1, cannon1);
		boss->addCannon(2, cannon2);

		// Create Interactive object factory
		InteractiveObjectFactory* mailboxFactory = InteractiveObjectFactory::create(OBJECT_MAILBOX, director->getWinSize().height * 1.6 / 800, false, MAILBOX_COLLISION_BITMASK, true, false, true);
		mailboxFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		mailboxFactory->setSpawnFrequency(5);
		mailboxFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		InteractiveObjectFactory* rocketFactory = InteractiveObjectFactory::create(OBJECT_ROCKET, director->getWinSize().height * 1.6 / 800, false, ROCKET_COLLISION_BITMASK, true, false, false);
		rocketFactory->setPositionInterval(Vec2(100, height));
		rocketFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 25.0 / 800), 0));
		rocketFactory->setSpawnFrequency(20);

		InteractiveObjectFactory* spikesFactory = InteractiveObjectFactory::create(OBJECT_SPIKES, director->getWinSize().height * 0.5 / 800, false, SPIKES_COLLISION_BITMASK, false, true, true);
		spikesFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		spikesFactory->setSpawnFrequency(5);
		spikesFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		thirdLevelLayer->setBackground(bckThirdLevel);
		thirdLevelLayer->setPlayer(hero);
		thirdLevelLayer->setBoss(boss);
		thirdLevelLayer->setDistanceToBoss(1000);
		thirdLevelLayer->addObjectFactory(mailboxFactory);
		thirdLevelLayer->addObjectFactory(rocketFactory);
		thirdLevelLayer->addObjectFactory(spikesFactory);

		//Create Scene
		GameLevel* firstLevel = GameLevel::create(thirdLevelLayer);

		return firstLevel;
	}

	return nullptr;
}
示例#24
0
文件: datatables.cpp 项目: Lo-X/ld32
std::vector<std::vector<Phase>> initializeBossPhases(World &world, Boss &boss)
{
    std::vector<std::vector<Phase>> data(Boss::TypeCount);

    // Welcome to one of the most un-readable code I've ever made :

    // Boss1 Phase1
    Phase b1p1(world, boss, sf::seconds(5.f));
    b1p1.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time){
        Player* player = world.getPlayerEntity();
        //world.shakeCameraFor(0.3f);
        boss.unsensible();
        if((b.getPosition().x-player->getPosition().x) > 40) {
            boss.move(Entity::Left);
        } else if((b.getPosition().x-player->getPosition().x) < 40) {
            boss.move(Entity::Right);
        } else {
            //boss.knock();
        }
    });
    data[Boss::Boss1].push_back(b1p1);
    // Boss1 Phase2
    Phase b1p2(world, boss, sf::seconds(3.f));
    b1p2.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time){
        b.sensible();
    });
    data[Boss::Boss1].push_back(b1p2);
    // Boss1 Phase3
    Phase b1p3(world, boss, sf::seconds(1.f));
    b1p3.addSkill(sf::seconds(0.9f), [&](Boss& b, sf::Time dt){
        if(randomInt(0,5) == 1) world.addMedkit(sf::Vector2f(randomFloat(10, 1270), 20));
    });
    data[Boss::Boss1].push_back(b1p3);
    // Boss1 Phase4
    Phase b1p4(world, boss, sf::seconds(1.f));
    b1p4.addSkill(sf::seconds(0.9f), [&](Boss& b, sf::Time dt){
        Player* player = world.getPlayerEntity();
        auto pos = player->getPosition();
        //world.addZombie(sf::Vector2f(pos.x, 100.f));
        //world.addZombie(sf::Vector2f(pos.x+50.f, 100.f));
        world.addZombie(sf::Vector2f(randomFloat(10, 1270), 100.f));
        b.playLocalSound(world.getCommandQueue(), Sounds::Boss1AddPop);
    });
    data[Boss::Boss1].push_back(b1p4);

    //////////////////////////////////////////////

    /*// Boss2 Phase2
    Phase b2p2(world, boss, sf::seconds(2.f));
    b2p2.addSkill(sf::seconds(0.90f), [&](Boss&, sf::Time){
    });
    data[Entity::Boss2].push_back(b2p2);
    // Boss2 Phase1
    Phase b2p1(world, boss, sf::seconds(1.2f));
    b2p1.addSkill(sf::seconds(0.5f), [&](Boss& b, sf::Time){
        PlayerEntity* player = world.player();
        if((b.getPosition().x-player->getPosition().x) > 0) {
            world.addCreature(2, 50.f);
        } else {
            world.addCreature(2, -50.f);
        }
    });
    data[Entity::Boss2].push_back(b2p1);
    // Boss2 Phase2
    data[Entity::Boss2].push_back(b2p2);
    data[Entity::Boss2].push_back(b2p1);
    data[Entity::Boss2].push_back(b2p2);
    data[Entity::Boss2].push_back(b2p1);
    // Boss1 Phase4
    Phase b2p3(world, boss, sf::seconds(0.f));
    b2p3.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time dt){
        PlayerEntity* player = world.player();
        if(b.getPosition().x < 512) {
            for(unsigned int i = 0; i < 5; ++i)
            {
                world.addCreature(2, 50.f + i*32.f);
            }
            world.addCreature(1, 380.f);
        } else {
            for(unsigned int i = 0; i < 5; ++i)
            {
                world.addCreature(2, -50.f - i*32.f);
            }
            world.addCreature(1, -380.f);
        }
    });
    data[Entity::Boss2].push_back(b2p3);
    // Boss2 Phase4
    Phase b2p4(world, boss, sf::seconds(4.f));
    b2p4.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time){
        PlayerEntity* player = world.player();
        if((b.getPosition().x-player->getPosition().x) > 0) {
            boss.move(Entity::Left);
        } else {
            boss.move(Entity::Right);
        }
    });
    data[Entity::Boss2].push_back(b2p4);
    // Boss2 Phase5
    Phase b2p5(world, boss, sf::seconds(2.f));
    b2p5.addSkill(sf::seconds(0.90f), [&](Boss& b, sf::Time){
        b.knock();
    });
    data[Entity::Boss2].push_back(b2p5);
    // Boss2 Phase6
    Phase b2p6(world, boss, sf::seconds(0.0f));
    b2p6.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time){
        PlayerEntity* player = world.player();
        if((b.getPosition().x-player->getPosition().x) > 0) {
            world.addCreature(3, 50.f);
        } else {
            world.addCreature(3, -50.f);
        }
    });
    data[Entity::Boss2].push_back(b2p6);
    // Boss2 Phase7
    Phase b2p7(world, boss, sf::seconds(4.1f));
    b2p7.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time){
        PlayerEntity* player = world.player();
        if((b.getPosition().x-player->getPosition().x) > 0) {
            boss.move(Entity::Right);
        } else {
            boss.move(Entity::Left);
        }
    });
    data[Entity::Boss2].push_back(b2p7);

    //////////////////////////////////////////////

    // Boss3 Phase1
    Phase b3p1(world, boss, sf::seconds(0.6f));
    b3p1.addSkill(sf::seconds(0.5f), [&](Boss& b, sf::Time){
        for(unsigned int i = 0; i < 6; ++i)
        {
            world.addCreature(3, 50.f + 150.f*i);
            world.addCreature(3, -50.f - 150.f*i);
        }
    });
    data[Entity::Boss3].push_back(b3p1);
    Phase b3p2(world, boss, sf::seconds(5.f));
    b3p2.addSkill(sf::seconds(0.90f), [&](Boss& b, sf::Time){b.knock();});
    data[Entity::Boss3].push_back(b3p2);
    // Boss1 Phase1
    Phase b3p3(world, boss, sf::seconds(5.f));
    b3p3.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time){
        PlayerEntity* player = world.player();
        world.shakeCameraFor(0.3f);
        if((b.getPosition().x-player->getPosition().x) > 0) {
            boss.move(Entity::Left);
        } else {
            boss.move(Entity::Right);
        }
    });
    data[Entity::Boss3].push_back(b3p3);
    data[Entity::Boss3].push_back(b3p1);
    // Boss1 Phase4
    Phase b3p4(world, boss, sf::seconds(3.f));
    b3p4.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time){
        b.knock();
    });
    data[Entity::Boss3].push_back(b3p4);
    // Boss3 Phase5
    Phase b3p5(world, boss, sf::seconds(2.f));
    b3p5.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time dt){
        b.setPosition(sf::Vector2f(b.getPosition().x, b.getPosition().y-500*dt.asSeconds()));
    });
    data[Entity::Boss3].push_back(b3p5);
    data[Entity::Boss3].push_back(b3p2);
    // Boss3 Phase6
    Phase b3p6(world, boss, sf::seconds(0.0f));
    b3p6.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time dt){
        PlayerEntity* player = world.player();
        b.setPosition(sf::Vector2f(player->getPosition().x, -160));
        world.addCreature(1, 50);
    });
    data[Entity::Boss3].push_back(b3p6);
    Phase b3p6bis(world, boss, sf::seconds(1.5f));
    b3p6bis.addSkill(sf::seconds(0.90f), [&](Boss& b, sf::Time){b.knock();});
    data[Entity::Boss3].push_back(b3p6bis);
    // Boss3 Phase7
    Phase b3p7(world, boss, sf::seconds(1.3f));
    b3p7.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time dt){
        if(b.getPosition().y < 512-105)
        {
            b.setPosition(sf::Vector2f(b.getPosition().x, b.getPosition().y+500*dt.asSeconds()));
        }
        else
        {
            world.shakeCamera();
            b.playLocalSound(world.getCommandQueue(), Sounds::BossCrush);
        }
    });
    data[Entity::Boss3].push_back(b3p7);
    data[Entity::Boss3].push_back(b3p1);
    // Boss3 Phase8
    data[Entity::Boss3].push_back(b3p5);
    data[Entity::Boss3].push_back(b3p6);
    data[Entity::Boss3].push_back(b3p6bis);
    data[Entity::Boss3].push_back(b3p7);
    data[Entity::Boss3].push_back(b3p1);
    data[Entity::Boss3].push_back(b3p5);
    // Boss3 Phase9
    Phase b3p9(world, boss, sf::seconds(1.5f));
    b3p9.addSkill(sf::seconds(0.f), [&](Boss& b, sf::Time dt){
        b.setPosition(1024+160, 512-105);
    });
    data[Entity::Boss3].push_back(b3p9);*/

    return data;
}
示例#25
0
int main()
{
	// options of pokemon to choose from
	string Mewtow;
	string Gastly;
	string Rhyhorn;
	string Pikachu;
	string Venomoth;

	string player1; // the pokemon the user chose


	cout << "Hello, are you ready to battle?" << endl;
	cout << "If so, please select a Pokemon you wish to take into battle." << endl;
	cout << endl;
	cout << "Mewtow" << endl;
	cout << "Gastly" << endl;
	cout << "Rhyhorn" << endl;
	cout << "Pikachu" << endl;
	cout << "Venomoth" << endl;
	cout << endl;
	cin >> player1;

	cout << "You selected " << player1 << endl;

	Pokemon p; // declares a pokemon object
	Boss b; // declare boss object
	srand(time(NULL));
	int a = rand() % 1;
	if ((a = 0)) // picks which boss pokemon will be battling
		cout << "and you will be battling Persian!" << endl;
	else
		cout << "and you will be battling Tauros!" << endl;

	cout << endl;

	cout << player1 << " is starting with a health of 300, " <<
		"while the enemy has 400." << endl;
	
	int hp = p.getHealth(), enemyhp = b.getHealth(), attack = p.getAttackPower(), enemyattack = b.getAttackPower();

	int x;

	do
	{
		// ask user if they would like to attack ant then show the impact the attack had on the boss
		cout << "Attack? 1-Yes or 2-No" << endl;
		cin >> x;
		if (x == 1)
		{
			int y;
			cout << "Do you want to: 1-Kick, 2-Punch, 3-Special Power" << endl;
			cin >> y;
			if (y == 1)
			{
				cout << "You kicked the Boss and now he has " << b.showEnemyHp(enemyhp, attack) << "HP left." << endl;
				enemyhp = b.showEnemyHp(enemyhp, attack);
				if (enemyhp == 0) // cout bosses hp and say player wins if it equals 0 or below
				{
					cout << "Congratulations! You beat the Boss!" << endl;
				}
			}
			else if (y == 2)
			{
				cout << "You Punched the Boss and now he has " << b.showEnemyHp(enemyhp, attack) << "HP left." << endl;
				enemyhp = b.showEnemyHp(enemyhp, attack);
				if (enemyhp == 0) // cout bosses hp and say player wins if it equals 0 or below
				{
					cout << "Congratulations! You beat the Boss!" << endl;
				}
			}
			else if (y == 3)
			{
				cout << "You used your Special Power on the Boss and now he has " << b.showEnemyHp(enemyhp, attack) << "HP left." << endl;

				enemyhp = b.showEnemyHp(enemyhp, attack);
				if (enemyhp == 0) // cout bosses hp and say player wins if it equals 0 or below
				{
					cout << "Congratulations! You beat the Boss!" << endl;
				}
			}
			else
			{
				cout << "That is not a valid choice." << endl;
			}
			cout << endl;

			cout << "The Boss hit you back.\n";
			cout << "You now have " << p.showHp(hp, enemyattack) << "HP left.\n\n";
			hp = p.showHp(hp, enemyattack); // declaring hp as the showing of the players health
			if (hp == 0) // determines if player has died or not
			{
				cout << "Oh no you died! Bummer." << endl;
			}
		}
		else if (x == 2)
		{
			cout << "You chose not to hit and was attacked.";
			cout << "You now have " << hp << "HP left.\n\n";
			if (hp == 0) // determines if player has died or not
			{
				cout << "Oh no you died! Bummer." << endl;
			}
		}
		else
		{
			cout << "That is not a valid choice.\n\n";

		}



	} while (hp > 0 && enemyhp > 0); // continue looping until one of the players have died