java实现抖音飞机大作战
本文实例为大家分享了java抖音飞机大作战的具体代码,供大家参考,具体内容如下
Airplane.java
packagezmf.game.shoot; importjava.util.Random; /** *@authorjcf *@Description:Airplane----敌机既是飞行物 *@date2018-03-2811:17:16 */ publicclassAirplaneextendsFlyingObjectimplementsEnemy{ /**敌机走步的步数**/ privateintspeed=2; publicAirplane(){ image=ShootGame.airplane; width=image.getWidth(); height=image.getHeight(); Randomrand=newRandom(); x=rand.nextInt(ShootGame.WIDTH-this.width); //y:负的敌机的高 y=-this.height; } @Override publicintgetScore(){ return5; } @Override publicvoidstep(){ y+=speed; } /** *是否越界 *@return */ @Override publicbooleanoutOfBounds(){ //敌机的y坐标大于窗口的高 returnthis.y>ShootGame.HEIGHT; } }
FlyingObject.java
packagezmf.game.shoot; importjava.awt.image.BufferedImage; /** *@authorjcf *@Description:飞行物主类 *@date2018-03-2811:17:16 */ publicabstractclassFlyingObject{ /**图片命名--java包自有的**/ protectedBufferedImageimage; /**宽**/ protectedintwidth; /**高**/ protectedintheight; /**x坐标**/ protectedintx; /**y坐标**/ protectedinty; /** *飞行物走步 */ publicabstractvoidstep(); /** *是否越界 *@return */ publicabstractbooleanoutOfBounds(); /** *敌人被子弹撞 *@parambullet *@return */ publicbooleanshootBy(Bulletbullet){ //this:敌人other:子弹 intx1=this.x; intx2=this.x+this.width; inty1=this.y; inty2=this.y+this.height; intx=bullet.x; inty=bullet.y; returnx>x1&&xy1&&y 完整源码下载地址:飞机大作战
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。