加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Explosion.java 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
luyanfei78 提交于 2021-04-13 22:33 . add initial files.
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);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化