0460 explosion
Animerad explosion.
Kod för klassen Explosion
public class Explosion extends Actor
{
// image from: https://commons.wikimedia.org/wiki/File:Explosion-155624_icon.svg
private GreenfootImage originalImage;
private int size = 10;
public Explosion()
{
// save original image
originalImage = getImage();
resizeImage();
}
private void resizeImage()
{
// create copy of the original image
GreenfootImage imageCopy = new GreenfootImage(originalImage);
imageCopy.scale(size, size);
// display copy
setImage(imageCopy);
}
public void act()
{
size = size + 10;
resizeImage();
if (size > 300)
{
getWorld().removeObject(this);
}
}
}
Uppgift
Lägg till explosioner i ett av dina spel.