代码拉取完成,页面将自动刷新
import greenfoot.*;
/**
* An explosion. It starts by expanding and then collapsing.
* The explosion will explode other obejcts that the explosion intersects.
*
* @author Poul Henriksen
* @version 1.0.1
*/
public class Explosion extends Actor
{
/** How many images should be used in the animation of the explostion */
private final static int IMAGE_COUNT= 12;
/**
* The images in the explosion. This is static so the images are not
* recreated for every object (improves performance significantly).
*/
private static GreenfootImage[] images;
/** Current size of the explosion */
private int imageNo = 0;
/** How much do we increment the index in the explosion animation. */
private int increment=1;
/**
* Create a new explosion.
*/
public Explosion()
{
initializeImages();
setImage(images[0]);
Greenfoot.playSound("MetalExplosion.wav");
}
/**
* Create the images for explosion.
*/
public synchronized static void initializeImages()
{
if(images == null)
{
GreenfootImage baseImage = new GreenfootImage("explosion-big.png");
images = new GreenfootImage[IMAGE_COUNT];
for (int i = 0; i < IMAGE_COUNT; i++)
{
int size = (i+1) * ( baseImage.getWidth() / IMAGE_COUNT );
images[i] = new GreenfootImage(baseImage);
images[i].scale(size, size);
}
}
}
/**
* Explode!
*/
public void act()
{
setImage(images[imageNo]);
imageNo += increment;
if(imageNo >= IMAGE_COUNT)
{
increment = -increment;
imageNo += increment;
}
if(imageNo < 0)
{
getWorld().removeObject(this);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。