有人知道怎么加飞机大战的背景音乐吗??

您所在的位置:网站首页 js背景音乐怎么做 有人知道怎么加飞机大战的背景音乐吗??

有人知道怎么加飞机大战的背景音乐吗??

2024-03-24 11:02| 来源: 网络整理| 查看: 265

package xiaoxueqi; import java.util.Random; public class Airplane extends FlyingObject implements Enemy{ private int speed = 4; private int life; public Airplane(){ life=3; this.image = ShootGame.airplane; width = image.getWidth(); height = image.getHeight(); y = -height; Random rand = new Random(); x = rand.nextInt(ShootGame.WIDTH - width); } public int getScore() { return 10; } public boolean outOfBounds() { return y>ShootGame.HEIGHT; } public void step() { y += speed; } }

英雄机

import java.awt.image.BufferedImage;

public class Hero extends FlyingObject{ private BufferedImage[] images = {}; //英雄机图片数组 private int index = 0; //切换图片 private int doubleFire; //双倍火力 private int tripleFire; private int life; //生命

public Hero(){ life = 10; //初始3条命 doubleFire = 0; tripleFire=0;//火力为0 images = new BufferedImage[]{ShootGame.hero0, ShootGame.hero1}; //两张图片切换 image = ShootGame.hero0; width = image.getWidth(); height = image.getHeight(); x = 150; y = 400; } public int isDoubleFire() { //获取双倍火力 return doubleFire; } public void setDoubleFire(int doubleFire) { this.doubleFire = doubleFire; } public int isTriple_Fire() { return tripleFire; } public void setTripleFire(int tripleFire) {//设置双倍火力 this.tripleFire = tripleFire; } public void addDoubleFire(){ //火力增加40 doubleFire+=40; } public void addTripleFire() { tripleFire+=60; } public void addLife(){ //增命 life++; } public void subtractLife(){ //减命 life--; } public int getLife(){ //得到命 return life; } public void moveTo(int x,int y){ // this.x = x - width/2; this.y = y - height/2;

}

public boolean outOfBounds() { return false; } public Bullet[] shoot(){ int xStep = width/4; int yStep = 20; if(00) { Bullet[] bullets = new Bullet[6]; bullets[0] = new Bullet(x+1*xStep,y-yStep); //y-yStep bullets[1] = new Bullet(x+2*xStep,y-yStep); bullets[2] = new Bullet(x+3*xStep,y-yStep); bullets[3] = new Bullet(x+4*xStep,y-yStep); bullets[4] = new Bullet(x-1*xStep,y-yStep); bullets[5] = new Bullet(x,y-yStep); return bullets; } else{ Bullet[] bullets = new Bullet[1]; bullets[0] = new Bullet(x+xStep,y-yStep); return bullets; } } public void step() { if(images.length>0){ image = images[index++/10%images.length]; //切换图片hero0,hero1 } } /** 碰撞算法 */ public boolean hit(FlyingObject other){ int x1 = other.x - this.width/2; //x1:敌人的x-1/2英雄机的宽 int x2 = other.x + this.width/2 + other.width; //敌人的x+敌人的宽+1/2英雄机的宽 int y1 = other.y - this.height/2; //y1:敌人的y-1/2英雄机的高 int y2 = other.y + this.height/2 + other.height; //y2:敌人的y+敌人的高+1/2英雄机的高 int herox = this.x + this.width/2; //x:英雄机的x+1/2英雄机的宽 int heroy = this.y + this.height/2; //y:英雄机的y+1/2英雄机的高 return herox>x1 && heroxy1 && heroy ShootGame.WIDTH-width){ //若x>=(窗口宽-蜜蜂宽),则xSpeed为-1,加-1即为向左 xSpeed = -1; } if(x


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3