I have 2 portals, one red, one blue, and when you touch one it teleports you to the other and removes both portals (otherwise you would get stuck in a loop of teleports). Any way to fix this?


public void act() { GameWorld board = (GameWorld) getWorld(); MouseInfo mouse = Greenfoot.getMouseInfo(); Actor wall; boolean can_use_portal = true; if (Greenfoot.mousePressed(null)) { if (mouse.getButton() == 1) { shootportal(1); //Shoots Red Portal } else { shootportal(2); //Shoots Blue Portal } } if(Greenfoot.isKeyDown("d") && canMove(1) == true) { setLocation(getX() + 5, getY()); //Move Right } if(Greenfoot.isKeyDown("a") && canMove(3) == true) { setLocation(getX() - 5, getY()); //Move Left } if ((getY() < (board.getHeight()-30)) && canMove(4) == true) { setLocation(getX(), getY() + 3); //Move Down } Actor redportal; Actor blueportal; blueportal bportal; redportal rportal; if (getObjectsInRange(1000, redportal.class).size() > 0 && getObjectsInRange(1000, blueportal.class).size() > 0) { bportal = (blueportal) getObjectsInRange(1000, blueportal.class).get(0); rportal = (redportal) getObjectsInRange(1000, redportal.class).get(0); if (getOneObjectAtOffset(0, 0, redportal.class) != null && can_use_portal) { can_use_portal = false; setLocation(bportal.getX(), bportal.getY()); } if ((getOneObjectAtOffset(0, 0, redportal.class) == null) || (getOneObjectAtOffset(0, 0, blueportal.class) == null)) { if (can_use_portal == false) { can_use_portal = true; } can_use_portal = true; } } if (getObjectsInRange(1000, redportal.class).size() > 0 && getObjectsInRange(1000, blueportal.class).size() > 0) { bportal = (blueportal) getObjectsInRange(1000, blueportal.class).get(0); rportal = (redportal) getObjectsInRange(1000, redportal.class).get(0); if (getOneObjectAtOffset(0, 0, blueportal.class) != null && can_use_portal) { can_use_portal = false; setLocation(rportal.getX(), rportal.getY()); } if ((getOneObjectAtOffset(0, 0, redportal.class) == null) || (getOneObjectAtOffset(0, 0, blueportal.class) == null)) { if (can_use_portal == false) { can_use_portal = true; } } } Actor finish_area; if (getOneObjectAtOffset(0, 0, finish_area.class) != null) { board.nextLevel(); } }