Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
5.9 kB
2
Indexable
Never
    srand(time(0));

    RenderWindow window(VideoMode(windowWidth, windowHeight), "The Game!");

    Texture t1, t2, t3;
    t1.loadFromFile("images/tiles.png");
    t2.loadFromFile("images/background.png");
    t3.loadFromFile("images/frame.png");
	//Sprite s(t1), background(t2), frame(t3);
    Sprite s(t1), frame(t3);
    sf::RectangleShape background(sf::Vector2f(windowWidth, windowHeight));
    background.setFillColor(sf::Color(200, 220, 255, 180));
	s.setScale(2,2);
    Font font;
    font.loadFromFile("Roboto-Regular.ttf");

    Text scoreText;
	Text highScoreText;
	Text text1, text2;
	Text gameOverText, playAgainText;

    scoreText.setFont(font);
    highScoreText.setFont(font);
    text1.setFont(font);
    text2.setFont(font);
    gameOverText.setFont(font);
    playAgainText.setFont(font);

	text1.setString("Score");
	text2.setString("High");

    scoreText.setFillColor(Color(35, 47, 68));
    highScoreText.setFillColor(Color(35, 47, 68));
    text1.setFillColor(Color(35, 47, 68));
    text2.setFillColor(Color(35, 47, 68));
    gameOverText.setFillColor(Color::Red);
    playAgainText.setFillColor(Color(35, 47, 68));

    scoreText.setCharacterSize(20);
    highScoreText.setCharacterSize(20);
    text1.setCharacterSize(20);
    text2.setCharacterSize(20);
    gameOverText.setCharacterSize(30);
    playAgainText.setCharacterSize(20);

    scoreText.setPosition(250, 20);  // Position on the right side
    highScoreText.setPosition(250, 50);
    gameOverText.setPosition(40, 220);
    playAgainText.setPosition(70, 260);

    sf::RectangleShape gridLines[gridWidth * gridHeight];

	for (int i = 3; i < gridHeight; ++i)
    {
        for (int j = 0; j < gridWidth; ++j)
        {
            gridLines[i * gridWidth + j].setSize(sf::Vector2f(blockSize - 1, blockSize - 1)); // Adjust size for line thickness
            gridLines[i * gridWidth + j].setFillColor(sf::Color::Transparent);
            gridLines[i * gridWidth + j].setOutlineThickness(1);
            gridLines[i * gridWidth + j].setOutlineColor(sf::Color::Black);
            gridLines[i * gridWidth + j].setPosition(j * blockSize, i * blockSize);
			gridLines[i * gridWidth + j].move(blockSize, 2 * blockSize);
        }
    }
    sf::RectangleShape playfieldBoundary(sf::Vector2f(playfieldWidth, playfieldHeight));
    playfieldBoundary.setFillColor(sf::Color(200, 220, 255));
    playfieldBoundary.setOutlineThickness(boundaryThickness);
    playfieldBoundary.setOutlineColor(sf::Color(100, 100, 150));
	playfieldBoundary.move(blockSize, 4 * blockSize);
	playfieldBoundary.setScale(2,2);

	sf::RectangleShape nextTempoBoundary(sf::Vector2f(playfieldWidth / 1.5, playfieldHeight / 5));
    nextTempoBoundary.setFillColor(sf::Color(200, 220, 255)); // Light blue background for playfield
    nextTempoBoundary.setOutlineThickness(boundaryThickness);
    nextTempoBoundary.setOutlineColor(sf::Color(100, 100, 150)); // Darker blue border
	nextTempoBoundary.move(blockSize + blockSize + playfieldWidth * 2, 4 * blockSize);
	nextTempoBoundary.setScale(2,2);

	sf::RectangleShape scoreBoundary(sf::Vector2f(playfieldWidth / 1.5, playfieldHeight / 12));
    scoreBoundary.setFillColor(sf::Color(200, 220, 255)); // Light blue background for playfield
    scoreBoundary.setOutlineThickness(boundaryThickness);
    scoreBoundary.setOutlineColor(sf::Color(100, 100, 150)); // Darker blue border
	scoreBoundary.move(blockSize + blockSize + playfieldWidth * 2, 4 * blockSize + playfieldHeight * 2 / 5 + blockSize);
	scoreBoundary.setScale(2,2);

	sf::RectangleShape highScoreBoundary(sf::Vector2f(playfieldWidth / 1.5, playfieldHeight / 12));
    highScoreBoundary.setFillColor(sf::Color(200, 220, 255)); // Light blue background for playfield
    highScoreBoundary.setOutlineThickness(boundaryThickness);
    highScoreBoundary.setOutlineColor(sf::Color(100, 100, 150)); // Darker blue border
	highScoreBoundary.move(blockSize + blockSize + playfieldWidth * 2, 4 * blockSize + playfieldHeight * 2 / 5 + blockSize + playfieldHeight * 2 / 12 + 8);
	highScoreBoundary.setScale(2,2);


	sf::FloatRect scoreRectangleBounds = scoreBoundary.getGlobalBounds();
    sf::FloatRect scoreTextBounds = scoreText.getLocalBounds();
    text1.setOrigin(scoreTextBounds.left + scoreTextBounds.width - 6, scoreTextBounds.top + 12 + scoreTextBounds.height / 2.0f);
    text1.setPosition(scoreRectangleBounds.left, scoreRectangleBounds.top + scoreRectangleBounds.height / 2.0f);
	text1.scale(2,2);

	sf::FloatRect highScoreRectangleBounds = highScoreBoundary.getGlobalBounds();
    sf::FloatRect highScoreTextBounds = highScoreText.getLocalBounds();
    text2.setOrigin(highScoreTextBounds.left + highScoreTextBounds.width - 6, highScoreTextBounds.top + 12 + highScoreTextBounds.height / 2.0f);
    text2.setPosition(highScoreRectangleBounds.left, highScoreRectangleBounds.top + highScoreRectangleBounds.height / 2.0f);
	text2.scale(2,2);

	sf::FloatRect backgroundBounds = background.getGlobalBounds();
    sf::FloatRect playAgainTextBounds = playAgainText.getLocalBounds();
    playAgainText.setOrigin(playAgainTextBounds.left + playAgainTextBounds.width, playAgainTextBounds.top + 12 + playAgainTextBounds.height / 2.0f);
    playAgainText.setPosition(backgroundBounds.left, backgroundBounds.top + backgroundBounds.height / 2.0f);
	playAgainText.scale(2,2);


    scoreText.setOrigin(scoreTextBounds.left + scoreTextBounds.width + 2, scoreTextBounds.top + 12 + scoreTextBounds.height / 2.0f);
	scoreText.scale(2,2);
    highScoreText.setOrigin(highScoreTextBounds.left + highScoreTextBounds.width + 2, highScoreTextBounds.top + 12 + highScoreTextBounds.height / 2.0f);
	highScoreText.scale(2,2);

	sf::FloatRect nextTempoBounds = nextTempoBoundary.getLocalBounds();
Leave a Comment