示例#1
0
bool CreditsMenu::isInRect(sf::Vector2i position, sf::RectangleShape menuItemRect)
{
	return(menuItemRect.getPosition().y < position.y && 
			menuItemRect.getPosition().y + menuItemRect.getSize().y > position.y &&
			menuItemRect.getPosition().x < position.x &&
			menuItemRect.getPosition().x + menuItemRect.getSize().x > position.x);
}
示例#2
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);
}
示例#3
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;
}
示例#4
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);
 }
	Player(sf::Vector2f position, sf::Vector2f size)
	{
		once = true;
		rect.setPosition(position);
		rect.setSize(size);
		rect.setFillColor(sf::Color::Green);
	}
//keyboard inputs (pressed)
void key_pressed_events(){
    if(event.key.code == sf::Keyboard::Left){
       square.move(x_move, 0);
       x_move -= (x_move > 0) ? x_move - 2 : 2;
       if(x_move <= -5){x_move = -5;}

       
       it = stars.begin();
       while(it != stars.end()){
            it -> move(x_move / -4, 0);
            it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240));
           if(it -> getPosition().x > window_x){
                it -> setPosition(0, it -> getPosition().y);}
            ++it;}
    }

    else if(event.key.code == sf::Keyboard::A){
       it = stars.begin();
       while(it != stars.end()){
            it -> move(6 / 4, 0);
            it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240));
           if(it -> getPosition().x > window_x){
                it -> setPosition(0, it -> getPosition().y);}
            ++it;}
    }

    else if(event.key.code == sf::Keyboard::Right){
        square.move(x_move, 0);
        x_move += 2;
        if(x_move >= 5){x_move = 5;}

       it = stars.begin();
       while(it != stars.end()){
           it -> move(x_move / -4, 0);
           it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
                rand() % (255 + 1 - 240) + 240,
                rand() % (255 + 1 - 240) + 240));
           if(it -> getPosition().x < 0){
                it -> setPosition(window_x, it -> getPosition().y);} 
           ++it;}
    }

    else if(event.key.code == sf::Keyboard::D){
       it = stars.begin();
       while(it != stars.end()){
            it -> move(6 / -4, 0);
            it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240,
                    rand() % (255 + 1 - 240) + 240));
            if(it -> getPosition().x < 0){
                it -> setPosition(window_x, it -> getPosition().y);}
            ++it;}
    }


}
示例#7
0
bool Tutorial::crossfade(float elapsedTime, sf::RectangleShape& rect1, sf::RectangleShape& rect2)
{
	float temp = alpha1 - elapsedTime * ANIMATION_SPEED;
	float temp2 = alpha2 + elapsedTime * ANIMATION_SPEED;
	// std::cout << "color " << static_cast<int>(temp) << std::endl;
	// std::cout << "color2 " << static_cast<int>(temp2) << std::endl;
	
	// ensure high calc times don't screw up the outcome (drag the window for a sec outputs a too high value)
	// maybe just limit it would be better.. 
	if (temp < alpha1)
	{
		alpha1 = temp;
		alpha2 = temp2;
	}

	if (alpha1 < 1)
	{
		alpha1 = 0;
		alpha2 = 255;
		rect1.setFillColor(sf::Color(255, 255, 255, static_cast<sf::Uint8>(alpha1)));
		return true;
	}
	// disabled because it should not be crossfaded only overlayed 
	//rect1.setFillColor(sf::Color(255, 255, 255, static_cast<sf::Uint8>(alpha1)));
	rect2.setFillColor(sf::Color(255, 255, 255, static_cast<sf::Uint8>(alpha2)));
	return false;
}
示例#8
0
void DropDown::arrange(sf::Text &text,sf::RectangleShape &shape)
{
	float ratiox = shape.getGlobalBounds().width/text.getGlobalBounds().width;
	float ratioy = (shape.getGlobalBounds().height/text.getGlobalBounds().height);
	ratioy*=0.5f;
	text.scale(ratiox,ratioy);
}
示例#9
0
    TestBox(bool isCollidable) :
        sg::Entity(isCollidable)
    {

        r0.setSize(sf::Vector2f(100.0f, 50.0f));
        r0.setOrigin(50.0f, 25.0f);
        this->addDrawable(r0, false);
        bs.addShape(r0);
        r1.setRadius(40.0f);
        r1.setOrigin(40.0f, 40.0f);
        r1.move(100.0f, 0.0f);
        r1.scale(2.0f, 1.0f);
        this->addDrawable(r1, false);
        bs.addShape(r1);
        r2.setSize(sf::Vector2f(250.0f, 10.0f));
        r2.setOrigin(125.0f, 5.0f);
        r2.rotate(-90.0f);
        this->addDrawable(r2, false);
        bs.addShape(r2);
        r3.setRadius(40.0f);
        r3.setOrigin(40.0f, 40.0f);
        r3.move(-100.0f, 0.0f);
        this->addDrawable(r3, false);
        bs.addShape(r3);
        //bs.rotate(-45.0f);
        this->addTransformable(bs);
        //this->rotate(45.0f);

    }
示例#10
0
    Board(int n, sf::Vector2f pos){

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

    }
示例#11
0
 el(sf::Vector2f p)
 {
     r.setSize(sf::Vector2f(50,50));
     r.setFillColor(sf::Color(2,136,209));
     pos = p;
     r.setPosition(pos);
 }
示例#12
0
    void init() {
        this->restart();
        // RectangleShapes
        sf::Vector2f unit(unit_w, unit_h);
        stone_view = sf::RectangleShape(unit);
        stone_view.setFillColor(sf::Color(255, 81, 68));
        body_view = sf::RectangleShape(unit);
        body_view.setFillColor(sf::Color(0, 204, 255));
        food_view = sf::RectangleShape(unit);
        food_view.setFillColor(sf::Color(19, 169, 136));

        // font & msg
        if (!font.loadFromFile("Inconsolata-Bold.ttf")) {
            puts("fonts loading error!");
            this->close();
        }
        msg1.setFont(font);
        msg1.setColor(sf::Color::White);
        msg1.setCharacterSize(50);
        msg1.setPosition(80, 100);
        msg2.setFont(font);
        msg2.setColor(sf::Color::White);
        msg2.setCharacterSize(25);
        msg2.setString("Press <Enter> to Replay");
        msg2.setPosition(60, 250);
    }
示例#13
0
 obstacle(sf::Vector2f p)
 {
     pos = p;
     r.setPosition(p);
     r.setSize(sf::Vector2f(50,50));
     r.setFillColor(sf::Color(255, 205, 210));
 }
示例#14
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);
}
示例#15
0
 inline TextSquare(Ctx& mCtx, const Vec2f& mPos) : Base{mCtx, mPos}
 {
     text = &create<Text>(ssvs::zeroVec2f);
     bg.setSize(Vec2f{65, 65});
     bg.setOutlineColor(sf::Color::White);
     bg.setOutlineThickness(3);
 }
示例#16
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);
 }
示例#17
0
    food()
    {
        srand(time(NULL));
        r.setSize(sf::Vector2f(50,50));
        r.setFillColor(sf::Color(255,193,7));
        generatePos();

    }
示例#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
//Method to check collision between 2 rectangles.
bool CollisionManager::CheckRectangleCollision(sf::RectangleShape entity1, sf::RectangleShape entity2)
{
	if (entity1.getGlobalBounds().intersects(entity2.getGlobalBounds()))
		return true;

	else
		return false;
}
bool CollisionChecker::IsPossibleCollisionWithTopOrBottomSide(sf::RectangleShape &r1, sf::RectangleShape &r2)
{
    if(r1.getPosition().x+r1.getGlobalBounds().width > r2.getPosition().x
    && r1.getPosition().x < r2.getPosition().x+r2.getGlobalBounds().width){
        return true;
    }

    return false;
}
示例#21
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);	
}
示例#22
0
文件: ogre_obj.hpp 项目: dvbuntu/ogre
 // Post battle update
 inline void set_info(int str)
 {
     info_str.setString(std::to_string(str));
     health_bar_bg.setSize(sf::Vector2f(get_max_hp()/scale, 10));
     health_bar_bg.setOutlineColor(sf::Color(125,125,125));
     health_bar_bg.setOutlineThickness(1);
     health_bar_current.setSize(sf::Vector2f(str/scale, 10));
     health_bar_current.setFillColor(get_life_color(str));
 }
示例#23
0
//keyboard inputs (release)
void key_released_events(){
   if(event.key.code == sf::Keyboard::Left){
        square.move((x_move) / 2, 0);
        x_move = 0;}

   else if(event.key.code == sf::Keyboard::Right){
        square.move(x_move / 2, 0);
        x_move = 0;}
}
示例#24
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);
 }
示例#25
0
    massCenter getMassCenter(){
        massCenter mc;

        mc.x = playerSprite.getPosition().x + (playerSprite.getSize().x/2);
        mc.y = playerSprite.getPosition().y + (playerSprite.getSize().y/2);

        return mc;

    }
bool CollisionChecker::IsPossibleCollisionWithLeftOrRightSide(sf::RectangleShape &r1, sf::RectangleShape &r2)
{
    if(r1.getPosition().y+r1.getGlobalBounds().height > r2.getPosition().y
    && r1.getPosition().y < r2.getPosition().y+r2.getGlobalBounds().height){
        return true;
    }

    return false;
}
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;
}
示例#28
0
//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);}
}
示例#29
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();
	}
}
示例#30
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);
            }