Good Morning,
i have a problem and i can´t solve it on my own. I found nothing about this topic. I have a little programm, where a player should kill zombies an other monsters. This is working quite good, but the hitbox isn´t always perfect. For example: My boss is a spider an i can only hit the body-part, not the legs. If i put the image in another class (wall for example) it the shots hit to early.
With this code it also hits to early. I also tried "Actor P9mm = this.getOneObjectAtOffset(15,15, P9mm.class);". Obviously not successfully. With this code it hits to late.
mfg, alex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public P9mm() { P9mmschauzuMaus(); image1 = new GreenfootImage( "bullet.png" ); setImage(image1); } public void act() { move( 15 ); /*Geschwindigkeit Kugel*/ Actor Wand = this .getOneObjectAtOffset( 15 , 15 , Wand. class ); if (Wand != null ) { getWorld().removeObject( this ); } else if (hitEdge()) { World w = getWorld(); w.removeObject( 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 | public int HP = 50 ; /*Lebensabzug für P9mm*/ public int DmgP9 = 1 ; public void Health() { Actor P9mm = this .getOneIntersectingObject(P9mm. class ); if (P9mm != null ) { if (HP >= 0 ) { getWorld().removeObject(P9mm); HP = HP - DmgP9; if (HP <= 0 ) { Greenfoot.playSound( "slurp.wav" ); getWorld().removeObject( this ); } } } } |