int r, g, b, player;
int speed = 3;
int count = 0;
public Player(int player,int r, int g, int b)
{
setRotation(270);
this.r = r;
this.g = g;
this.b = b;
this.player = player;
getImage().setColor(new Color(r,g,b));
getImage().fillRect(0,0,40,40);
}
public void act()
{
count++;
getWorld().addObject(new Tail( r, g, b))
move(speed);
moveAround();
eatFood();
}
public void moveAround()
{
if(this.player == 0){
if(Greenfoot.isKeyDown("right"))
setRotation(0);
if(Greenfoot.isKeyDown("left"))
setRotation(180);
if(Greenfoot.isKeyDown("up"))
setRotation(270);
if(Greenfoot.isKeyDown("down"))
setRotation(90);
}
if(this.player == 4){
if(Greenfoot.isKeyDown("d"))
setRotation(0);
if(Greenfoot.isKeyDown("a"))
setRotation(180);
if(Greenfoot.isKeyDown("w"))
setRotation(270);
if(Greenfoot.isKeyDown("s"))
setRotation(90);
}
// Add your action code here.
}
public void eatFood()
{
if(isTouching(Food.class) && player == 0)
{
MyWorld myWorld = (MyWorld) getWorld();
myWorld.blueCounter.addScore();
}
if(isTouching(Food.class) && player == 4)
{
MyWorld myWorld = (MyWorld) getWorld();
myWorld.greenCounter.addScore();
}
}
}
