Example #1
0
	void resetBall() {
		FloatRect p = player.getGlobalBounds();
		FloatRect b = ball.getGlobalBounds();
		ball.setPosition(p.left + p.width/2 + 5, p.top);
		ballSpeed.x = 0.1f;
		ballSpeed.y = -0.3f;
	}
Example #2
0
/*
Determine si le bouton de la boite de dialogue selectionné par le clic
de la souris est celui d'annulation.
*/
bool MainTool::isCancelClicked(int x, int y)
{
	Text ok;
	ok.setFont(font);
	ok.setString("Sauver");
	ok.setCharacterSize(12);
	FloatRect fro = ok.getLocalBounds();

	Text cancel;
	cancel.setFont(font);
	cancel.setString("Annuler");
	cancel.setCharacterSize(12);
	FloatRect frc = cancel.getLocalBounds();

	cancel.setPosition((400 - 40 - fro.width - frc.width) / 2 + 30 + fro.width, 70);

	RectangleShape buttonCancel;
	buttonCancel.setSize(Vector2f(frc.width + 10, frc.height + 10));
	buttonCancel.setPosition(cancel.getPosition().x - 5, cancel.getPosition().y);

	if (buttonCancel.getGlobalBounds().contains(x, y))
		return true;
	else
		return false;
}
Example #3
0
void Game::interfejs(float hp, float bullets, Text &h, Text &b, Vector2f poz, float magazynek, int runda, Text &round, int ile_zombii, Text &licznik_zombie, Text &gun_name, string gun, RectangleShape &sprint, bool isSprint, Time czas)
{
	h.setString("hp: "+to_string((int)hp));
	b.setString("bullets: "+to_string((int)magazynek)+" / " +to_string((int)bullets));
	h.setPosition(poz.x + 1280 / 2-80, poz.y - 360+20);
	b.setPosition(poz.x + 1280 / 2 - 265, poz.y + 360 - 40);
	gun_name.setString(gun);
	gun_name.setPosition(poz.x + 1280 / 2 - 265, poz.y + 360 - 80);
	round.setString("round: " + to_string(runda));
	round.setPosition(poz.x - 1280 / 2 + 10, poz.y + 360 - 40);
	licznik_zombie.setString("zombies left to kill: " + to_string(ile_zombii));
	licznik_zombie.setPosition(poz.x - 1280 / 2 +10 , poz.y - 360 + 20);
	sprint.setPosition(poz.x + 1280 / 2 - 90, poz.y - 360 + 70);
	if(isSprint && sprint.getSize().x >0)
	sprint.setSize(Vector2f(sprint.getGlobalBounds().width -(15.0f*czas.asSeconds()), sprint.getGlobalBounds().height ));
	else
	{
		if(sprint.getSize().x <= 15*5)sprint.setSize(Vector2f(sprint.getGlobalBounds().width + (7.5f*0.5f*czas.asSeconds()), sprint.getGlobalBounds().height));
	}
}
Example #4
0
	void checkCollisions() {
		if (intersects(player, left) || intersects(player, right)) {
			FloatRect l = left.getGlobalBounds();
			FloatRect r = right.getGlobalBounds();
			Vector2f p = player.getPosition();
			p.x = clamp(p.x, l.left + l.width + 5, r.left - player.getGlobalBounds().width - 5);
			player.setPosition(p);
			blap.play();
		}

		if (intersects(ball, top)) {
			FloatRect t = top.getGlobalBounds();
			FloatRect b = ball.getGlobalBounds();
			ballSpeed.y = abs(ballSpeed.y);
			int u = t.top + t.height - b.top;
			ball.move(0, 2*u);
			blop.play();
		}

		if (intersects(ball, left)) {
			FloatRect l = left.getGlobalBounds();
			FloatRect b = ball.getGlobalBounds();
			ballSpeed.x = abs(ballSpeed.x);
			int u = l.left + l.width - b.left;
			b.left = l.left + l.width + u;
			ball.setPosition(b.left, b.top);
			blop.play();
		}

		if (intersects(ball, right)) {
			FloatRect r = right.getGlobalBounds();
			FloatRect b = ball.getGlobalBounds();
			ballSpeed.x = -abs(ballSpeed.x);
			int u = b.left + b.width - r.left;
			b.left = r.left - b.width - u;
			ball.setPosition(b.left, b.top);
			blop.play();
		}

		if (intersects(ball, bottom)) {
			blam.play();
			playerLives--;
			stringstream str;
			str<<playerLives;
			lives.setString(str.str());
			lives.setPosition(width/2 - lives.getGlobalBounds().width/2, height - 60);
			resetBall();
		}

		if (intersects(ball, player)) {
			FloatRect p = player.getGlobalBounds();
			FloatRect b = ball.getGlobalBounds();

			Vector2f o(p.left + p.width/2, p.top + p.height/2);
			Vector2f om(b.left + p.width/2 - o.x, b.top + b.width/2 - o.y);
			om.x /= p.width;
			om.y /= p.height;
			float angle = atan2(om.y, om.x);
			if (angle <= -PI/4 && angle >= -3*PI/4) {
				ballSpeed.y = -abs(ballSpeed.y);
				ballSpeed.x = (b.left + b.width/2 - p.left - p.width/2) / 200;
				int u = b.top + b.height - p.top;
				b.top = p.top - b.height - u;
				ball.setPosition(b.left, b.top);
				ballSpeed.x *= 1.02f;
				ballSpeed.y *= 1.02f;
				blip.play();
			}
		}

		if (grid.collide(ball, ballSpeed, playerScore)) {
			blap.play();
			playerScore += 200;
			stringstream str;
			str<<playerScore<<" pts ";
			score.setString(str.str());
			score.setPosition(width/2 + score.getGlobalBounds().width/2 - margin, height - 60);
		}

		if (grid.isGameWon())
			gameState = GAME_WON;
		if (playerLives <= 0)
			gameState = GAME_LOST;
	}