1 Star 0 Fork 79

Dio/asteroids

forked from 吕焱飞/asteroids 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Explosion.java 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
Dio 提交于 2021-05-01 21:53 . update Explosion.java.
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);//size是大图片宽度/12. 、、scale缩放。
}
}
}
/**
* Explode!
*/
public void act()
{
setImage(images[imageNo]);
imageNo += increment;
if(imageNo >= IMAGE_COUNT)
{
increment = -increment;
imageNo += increment;
}
if(imageNo < 0)
{
getWorld().removeObject(this);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/i-am-the-ghost-cicada/asteroids.git
git@gitee.com:i-am-the-ghost-cicada/asteroids.git
i-am-the-ghost-cicada
asteroids
asteroids
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385