這篇文章給大家分享的是有關(guān)java如何實現(xiàn)抖音飛機(jī)大作戰(zhàn)的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
創(chuàng)新互聯(lián)主營綦江網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶App定制開發(fā),綦江h(huán)5成都微信小程序搭建,綦江網(wǎng)站營銷推廣歡迎綦江等地區(qū)企業(yè)咨詢
具體內(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如何實現(xiàn)抖音飛機(jī)大作戰(zhàn)”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
網(wǎng)頁題目:java如何實現(xiàn)抖音飛機(jī)大作戰(zhàn)
文章出自:http://chinadenli.net/article20/ppjoco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、微信小程序、網(wǎng)站營銷、Google、企業(yè)建站、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)