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?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 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(); } } |