Beispiel #1
0
void Toolbar::drawBar(RenderWindow & window)
{
    int width = TILE_SIZE*(drawTools.size()+ mainTools.size()) + 40 + 5 * (drawTools.size() - 1);

    //build framework
    RectangleShape framework;
    framework.setPosition((window.getSize().x - width) / 2, 0);
    framework.setSize(Vector2f(width, TILE_SIZE+10));
    framework.setFillColor(Color(140,140,140,255));
    window.draw(framework);

    //Add tools
    for (int i = 0; i < drawTools.size()+mainTools.size(); i++)
    {
        if (i < drawTools.size())
        {
            drawTools[i]->setPosition(framework.getPosition().x + 10 + (TILE_SIZE + 5)*i, 5);
            window.draw(*drawTools[i]);
        }
        else
        {
            mainTools[i- drawTools.size()]->setPosition(framework.getPosition().x + 30 + (TILE_SIZE + 5)*i, 5);
            window.draw(*mainTools[i - drawTools.size()]);
        }
    }
}
Beispiel #2
0
//Точка входит в квадрат?
bool Check(RectangleShape rect, CircleShape shape){
	Vector2f coordrect = rect.getPosition();
	Vector2f coordshape = shape.getPosition();

	if (coordrect.x <= coordshape.x &&
		coordrect.y <= coordshape.y &&
		coordrect.x + rect.getSize().x >= coordshape.x &&
		coordrect.y + rect.getSize().y >= coordshape.y)
	{
		return true;
	}
	else { return false; }
}
Beispiel #3
0
	Player(int player, float x, float y){
		// == Создание игрока ==
		rectangle.setPosition(Vector2f(x, y));		//Позиция игрока
		this->player = player;						//ID игрока
		rectangle.setSize(Vector2f(20, 20));		//Размер
		rectangle.setFillColor(Color::Green);		//Цвет

		// == Создание пушки ==
		Vector2f centerTank = { 0, 0 };
		centerTank.x = rectangle.getPosition().x + (rectangle.getSize().x / 2);	//Центр танка по x
		centerTank.y = rectangle.getPosition().y + (rectangle.getSize().y / 2);	//Центр танка по y

		turret.setPrimitiveType(LinesStrip);

		turret.append(centerTank);	//Начало пушки из танка
		centerTank.y -= 25;
		turret.append(centerTank);	//Смещение по y на 10
	};
Beispiel #4
0
 float x() const noexcept { return shape.getPosition().x; }
Beispiel #5
0
 float x() { return shape.getPosition().x; }
Beispiel #6
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;
	}