Example #1
0
	void draw(sf::RenderTarget &tg)
	{
		if (first)
		{
			rt.clear();
			rt.draw(sprite);
			rt.draw(logo);
			if (logo.getPosition().y == 0.0)rt.draw(press);

			if (check && timer.getElapsedTime().asSeconds() < 1)
			{
				if ((int)(rand() % 10) == 3) rt.clear(sf::Color::White);
			}
		}
		else
		{
			rt.clear(sf::Color::White);
			rt.draw(system);
			rt.draw(back2);
			rt.draw(pointer);
		}
		rt.display();
		sm.draw(rt, tg);
		if (first) tg.draw(v);
	};
Example #2
0
	void run()
	{
		while (m_window.isOpen())
		{
			sf::Event event;
			while (m_window.pollEvent(event))
			{
				if (event.type == sf::Event::Closed)
					m_window.close();
			}

			// Update the position of the 'flashlight' to the current mouse position
			m_pos = static_cast<sf::Vector2f>(sf::Mouse::getPosition(m_window));
			m_flashlight.setPosition(m_pos);

			// Stance-out the 'flashlight' circle
			m_layer.clear();
			m_layer.draw(m_flashlight, sf::BlendMultiply);
			m_layer.display();

			m_window.clear(sf::Color::Blue);

			// Draw the layer sprite on top of the 'scene'
			m_window.draw(m_rect);
			m_window.draw(m_sprite);

			m_window.display();
		}
	}
Example #3
0
bool AppState::render(sf::RenderTexture& texture, int frame)
{
  texture.clear();

  if (m_preDesktopRenderFunctor) m_preDesktopRenderFunctor(texture, frame);
  the_desktop.render(texture, frame);
  if (m_postDesktopRenderFunctor) m_postDesktopRenderFunctor(texture, frame);

  texture.display();
  return true;
}
Example #4
0
	void generateSpot()
	{
		m_flashlightTexture.clear();

		// Draw 6 circles with increasing transparency
		for (unsigned int i = 0; i < 6; ++i)
		{
			sf::CircleShape temp(30.f - (i*2.f));
			temp.setOrigin(sf::Vector2f(30.f - (i*2.f), 30.f - (i*2.f)));
			temp.setFillColor(sf::Color(255, 255, 255, 101 - (i * 20)));
			temp.setPosition(sf::Vector2f(30.f, 30.f));

			m_flashlightTexture.draw(temp, sf::BlendNone);
		}

		//m_flashlightTexture.display();
	}
Example #5
0
		void        draw      (sf::RenderTarget & target, sf::RenderStates states = sf::RenderStates::Default) const
		{
			lightBuffer.clear();
			texture.display();
			states.texture = &texture.getTexture();
			for (const auto & light : lights)
			{
				light.draw(lightBuffer, getView(), states);
			}
			sf::Vector2f dimensions = sf::Vector2f(texture.getSize());
			sf::VertexArray vertices(sf::Quads, 4);
			vertices[0] = sf::Vertex(sf::Vector2f(0.f, 0.f), sf::Color(255, 255, 255, minAlpha), sf::Vector2f(0.f, 0.f));
			vertices[1] = sf::Vertex(sf::Vector2f(dimensions.x, 0.f), sf::Color(255, 255, 255, minAlpha), sf::Vector2f(dimensions.x, 0.f));
			vertices[2] = sf::Vertex(dimensions, sf::Color(255, 255, 255, minAlpha), dimensions);
			vertices[3] = sf::Vertex(sf::Vector2f(0.f, dimensions.y), sf::Color(255, 255, 255, minAlpha), sf::Vector2f(0.f, dimensions.y));
			lightBuffer.draw(vertices, states);
			lightBuffer.display();
			target.draw(sf::Sprite(lightBuffer.getTexture()));
		}
Example #6
0
		void        clear     (const sf::Color & color = sf::Color::Black)
		{
			texture.clear(color);
		}
Example #7
0
  void onRender(sf::RenderWindow &window, double time, double deltaTime)
  {
    double thermalViewYawRange = thermalViewPitchRange/windowHeight*windowWidth;
    double vxmin = 0.0;//viewYaw-thermalViewYawRange/2.0;
    double vxmax = 360.0;//viewYaw+thermalViewYawRange/2.0;
    double vymin = 0;//viewPitch-thermalViewPitchRange/2.0;
    double vymax = thermalObservedPitchRange;//viewPitch+thermalViewPitchRange/2.0;

    double cursorTemp = 0.0;
    double cursorOverlap = 0.0;

    window.clear(sf::Color::Black);

    sf::RectangleShape pixel;
    //pixel.setSize(sf::Vector2f(thermalViewPixelSize, thermalViewPixelSize));

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::P)) {
      viewImage.clear();
      for(int px = 0; px < windowWidth; px += thermalViewPixelSize) {
        for(int py = 0; py < windowHeight; py += thermalViewPixelSize) {
          updatedPixels.push_back(sf::Vector2<int>(px, py));
        }
      }
    } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::C)) {
      /*std::vector<RectTree<SensorReading>::RectResult> resList;
      readingsTree.retrieveAllRects(resList);
      readingsTree.removeResults(resList);*/
      viewImage.clear();
      readingsTree.reset(0.0, 0.0, 360.0, thermalObservedPitchRange, 4);
    }

    //std::deque< sf::Vector2<int> >::iterator iter = updatedPixels.begin();
    auto iter = updatedPixels.begin();
    for(; iter != updatedPixels.end(); iter++) {
      int px = iter->x, py = iter->y;

      double vx = vxmin+(vxmax-vxmin)*((double)px/(double)windowWidth );
      double vy = vymin+(vymax-vymin)*((double)py/(double)windowHeight);
      double vw = thermalPixelSizeYaw;
      double vh = thermalPixelSizePitch;

      std::vector<RectTree<SensorReading>::RectResult> resList;
      readingsTree.findRectsAtPoint(vx, vy, resList);

      std::vector<RectTree<SensorReading>::RectResult> delList;

      pixel.setPosition(sf::Vector2f(px, py));
      pixel.setSize(sf::Vector2f(
        thermalViewPixelSize,
        thermalViewPixelSize //(double)thermalViewPixelSize/(double)windowWidth*(double)windowHeight
      ));

      double temp = 0.0; int count = 0; double sum = 0;
      RectTree<SensorReading>::RectResult *oldestRes = NULL; double oldestTime = 0.0;
      std::vector<RectTree<SensorReading>::RectResult>::iterator iter = resList.begin();
      for(; iter != resList.end(); iter++) {
        RectTree<SensorReading>::RectResult &res = *iter;
        double age = time-res.rect->value.time;
        /*if(res.rect->value.time < oldestTime || oldestRes == NULL) {
          oldestTime = res.rect->value.time;
          oldestRes = &res;
        }*/
        double ageScalar = 1.0/(1.0+age);
        temp += res.rect->value.temp*ageScalar;
        sum += ageScalar;
        count++;
      }
      if(count > 40) {
        delList.insert(delList.end(), resList.begin(), resList.begin()+10);
      }
      temp /= sum;
      if(count > 0) {
        pixel.setFillColor(getThermalPixelColor(temp));
      } else {
        pixel.setFillColor(sf::Color::Black);
      }
      viewImage.draw(pixel);
      if(
            cursorX > px && cursorX < px+thermalViewPixelSize
        &&  cursorY > py && cursorY < py+thermalViewPixelSize
      ) {
        cursorTemp = temp;
      }

      readingsTree.removeResults(delList);
    }
    int updatedPixelCount = updatedPixels.size();
    updatedPixels.clear();

    viewImage.display();
    sf::Sprite sprite(viewImage.getTexture());
    window.draw(sprite);


    if(0) {
      std::vector<RectTree<SensorReading>::RectResult> resList;
      readingsTree.retrieveAllRects(resList);

      std::vector<RectTree<SensorReading>::RectResult>::iterator iter = resList.begin();
      for(; iter != resList.end(); iter++) {
        RectTree<SensorReading>::RectResult &res = *iter;
        double px = res.rect->x/vxmax*windowWidth;
        double py = res.rect->y/vymax*windowHeight;
        double pw = res.rect->w/vxmax*windowWidth;
        double ph = res.rect->h/vymax*windowHeight;
        pixel.setFillColor(sf::Color(255*(double)res.rect->value.temp/30.0, 50, 50, 100));
        pixel.setPosition(sf::Vector2f(px, py));
        pixel.setSize(sf::Vector2f(pw, ph));
        sf::RenderStates rs;
        rs.blendMode = sf::BlendAlpha;
        window.draw(pixel);
      }
    }
    if(1) {
      pixel.setFillColor(sf::Color(255, 255, 255));
      std::vector<RectTree<SensorReading>::RectResult> resList;
      double cvx = (double)cursorX/(double)windowWidth*vxmax;
      double cvy = (double)cursorY/(double)windowHeight*vymax;
      readingsTree.findRectsAtPoint(cvx, cvy, resList);

      updatedPixels.push_back(sf::Vector2<int>(
        floor(cursorX/thermalViewPixelSize)*thermalViewPixelSize,
        floor(cursorY/thermalViewPixelSize)*thermalViewPixelSize
      ));
      
      std::vector<RectTree<SensorReading>::RectResult>::iterator iter = resList.begin();
      for(; iter != resList.end(); iter++) {
        RectTree<SensorReading>::RectResult &res = *iter;
        double px = res.rect->x/vxmax*windowWidth;
        double py = res.rect->y/vymax*windowHeight;
        double pw = res.rect->w/vxmax*windowWidth;
        double ph = res.rect->h/vymax*windowHeight;
        pixel.setPosition(sf::Vector2f(px, py));
        pixel.setSize(sf::Vector2f(pw, ph));
        window.draw(pixel);
        cursorOverlap++;
      }

      // RectTree<SensorReading>::Node &node = readingsTree.getNodeAtPoint(cvx, cvy);
      // pixel.setPosition(sf::Vector2f(node.x/vxmax*windowWidth, node.y/vymax*windowHeight));
      // pixel.setSize(sf::Vector2f(node.w/vxmax*windowWidth, node.h/vymax*windowHeight));
      // pixel.setFillColor(sf::Color::Green);
      // window.draw(pixel);
    }

    sf::Text text;
    text.setFont(font);
    std::stringstream ss;
    ss << viewYaw << ", " << viewPitch << "; "
       << drAlpha << ", " << drGamma
       << " -- " << cursorTemp << ", " << cursorOverlap
       << " -- " << 1/deltaTime << "FPS, " << updatedPixelCount
    ;
    text.setString(ss.str());
    text.setCharacterSize(24);
    text.setColor(sf::Color::White);

    window.draw(text);
    window.display();
  }
Example #8
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;
			}
		}
	}
}