This site requires JavaScript, please enable it in your browser!
Greenfoot back
Mepp
Mepp wrote ...

2013/3/1

How to code an area check?

Mepp Mepp

2013/3/1

#
Hi guys, I need to code an "public boolean checkFront(){}" method, that checks an spcified area in Front of an moving object from the class "Spieler" (extends Actor). If theres an other Object of the Class "Spieler" or an object of the class "Wallpiece" or if the area is to close to the border of the World, it should return "true" . I need also in that style a mehtod checkLeft() and checkRight(), they should check an specified area left/right of the object. I tried to make an object of the class "Checker"(just existing to exist), that moves through this are, but it took to much of the CPU resources, the game started to lag, so this isnt an Option.
danpost danpost

2013/3/1

#
Sounds like that the 'checkFront' method will call either 'checkLeft' or 'checkRight' depending on which way is toward the front of the actor. For the two individual side methods, you probably want to save the current location of the actor in local fields, then move the actor toward the side being checked. Next save the boolean returns of your checks in local fields and move the actor back to where it started. Finally return the OR'ed combination of boolean results.
You need to login to post a reply.