I am having trouble finding out how to make it so that the actor can't go through the ground. I would like the ground to be like a solid block so nothing can pass through. Please and Thank you.


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 | class CantGoThroughBlocks() { boolean blockedOnRight; public void act() { checkForCollisions(); if (blockedOnRight) { //do nothing } else { moveRight(); } } public void checkForCollisions() { Block b = getOneObjectAtOffset( this .getWidth()/ 2 + 1 , 0 ,Block. class ); if (b != null ) { blockedOnRight = true ; } else { blockedOnRight = false ; } } public void moveRight() { // insert incredibley creative and // brilliant code here } } |
1 2 3 4 5 6 | public boolean hit( int xoffset, int yoffset) //called by typing if(hit(int, int)) { stop moving in current direction } { Ground g = (Ground) getOneObjectAtOffset(xoffset, yoffset, Ground. class ); //check for ground at the given offsets if (g != null ) { return true ; } //if ground is found, return true return false ; //otherwise return false } |