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.
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 } }
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 }