[java]代码库
public class World extends JPanel {
public static final int WIDTH = 400;//public static final int WIDTH=400;
public static final int HEIGHT = 700;//public static final int HEIGHT=700;
private Sky sky = new Sky();//private Sky sky=new Sky();
private Hero hero = new Hero();//private Hero hero=new Hero();
private FlyingObject[] enemies = {}; // 敌人数组 private FlyingObject []enemies={};
private Bullet[] bullets = {}; // 子弹数组 private Bullet[]bullets={};
public static final int START = 0;//public static final int START=0;
public static final int RUNNING = 1;//public static final int RUNNING=1;
public static final int PAUSE = 2;//public static final int PAUSE=2;
public static final int GAME_OVER = 3;//public static final int GAME_OVER=3;
private int state = START;//private int state=START;
public static BufferedImage start;//public static BufferedImage start;
public static BufferedImage pause;//public static BufferedImage pause;
public static BufferedImage gameover;//public static BufferedImage gameover;
static {//static{静态块
start = Images.loadImage("start.png");//start=Images.loadImage("start.png);
pause = Images.loadImage("pause.png");//pause=Images.loadImage("pause.png");
gameover = Images.loadImage("gameover.png");//gameover=Images.loadImage("gameover.png");
}
public FlyingObject nextOne() {//public FlyingObject nextOne(){
Random rand = new Random();//Random rand=new Random();
int type = rand.nextInt(20);//int type=rand .nextInt(20);
if (type < 5) {//if(type<5){
return new Bee();//return new Bee();
} else if (type < 20) {//else if (type<20){
return new Airplane();//return new Airplane();
} else {//else
return new BigAirplane();//return new BigAirplane();
}
}
int flyEnterIndex = 0;//int flyEnterIndex=0;
public void enterAction() {//public void enterAction(){
flyEnterIndex++;//flyEnterIndex++;
if (flyEnterIndex % 40 == 0) {//if(flyEnterIndex%40==0){
FlyingObject obj = nextOne();//FlyingObject obj=nextOne;
enemies = Arrays.copyOf(enemies, enemies.length + 1);//enemies =Arrays.copyOf(enemies,enemies.length+1);
enemies[enemies.length - 1] = obj;//enemies [enemies.length-1]=obj;
}
}
public void stepAction() {//public void stepAction(){
sky.step();//sky.step();
for (int i = 0; i < enemies.length; i++) {//for(int i=0;i<enemies.length;i++)
enemies[i].step();//enemies[i].step();
}
for (int i = 0; i < bullets.length; i++) {//for(int i=0;i<bullets.length;i++)
bullets[i].step();//bullets[i].step();
}
}
int shootIndex = 0;//int shootIndex=0;
public void shootAction() {//public void shootAction(){
shootIndex++;//shootIndex++;
if (shootIndex % 30 == 0) {//if(shootIndex%30==0){
Bullet[] bs = hero.shoot();//Bullets[]bs=hero.shoot();
bullets = Arrays.copyOf(bullets, bullets.length + bs.length);
System.arraycopy(bs, 0, bullets, bullets.length - bs.length, bs.length);
}//bullets=Arrays.copyOf(bullets,bullets.length+bs.length);
}//System.arraycopy(bs,0,bullets,bullets.length-bs.length,bs.length);
private int score = 0;//private int score=0;
public void bangAction() {//public void bangAction()
for (int i = 0; i < bullets.length; i++) {//for(int i=0;i<bullets.length;i++){
Bullet b = bullets[i];//Bullets b=bullets[i]
for (int j = 0; j < enemies.length; j++) {//for(int j=0;j<enemies.length;j++){
FlyingObject f = enemies[j];//FlyingObject f=enemies[j];
if (b.isLife() && f.isLife() && b.hit(f)) {//if(b.islife()&&f.isLife()&&b.hit(f)){
b.goDead();//b.goDead();
f.goDead();//f.goDead();
if (f instanceof Enemy) {//if(f instanceof Enemy){
Enemy e = (Enemy) f;//Enemy e=(Enemy) f;
score += e.getScore();//score+=e.getScore();
}
if (f instanceof Award) {//if(f instanceof Award){
Award a = (Award) f;//Award a=(Award)f;
int type = a.getType();//int type=a.getType();
switch (type) {//switch(type){
case Award.DOUBLE_FIRE://case Award.DOUBLE_FIRE:
hero.addDoubleFire();//hero.addDoubleFire();
break;//break;
case Award.LIFE://case Award.LIFE:
hero.addLife();//hero.addLife
break;//break;
}
}
}
}
}
}
中级程序员
by: LinKin 发表于:2019-10-28 09:25:01 顶(0) | 踩(0) 回复
羡慕
回复评论