예제 #1
0
static void fill_shape(sf::RenderTarget& target, sf::Shape& shape, int x, int y, sf::Color colour) {
	shape.setPosition(x, y);
	shape.setFillColor(colour);
	setActiveRenderTarget(target);
	target.draw(shape);
	
}
예제 #2
0
static void frame_shape(sf::RenderTarget& target, sf::Shape& shape, int x, int y, sf::Color colour) {
	shape.setPosition(x, y);
	shape.setOutlineColor(colour);
	shape.setFillColor(sf::Color::Transparent);
	// TODO: Determine the correct outline value; should be one pixel, not sure if it should be negative
	shape.setOutlineThickness(-1.0);
	target.draw(shape);
}
	void move(std::vector<Snake>& snakes) {
	
		
		int size = snake.size();
		sf::Vector2f t,old=snake[size-1];
		
		
		if (inventory!=NULL) {
			inventory->setPosition(snake[size-1]+sf::Vector2f(15,15));
		};
		if (has_eaten) {
			snake.push_back(snake[size-1]+movedir);
			has_eaten=false;
		} else
			
			//this shit's retarded yo - beware or refactor.
			for (int i = size-1 ; i >=0 ; i--) {
				if (i==size-1) {
					snake[size-1]+=movedir;
					
				//collisions and frags
					for (int sn=0;sn <snakes.size();sn++) {
						for (int y=0;y<=snakes[sn].snake.size();y++) {
							//If we're going through ourselves and we're at the head,skip collission
							if ((snakes[sn].id==id) && (y==size-1)) continue;
							if (sf::FloatRect(snakes[sn].snake[y],sf::Vector2f(20,20)).contains(snake[size-1]+movedir)) {
								
								//std::cout << std::to_string(id) << " crash " << std::to_string(snake2.id) << " " <<  std::to_string(y) << "\n";
							
								if (id!=snakes[sn].id) {snakes[sn].score+=1;}
								else score--;
								reset();
								return;
							};
						}
					};
				}
				else {
					t=snake[i];
					snake[i]=old;
					old=t;
				};
				
				//wrap-around
				if (snake[i].x<-15) 
					snake[i].x=XRES-30;
				else if (snake[i].x>XRES)
					snake[i].x=-15;
				
				if (snake[i].y<-15) 
					snake[i].y=YRES-30;
				else if (snake[i].y>YRES)
					snake[i].y=-15;	
			};
	};