您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)java如何實(shí)現(xiàn)抖音飛機(jī)大作戰(zhàn)的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
具體內(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; } }
感謝各位的閱讀!關(guān)于“java如何實(shí)現(xiàn)抖音飛機(jī)大作戰(zhàn)”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。