Hello
I have the following code for a wall:
This wall fills up quite a bit of my world, as i am making a maze.
I have a Bullet actor, that is being shot from my character, and is supposed to disappear upon hitting the world edges, and upon hitting these walls. The full code for the bullet actor looks like this
Now, could anyone here possibly help me, or direct me as to which code i should put where, in order to make the bullets disappear upon hitting the Wall.class? it would be very much appreciated
Please note that the bullet is fairly large, so the distance to the wall at which the bullet is removed, needs to be very close to the wall, so that the bullet isnt just removed upon being created ( due to always being close to a wall )
Thanks everyone :)
1 2 3 4 5 6 7 8 9 | public class Wall extends Actor { public Wall() { GreenfootImage img = new GreenfootImage( 20 , 20 ); img.fill(); setImage(img); } } |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | public class Bullet extends Actor { /** * Act - do whatever the Bullet wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Bullet() { getImage().scale( 65 , 65 ); } public void act() { Kill(); WorldEdge(); } public void Kill() { move( 10 ); Actor enemy; enemy = getOneObjectAtOffset( 0 , 0 , Enemy. class ); if (enemy != null ) { World world; world = getWorld(); world.removeObject(enemy); } } public void WorldEdge() { if (atWorldEdge()) { getWorld().removeObject( this ); } } public boolean atWorldEdge() { if (getX() < 10 || getX() > getWorld().getWidth()- 10 ) { return true ; } if (getX() < 10 || getY() > getWorld().getHeight()- 10 ) { return true ; } else { return false ; } } } |