1 Star 0 Fork 80

陈航 / asteroids

forked from 吕焱飞 / asteroids 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Bullet.java 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
luyanfei78 提交于 2020-04-15 10:17 . asteroids initialized.
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/chen-hang520/asteroids.git
git@gitee.com:chen-hang520/asteroids.git
chen-hang520
asteroids
asteroids
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891