Beispiel #1
0
	Application() :
		m_window(sf::VideoMode(300, 300), "Flashlight!"),
		m_layer(),
		m_rect(sf::Vector2f(100.f, 100.f)),
		m_pos(0.f, 0.f)
	{
		m_window.setFramerateLimit(60);
		m_window.setMouseCursorVisible(false);

		m_layer.create(300, 300);
		m_flashlightTexture.create(60, 60);

		// We want to have semi-transparent edges.
		generateSpot();

		m_flashlight.setTexture(m_flashlightTexture.getTexture(), true);
		m_flashlight.setPosition(150.f, 150.f);
		m_flashlight.setOrigin(30.f, 30.f);

		m_rect.setFillColor(sf::Color::Red);
		m_rect.setPosition(100.f, 100.f);

		m_sprite.setTexture(m_layer.getTexture());
	}
Beispiel #2
0
  ThermalScannerApp()
    : readingsTree(
        0.0, 0.0, 360.0, thermalObservedPitchRange, 4
      )
    , scannerThread(&ThermalScannerApp::scannerThreadFunc, this)
    , httpdThread(&ThermalScannerApp::httpdThreadFunc, this)
    , wsdThread(&ThermalScannerApp::wsdThreadFunc, this)
  {
    isRunning = true;

    viewPitch = thermalViewPitchRange/2.0;
    viewYaw = 180.0;
    isViewLockedToDeviceOrientation = false;

    prevThermalUpdateTime = 0.0;

    viewImage.create(windowWidth, windowHeight);

    for(int i = 0; i < 0; i++) {
      RectTree<SensorReading>::Rect rect(
        (double)rand()/(double)RAND_MAX*360.0,
        (double)rand()/(double)RAND_MAX*thermalObservedPitchRange,
        (double)rand()/(double)RAND_MAX*50.0,
        (double)rand()/(double)RAND_MAX*50.0,
        SensorReading((double)rand()/(double)RAND_MAX*30.0, 5)
      );
      readingsTree.add(rect);
    }

    if(!font.loadFromFile("Arial Black.ttf")) {
      throw std::runtime_error("Unable to load font!");
    }

    sensorUpdateDelay = 35;
    scannerThread.launch();

    httpdThread.launch();

    //wsdThread.launch();
    wsdThread.launch();
  }
void GuiElement::adjustRenderTexture(sf::RenderTexture& texture)
{
    P<WindowManager> window_manager = engine->getObject("windowManager");
    //Hack the rectangle for this element so it sits perfectly on pixel boundaries.
    sf::Vector2f half_pixel = (window_manager->mapPixelToCoords(sf::Vector2i(1, 1)) - window_manager->mapPixelToCoords(sf::Vector2i(0, 0))) / 2.0f;
    sf::Vector2f top_left = window_manager->mapPixelToCoords(window_manager->mapCoordsToPixel(sf::Vector2f(rect.left, rect.top) + half_pixel));
    sf::Vector2f bottom_right = window_manager->mapPixelToCoords(window_manager->mapCoordsToPixel(sf::Vector2f(rect.left + rect.width, rect.top + rect.height) + half_pixel));
    rect.left = top_left.x;
    rect.top = top_left.y;
    rect.width = bottom_right.x - top_left.x;
    rect.height = bottom_right.y - top_left.y;

    sf::Vector2i texture_size = window_manager->mapCoordsToPixel(sf::Vector2f(rect.width, rect.height) + half_pixel) - window_manager->mapCoordsToPixel(sf::Vector2f(0, 0));
    unsigned int sx = powerOfTwo(texture_size.x);
    unsigned int sy = powerOfTwo(texture_size.y);
    if (texture.getSize().x != sx && texture.getSize().y != sy)
    {
        texture.create(sx, sy, false);
    }
    //Set the view so it covers this elements normal rect. So we can draw exactly the same on this texture as no the normal screen.
    sf::View view(rect);
    view.setViewport(sf::FloatRect(0, 0, float(texture_size.x) / float(sx), float(texture_size.y) / float(sy)));
    texture.setView(view);
}
Beispiel #4
0
		LightMap(unsigned int width, unsigned int height, sf::Uint8 minA = sf::Uint8(0)) : minAlpha(minA)
		{
			texture.create(width, height);
			lightBuffer.create(width, height);
		}
Beispiel #5
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;
	};
Beispiel #6
0
int main(){
	Node* head = new Node(SIZE / 2,SIZE/2,UP);
	head->next = new Node(SIZE/2,SIZE/2-1,UP);
	head->next->next = new Node(SIZE/2,SIZE/2 - 2,UP);
	head->next->next->next = new Node(SIZE/2,SIZE/2-3,UP);
	head->next->next->next->next = new Node(SIZE/2,SIZE/2-4,UP);
	head->next->next->next->next->next = nullptr;
	float speed = 150;
	sf::SoundBuffer soundBuffer;
	soundBuffer.loadFromFile("boop.wav");
	sf::Sound sound;
	sound.setBuffer(soundBuffer);
	gameOver = false;
	  srand (time(NULL));

	//sq[32][32] = UP;
	//sq[32][31] = UP;
	//sq[32][30] = UP;
	//sq[32][29] = UP;
	//sq[32][28] = UP;
	for(int x = 0; x <SIZE; x++){
		for( int y = 0; y < SIZE; y++){
			blacklist[x][y] = false;
		}
	}
	

	sf::RenderWindow window(sf::VideoMode(640, 640, 32), "Snake", sf::Style::Titlebar | sf::Style::Close);
	sf::Clock clock;
	clock.restart();
	sf::Event windowEvent;
	renderTexture.create(640,640);
	renderTexture.display();
	sf::Texture gameOverScreen;
	gameOverScreen.loadFromFile("gameover.png", sf::IntRect(320,192,640,640));
	sf::Sprite sprite;
	sprite.setTexture(gameOverScreen);
	bool upPress, downPress, leftPress, rightPress = false;
	int addCount = 0;
	int soundCount = 0;

	while(window.isOpen()){
		bool anyEvent = false ;
		while (window.pollEvent(windowEvent))
		{//Event Handling
			anyEvent = true;
			switch (windowEvent.type)
			{
				//running = false;
			case sf::Event::KeyPressed:
				if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
					//std::cout << "left" << leftPress <<"\n";
					if(head->dir != RIGHT && !leftPress){
						head->dir = LEFT;
						leftPress = true;
					}
				}else{
					leftPress = false;
				}

				if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
					//std::cout << "right\n";
					if(head->dir != LEFT && !rightPress){
						head->dir = RIGHT;
						rightPress = true;
					}
				}else{
					//std::cout << "rightcall";
					rightPress = false;
				}

				if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){//inverted
					//std::cout << "down\n";
					if(head->dir != DOWN && !upPress){
						head->dir = UP;
						upPress = true;
					}
				}else{
					upPress = false;
				}


				if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){//inverted
					//std::cout << "up\n";
					if(head->dir != UP && !downPress){
						head->dir = DOWN;
						downPress = true;
					}
				}else{
					downPress = false;
				}

				break;

			case sf::Event::Closed:
				//delete head;
				window.close();
				break;

			}
		}//\EventHandling
		if(!anyEvent){
			leftPress = false;
			rightPress = false;
			upPress = false;
			downPress = false;
		}
		anyEvent = false;


		//for(int x = 0; x < 64; ++x){
		//	for(int y = 0; y < 64; ++y){
		sf::Time t = clock.getElapsedTime();
		if(t.asMilliseconds() > speed){
			updatePos(*head);
			updateDir(*head);
			soundCount++;
			if(soundCount > 5){
				sound.play();
				soundCount = 0;
			}
			clock.restart();
			if(!gameOver)
				gameOver = !checkBounds(*head);
			checkIntersect(*head);//gen blacklist
			if(addCount > 0){
				--addCount;
				Node* end = getEnd(*head);
				switch(end->dir){
				case UP:
					end->next = new Node(end->x, end->y - 1, end->dir);//backwards
					break;
				case DOWN:
					end->next = new Node(end->x, end->y + 1, end->dir);//backwards
					break;
				case LEFT:
					end->next = new Node(end->x + 1, end->y, end->dir);//backwards
					break;
				case RIGHT:
					end->next = new Node(end->x - 1, end->y, end->dir);//backwards
					break;}
				end->next->next = nullptr;
			}

			if(newFood){
				addCount = 4;
				if(speed >100){
				speed *= .95;
				//sound.setPitch(sound.getPitch()*1.1);
				}
				foodX = rand() % SIZE;
				foodY = rand() % SIZE;
				while(blacklist[foodX][foodY] == true){
					foodX = rand() % SIZE;
					foodY = rand() % SIZE;
				}

				newFood = false;
			}
		}
		if(gameOver){
			window.draw(sprite);
			window.display();
			gameOver = false;
			sf::Time t = sf::seconds(.5);
			for(int i = 0; i < 6; ++i)
			sf::sleep(t);
			delete head->next;
			head->x = SIZE/2;
			head->y = SIZE/2;
			head->next = new Node(SIZE/2,SIZE/2-1,UP);
			head->next->next = new Node(SIZE/2,SIZE/2 - 2,UP);
			head->next->next->next = new Node(SIZE/2,SIZE/2-3,UP);
			head->next->next->next->next = new Node(SIZE/2,SIZE/2-4,UP);
			head->next->next->next->next->next = nullptr;
			float speed = 150;
			foodX = SIZE*.75;
			foodY = SIZE*.75;
			newFood = false;
		}
		if(!gameOver){
			displaySnake(*head);
			
			sf::RectangleShape draw1 = sf::RectangleShape(sf::Vector2f(640/SIZE,640/SIZE));
			draw1.setPosition(sf::Vector2f(foodX * (640/SIZE), foodY * (640/SIZE)));
			draw1.setFillColor(sf::Color::White);
			renderTexture.draw(draw1);
		}
		sf::Texture texture = renderTexture.getTexture();
		// draw it to the window
		sf::Sprite sprite(texture);
		window.draw(sprite);
		window.display();
		renderTexture.clear();
		for(int x = 0; x < SIZE; x++){
			for( int y = 0; y < SIZE; y++){
				blacklist[x][y] = false;
			}
		}
	}
}