예제 #1
0
void OnMouseUp(thor::ActionContext<std::string> context)
{
	emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
	if (selected_rune == 1)
	{
		// Build color gradient
		thor::ColorGradient gradient;
		gradient[0.f] = sf::Color::Yellow;
		gradient[0.5f] = sf::Color::Red;
		gradient[1.f] = sf::Color::Black;

		// Create color and fade in/out animations
		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		particle_system.clearAffectors();
		// Add particle affectors
		particle_system.addAffector(thor::AnimationAffector(colorizer));
		particle_system.addAffector(thor::AnimationAffector(fader));
		particle_system.addAffector(thor::TorqueAffector(100.f));

		emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
		emitter.setParticleVelocity(thor::Distributions::circle(sf::Vector2f(0.0f, 0.0f), 100.f));
		emitter.setEmissionRate(50.0f);
		particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(0.35f));
	}
	else if (selected_rune == 2)
	{
		// Build color gradient
		thor::ColorGradient gradient;
		gradient[0.f] = sf::Color::Blue;
		gradient[0.5f] = sf::Color::Black;
		gradient[1.f] = sf::Color::Black;

		// Create color and fade in/out animations
		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		particle_system.clearAffectors();
		// Add particle affectors
		particle_system.addAffector(thor::AnimationAffector(colorizer));
		particle_system.addAffector(thor::AnimationAffector(fader));
		particle_system.addAffector(thor::TorqueAffector(100.f));

		emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
		emitter.setParticleVelocity(thor::Distributions::deflect(sf::Vector2f(0.0f, -100.0f), 90.0f));
		emitter.setEmissionRate(100.0f);
		particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(0.35f));
	}
	else if (selected_rune == 3)
	{
		// Build color gradient
		thor::ColorGradient gradient;
		gradient[0.f] = sf::Color::Green;
		gradient[0.5f] = sf::Color::Cyan;
		gradient[1.f] = sf::Color::Black;

		// Create color and fade in/out animations
		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		particle_system.clearAffectors();
		// Add particle affectors
		particle_system.addAffector(thor::AnimationAffector(colorizer));
		particle_system.addAffector(thor::AnimationAffector(fader));
		particle_system.addAffector(thor::TorqueAffector(100.f));

		emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
		emitter.setParticleVelocity(thor::Distributions::rect(sf::Vector2f(0.0f, 0.0f), sf::Vector2f(100.0f, 100.0f)));
		emitter.setEmissionRate(150.0f);
		particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(2.0f));
	}
	else if (selected_rune == 4)
	{
		// Build color gradient
		thor::ColorGradient gradient;
		gradient[0.f] = sf::Color::Magenta;
		gradient[0.5f] = sf::Color::Green;
		gradient[1.f] = sf::Color::Black;

		// Create color and fade in/out animations
		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		particle_system.clearAffectors();
		// Add particle affectors
		particle_system.addAffector(thor::AnimationAffector(colorizer));
		particle_system.addAffector(thor::AnimationAffector(fader));
		particle_system.addAffector(thor::TorqueAffector(100.f));
		emitter.setParticleVelocity(thor::Distributions::circle(sf::Vector2f(0.0f, 0.0f), 250.0f));
		emitter.setEmissionRate(500.0f);
		particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(1.0f));
	}
}
예제 #2
0
	MainMenu() : system(TextureManager::instance().getTexture("assets/rticle.png"))
	{
		pointer.setTexture(TextureManager::instance().getTexture("assets/two_pointer.png"));
		//pointer.setPosition(1183, 427);

		//system = new thor::ParticleSystem();

		emitter.setEmissionRate(0.5f);
		emitter.setParticleLifetime( sf::seconds(40) );

		emitter.setParticleRotation( thor::Distributions::uniform(0.f, 360.f) );
		emitter.setParticlePosition( sf::Vector2f(1260,740) );
		emitter.setParticleScale(sf::Vector2f(0.1,0.1));

		system.addEmitter(thor::refEmitter(emitter));

		thor::ColorGradient gradient;
		gradient[0.0f] = sf::Color::Magenta;
		gradient[0.1f] = sf::Color::Red;
		gradient[0.2f] = sf::Color::Blue;
		gradient[0.3f] = sf::Color::Cyan;
		gradient[0.4f] = sf::Color::Green;
		gradient[0.5f] = sf::Color::Red;
		gradient[0.6f] = sf::Color::Magenta;
		gradient[0.7f] = sf::Color::Cyan;
		gradient[0.8f] = sf::Color::Red;
		gradient[0.9f] = sf::Color::Blue;
		gradient[1.0f] = sf::Color::Red;

		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		system.addAffector( thor::ScaleAffector(sf::Vector2f(0.1f,0.1)));	
		system.addAffector( thor::AnimationAffector(fader) );
		system.addAffector( thor::AnimationAffector(colorizer) );

		sprite = AnimatedSprite(sf::seconds(0.3));

		v.setTexture(TextureManager::instance().getTexture("assets/one_upper.png"));
		back2.setTexture(TextureManager::instance().getTexture("assets/two_menu.png"));
		logo.setTexture(TextureManager::instance().getTexture("assets/one_logo.png"));
		press.setTexture(TextureManager::instance().getTexture("assets/one_anybutton.png"));
		anim.setSpriteSheet(TextureManager::instance().getTexture("assets/one_animooted.jpg"));

		for (int i = 0; i < 5; i++)
		{
			anim.addFrame(sf::IntRect(0, 800 * i, WIDTH, HEIGHT));
		}

		sprite.setAnimation(anim);
		sprite.setLooped(true);
		sprite.play();

		logo.setColor(sf::Color(255,255,255,0));
		press.setColor(sf::Color(255,255,255,0));
		pointer.setColor(sf::Color(255,255,255,0));
		press.setPosition(WIDTH/2 - press.getTextureRect().width/2, HEIGHT/2 - press.getTextureRect().height/2 + 100);
		pressFading = true;

		newLogoY = 800;
		oTweener.addTween(&CDBTweener::TWEQ_BACK, CDBTweener::TWEA_INOUT, 2.f, &newLogoY, 0.0f);

		first = true;

		pressFactor = 0.2;
		transition = false;
		check = false;
		
		sm.init(sf::Vector2f(WIDTH, HEIGHT));
		rt.create(WIDTH, HEIGHT);

		MusicManager::instance().playMusicFast("low");

		selection = 1;
	};
예제 #3
0
int main()
{
	deltaTime = 0;
	sfg::SFGUI sfgui;

	// map sprite
	sf::Texture map_texture;
	sf::Sprite map_sprite;
	map_texture.loadFromFile("resources/map.png");
	map_sprite.setTexture(map_texture);

	// window
	window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32), "Runestone");
	view.setSize(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT));
	view.setCenter(sf::Vector2f(0, 0));
	window.setView(view);

	// timer
	sf::Clock clock;

	// thor actions
	thor::Action quit(sf::Event::Closed);
	thor::Action left(sf::Keyboard::A, thor::Action::Hold);
	thor::Action right(sf::Keyboard::D, thor::Action::Hold);
	thor::Action up(sf::Keyboard::W, thor::Action::Hold);
	thor::Action down(sf::Keyboard::S, thor::Action::Hold);
	thor::Action mouse_down(sf::Mouse::Left, thor::Action::PressOnce);
	thor::Action mouse_up(sf::Mouse::Left, thor::Action::ReleaseOnce);

	// thor action map
	thor::ActionMap<std::string> action_map;
	action_map["quit"] = quit;
	action_map["left"] = left;
	action_map["right"] = right;
	action_map["up"] = up;
	action_map["down"] = down;
	action_map["mouse_down"] = mouse_down;
	action_map["mouse_up"] = mouse_up;
	thor::ActionMap<std::string>::CallbackSystem action_callbacks;
	action_callbacks.connect("quit", &OnQuit);
	action_callbacks.connect("left", &OnLeft);
	action_callbacks.connect("right", &OnRight);
	action_callbacks.connect("up", &OnUp);
	action_callbacks.connect("down", &OnDown);
	action_callbacks.connect("mouse_down", &OnMouseDown);
	action_callbacks.connect("mouse_up", &OnMouseUp);

	// thor particles
	sf::Texture particleTexture;
	particleTexture.loadFromFile("Media/particle.png");
	emitter.setEmissionRate(100.0f);
	emitter.setParticleLifetime(sf::seconds(1.0f));

	particle_system.setTexture(particleTexture);

	// sfgui
	auto sfgui_window = sfg::Window::Create();
	sfgui_window->SetTitle("Runestones: ");
	auto rune_one = sfg::Button::Create("Rune One");
	rune_one->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneOne));
	rune_one->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked));
	auto rune_two = sfg::Button::Create("Rune Two");
	rune_two->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneTwo));
	rune_two->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked));
	auto rune_three = sfg::Button::Create("Rune Three");
	rune_three->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneThree));
	rune_three->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked));
	auto rune_four = sfg::Button::Create("Rune Four");
	rune_four->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneFour));
	rune_four->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked));
	auto hbox = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL, 4.0f);
	hbox->Pack(rune_one);
	hbox->Pack(rune_two);
	hbox->Pack(rune_three);
	hbox->Pack(rune_four);
	sfgui_window->Add(hbox);
	sfgui_window->SetStyle(!sfg::Window::Style::RESIZE);
	sfgui_window->SetPosition(sf::Vector2f((WINDOW_WIDTH / 2.0f) -
		(sfgui_window->GetAllocation().width / 2.0f), WINDOW_HEIGHT - sfgui_window->GetAllocation().height));

	// tileset
	sf::Texture tileTexture;
	tileTexture.loadFromFile("resources/tiles.png");
	rf::TileMap tileMap(4, 8);
	tileMap.setTexture(tileTexture);
	int layout[4][8] = 
	{
		{-1, -1, -1, 1, 1, -1, -1, -1},
		{1,1,1,1,1,1,1,1},
		{-1,-1,1,1,1,1,-1,-1},
		{1,1,1,1,1,1,1,1}
	};

	for (size_t i = 0; i < 4; i++)
	{
		for (size_t j = 0; j < 8; j++)
		{
			tileMap.setTile(layout[i][j], i, j);
		}
	}

	while (window.isOpen())
	{
		deltaTime = clock.restart().asSeconds();
		action_map.clearEvents();

		sf::Event event;
		while (window.pollEvent(event))
		{
			sfgui_window->HandleEvent(event);
			action_map.pushEvent(event);
		}

		particle_system.update(sf::seconds(deltaTime));

		sfgui_window->Update(deltaTime);
		action_map.invokeCallbacks(action_callbacks, &window);
		window.setView(view);
		window.clear(sf::Color::Black);
		window.draw(map_sprite);
		window.draw(tileMap);
		window.draw(particle_system);
		sfgui.Display(window);
		window.display();
	}

	return 0;
}
예제 #4
0
	void update(sf::Time time)
	{
		MusicManager::instance().update(time);

		system.update(time);

		sm.update();
		oTweener.step(time.asMilliseconds() / 1000.f);

		if ((int)(rand() % 90) == 3 && first) sm.setCurrentEffect("distortion", sf::seconds(0.05));
		if ((int)(rand() % 100) == 3 && !first) sm.setCurrentEffect("inversion", sf::seconds(1));

		if (first)
		{
			logo.setColor(sf::Color(255,255,255,interpolateLinear(logo.getColor().a, 255, 0.05f)));
			logo.setPosition(0, newLogoY);

			if (!pressFading)
			{
				press.setColor(sf::Color(255,255,255,interpolateLinear(press.getColor().a, 0,pressFactor)));
				if (press.getColor().a < 7)
				{
					pressFading = true;
				}
			}
			else
			{
				press.setColor(sf::Color(255,255,255,interpolateLinear(press.getColor().a, 255, pressFactor)));
				if (press.getColor().a > 243)
				{
					pressFading = false;
				}
			}

			sprite.update(time);

			if (transition && timer.getElapsedTime().asSeconds() > 0.5)
			{
				press.setColor(sf::Color(255,255,255,0));
			}

			if (transition && timer.getElapsedTime().asSeconds() > 0.5)
			{
				transition = false;
				oTweener.addTween(&CDBTweener::TWEQ_BACK, CDBTweener::TWEA_INOUT, 2.f, &newLogoY, -800.0f);
			}

			if (!transition && logo.getPosition().y <= -800 && !check)
			{
				sm.setCurrentEffect("rgb", sf::seconds(1));
				check = true;
				timer.restart();SoundManager::instance().playNoiseSound();
			}
			if (check && timer.getElapsedTime().asSeconds() > 1)
			{
				first = false;
				MusicManager::instance().playMusicFast("battle");				
				pressFading = true;
			}
		}		
		else
		{
			pressFactor = 0.2;
			if (!pressFading)
			{
				pointer.setColor(sf::Color(255,255,255,interpolateLinear(pointer.getColor().a, 0,pressFactor)));
				if (pointer.getColor().a < 7)
				{
					pressFading = true;
				}
			}
			else
			{
				pointer.setColor(sf::Color(255,255,255,interpolateLinear(pointer.getColor().a, 255, pressFactor)));
				if (pointer.getColor().a > 243)
				{
					pressFading = false;
				}
			}

			switch (selection)
			{
			case 0:
				pointer.setPosition(1183, 415);
				break;
			case 1:
				pointer.setPosition(1183, 531);
				break;
			case 2:			
				pointer.setPosition(1183, 645);
				break;
			default:
				break;
			}
		}
	};