package ;
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(\ } 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(\幼圆\ g.drawString(\ } }
// // // // // // // //
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(isUP && !isDown && !isLeft && isRight){ 右上 x=x+5; y=y-5;
}else if(!isUP && isDown && !isLeft && isRight){ 右下 x=x+5; y=y+5; } }
boolean isUP = false; boolean isDown = false; boolean isLeft = false; boolean isRight = false;
// 摁下
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_D) { isRight=true;
} else if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A) { isLeft=true;
} else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_W) { isUP=true;
} else if (keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_S) { isDown=true; } }
// 放开
public void keyReleased(KeyEvent e) { int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_D) { isRight=false;
} else if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A) { isLeft=false;
} else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_W) { isUP=false;
} else if (keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_S) { isDown=false; } }
public Rectangle getRectangle(){ return new Rectangle(x,y,feijiImage.getWidth(null),feijiImage.getHeight(null)); } }
package ;
public class PlaneStatus {
public static int roleNum = 1;
public static int playStatus = 0;// 0 游戏开始前 1 第一关 -1 游戏结束 }
package ;
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 Power {
Image PowerImage = null; int x = 20; int y = 0;
public Power() {
this.x=(int)(Math.random()*540)+20; try {
PowerImage = ImageIO.read(Gift.class.getClassLoader() .getResourceAsStream(\ } catch (IOException e) { e.printStackTrace(); } }
public void draw(Graphics g) { // 画血瓶图片
g.drawImage(PowerImage, x, y, null); // 血瓶移动 y++; }
public Rectangle getRectangle(){ return
Rectangle(x,y,PowerImage.getWidth(null),PowerImage.getHeight(null)); } }
package ;
import java.awt.Graphics; import java.awt.Image;
new
import java.awt.Rectangle;
import java.awt.event.KeyEvent; import java.io.IOException; import java.util.ArrayList; import java.util.List;
import javax.imageio.ImageIO;
// 第一关
public class Play01 {
static int count=0;
Image bgImage = null;
// 战机
Plane plane = new Plane(); // 战机子弹
List
List
//List
List
bgImage = ImageIO.read(Play01.class.getClassLoader() .getResourceAsStream(\ } catch (IOException e) { e.printStackTrace(); } }
int bgY1 = 0; int bgY2 = -600; int fireTime = 0; boolean flag=false;
public void draw(Graphics g) { // 画背景图片