admin 管理员组文章数量: 887021
2024年3月1日发(作者:删除文件恢复免费版下载)
package com;
import ;
import ;
import cs;
import ;
import gle;
import nt;
import ption;
import O;
public class Plane {
Image feijiImage = null;
int x = 300;
int y = 700;
int lifeCount=5;
public Plane() {
try {
feijiImage = (ssLoader()
.getResourceAsStream("images/"));
} catch (IOException e) {
tackTrace();
}
}
public void draw(Graphics g) {
// 画飞机图片
age(feijiImage, x, y, null);
// 飞机移动
();
// 血条
if(lifeCount>0){
or();
ct(20, 80, 100, 10);
or();
ct(20, 80, (100/5)*lifeCount, 10);
or();
t(new Font("幼圆", , 30));
ring("Score:"+, 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(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 = Code();
if (keyCode == _RIGHT || keyCode == _D) {
isRight=true;
} else if (keyCode == _LEFT || keyCode == _A) {
isLeft=true;
} else if (keyCode == _UP || keyCode == _W) {
isUP=true;
} else if (keyCode == _DOWN || keyCode == _S) {
isDown=true;
}
// 放开
public void keyReleased(KeyEvent e) {
int keyCode = Code();
if (keyCode == _RIGHT || keyCode == _D) {
isRight=false;
} else if (keyCode == _LEFT || keyCode == _A) {
isLeft=false;
} else if (keyCode == _UP || keyCode == _W) {
isUP=false;
} else if (keyCode == _DOWN || keyCode == _S) {
isDown=false;
}
}
public Rectangle getRectangle(){
return new Rectangle(x,y,th(null),ght(null));
}
}
package com;
public class PlaneStatus {
public static int roleNum = 1;
public static int playStatus = 0;// 0 游戏开始前 1 第一关 -1 游戏结束
}
package com;
import cs;
import ;
import gle;
import nt;
import ption;
import O;
public class Power {
Image PowerImage = null;
int x = 20;
int y = 0;
public Power() {
this.x=(int)(()*540)+20;
try {
PowerImage = (ssLoader()
.getResourceAsStream("images/"));
} catch (IOException e) {
tackTrace();
}
}
public void draw(Graphics g) {
// 画血瓶图片
age(PowerImage, x, y, null);
// 血瓶移动
y++;
}
public Rectangle getRectangle(){
return new Rectangle(x,y,th(null),ght(null));
}
}
package com;
import cs;
import ;
import gle;
import nt;
import ption;
import ist;
import ;
import O;
// 第一关
public class Play01 {
static int count=0;
Image bgImage = null;
// 战机
Plane plane = new Plane();
// 战机子弹
List
// 敌机
List
// 敌机子弹
//List
// 血瓶
List
List
public Play01() {
try {
bgImage = (ssLoader()
.getResourceAsStream("images/bg_"));
} catch (IOException e) {
tackTrace();
}
}
int bgY1 = 0;
int bgY2 = -600;
int fireTime = 0;
boolean flag=false;
public void draw(Graphics g) {
// 画背景图片
age(bgImage, 0, bgY1, null);
bgY1 += 5;
if (bgY1 <= 600) {
bgY1 = 0;
}
age(bgImage, 0, bgY2, null);
bgY2 += 5;
if (bgY2 >= 0) {
bgY2 = -600;
}
// 清理战机子弹
for (int i = 0; i < (); i++) {
MyZiDan myZidan = (i);
if (myZidan.x > 800) {
(i);
}
}
// 添加子弹
if (isFire1 == true && flag==false) {
if (fireTime % 8 == 0) {
(new MyZiDan(plane.x + 25, plane.y + 0));
}
fireTime++;
}
if (isFire1== true && flag==true) {
if (fireTime % 4 == 0) {
}
(new MyZiDan(plane.x +8, plane.y +0));
(new MyZiDan(plane.x +52, plane.y +0));
}
fireTime++;
// 画战机子弹
for (int i = 0; i < (); i++) {
MyZiDan myZidan = (i);
(g);
}
// 清理敌机
for (int i = 0; i < (); i++) {
Diji dj = (i);
if (dj.x < -100) {
(i);
}
}
// 抽奖:添加敌机
if ((int) (() * 20) == 5) {
(new Diji());
}
// 抽奖:添加血瓶
if ((int) (() * 1000) == 5) {
(new Gift());
}
for (int i = 0; i < (); i++) {
Gift gift = (i);
(g);
}
//
// 抽奖:添加power
if ((int) (() * 1000) == 5) {
(new Power());
}
for (int i = 0; i < (); i++) {
Power power = (i);
(g);
}
// 画敌机
for (int i = 0; i < (); i++) {
Diji dj = (i);
(g);
}
// 画飞机
(g);
// 判断战机相撞
for (int i = 0; i < (); i++) {
// 先得到每一个敌机
Diji dj = (i);
Rectangle r1 = tangle();
Rectangle r2 = tangle();
if (ects(r2)) {
(i);
unt = unt - 1;
if(unt>0)
flag=false;
if(unt<1){ atus=-1; }
}
}
// 判断战机和血瓶相撞
for (int i = 0; i < (); i++) {
}
// 先得到每一个血瓶
Gift gift = (i);
Rectangle r1 = tangle();
Rectangle r2 = tangle();
if (ects(r2)) {
(i);
}
if (unt <5) {
}
unt = unt + 1;
//// 判断战机和Power相撞
for (int i = 0; i < (); i++) {
// 先得到每一个power
Power power = (i);
Rectangle r1 = tangle();
Rectangle r2 = tangle();
if (ects(r2)) {
(i);
flag=true;
}
}
// 判断敌机在中弹
for (int i = 0; i < (); i++) {
// 得到每个战机子弹
MyZiDan myzidan = (i);
Rectangle r1 = tangle();
for (int j = 0; j < (); j++) {
// 每一个敌机
Diji diji = (j);
Rectangle r2 = tangle();
if (ects(r2)) {
(i);
(j);
count++;
}
}
}
}
}
boolean isFire1 = false;
boolean isFire2 = false;
public void keyPressed(KeyEvent e) {
ssed(e);
if (Code() == _J) {
isFire1 = true;
}
/*if (Code() == _K) {
isFire2 = true;
}*/
}
public void keyReleased(KeyEvent e) {
eased(e);
if (Code() == _J) {
isFire1 = false;
fireTime = 0;
}
/*if (Code() == _K) {
isFire2 = false;
fireTime = 0;
}*/
if( Code()==_P){
for(int i=0;i<();i++)
(i);
}
}
package com;
import ;
import ;
import cs;
import ;
import nt;
import ption;
import O;
// 游戏结束
public class Over {
Image obg=null;
Image ng=null;
public Over() {
try {
obg
(ssLoader().getResourceAsStream("images/")); ng
(ssLoader().getResourceAsStream("images/"));
} catch (IOException e) {
tackTrace();
}
}
public void draw(Graphics g){
age(obg, 0, 0, null);
age(ng, 120,100, null);
or();
t(new Font("幼圆", , 40));
ring("游戏结束啦!",200 ,600 );
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
}
package com;
import ;
import cs;
import ;
=
=
import pter;
import nt;
import ;
public class MainFrame extends JFrame {
Before before =new Before();
Play01 play01 = new Play01();
Over over = new Over();
public MainFrame() {
//
//
//
//
//
//
//
设置标题
le(" 让子弹飞一会~");
设置大小
e(600, 800);
定位居中
ationRelativeTo(null);
添加关闭操作
aultCloseOperation(_ON_CLOSE);
禁止重置大小z
izable(false);
添加键盘监听器
KeyListener --> KeyAdapter
Listener(new KeyAdapter(){
@Override
public void keyPressed(KeyEvent e) {
if(atus == 0){
ssed(e);
}else if(atus ==1){
ssed(e);
}else if(atus==-1){
ssed(e);
}
}
@Override
public void keyReleased(KeyEvent e) {
if(atus == 0){
eased(e);
}else if(atus ==1){
eased(e);
}else if(atus==-1){
eased(e);
}
}
});
//
//
//
启动一个线程:每隔20 毫秒执行一次
new Thread(){
public void run(){
while(true){
t();
try {
(20);
} catch (InterruptedException e) {
tackTrace();
}
}
}
}.start();
显示
ible(true);
}
Image bufferImage =null;
这个方法也是20毫秒执行一次
public void paint(Graphics g){
if(bufferImage==null){
bufferImage = Image(600, 800);
}
Graphics g4Image = phics();
or();
ct(0, 0, 600, 800);
(g4Image);
age(bufferImage, 0, 0, null);
}
public void draw(Graphics g){
if(atus == 0){
(g);
}else if(atus ==1){
(g);
}else if(atus==-1){
(g);
}
}
public static void main(String[] args) {
new MainFrame();
}
}
package com;
import cs;
import ;
import gle;
import ption;
import O;
public class MyZiDan {
Image zidanImage = null;
int x ;
int y ;
public MyZiDan(int x,int y) {
this.x=x;
this.y=y;
try {
zidanImage = (ssLoader()
.getResourceAsStream("images/"));
} catch (IOException e) {
tackTrace();
}
}
public void draw(Graphics g) {
// 画我军子弹图片
age(zidanImage, x, y, null);
// 我的飞机子弹移动速度
y-=20;
}
public Rectangle getRectangle(){
return new Rectangle(x,y,th(null),ght(null));
}
}
package com;
import cs;
import ;
import gle;
import nt;
import ption;
import O;
public class Diji {
Image dijiImage = null;
int y = -20;
int x = 10;//20 ~ 760
int r;
public Diji() {
this.x=(int)(()*540)+40;
try {
r = (int)(()*3)+1;
dijiImage = (ssLoader()
.getResourceAsStream("images/diji_"+r+".png"));
} catch (IOException e) {
tackTrace();
}
}
public void draw(Graphics g) {
//
//
}
画敌机图片
age(dijiImage, x, y, null);
敌机移动
if(r==1){
y+=4;
}else if(r==2){
y+=4;
}else if(r==3){
y+=7;
}
}
public Rectangle getRectangle(){
return new Rectangle(x,y,th(null),ght(null));
}
package com;
import cs;
import ;
import gle;
import nt;
import ption;
import O;
public class Gift {
Image GiftImage = null;
int x = 20;
int y = 0;
public Gift() {
this.x=(int)(()*540)+20;
try {
GiftImage = (ssLoader()
.getResourceAsStream("images/"));
} catch (IOException e) {
tackTrace();
}
}
public void draw(Graphics g) {
// 画血瓶图片
age(GiftImage, x, y, null);
// 血瓶移动
y++;
}
public Rectangle getRectangle(){
return new Rectangle(x,y,th(null),ght(null));
}
}
package com;
import cs;
import ;
import gle;
import ption;
import O;
public class DijiZiDan {
Image zidanImage = null;
int x ;
int y ;
int fangxiang =0;
public DijiZiDan(int x,int y) {
this.x=x;
this.y=y;
fangxiang = (int)(()*5);//0 ~ 7
try {
zidanImage = (ssLoader()
.getResourceAsStream("images/"));
} catch (IOException e) {
tackTrace();
}
}
public void draw(Graphics g) {
//
//
//
//
//
//
画敌机子弹图片
age(zidanImage, x, y, null);
移动
();
}
public void move(){
if(fangxiang==0){
下
y=y+2;
}else if(fangxiang==1){
左
x=x-2;
}else if(fangxiang==2){
右
x=x+2;
}else if(fangxiang==3){
左下
x=x-2;
y=y+2;
}else if(fangxiang==4){
// 右下
x=x+2;
y=y+2;
}
}
public Rectangle getRectangle(){
return new Rectangle(x,y,th(null),ght(null));
}
}
package com;
import ;
import ;
import cs;
import ;
import nt;
import ption;
import O;
// 游戏开始之前
public class Before {
Image bg=null;
Image wfeiji=null;
Image kdiji1=null;
Image kdiji2=null;
Image kdiji3=null;
public Before() {
try {
bg
(ssLoader().getResourceAsStream("images/"));
wfeiji
(ssLoader().getResourceAsStream("images/feiji_"));
kdiji1
(ssLoader().getResourceAsStream("images/kdiji_"));
kdiji2
(ssLoader().getResourceAsStream("images/kdiji_"));
kdiji3
(ssLoader().getResourceAsStream("images/kdiji_"));
=
=
=
=
=
//
} catch (IOException e) {
tackTrace();
}
}
int time=0;
public void draw(Graphics g){
if(m==1){
}
// 画妹妹
age(bg, 0, 0, null);
age(wfeiji, 260, 600, null);
age(kdiji1, 200, 50, null);
age(kdiji1, 400, 50, null);
age(kdiji1, 150, 480, null);
age(kdiji1, 400, 480, null);
age(kdiji2, 100, 200, null);
age(kdiji2, 300, 100, null);
age(kdiji2, 480, 200, null);
age(kdiji3, 300, 300, null);
age(kdiji3, 70, 400, null);
age(kdiji3, 510, 400, null);
画回车符
time++;
or();
t(new Font("幼圆", , 30));
if(time<=10){
ring("[Enter]>>", 50, 750);
}else if(time<=20){
ring("[Enter] >>", 50, 750);
}else if(time<=30){
ring("[Enter] >>", 50, 750);
if(time==30){
time=0;
}
}
}
public void keyPressed(KeyEvent e) {
int keyCode = Code();
if(keyCode == _ENTER){
}
atus=1;
}
if(keyCode ==_LEFT ||keyCode==_RIGHT ){
m = m;//1~2 互换
}
}
public void keyReleased(KeyEvent e) {
}
版权声明:本文标题:飞机大战 java 源代码 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1709285374h542032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论