Tron
Tron
Tron
hpp>
#include <time.h>
using namespace sf;
struct player
{ int x,y,dir;
Color color;
player(Color c)
{
x=rand() % W;
y=rand() % H;
color=c;
dir=rand() % 4;
}
void tick()
{
if (dir==0) y+=1;
if (dir==1) x-=1;
if (dir==2) x+=1;
if (dir==3) y-=1;
Vector3f getColor()
{return Vector3f(color.r,color.g,color.b);}
};
int main()
{
srand(time(0));
Texture texture;
texture.loadFromFile("background.jpg");
Sprite sBackground(texture);
Sprite sprite;
RenderTexture t;
t.create(W, H);
t.setSmooth(true);
sprite.setTexture(t.getTexture());
t.clear(); t.draw(sBackground);
bool Game=1;
while (window.isOpen())
{
Event e;
while (window.pollEvent(e))
{
if (e.type == Event::Closed)
window.close();
}
if (!Game) continue;
for(int i=0;i<speed;i++)
{
p1.tick(); p2.tick();
if (field[p1.x][p1.y]==1) Game=0;
if (field[p2.x][p2.y]==1) Game=0;
field[p1.x][p1.y]=1;
field[p2.x][p2.y]=1;
CircleShape c(3);
c.setPosition(p1.x,p1.y); c.setFillColor(p1.color); t.draw(c);
c.setPosition(p2.x,p2.y); c.setFillColor(p2.color); t.draw(c);
t.display();
}
return 0;
}