示例#1
0
	Pong() : gameWindow(sf::VideoMode(600, 480), "Pong")
	{
		ball.setFillColor(sf::Color::Cyan);
		ball.setPosition(100.0, 100.0);
		ball.setRadius(10.f);

		p1Paddle.setFillColor(sf::Color::Green);
		p1Paddle.setPosition(10.0, 100.0);
		p1Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p2Paddle.setFillColor(sf::Color::Red);
		p2Paddle.setPosition(580.0, 100.0);
		p2Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p1MovingUp = false;
		p1MovingDown = false;
		p2MovingUp = false;
		p2MovingDown = false;

		ballMovement = sf::Vector2f(ballSpeed, ballSpeed);
		font.loadFromFile("arial.ttf");

		p1ScoreText.setPosition(150, 10);
		p1ScoreText.setFont(font);
		p1ScoreText.setString(std::to_string(p1Score));
		p1ScoreText.setColor(sf::Color::Red);
		p1ScoreText.setCharacterSize(24);

		p2ScoreText.setPosition(450, 10);
		p2ScoreText.setFont(font);
		p2ScoreText.setString(std::to_string(p2Score));
		p2ScoreText.setColor(sf::Color::Red);
		p2ScoreText.setCharacterSize(24);
	}
示例#2
0
    void Physic(float time)
    {
        Control(time);

        if (recShape->getPosition().x <= 50)
            recShape->setPosition(sf::Vector2f(50, recShape->getPosition().y));
        else if (recShape->getPosition().x >= 974)
            recShape->setPosition(sf::Vector2f(974, recShape->getPosition().y));
    }
//set square (user) position
void set_square_position(){
    sf::Vector2f v = square.getPosition();

    if(v.x < 0){
        square.setPosition(0, window_y - shape_size);}

    else if(v.x > window_x){
        square.setPosition(window_x - shape_size, window_y - shape_size);}
}
示例#4
0
void WindowCreateThing::init(sf::RenderWindow &window) {

    rectTitle.setSize(sf::Vector2f(window.getSize().x*0.45, window.getSize().y*0.07));
    rectTitle.setPosition(sf::Vector2f(window.getSize().x/2-(rectTitle.getSize().x/2), window.getSize().x/4-(rectTitle.getSize().y/2)));
    rectTitle.setFillColor(sf::Color(158, 158, 158));
    rectTitle.setOutlineColor(sf::Color::Black);
    rectTitle.setOutlineThickness(1.f);

    rectMain.setSize(sf::Vector2f(window.getSize().x*0.45,window.getSize().y*0.45));
    rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y));
    rectMain.setFillColor(sf::Color::White);
    rectMain.setOutlineColor(sf::Color::Black);
    rectMain.setOutlineThickness(1.f);

    load();


    starting_position = sf::Mouse::getPosition(window);



    textTitle.setFont(font);
    textTitle.setString("CreateThings.txt");
    textTitle.setCharacterSize(24);
    textTitle.setColor(sf::Color::White);
    textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1));
    //textTitle.setPosition(sf::Vector2f(400,10));

    textClose.setFont(font);
    textClose.setString("X");
    textClose.setStyle(sf::Text::Bold);
    textClose.setCharacterSize(35);
    textClose.setColor(sf::Color::White);
    textClose.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x-30, rectTitle.getPosition().y+rectTitle.getSize().y*0.05));


    ///// FOLDER ICONE
    textureFolder.setSmooth(true);
    spriteFodler.setTexture(textureFolder);
    sf::Vector2f targetSize(25.0f, 25.0f);
    spriteFodler.setScale(
        targetSize.x / spriteFodler.getLocalBounds().width,
        targetSize.y / spriteFodler.getLocalBounds().height);
    spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-targetSize.x, textTitle.getPosition().y));




    ///// CLOSE ICONE
    /*textureClose.setSmooth(true);
    spriteClose.setTexture(textureClose);
    sf::Vector2f targetSize2(window.getSize().y*0.07, window.getSize().y*0.07);
    spriteClose.setScale(
        targetSize2.x / spriteClose.getLocalBounds().width,
        targetSize2.y / spriteClose.getLocalBounds().height);
    spriteClose.setPosition(rectTitle.getPosition().x+rectTitle.getSize().x-targetSize2.x, rectTitle.getPosition().y);*/
}
示例#5
0
文件: main.cpp 项目: gAndy50/Misc
void GameLoop()
{
	while (GameRunning)
	{
		sf::Event Event;

		while (GameWin.pollEvent(Event))
		{
			if (Event.type == sf::Event::Closed)
			{
				GameWin.close();
				GameRunning = false;
			}

			if (Event.type == sf::Event::KeyPressed)
			{
				if (Event.key.code == sf::Keyboard::Escape)
				{
					GameWin.close();
					GameRunning = false;
				}

				if (Event.key.code == sf::Keyboard::P && Paused == true)
				{
					Paused = false;
				}
				else if (Event.key.code == sf::Keyboard::P && Paused == false)
				{
					Paused = true;
				}
			}

			if (Event.type == sf::Event::KeyReleased)
			{
				
			}
		}

		if(!Paused)
		World->Step(timeStep, velIter, posIter);

		b2Vec2 pos = Body->GetPosition();
		float angle = Body->GetAngle();

		box.setPosition(pos.x, pos.y);
		box.setRotation(angle);

		b2Vec2 pos2 = Body2->GetPosition();
		float angle2 = Body2->GetAngle();

		box2.setPosition(pos2.x, pos2.y);
		box2.setRotation(angle2);

		DrawGame();
	}
}
示例#6
0
        void handle () {
            rotate();
            float percentageHealth = float((Health/MaxHealth) * 100);
            HealthBarGreen.setSize(sf::Vector2f(percentageHealth * (HealthBarSize / percentageHealth), 5));

            NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4);
            PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing);
            HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);
            HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);
            }
示例#7
0
void Sprited::draw(sf::RenderWindow *window)
{
    // Scroll sprite
    sf::Vector2i shift = this->currentAnimation->frames[this->currentFrame];
    this->sprite.setTextureRect(sf::IntRect(shift.x, shift.y, this->width, this->height));

    this->sprite.setRotation((this->getWRotation() - this->camera->getWRotation()) / (2 * M_PI) * 360); // + this->wRotation / (2 * M_PI) * 360);

    if (this->camera) {
        // Transform sprite wPosition based on camera wPosition & wRotation
        this->sprite.setPosition(this->applyCameraTransformation(this->getWPosition()));
    } else {
        // No camera set, meaning this object's wPosition is not affected by camera.
        this->sprite.setPosition(this->getWPosition().x, this->getWPosition().y);
    }

    window->draw(this->sprite);

    Movable::draw(window);

#ifdef DEBUG
    static sf::RectangleShape origin;
    origin.setOrigin(2, 2);
    origin.setSize(sf::Vector2f(5, 5));
    origin.setPosition(this->sprite.getPosition());
    origin.setFillColor(sf::Color(255, 0, 0, 128));
    window->draw(origin);

    static sf::RectangleShape rect;
    rect.setFillColor(sf::Color::Transparent);
    rect.setOutlineThickness(1);
    rect.setOutlineColor(sf::Color::Blue);
    rect.setOrigin(this->sprite.getOrigin());
    rect.setPosition(this->sprite.getPosition());
    rect.setRotation(this->sprite.getRotation());
    rect.setSize(sf::Vector2f(this->sprite.getTextureRect().width, this->sprite.getTextureRect().height));
    window->draw(rect);

    sf::FloatRect wHitbox = this->getWHitbox();
    static sf::RectangleShape hitboxRect;
    hitboxRect.setFillColor(sf::Color::Transparent);
    hitboxRect.setOutlineThickness(1);
    hitboxRect.setOutlineColor(sf::Color::Red);
    hitboxRect.setOrigin(sf::Vector2f(wHitbox.width / 2, wHitbox.height / 2));
    hitboxRect.setSize(sf::Vector2f(wHitbox.width, wHitbox.height));
    hitboxRect.setPosition(this->applyCameraTransformation(this->getWPosition()));
    hitboxRect.setRotation(-this->camera->getWRotation() / M_PI * 180);
    window->draw(hitboxRect);
#endif
}
 el(sf::Vector2f p)
 {
     r.setSize(sf::Vector2f(50,50));
     r.setFillColor(sf::Color(2,136,209));
     pos = p;
     r.setPosition(pos);
 }
 obstacle(sf::Vector2f p)
 {
     pos = p;
     r.setPosition(p);
     r.setSize(sf::Vector2f(50,50));
     r.setFillColor(sf::Color(255, 205, 210));
 }
示例#10
0
void PongGame::setUpBall(int const mainWindowWidth, int const mainWindowHeight, sf::RectangleShape &ball) {
    ball.setPosition(mainWindowWidth / 2, mainWindowHeight / 2);
    ball.setSize(sf::Vector2f(20, 20));
    ball.setFillColor(sf::Color::Red);
    ball.setOutlineColor(sf::Color::Yellow);
    ball.setOutlineThickness(2);
}
示例#11
0
/*
 *  Mostra na tela os indicadores básicos do jogo:
 *  vidas restantes, HP e pontuação.
 */
void Jogo::exibeHud()
{
    float x = 0.10 * janela.getSize().x;
    float y = 0.15 * janela.getSize().y;

    /* Desenha vidas extras da nave */
    static sf::CircleShape losango(20.0, 4);
    for (int i = 0; i < nave->getVidas(); i++) {
        double deltaX = 2.5 * losango.getRadius();
        losango.setPosition(x + (i * deltaX), y);
        janela.draw(losango); 
    }
    /* Desenha caixa da lifebar */
    y += 3.0 * losango.getRadius();
    static sf::RectangleShape caixa({200.0, 10.0});
    caixa.setPosition(x, y);
    caixa.setFillColor(sf::Color::Blue);
    janela.draw(caixa);

    /* Desenha lifebar com parcial do HP */
    float k = (float) nave->getHP() / nave->getHPMax();
    sf::RectangleShape lifebar({k * caixa.getSize().x,
                                    caixa.getSize().y});
    lifebar.setPosition(x, y);
    lifebar.setFillColor(k > 0.25 ? sf::Color::Green : sf::Color::Red);
    janela.draw(lifebar);

    /* Imprime pontuação (e, se for o caso, mensagem de pausa) */
    y += 2.5 * lifebar.getSize().y;
    sf::String str = "Score: " + std::to_string(nave->getScore());
    if (pausado) str += " (pausa)";
    sf::Text texto(str, fonte, 20);
    texto.setPosition(x, y);
    janela.draw(texto);
}
示例#12
0
 // As with the ball, we construct the paddle with
 // arguments for the initial position and initialize
 // the SFML rectangle shape.
 Paddle(float mX, float mY)
 {
     shape.setPosition(mX, mY);
     shape.setSize({defWidth, defHeight});
     shape.setFillColor(defColor);
     shape.setOrigin(defWidth / 2.f, defHeight / 2.f);
 }
示例#13
0
    Board(int n, sf::Vector2f pos){

        boardSprite.setSize(sf::Vector2f(n, 2));
        boardSprite.setFillColor(sf::Color::Blue);
        boardSprite.setPosition(pos);

    }
示例#14
0
    void Control(float time)
    {
        /*if (event.type == sf::Event::KeyPressed)
        {
        	if (event.key.code == sf::Keyboard::A || event.key.code == sf::Keyboard::Left)
        		recShape->setPosition(sf::Vector2f(recShape->getPosition().x - 10. * time, recShape->getPosition().y));
        	else if (event.key.code == sf::Keyboard::D || event.key.code == sf::Keyboard::Right)
        		recShape->setPosition(sf::Vector2f(recShape->getPosition().x + 10. * time, recShape->getPosition().y));
        	std::cout << "press";
        }*/

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::A) || sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            recShape->setPosition(sf::Vector2f(recShape->getPosition().x - 0.5 * time, recShape->getPosition().y));
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D) || sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            recShape->setPosition(sf::Vector2f(recShape->getPosition().x + 0.5 * time, recShape->getPosition().y));
    }
示例#15
0
文件: Main.cpp 项目: SGBon/emu-chip8
int main() {
	sgb::Chip8 chip8;
	chip8.loadGame("PONG2");

	back.create(64, 32, sf::Color::Black);
	backshape.setPosition(0, 0);
	backtext.loadFromImage(back);
	backshape.setTexture(&backtext);

	while(window.isOpen()){
		sf::Event event;
		while (window.pollEvent(event)) {
			if (event.type == sf::Event::Closed)
				window.close();
		}

		// emulate one cycle
		chip8.emulateCycle();

		// if drawflag is set, update screen;
		if (chip8.drawFlag)
			updateGraphics(chip8);

		//query keys
		chip8.setKeys();
		sf::sleep(sf::seconds(1.0f/500.0f));
	}

	return 0;
}
	Player(sf::Vector2f position, sf::Vector2f size)
	{
		once = true;
		rect.setPosition(position);
		rect.setSize(size);
		rect.setFillColor(sf::Color::Green);
	}
示例#17
0
void Snake::Render(sf::RenderWindow& window) {
	if (_body.empty()) { return; }

	// Draw head
	auto head = _body.begin();
	_bodyRect.setFillColor(sf::Color::Yellow);
	_bodyRect.setPosition(head->position.x * _size, head->position.y * _size);
	window.draw(_bodyRect);

	// Draw body
	_bodyRect.setFillColor(sf::Color::Green);
	for (auto itr = _body.begin() + 1; itr != _body.end(); ++itr) {
		_bodyRect.setPosition(itr->position.x * _size, itr->position.y * _size);
		window.draw(_bodyRect);
	}
}
示例#18
0
 Particle(sf::Vector2i position)
 {
     rect.setSize(sf::Vector2f(2,2));
     rect.setOrigin( sf::Vector2f(1,1) );
     rect.setFillColor( sf::Color::Red );
     rect.setPosition( (sf::Vector2f)position );
     velocity = sf::Vector2f(0,0);
 }
示例#19
0
 el(int x , int y)
 {
     r.setSize(sf::Vector2f(50,50));
     r.setFillColor(sf::Color(2,136,209));
     pos.x = x;
     pos.y = y;
     r.setPosition(pos);
 }
sf::RectangleShape Spriteeditor::shapeRealBorder(Sprite * sprite, sf::RectangleShape shape)
{
	shape.setPosition(sprite->getPosition().x, sprite->getPosition().y);
	sf::Rect<float> border = sprite->getLocalBounds();
	shape.setSize(sf::Vector2f(border.width, border.height));
	shape.setScale(sprite->getScale());
	shape.setRotation(sprite->getRotation());
	return shape;
}
示例#21
0
 void init(const sf::Vector2f& position, const string filename)
 {
     _event = Event::NONE;
     _shape->setPosition(position);
     _shape->setSize(sf::Vector2f(TAILLE_SQUARE, TAILLE_SQUARE));
     _shape->setFillColor(sf::Color::Black);
     _shape->setOutlineColor(sf::Color::White);
     _shape->setOutlineThickness(1);
 }
示例#22
0
void displaySnake(Node &node)
{
	draw.setPosition(sf::Vector2f(node.x * (640/SIZE), node.y * (640/SIZE)));
	draw.setFillColor(sf::Color::White);
	//draw.setFillColor(sf::Color::Black);
	renderTexture.draw(draw);
	if(node.next != nullptr)
		displaySnake(*node.next);	
}
bool game_init()
{
     r.setPosition(100, 100);
    r.setFillColor(sf::Color(255, 255, 255));
    r.setSize(sf::Vector2f(20, 20));
    color = sf::Color::White;


    return true;
}
示例#24
0
void PongGame::updatePositionOfPlayer(sf::RectangleShape &player) {
    sf::FloatRect topRectangleGlobalBounds = topRectangle.getGlobalBounds();
    sf::FloatRect bottomRectangleGlobalBounds = bottomRectangle.getGlobalBounds();
    sf::Vector2f playerPosition = player.getPosition();
    float topConstraint = topRectangleGlobalBounds.top + topRectangleGlobalBounds.height + 5;
    float bottomConstraint = bottomRectangleGlobalBounds.top - player.getSize().y - 5;
    playerPosition.y = getYCoordinate((int const) playerPosition.y, (int const) topConstraint,
            (int const) bottomConstraint);
    player.setPosition(playerPosition);
}
示例#25
0
	void update(sf::RenderWindow& _window) {
		_spriteG.move(_velocity.x, _velocity.y);//Personnage qui bouge


		sf::Vector2f _positionRect = sf::Vector2f(43, 50);
		_positionRect.x = _spriteG.getPosition().x;
		_positionRect.y = _spriteG.getPosition().y;

		_rect.setPosition(_positionRect.x, _positionRect.y);
	}
示例#26
0
//draw the enemies
sf::RectangleShape RectanglePosition(sf::RectangleShape shape, float windowX, float windowY)
{

	int myX = RandomNumber(windowX);
	int myY = RandomNumber(windowY);

	shape.setPosition(myX, myY);

	return shape;

}
示例#27
0
文件: map.hpp 项目: BACKDRA4T/SNAKE
void Map::spawnFood() // Fix so doesn't spawn on snake
{
	//Generate Random Numbers For Grid Pos For Food
	srand(time(NULL));
	int randomTile = rand() % numTiles;

	if(foodSpawned != true)
	{
		food.setSize(sf::Vector2f(18, 18));
		food.setFillColor(sf::Color::Red);
		sf::Color outlineColour(145, 145, 145);
		food.setOutlineColor(outlineColour);
		food.setOutlineThickness(2);
		food.setPosition(tiles[randomTile].getPosition().x, tiles[randomTile].getPosition().y);
		foodSpawned = true;
	}
	else
	{
		food.setPosition(tiles[randomTile].getPosition().x, tiles[randomTile].getPosition().y);
	}
}
    Info(sf::String& text)
    {
        box.setPosition(100,100);
        box.setFillColor(sf::Color(245,248,6));
        box.setSize(sf::Vector2f(300,300));
        box.setOutlineColor(sf::Color::Red);
        box.setOutlineThickness(3);

        InfoText.setString(text);
        InfoText.setPosition(110,110);
        InfoText.setFillColor(sf::Color::White);
    }
示例#29
0
 void generatePos()
 {
     bool OK = true;
     do
     {
         pos.x = ( rand() % 14 + 1 ) * 50;
         pos.y = ( rand() % 14 + 1 ) * 50;
         if(o.lookFor(sf::Vector2f(pos.x, pos.y)) || snake.lookFor(sf::Vector2f(pos.x, pos.y))) OK = false;
     }
     while(!OK);
     r.setPosition(pos);
 }
示例#30
0
 StatusBox(uint _x, uint _y, float _width, float _height, const GuiStyle& _style) :
     BaseBox(_x, _y, _width, _height, _style)
 {
     blackbox = new sf::RectangleShape();
     blackbox->setFillColor(sf::Color::Black);
     blackbox->setSize({_width, _height});
     blackbox->setPosition(sf::Vector2f(_x, _y));
     
     textbox = new sf::Text;
     textbox->setPosition(_x, _y);
     textbox->setFont(*style.font);
     textbox->setCharacterSize(style.fontsize);
 }