Ejemplo n.º 1
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);

    }
Ejemplo n.º 2
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
}
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
void cWindow::paintLighting()
{
	float power;
	int tex;
	int lightsDisplayed = 0;
	int priority = 0;

	for (int a = 0; a < 2; a++)
	{
		priority = 0;
		while (priority < LIMIT_PRIORITY_LIGHT && lightsDisplayed < game.unitCounter)
		{
			for (int i = 0; i < game.unitCounter; i++)
			{
				if (game.unit[i].light.priority == priority && game.unit[i].light.power > 0 && game.unit[i].light.texture != -1)
				{
					tex = game.unit[i].light.texture;
					brushRect.setTexture(&visual.gameTex[tex].handle);
					brushRect.setPosition(game.unit[i].pos);
					brushRect.setFillColor(sf::Color(255, 255, 255, max(0.00f, min(255.00f, 300.00f - game.ambientLight))));
					if (!settings.enableDynamicLight) {
						brushRect.setTexture(&visual.gameTex[visual.addTexture("light_white.png")].handle);
						brushRect.setFillColor(sf::Color(255, 255, 255, 50.00f));
					}
					brushRect.setTextureRect(sf::IntRect(0, 0, visual.gameTex[tex].handle.getSize().x, visual.gameTex[tex].handle.getSize().y));
					power = game.unit[i].light.power;
					if (game.unit[i].light.flickerMod != 0.00f) {
						power += power * (game.unit[i].light.flickerMod * abs(game.unit[i].light.flickerCurTime / game.unit[i].light.flickerTime - 1.00f));
						power += math.randf(-5.00f, 5.00f);
					}
					brushRect.setOrigin(sf::Vector2f(power, power));
					brushRect.setSize(sf::Vector2f(power * 2.00f, power * 2.00f));
					// Directional
					brushRect.setRotation(0.00f);
					if (game.unit[i].light.directional) {
						brushRect.setRotation(-game.unit[i].facingAngle);
					}
					// Painting to two textures
					if (settings.enableDynamicLight && a == 0) { window.texHandleLight.draw(brushRect, window.matrixHandle); }
					else if (settings.enableDynamicLight && a == 1) { window.texHandleLightMult.draw(brushRect, window.matrixHandle); }
					else { window.texHandle.draw(brushRect, window.matrixHandle); }
				}
			}
			priority += 1;
		}
		if (!math.intToBool(settings.enableBetterLight)) { break; }
	}
	brushRect.setRotation(0.00f);
	window.texHandleLight.display();
	if (settings.enableBetterLight) { window.texHandleLightMult.display(); }
}
Ejemplo n.º 6
0
	BroadphaseDemo(sf::RenderWindow &window) : Demo(window), broadphase(100, 100), mouseObject(sf::Vector2f(50, 50)) {
		// set up our mouse object
		mouseObject.setOrigin(mouseObject.getSize() / 2.0f);
		mouseObject.setOutlineThickness(2);
		mouseObject.setFillColor(sf::Color(0, 200, 0));

		// set up some random rectangles
		for (size_t i = 0; i < 2500; ++i) {
			sf::RectangleShape *object = new sf::RectangleShape(sf::Vector2f(randb(5, 15), randb(5, 15)));
			object->setOrigin(object->getSize() / 2.0f);
			object->setOutlineThickness(2);
			objects.push_back(object);
		}
	}
Ejemplo n.º 7
0
void cWindow::paintClouds()
{
	brushRect.setScale(vec2f(1.00f, 1.00f));
	brushRect.setFillColor(color(0, 0, 0));
	//brushRect.setTexture(&visual.gameTex[database.texture[TEX_CLOUD]].handle);
	sf::FloatRect camRect(camera.pos.x, camera.pos.y, camera.res.x, camera.res.y);
	mutex.renderClouds.lock();
	visual.cloudsPainted = 0;
	for (int i = 0; i < (int)weather.cloud.size(); i++)
	{
		//brushRect.setTexture(&weather.cloudTexture[i], true);
		brushRect.setTexture(&visual.gameTex[weather.cloud[i].tex].handle, true);
		brushRect.setPosition(weather.cloud[i].pos);
		brushRect.setSize(weather.cloud[i].size);
		brushRect.setOrigin(weather.cloud[i].size / 2.00f);
		if (camRect.intersects(brushRect.getGlobalBounds())) {
			window.texHandleShadow.draw(brushRect, window.matrixHandle);
			visual.cloudsPainted += 1;
		}
	}
	mutex.renderClouds.unlock();
}
Ejemplo n.º 8
0
void cWindow::paintParticles()
{
	cParticleUnit* unit;
	float shadowBrightness = (game.ambientLight - 150.00f) / 255.00f * 210.00f;
	shadowBrightness = max(0.00f, min(255.00f, shadowBrightness));
	if (!settings.enableParticleShadows) { shadowBrightness = 0.00f; }
	visual.particlesPainted = 0;

	mutex.renderParticles.lock();
	int repeats = 1;
	if (settings.enableParticleShadows && settings.enableBetterParticleShadows) { repeats += 1; }
	for (int a = 0; a < repeats; a++)
	{
		for (int i = 0; i < (int)particle.unit.size(); i++)
		{
			// Setup
			unit = &particle.unit[i];
			brushRect.setSize(unit->size * 0.50f * (unit->lifetime / unit->lifetimeMax) + unit->size * 0.50f);
			brushRect.setOrigin(unit->size / 2.00f);
			if (i == 0 || particle.unit[i].type != particle.unit[i - 1].type)
			{
				brushRect.setTexture(&visual.gameTex[unit->texture].handle, true);
			}

			// Display
			float transpar = (unit->fadeVal / unit->fadeMax);
			if (a == 0)
			{
				if (shadowBrightness > 0.00f && settings.enableParticleShadows && !settings.enableBetterParticleShadows)
				{
					brushRect.setPosition(unit->shadowPos);
					brushRect.setFillColor(color(0, 0, 0, shadowBrightness * transpar));
					window.texHandle.draw(brushRect, window.matrixHandle);
				}
				brushRect.setPosition(unit->pos);
				brushRect.setFillColor(color(255, 255, 255, 255 * transpar));
				window.texHandle.draw(brushRect, window.matrixHandle);
				visual.particlesPainted += 1;
			}
			else if (a == 1)
			{
				brushRect.setPosition(unit->shadowPos);
				brushRect.setFillColor(color(0, 0, 0, 255 * transpar));
				window.texHandleShadow.draw(brushRect, window.matrixHandle);
				if (settings.enablePreciseParticleShadows)
				{
					brushRect.setPosition(unit->pos);
					brushRect.setFillColor(color(255, 255, 255, 255 * transpar));
					window.texHandleShadow.draw(brushRect, window.matrixHandle);
				}
			}
		}
	}
	mutex.renderParticles.unlock();


	/*for (int i = 0; i < (int)particle.unit.size(); i++)
	{
		// Setup
		unit = &particle.unit[i];
		brushRect.setSize(unit->size * 0.50f * (unit->lifetime / unit->lifetimeMax) + unit->size * 0.50f);
		brushRect.setOrigin(unit->size / 2.00f);
		if (i == 0 || particle.unit[i].type != particle.unit[i - 1].type)
		{
			brushRect.setTexture(&visual.gameTex[unit->texture].handle, true);
		}

		// Display
		float transpar = (unit->fadeVal / unit->fadeMax);
		if (shadowBrightness > 0.00f)
		{
			brushRect.setPosition(unit->shadowPos);
			brushRect.setFillColor(color(0, 0, 0, shadowBrightness * transpar));
			window.texHandle.draw(brushRect, window.matrixHandle);
		}
		brushRect.setPosition(unit->pos);
		brushRect.setFillColor(color(255, 255, 255, 255 * transpar));
		window.texHandle.draw(brushRect, window.matrixHandle);
		visual.particlesPainted += 1;
	}*/
}
Ejemplo n.º 9
0
void table()
{
	sf::Vector2f tbBorder(WIDTH, borderDepth);
	sf::Vector2f lrBorder(borderDepth, HEIGHT);
	sf::Vector2f matSize(WIDTH - 2 * borderDepth, HEIGHT - 2 * borderDepth);
	float borderPosX[4] = {0.f, 0.f, 0.f, WIDTH - borderDepth};
	float borderPosY[4] = {0.f, HEIGHT - borderDepth, 0.f, 0.f};
	float pocketPosX[3] = {borderLeft, WIDTH / 2, borderRight};
	float pocketPosY[2] = {borderTop - 5, borderBot + 5};
	float pocket2OrigX[6] = { pocketRad, pocketRad, pocketRad, pocketRad, pocketRad, pocketRad};
	float pocket2OrigY[6] = { 0, pocketRad, 0, pocketRad, 0, pocketRad };
	float pocket2Angle[6] = { -45, 45, 0, 0, 45, -45 };
	
	mat.setSize(matSize);
	mat.setOrigin(matSize.x / 2, matSize.y / 2);
	mat.setPosition(WIDTH/2, HEIGHT/2);
	mat.setFillColor(darkGreen);

	for (int i = 0; i < 4; i++)
	{
		if (i < 2) { borders[i].setSize(tbBorder); }
		else { borders[i].setSize(lrBorder); }
		borders[i].setPosition(borderPosX[i], borderPosY[i]);
		borders[i].setFillColor(brown);
		borders[i].setOutlineColor(sf::Color::Black);
		borders[i].setOutlineThickness(1);
	}

	for (int i = 0; i < 6; i++)
	{
			pockets[i].setRadius(pocketRad);
			pockets[i].setOrigin(pocketRad, pocketRad);
			pockets[i].setFillColor(sf::Color::Black);
		if ((i != 2) && (i != 3))
		{
			pockets2[i].setSize(pocket2Size);
			pockets2[i].setOrigin(pocket2OrigX[i], pocket2OrigY[i]);
			pockets2[i].setFillColor(sf::Color::Black);
			pockets2[i].setRotation(pocket2Angle[i]);
		}
	}

	pockets[0].setPosition(borderLeft, borderTop);
	pockets[1].setPosition(borderLeft, borderBot);
	pockets[2].setPosition(WIDTH / 2, borderTop);
	pockets[3].setPosition(WIDTH / 2, borderBot);
	pockets[4].setPosition(borderRight, borderTop);
	pockets[5].setPosition(borderRight, borderBot);

	for (int i = 0; i < pockets2.size(); i++)
		pockets2[i].setPosition(pockets[i].getPosition());

	BILLIARDS.draw(mat);
	for (int i = 0; i < borders.size(); i++) { BILLIARDS.draw(borders[i]); }
	for (int i = 0; i < pockets.size(); i++) 
	{ 
		BILLIARDS.draw(pockets[i]);
		BILLIARDS.draw(pockets2[i]);
	}

	MoveDraw();
}
Ejemplo n.º 10
0
	Brick(float mX, float mY) {
		shape.setPosition(mX, mY);
		shape.setSize({blockWidth, blockHeight});
		shape.setFillColor(sf::Color::Yellow);
		shape.setOrigin(blockWidth /2.f, blockHeight /2.f );
	}
Ejemplo n.º 11
0
	Paddle(float mX, float mY) {
		shape.setPosition(mX, mY);
		shape.setSize({paddleWidth, paddleHeight});
		shape.setFillColor(sf::Color::Red);
		shape.setOrigin(paddleWidth /2.f, paddleHeight /2.f );
	}
Ejemplo n.º 12
0
void MameUIsenWindow::centerElement(sf::RectangleShape& rectangleShape)
{
	sf::FloatRect fr = rectangleShape.getLocalBounds();
	rectangleShape.setOrigin(fr.left + fr.width/2.0f, fr.top + fr.height/2.0f);
}
Ejemplo n.º 13
0
        Player () {
            PlayerNumber = totalPlayers;
            Sprite = loadSpriteData("Player " + intToString(PlayerNumber + 1));
            //Get Global width, seperate to rotation
            CharacterWidth = Sprite.getGlobalBounds().width;
            nameSpacing = 30;
            healthBarSpacing = nameSpacing + 15;

            Sprite.setOrigin(Sprite.getGlobalBounds().width/2, Sprite.getGlobalBounds().height/2);
            Sprite.setPosition((App.getSize().x/2) - (Sprite.getGlobalBounds().width/2), (App.getSize().y/2) - (Sprite.getGlobalBounds().height/2));

            //PlayerName.setFont(sf::Font::getDefaultFont());
            PlayerName.setCharacterSize(15);
            PlayerName.setString("Player: " + intToString(PlayerNumber + 1));
            PlayerName.setOrigin(PlayerName.getGlobalBounds().width/2, PlayerName.getGlobalBounds().height/2);
            PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing);

            NameOutline.setSize(sf::Vector2f(PlayerName.getGlobalBounds().width, PlayerName.getGlobalBounds().height));
            NameOutline.setOutlineThickness(2);
            NameOutline.setFillColor(sf::Color(0, 0, 0, 120));
            NameOutline.setOutlineColor(sf::Color::Black);
            NameOutline.setOrigin(NameOutline.getGlobalBounds().width/2, NameOutline.getGlobalBounds().height/2);
            NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4);

            MaxHealth = Health = 100;
            HealthBarSize = 50;

            HealthBarRed.setSize(sf::Vector2f(HealthBarSize, 5));
            HealthBarRed.setOutlineThickness(1);
            HealthBarRed.setFillColor(sf::Color::Red);
            HealthBarRed.setOutlineColor(sf::Color::Black);
            HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);

            HealthBarGreen.setSize(sf::Vector2f(HealthBarSize, 5));
            HealthBarGreen.setOutlineThickness(1);
            HealthBarGreen.setFillColor(sf::Color::Green);
            HealthBarGreen.setOutlineColor(sf::Color::Black);
            HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);

            if (controllerConnected) {
                ControlScheme = ControlSchemes::Joystick;
                Key k;
                k.InputType = Input::JoystickMovedNeg;
                k.KeyCode = sf::Joystick::Axis::Y;
                Bindings["Up"] = k;

                k.InputType = Input::JoystickMovedPos;
                k.KeyCode = sf::Joystick::Axis::Y;
                Bindings["Down"] = k;

                k.InputType = Input::JoystickMovedNeg;
                k.KeyCode = sf::Joystick::Axis::X;
                Bindings["Left"] = k;

                k.InputType = Input::JoystickMovedPos;
                k.KeyCode = sf::Joystick::Axis::X;
                Bindings["Right"] = k;
                } else {
                    ControlScheme = ControlSchemes::KeyboardMouse;
                    Key k;
                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::W;
                    Bindings["Up"] = k;

                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::S;
                    Bindings["Down"] = k;

                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::A;
                    Bindings["Left"] = k;

                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::D;
                    Bindings["Right"] = k;
                    }

            totalPlayers++;
            }
void centerOrigin(sf::RectangleShape& shape)
{
    sf::FloatRect bounds = shape.getLocalBounds();
    shape.setOrigin(std::floor(bounds.left + bounds.width/2.f), std::floor(bounds.top + bounds.height/2.f));
}
Ejemplo n.º 15
0
 inline void update(FT mFT) override
 {
     shp.setPosition(cPhys->getPosPx());
     shp.setSize(cPhys->getSizePx());
     shp.setOrigin(cPhys->getHalfSizePx());
 }
Ejemplo n.º 16
0
 Player()
 {
     recShape = new sf::RectangleShape(sf::Vector2f(100, 10));
     recShape->setOrigin(sf::Vector2f(50, 0));
     recShape->setPosition(sf::Vector2f(512, 600));
 }