飞机大战 JAVA源代码
package com;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Plane {
Image feijiImage = null;
int x = 300;
int y = 700;
int lifeCount=5;
public Plane() {
try {
feijiImage = ImageIO.read(Plane.class.getClassLoader()
.getResourceAsStream("images/feiji.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void draw(Graphics g) {
// 画飞机图片
g.drawImage(feijiImage, x, y, null);
// 飞机移动
this.move();
// 血条
if(lifeCount>0){
g.setColor(Color.WHITE);
g.fillRect(20, 80, 100, 10);
g.setColor(Color.red);
g.fillRect(20, 80, (100/5)*lifeCount, 10);
g.setColor(Color.blue);
g.setFont(new Font("幼圆", Font.BOLD, 30));
g.drawString("Score:"+Play01.count, 20, 60);
}
}
public void move(){
if(isUP&& !isDown && !isLeft && !isRight){
// 上
y=y-5;
}else if(!isUP&& isDown&& !isLeft && !isRight){
// 下
y=y+5;
}else if(!isUP&& !isDown&& isLeft && !isRight){
// 左
x=x-5;
}else if(!isUP&& !isDown&& !isLeft && isRight){
// 右
x=x+5;
}else if(isUP&& !isDown && isLeft && !isRight){
// 左上
x=x-5;
y=y-5;
}else if(!isUP&& isDown&& isLeft && !isRight){
// 左下
x=x-5;
y=y+5;
}else if