コード例 #1
0
ファイル: bre.cpp プロジェクト: NotNallath/iMvaders
void BreEnemyHud::render(sf::RenderTarget& window)
{
    if (!owner)
        return;

    sf::RectangleShape healthBarBG(sf::Vector2f(280, 10));
    healthBarBG.setFillColor(sf::Color::Transparent);
    healthBarBG.setOutlineColor(sf::Color(128, 128, 128, 128));
    healthBarBG.setOutlineThickness(1);
    healthBarBG.setPosition(20, 10);
    window.draw(healthBarBG);

    sf::RectangleShape healthBar(sf::Vector2f(280 * owner->health / BreEnemy::maxHealth, 10));
    healthBar.setFillColor(sf::Color(212, 0, 0, 128));
    healthBar.setPosition(20, 10);
    window.draw(healthBar);
    
    if (owner->difficulty > 2)
    {
        sf::RectangleShape shieldBarBG(sf::Vector2f(280, 8));
        shieldBarBG.setFillColor(sf::Color::Transparent);
        shieldBarBG.setOutlineColor(sf::Color(128, 128, 128, 128));
        shieldBarBG.setOutlineThickness(1);
        shieldBarBG.setPosition(20, 25);
        window.draw(shieldBarBG);

        sf::RectangleShape shieldBar(sf::Vector2f(280 * owner->shieldStrength / BreEnemy::maxShieldStrength, 8));
        shieldBar.setFillColor(sf::Color(100, 100, 212, 192));
        shieldBar.setPosition(20, 25);
        window.draw(shieldBar);
        
        if (owner->shieldStrength < BreEnemy::maxShieldStrength)
        {
            sf::RectangleShape shieldCharge(sf::Vector2f(280 * owner->shieldCharge / BreEnemy::shieldChargeTime, 3));
            shieldCharge.setFillColor(sf::Color(100, 100, 212, 192));
            shieldCharge.setPosition(20, 30);
            window.draw(shieldCharge);
        }
    }
}
コード例 #2
0
ファイル: game.c プロジェクト: ljg6/MyGame2D
int levelTwo()
{
	

	moving = 0;
	SDL_RenderClear(gt_graphics_get_active_renderer());
	ResetBuffer();

	backOffset = ((int)camera.x+3200)%3200;
	offset = ((int)camera.x+1600)%1600;

	drawSprite(moonBack,0,vec2d(0,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	
	drawSprite(levelTwoBackTrees,0,vec2d(-backOffset,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
    drawSprite(levelTwoFrontTrees,0,vec2d(-offset,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	drawSprite(levelTwoFloor,0,vec2d(-offset,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	
	drawSprite(levelTwoFrontTrees,0,vec2d(-offset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	drawSprite(levelTwoBackTrees,0,vec2d(-backOffset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer());
	drawSprite(levelTwoFloor,0,vec2d(-offset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer());

	



	entity_think_all();
	entity_touch_all();
	entity_update_all();
	entity_draw_all();
	if(player->position.x >= 300)
		{
			camera.x = player->position.x - 300;
			
		}
	if(player->position.x < 300)
		{
			camera.x = 0;
			
		}
	if(xDistance == 12000.00)
	{
		done = 1;
	}

	healthBar();
    NextFrame();
    SDL_PumpEvents();
	diff = (gt_graphics_now - gt_graphics_then);
	
	if(playerData.shotTimer>0)
	{
		playerData.shotTimer -= diff;
	}
    keys = SDL_GetKeyboardState(NULL);
    if(keys[SDL_SCANCODE_ESCAPE])
    {
        done = 1;
    }
	else if(keys[SDL_SCANCODE_W])
	{
		moving = 1;
		moveCharacter(DIR_UP,player);
		yDistance = player->position.y;
	}
	else if(keys[SDL_SCANCODE_A])
	{
		moving = 1;
		moveCharacter(DIR_LEFT,player);
		xDistance = player->position.x;
	}
	else if(keys[SDL_SCANCODE_D])
	{
		moving = 1;
		moveCharacter(DIR_RIGHT,player);
		xDistance = player->position.x;
		
	}
	else if(keys[SDL_SCANCODE_S])
	{
		moving = 1;
		moveCharacter(DIR_DOWN,player);
		yDistance = player->position.y;
	}
	else if(keys[SDL_SCANCODE_1])
	{
		fire_Pistol();
	}
	else if(keys[SDL_SCANCODE_2])
	{
		fire_Shotgun();
	}
	else if(keys[SDL_SCANCODE_3])
	{
		fire_Machinegun();
	}
	else if(keys[SDL_SCANCODE_4])
	{
		fire_Heavy_Machinegun();
	}
	else if(keys[SDL_SCANCODE_P])
	{
		saveState();
	}
	else if(keys[SDL_SCANCODE_O])
	{
		loadState();
	}
	if(moving == 0)
	{
		resetAnimation(player, 0);
	}


	
  
  return 0;
}
コード例 #3
0
void Game::paintEvent(QPaintEvent *event)
{
	if(gameStarted)
	{
		///*** Setup Painter ***///
		QPainter painter(this);
		QBrush normal(painter.brush());
		QBrush manaBar(Qt::blue,Qt::SolidPattern);
		QBrush healthBar(Qt::green,Qt::SolidPattern);
		
		///*** Prevent painter from drawing if the game is over ***///
		if (gameOver) 
		{
			painter.end();
			QPainter painter(this);
		
			QFont font("Courier", 15, QFont::DemiBold);
			QFontMetrics fm(font);
			int textWidth = fm.width("Game Over!");
			int textWidth2 = fm.width("Press ESC to close window");

			painter.setFont(font);

			painter.translate(QPoint(400, 300));
			painter.drawText(-textWidth/2, 0, "Game Over!");
			painter.drawText(-textWidth2/2, 15, "Press ESC to close window");
			killTimer(timerId);
			std::cout << "BLAHBLAHBLAH\n";
		}
	
		///*** Draw Player ***///
		if(player->getType() == TANK)
		{
			if(player->getCanAttack())
				painter.drawImage(player->getLocation().x()-9,player->getLocation().y()-5,player->getAttackFrame());
			if(player->getAttacking())
				painter.drawImage(player->getLocation().x()-10,player->getLocation().y()-10,player->getManaAttackFrame());
		} else if(player->getType() == ASSN) {
			if(player->getCanAttack())
			{
				painter.drawImage(player->getLocation().x()-20,player->getLocation().y()-17,player->getAttackFrame());
			}
			if(player->bombSet)
				painter.drawImage(player->bomb->getLocation().x()-20,player->bomb->getLocation().y()-17,player->getManaAttackFrame());
		}
	
		///*** Draw Enemies ***///
		for(int i=0;i<drones.size();i++)
		{
			painter.setBrush(healthBar);
			painter.drawRect(drones.at(i)->getLocation().x()-15,drones.at(i)->getLocation().y()-20,drones.at(i)->getHealth(), 4);
			painter.setBrush(normal);
			painter.drawImage(drones.at(i)->getLocation().x()-15,drones.at(i)->getLocation().y()-15,drones.at(i)->getAttackFrame());
		}
		if(canSpawnArcher)
		{
			for(int i=0;i<archers.size();i++)
			{
				painter.setBrush(normal);
				painter.drawImage(archers.at(i)->getLocation().x()-15,archers.at(i)->getLocation().y()-15,archers.at(i)->getAttackFrame());
				if(archers.at(i)->getAttacking())
				{
					painter.setBrush(manaBar);
					painter.drawEllipse(archers.at(i)->bullet->getLocation().x(),archers.at(i)->bullet->getLocation().y(),10,10);

				}
			}
		}
	
		///*** Draw Status Bars ***///
		painter.setBrush(healthBar);
		painter.drawRect(5,5,player->getHealth(),10);
		painter.setBrush(normal);
		painter.drawRect(5,5,player->getMaxHealth(),10);
		painter.setBrush(manaBar);
		painter.drawRect(5,20,player->getMana(),10);
		painter.setBrush(normal);
		painter.drawRect(5,20,player->getMaxMana(),10);
	
		///*** Give player tips at appropriate levels ***///
		if (player->getXP() < 1) 
		{
			if(player->getType() == TANK)
			{	
				QFont font("Courier", 15, QFont::DemiBold);
				QFontMetrics fm(font);
				int textWidth = fm.width("Left Click to 'Enrage', then run into an enemy!");

				painter.setFont(font);

				painter.translate(QPoint(400, 300));
				painter.drawText(-textWidth/2, 0, "Left Click to 'Enrage', then run into an enemy!");
			}
			else if(player->getType() == ASSN)
			{	
				QFont font("Courier", 15, QFont::DemiBold);
				QFontMetrics fm(font);
				int textWidth = fm.width("Left Click to Slash enemies, but don't get too close!");

				painter.setFont(font);

				painter.translate(QPoint(400, 300));
				painter.drawText(-textWidth/2, 0, "Left Click to Slash enemies, but don't get too close!");
			}
		}
		if (player->getXP() == 5) 
		{
			QFont font("Courier", 15, QFont::DemiBold);
			QFontMetrics fm(font);
			int textWidth = fm.width("Level Up!\nRight Click for New Skill");

			painter.setFont(font);

			painter.translate(QPoint(400, 300));
			painter.drawText(-textWidth/2, 0, "Level Up! Right Click for New Skill");
			level=2;
			emit levelChanged(level);
			canSpawnArcher = true;
		}
		if (player->getXP() == 10)
		{
			QFont font("Courier", 15, QFont::DemiBold);
			QFontMetrics fm(font);
			int textWidth = fm.width("Level Up!");

			painter.setFont(font);

			painter.translate(QPoint(400, 300));
			painter.drawText(-textWidth/2, 0, "Level Up!");
			canSpawnArcher = true;
			level=3;
			emit levelChanged(level);
		}
	}
}