1 Star 0 Fork 55

erido-8/asteroids-initial

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Bullet.java 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
luyanfei78 提交于 2021-04-13 22:33 . add initial files.
import greenfoot.*;
/**
* A bullet that can hit asteroids.
*
* @author Poul Henriksen
* @author Michael Kölling
*/
public class Bullet extends SmoothMover
{
/** The damage this bullet will deal */
private static final int damage = 16;
/** A bullet looses one life each act, and will disappear when life = 0 */
private int life = 30;
/**
* Default constructor for testing.
*/
public Bullet()
{
}
/**
* Create a bullet with given speed and direction of movement.
*/
public Bullet(Vector speed, int rotation)
{
super(speed);
setRotation(rotation);
addToVelocity(new Vector(rotation, 15));
Greenfoot.playSound("EnergyGun.wav");
}
/**
* The bullet will damage asteroids if it hits them.
*/
public void act()
{
if(life <= 0) {
getWorld().removeObject(this);
}
else {
life--;
move();
checkAsteroidHit();
}
}
/**
* Check whether we have hit an asteroid.
*/
private void checkAsteroidHit()
{
Asteroid asteroid = (Asteroid) getOneIntersectingObject(Asteroid.class);
if (asteroid != null)
{
getWorld().removeObject(this);
asteroid.hit(damage);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/erido-8/asteroids-initial.git
git@gitee.com:erido-8/asteroids-initial.git
erido-8
asteroids-initial
asteroids-initial
master

搜索帮助