示例#1
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(); }
}
示例#2
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;
}
示例#3
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();
}
示例#4
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;
	}*/
}