java實(shí)現(xiàn)抖音飛機(jī)大作戰(zhàn)
本文實(shí)例為大家分享了java抖音飛機(jī)大作戰(zhàn)的具體代碼,供大家參考,具體內(nèi)容如下
Airplane.java
package zmf.game.shoot;
import java.util.Random;
/**
* @author jcf
* @Description: Airplane----敵機(jī)既是飛行物
* @date 2018-03-28 11:17:16
*/
public class Airplane extends FlyingObject implements Enemy{
/** 敵機(jī)走步的步數(shù) **/
private int speed = 2;
public Airplane(){
image = ShootGame.airplane;
width = image.getWidth();
height = image.getHeight();
Random rand = new Random();
x = rand.nextInt(ShootGame.WIDTH - this.width);
//y:負(fù)的敵機(jī)的高
y = -this.height;
}
@Override
public int getScore(){
return 5;
}
@Override
public void step(){
y += speed;
}
/**
* 是否越界
* @return
*/
@Override
public boolean outOfBounds(){
//敵機(jī)的y坐標(biāo)大于窗口的高
return this.y > ShootGame.HEIGHT;
}
}
FlyingObject.java
package zmf.game.shoot;
import java.awt.image.BufferedImage;
/**
* @author jcf
* @Description: 飛行物主類
* @date 2018-03-28 11:17:16
*/
public abstract class FlyingObject {
/** 圖片命名--java包自有的 **/
protected BufferedImage image;
/** 寬 **/
protected int width;
/** 高 **/
protected int height;
/** x坐標(biāo) **/
protected int x;
/** y坐標(biāo) **/
protected int y;
/**
* 飛行物走步
*/
public abstract void step();
/**
* 是否越界
* @return
*/
public abstract boolean outOfBounds();
/**
* 敵人被子彈撞
* @param bullet
* @return
*/
public boolean shootBy(Bullet bullet){
//this:敵人 other:子彈
int x1 = this.x;
int x2 = this.x + this.width;
int y1 = this.y;
int y2 = this.y + this.height;
int x = bullet.x;
int y = bullet.y;
return x > x1 && x < x2
&&
y > y1 && y < y2;
}
}
完整源碼下載地址:飛機(jī)大作戰(zhàn)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Boot整合Web項(xiàng)目常用功能詳解
這篇文章主要介紹了Spring Boot整合Web項(xiàng)目常用功能詳解,在Web應(yīng)用開(kāi)發(fā)過(guò)程中,可以通過(guò)Spring Boot的Starter來(lái)將這些常用功能進(jìn)行整合與集中維護(hù),以達(dá)到開(kāi)箱即用的目的。,需要的朋友可以參考下2019-06-06
解析Java中的定時(shí)器及使用定時(shí)器制作彈彈球游戲的示例
這篇文章主要介紹了Java中的定時(shí)器及使用定時(shí)器制作彈彈球游戲的示例,文中同時(shí)也分析了定時(shí)器timer的缺點(diǎn)及相關(guān)替代方案,需要的朋友可以參考下2016-02-02
深入了解Spring Boot2.3.0及以上版本的Liveness和Readiness功能
這篇文章主要介紹了Spring Boot2.3.0及以上版本的Liveness和Readiness功能示例深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10
SpringBoot下使用自定義監(jiān)聽(tīng)事件的流程分析
事件機(jī)制是Spring的一個(gè)功能,目前我們使用了SpringBoot框架,所以記錄下事件機(jī)制在SpringBoot框架下的使用,同時(shí)實(shí)現(xiàn)異步處理,這篇文章主要介紹了SpringBoot下使用自定義監(jiān)聽(tīng)事件,需要的朋友可以參考下2023-08-08
Javaweb監(jiān)聽(tīng)器實(shí)例之統(tǒng)計(jì)在線人數(shù)
這篇文章主要為大家詳細(xì)介紹了Javaweb監(jiān)聽(tīng)器實(shí)例之統(tǒng)計(jì)在線人數(shù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11
java運(yùn)行jar包提示?“XXX中沒(méi)有主清單屬性”?"找不到主類”兩種解決辦法
本文主要介紹了java運(yùn)行jar包提示?“XXX中沒(méi)有主清單屬性”?"找不到主類”兩種解決辦法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06

