雷霆战机java课程设计总结_雷霆战机(学java以来第一个能稍微看看的程序)

这是一个基于Java的雷霆战机游戏程序设计,包括敌机(Airplane)、奖励(Bee)、大BOSS(Boss)和玩家飞机(Hero)等类的实现,实现了敌机的移动、玩家射击、碰撞检测等功能。游戏还包括了子弹(Bullet)和Boss子弹(BossBullet)的运动逻辑。通过定时器更新游戏状态,并根据得分判断游戏是否结束。
摘要由CSDN通过智能技术生成

package FlyHero;

import java.util.Random;

public class Airplane extends FlyingObject implements Enemy{

private int speed = 2;

public Airplane(){

this.image = ShootGame.airplane;

width = image.getWidth();

height = image.getHeight();

y = -height;

Random rand = new Random();

x = rand.nextInt(ShootGame.WIDTH - width);

}

@Override

public void step(){

y += speed;

}

@Override

public int getScore(){

return 3;

}

}

//-----------------------------------------------------------------------------------------------------------------------

package FlyHero;

public interface Award {

int DOUBLE_FIRE = 0;

int LIFE = 1;

int getType();

}

//-----------------------------------------------------------------------------------------------------------------------

package FlyHero;

import java.util.Random;

public class Bee extends FlyingObject implements Award{

private int xSpeed = 1;

private int ySpeed = 2;

private int awardType;

public Bee(){

this.image = ShootGame.bee;

width = image.getWidth();

height = image.getHeight();

y = -height;

Random rand = new Random();

x = rand.nextInt(ShootGame.WIDTH - width);

awardType = rand.nextInt(2);

}

@Override

public void step(){

x += xSpeed;

y += ySpeed;

if(x>ShootGame.WIDTH-width){

xSpeed = -1;

}

if(x<0){

xSpeed = 1;

}

}

public int getType(){

return awardType;

}

}

//-----------------------------------------------------------------------------------------------------------------------

package FlyHero;

import java.util.Random;

public class Boss extends FlyingObject implements Enemy{

private int awardType;

private int xSpeed = 1;

private int ySpeed = 2;

private int life;

static int i;

@Override

public void step(){

x += xSpeed;

y  = 10;

if(x>ShootGame.WIDTH-width){

xSpeed = -1;

}

if(x<0){

xSpeed = 1;

}

i = x;

}

public Boss(){

life = 100;

this.image = ShootGame.boss0;

width = image.getWidth();

height = image.getHeight();

y = this.y+100;

Random rand = new Random();

//        x = this.x;

awardType = rand.nextInt(2);

}

public BossBullet[] shoot(){

int xStep = this.width/4;

int yStep = 20;

BossBullet[] bossbullets = new BossBullet[1];

bossbullets[0] = new BossBullet(this.i+2*xStep-16,this.y-yStep);

return bossbullets;

}

@Override

public int getScore(){

return 50;

}

public int getType(){

return awardType;

}

public boolean die(){

return false;

}

public void subtractLife(){

life--;

}

public int getLife(){

return life;

}

public boolean hit(FlyingObject other){

int x1 = other.x - this.width/2;

int x2 = other.x + this.width/2 + other.width;

int y1 = other.y - this.height/2;

int y2 = other.y + this.height/2 + other.height;

int herox = this.x + this.width/2;

int heroy = this.y + this.height/2;

return herox>x1 && heroxy1 && heroy

}

}

//-----------------------------------------------------------------------------------------------------------------------

package FlyHero;

public class BossBullet extends FlyingObject{

pr

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值