This site requires JavaScript, please enable it in your browser!
Greenfoot back
dillyduck
dillyduck wrote ...

2017/2/13

Splitting an object into 2

dillyduck dillyduck

2017/2/13

#
hello im trying to make a game in which my rocket fires a laser and destroys an asteroid. However i want to make it so when i fire at an asteroid it splits into 2. Any advise?
Nosson1459 Nosson1459

2017/2/13

#
Add another object in the same location as the asteroid you hit, and have the images of the now two different actors smaller than the first original actor's image.
dillyduck dillyduck

2017/2/13

#
Should i add an actor class in this line of code?
Actor asteroid = getOneIntersectingObject(BigAsteroid.class);
          
          if(asteroid != null )
             {
             getWorld().removeObject(asteroid); 
             
             Space point = (Space)getWorld();
             point.addScore(100);
             }  
this is in my laser class so that if my laser touchers a BigAsteroid, it disappears. How do I say to make 2 SmallAsteroid appear then ?
Nosson1459 Nosson1459

2017/2/13

#
In this 'if' you should add two little asteroids, with two separate addObjects (I only had one type of asteroid but I changed the size of the image, when it was a certain size the little asteroid will just disappear and not get smaller until it's one pixel in size). And you should probably remove the bullet at the end of the 'if' also.
danpost danpost

2017/2/13

#
Create new SmallAsteroid objects using:
Actor smallAsteroid1 = new SmallAsteroid();
Then use 'getWorld().addObject(smallAsteroid1, << wherever >>);'.
You need to login to post a reply.