so i basically made the game tron having 2 players who run around with trails behind them now the game is basically complete but i want to know not to run into myself. i tried doing if can see redtrail (trail of the red player) but when the game starts the game ends because the trail got placed behind the red player right away. heres my code. for player
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Red here. * * @author (your name) * @version (a version number or a date) */ public class Red extends Players { /** * Act - do whatever the Red wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(); Trail(); Screen(); } private int xDirection, yDirection; public void move() { int dx = 0; int dy = 0; if (Greenfoot.isKeyDown("left")) dx--; if (Greenfoot.isKeyDown("right")) dx++; if (Greenfoot.isKeyDown("up")) dy--; if (Greenfoot.isKeyDown("down")) dy++; if (dx*dy == 0 && dx+dy != 0) { xDirection = dx; yDirection = dy; } setLocation(getX()+4*xDirection, getY()+4*yDirection); } public void Screen() { if(canSee(BlueTrail.class)) { LoseScreen(); } if(canSee(Blue.class)) { NoWinner(); } if(canSee(RedTrail.class)) { } if(canSee(YellowTrail.class)) { Greenfoot.stop(); } if(canSee(Yellow.class)) { Greenfoot.stop(); } } public void LoseScreen() { Greenfoot.stop(); } public void NoWinner() { String text = "Game Over!It is a Draw!"; Greenfoot.stop(); } public void Trail() { int xOff = 5; int yOff = 5; getWorld().addObject(new RedTrail(), getX(), getY()); } }