Hi, I have written code which should enable Mario to kill a goomba if he is above the goomba, but he will die if he is next to the goomba
This is in my Mario class. For my goomba class, I have this:
For some reason, even when I stand next to a goomba, Mario kills the goomba. No matter what, the goomba dies. I dont understand why this isnt working. Could someone please help me out? Thanks in advance
public boolean onGoomba() { Actor under = getOneObjectAtOffset (0, getImage().getHeight() / 2, Goomba.class); Actor under1 = getOneObjectAtOffset (1, getImage().getHeight() / 2, Goomba.class); Actor under2 = getOneObjectAtOffset (-1, getImage().getHeight() / 2, Goomba.class); if (under != null || under1 != null || under2 != null) { return true; } else { return false; } } public void checkKill() { if (canSee (Goomba.class) && onGoomba()==true) { MyWorld x = (MyWorld) this.getWorld(); Goomba current = getGoomba(Goomba.class); for(int i=0;i<2;i++){ if(x.enemies1[i]==current){ x.enemies1[i]=null; Greenfoot.playSound("GoombaDead.mp3"); } } x.removeObject(current); vSpeed = -20; fall(); } }
public void killMario() { if (canSee(Mario.class) && nextToMarioLeft()==true || canSee(Mario.class) && nextToMarioRight()==true) { eat(Mario.class); Greenfoot.stop(); } } public boolean belowMario() { Actor above = getOneObjectAtOffset (0, getImage().getHeight() / 2, Mario.class); return above !=null; } public boolean nextToMarioLeft() { Actor nextto = getOneObjectAtOffset (getImage().getWidth() / 2, 0, Mario.class); return nextto != null; } public boolean nextToMarioRight() { Actor nextto = getOneObjectAtOffset (-(getImage().getWidth()/2), 0, Mario.class); return nextto != null; }