Java课程设计小游戏
发布时间:2020-02-20 17:05:21
发布时间:2020-02-20 17:05:21
《高级语言程序设计》课程设计报告
1、 程序设计说明书
【设计题目】
雷霆行动游戏程序
【问题描述】
雷霆行动是一款供大家休闲娱乐的小游戏,游戏通过鼠标控制我方飞机hero的移动,达到躲 闪敌机的目的;利用鼠标键发射子弹和导弹,达到击毁敌机的目的,摧毁敌机有积分。此游戏为闯 关积分类小游戏。
【软件功能】
1.按鼠标左键,游戏开始。
2.利用鼠标移动控制hero自由移动,闪躲敌方子弹。
3.利用鼠标左键发射子弹,实现打中敌方飞机的功能;利用鼠标右键释放导弹,实现摧毁大量敌 机的功能,击中一个敌方飞机积一分。
4.hero碰到对方子弹会消耗生命,消耗生命的多少,依据子弹的不同而不同。
5.一关之后会进入下一关。
6.游戏右上角红色的进度条表示hero的生命,当红色全部消失之后,游戏结束,显示死亡。
7.游戏结束后,可重新开始,同1。
【算法思想】
1.创建游戏主界面,确定窗口的坐标。
2.设计游戏开始界面显示信息及信息坐标。
3.设置游戏进行中的信息,hero的移动、释放子弹和导弹,达到击毁敌机的目的。
4.处理游戏进行中的子弹、大爆、爆炸、敌机消失和存在的条件。
5.设置进入下一关的条件。
6.设计游戏结束界面显示信息及信息坐标。
7.处理游戏重新开始满足的条件。
8.装载图像。
9.对游戏进行调试和改进,使这个游戏更加完善。
【类的设计】
本程序共有七个类:
1.MainPanel
属性:BBv为子弹数组,EEv为敌机数组,BOMBv为爆炸数组,EBv为敌机子弹数组,DBv 为大爆数组,E-num为敌机数量,E-max敌机最大数,E-vel为敌机速度,E-mov为敌机 横移几率,E-hit为敌机开火几率,Sum为击毁敌机数量,hero-hp为hero生命,back至 db-2均为图片,tracker为媒体跟踪器,y为背景滚动变量,seq为hero的动画变量,isfire 为hero开火,isblast为是否发爆,blastnum为大爆的数量,blastc为控制大爆,f、ff、s、 ss均为游戏界面上显示的信息;
方法:MainPanel(Game)构造方法,paint(Graphics)建立游戏开始界面如显示的文字,run()控制 对象移动,BBmove(int,int)子弹的移动方法,DBmove(int,int)大爆的移动方法, mouseDragged(MouseEvent) 鼠标的拖拽用来保证hero不出界,mouseMoved(MouseEvent) 鼠标的移动用来控制hero移动,mousePressed(MouseEvent) 鼠标按键在组件上按下时调 用,重新开始游戏,mouseClicked(MouseEvent)鼠标按键在组件上单击(按下并释放) 时调用,释放子弹,mouseReleased(MouseEvent)鼠标按钮在组件上释放时调用, mouseEntered(MouseEvent)鼠标进入组件上调用,mouseExited(MouseEvent)鼠标离开组 件时调用;
功能:游戏的开始、运行、结束与重新开始。
2.Game继承JFrame
属性:x为游戏主界面的横坐标,y为游戏主界面的纵坐标,pl为hero的子弹;
方法:Game()创建游戏主界面,main(String [])主方法;
功能:创建出游戏的主界面。
3.Blast(大爆)
属性:x为大爆的横坐标,y为大爆的纵坐标,cont为数量,islive为hero存活;
方法:Blast(int,int)建立大爆的坐标,grow()构造方法;
功能:构造一个大爆(导弹爆炸)的类。
4.Bomb(爆炸)
属性:x为爆炸的横坐标,y为爆炸的纵坐标,cont为数量,islive为hero存活;
方法:Bomb(int,int)建立爆炸的坐标,grow()构造方法;
功能:构造一个爆炸(子弹击中敌机)的类。
5.Enemy(敌机)
属性:x为敌机的横坐标,y为敌机的纵坐标,vx敌机数组的横坐标,vy为敌机数组的纵坐标, r为敌机横移几率,f为敌机开火几率,toleft为向左移动敌机,toright为向右移动敌机;
方法:Enemy(int,int,int,int)建立敌机的坐标,move(int)实现敌机的移动,tofire()敌机释 放子弹,hit(int,int)敌机的子弹攻击hero,hitblast(int,int)子弹产生爆炸;
功能:构造一个敌机的类,实现敌机的移动。
6.EnemyBullet(敌机子弹)
属性:x、y为敌机子弹的坐标,vx、vy为敌机子弹数组的坐标;
方法:move()实现敌机子弹的移动,hit(int,int)敌机子弹攻击hero;
功能:构造一个敌机子弹的类,实现敌机子弹的移动和攻击。
7.PlayerBullet(hero子弹)
属性:x、y为hero子弹的坐标,v为hero子弹的速度;
方法:move()实现hero子弹的移动,hit(int,int)hero子弹攻击敌机;
功能:构造一个hero子弹的类,实现hero子弹的移动和攻击。
【用户界面】
游戏开始界面
游戏进行中界面
游戏结束界面
【程序技巧】
1.建立一个主类,其余六个类均通过这个主类来调用
2.响应鼠标事件
3.用户界面采用图形用户界面
4.利用媒体跟踪器监测图像的装载
5.无效的子弹和被摧毁的敌机能及时处理,未被摧毁的敌机与子弹可以保留
6.游戏失败可以重新开始
【模块划分及调用关系】
【模块流程图】
游戏界面主框架模块:
游戏操作模块:
【运行说明】
按鼠标左键开始游戏,鼠标移动控制hero的移动,按鼠标左键打出子弹,攻击敌机,每打死 一个敌机积一分,按鼠标右键放导弹,实现摧毁大量敌机的功能,本游戏共三关,若游戏中途失 败,可以重新开始。
2、 程序上机调试报告
【语法错误及其排除】
1.无法更改导弹数量。解决方法:添加Blastnum=10语句,即有十个导弹;
2.个别图片运行不出来。解决方法:将图片格式与程序中相匹配;
3.文字在程序中写出,但在游戏过程中不显示。解决方法:将文字的坐标调试好。
【算法错误及其排除】
1.点击鼠标右键无法实现大爆。解决方法:mouseReleased(MouseEvent e)
2.hero的子弹打中敌机后敌机没有消失。解决方法:EBv.remove(i);
3、 程序测试结果
【测试数据】
我方飞机的移动,是否能打出子弹,导弹的释放,能否摧毁敌方飞机,是否可以积分。
【输出结果】
游戏初始化
子弹爆炸情况
大爆(导弹爆炸)、飞机移动
【收获及体会】
本来以为课程设计是个很简单的事情,但是随着程序的编写,发现这是一个非常不容易的过程,通过去图书馆和上网查找资料,我发现我还有很多不足,并通过查JDK手册我也学习了很多知识,我意识到JDK手册是非常好的一种学习Java的工具,Java在生活中有很重要的应用性,这提高了我的学习兴趣。编写程序的过程中我也遇到了很多困难,当程序出现错误运行不出来时,我非常着急,在冷静地分析、调通程序之后,我意识到有耐心、有恒心是多么重要啊!在今后的学习生活中,我会更加努力,认真、耐心、细心地处理事情,相信我会逐步提高自己的能力。
4、 源程序代码(Java语言,要求有尽可能多的注释语句)
package lightning;
import java.awt.*;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.MediaTracker;
import javax.swing.*;
import java.awt.event.*;
import java.util.EventListener;
import java.util.Vector;
import lightning.*;
public class MainPanel extends JPanel implements Runnable,MouseMotionListener,MouseListener{
Game a;
Vector BBv=new Vector();//子弹数组
Vector EEv=new Vector();//敌机数组
Vector BOMBv=new Vector();//爆炸数组
Vector EBv=new Vector();//敌机子弹数组
Vector DBv=new Vector();//大爆数组
int E_num;
int E_max;//敌机最大数
int E_vel;//敌机速度
int E_mov;//敌机横移几率
int E_hit;//敌机开火几率
int Sum;//击坠敌机数量,击坠一个敌机积一分
int hero_hp;//hero生命
Image back=null;//背景图片
Image hero=null;//hero图片
Image fire=null;//hero子弹图片
Image fire_l=null;//hero子弹2图片
Image el_0=null;//敌机图片
Image el_0_l=null;//敌机left图片
Image el_0_r=null;//敌机right图片
Image el_bb=null;//敌机子弹图片
Image el_bb_0=null;//敌机子弹2图片
Image bomb_0=null;//敌机爆炸0图片
Image bomb_1=null;//敌机爆炸1图片
Image bomb_2=null;//敌机爆炸2图片
Image bomb_3=null;//敌机爆炸3图片
Image db_1=null;//大爆1图片
Image db_2=null;//大爆2图片
MediaTracker tracker=null;//媒体跟踪器,用来监测图像的装载
Thread Game_star;
int y;//背景滚动变量
int hero_oldx,hero_oldy;//hero的旧x,y坐标
int hero_x,hero_y;//hero的新x,y坐标
int seq;//hero的动画变量
boolean isfire;//hero开火
boolean isblast;//是否发爆
int BBx,BBy;//子弹的横纵坐标
int DBx,DBy;//大爆的横纵坐标
int blastnum;//大爆的数量
boolean blastc;//控制大爆
Font f=new Font("黑体",Font.BOLD,30);
Font ff=new Font("黑体",Font.BOLD,90);
Font S=new Font("幼圆",Font.BOLD,15);
Font SS=new Font("幼圆",Font.BOLD,25);
MainPanel(Game a) {
this.a=a;
tracker=new MediaTracker(this);
//将以下图片加到媒体跟踪器中
back=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("back3.jpg"));
tracker.addImage(back,0);
hero=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("hero.jpg"));
tracker.addImage(hero,1);
fire=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("herozidan.jpg"));
tracker.addImage(fire,2);
fire_l=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("herozidan2.jpg"));
tracker.addImage(fire_l,3);
el_0=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("diji.jpg"));
tracker.addImage(el_0,4);
el_0_l=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("dijileft.jpg"));
tracker.addImage(el_0_l,5);
el_0_r=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("dijiright.jpg"));
tracker.addImage(el_0_r,6);
el_bb=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("dijizidan.jpg"));
tracker.addImage(el_bb,7);
el_bb_0=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("el_bb_0.jpg"));
tracker.addImage(el_bb_0,8);
bomb_0=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("bomb_0.jpg"));
tracker.addImage(bomb_0,9);
bomb_1=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("bomb_1.jpg"));
tracker.addImage(bomb_1,10);
bomb_2=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("bomb_2.jpg"));
tracker.addImage(bomb_2,11);
bomb_3=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("bomb_3.jpg"));
tracker.addImage(bomb_3,12);
db_1=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("db1.jpg"));
tracker.addImage(db_1,13);
db_2=Toolkit.getDefaultToolkit().getImage(MainPanel.class.getResource("db2.jpg"));
tracker.addImage(db_2,14);
this.addMouseMotionListener(this);
this.addMouseListener(this);
Game_star=new Thread(this);
y=-(5*a.y);
hero_x=a.x/2-50;
hero_y=a.y-150;
hero_oldx=hero_x;
hero_oldy=hero_y;
hero_hp=-1;
seq=0;
Sum=0;
E_num=0;
E_max=9;
E_vel=7;
E_mov=90;
E_hit=97;
isfire=false;
isblast=false;
blastnum=10;
blastc=false;
}
public void paint(Graphics g){
g.drawImage(back,0,y,a.x,a.y*6,this);
g.setColor(Color.RED);
g.setFont(S);
g.drawString("导弹:"+blastnum,a.x-400,25);//绘制大爆的数量
g.drawString("生",a.x-200,40);
g.drawString("命",a.x-200,55);
g.fillRect(a.x-150,65,10,hero_hp);
g.setColor(Color.BLACK);
g.drawRect(a.x-20,64,10,300);
if(seq==0){
g.setColor(Color.RED);
}
if(seq==1){
g.setColor(Color.BLACK);
}
g.setFont(S);
g.drawString("积分:",a.x-250,25);
g.drawString(String.valueOf(Sum),a.x-210,25);
g.setFont(f);
if(hero_hp==-1){
g.setFont(f);
g.setColor(Color.RED);
g.drawString("雷霆行动",a.x/2-a.x/3,a.y/2-a.y/8);
g.drawString("你能消灭多少敌机?",a.x/2-a.x/3,a.y/2-a.y/16);
g.setFont(SS);
g.setColor(Color.RED);
g.drawString("请按下鼠标左键开始",a.x/2-a.x/4,a.y/2+a.y/8);
g.dispose();
try{
Thread.sleep(50);
}catch(Exception e){
}
this.Game_star=null;
}
//如果游戏结束显示如下信息
else if(hero_hp<0){
g.setFont(ff);
g.setColor(Color.RED);
g.drawString("GAME", a.x / 2 - a.x / 4, a.y / 2 - a.y / 16);
g.drawString("OVER", a.x / 2 - a.x / 4, a.y / 2 + a.y / 16);
g.setFont(SS);
g.setColor(Color.RED);
g.drawString("请按下鼠标左键重来", a.x / 2 - a.x / 4, a.y / 2 + a.y / 10);
g.dispose();
try {
Thread.sleep(50);
}
catch (Exception e) {
}
this.Game_star=null;
}
//显示信息
if(Math.abs(y)>(a.y)*5-50){
g.drawString("本游戏即将开始",a.x/2-a.x/4,a.y/2-a.y/8);
g.drawString("练习模式",a.x/2-a.x/4,a.y/2-a.y/16);
}
if(Math.abs(y)>(a.y)*4 && Math.abs(y)<(a.y)*4+150){
E_max=13;
E_vel=7;
E_mov=90;
E_hit=95;
g.drawString("第一关即将开始",a.x/2-a.x/4,a.y/2-a.y/8);
}
if(Math.abs(y)>(a.y)*3 && Math.abs(y)<(a.y)*3+150){
E_max=16;
E_vel=9;
E_mov=90;
E_hit=93;
g.drawString("第二关即将开始",a.x/2-a.x/4,a.y/2-a.y/8);
}
if(Math.abs(y)>(a.y)*2 && Math.abs(y)<(a.y)*2+150){
E_max=29;
E_vel=11;
E_mov=90;
E_hit=91;
g.drawString("第三关即将开始",a.x/2-a.x/4,a.y/2-a.y/8);
}
if(Math.abs(y)>(a.y) && Math.abs(y)<(a.y)+150){
E_max=32;
E_vel=13;
E_mov=90;
E_hit=89;
g.drawString("最后了祝你好运",a.x/2-a.x/4,a.y/2-a.y/8);
}
if(y==0){
E_max=40;
E_vel=18;
E_mov=90;
E_hit=86;
g.drawString("向上帝祈祷吧!",a.x/2-a.x/4,a.y/2-a.y/8);
}
//处理敌机子弹s
for(int i=0;i
EnemyBullet ebs;
ebs=(EnemyBullet)EBv.elementAt(i);
if(ebs.y>-50){
if(ebs.cont<6){
g.drawImage(el_bb,ebs.x,ebs.y,13,20,this);
}
if(ebs.cont>=6){
g.drawImage(el_bb_0,ebs.x,ebs.y,13,15,this);
}
}
}
//处理子弹s
for(int i=0;i
PlayerBullet bs;
bs=(PlayerBullet)BBv.elementAt(i);
if(bs.y>-50){
if(bs.cont<3){
g.drawImage(fire_l,bs.x,bs.y,30,30,this);
}
if(bs.cont>=3){
g.drawImage(fire,bs.x,bs.y,30,30,this);
}
}
}
//处理大爆
for(int i=0;i
Blast blast;
blast=(Blast)DBv.elementAt(i);
if(blast.islive){
if(blast.cont<10){
//System.out.println(""+blast.x+" "+blast.y);
g.drawImage(db_1,blast.x,blast.y,200,200,this);
}
if(blast.cont>10 && blast.cont<20){
g.drawImage(db_2,blast.x,blast.y,200,200,this);
}
}else{
DBv.remove(i);
}
}
//处理爆炸s
for(int i=0;i
Bomb bombs;
bombs=(Bomb)BOMBv.elementAt(i);
if(bombs.islive){
if(bombs.cont<10){
g.drawImage(bomb_0,bombs.x,bombs.y,50,50,this);
}
if(bombs.cont>10 && bombs.cont<20){
g.drawImage(bomb_1,bombs.x,bombs.y,50,50,this);
}
if(bombs.cont>20 && bombs.cont<40){
g.drawImage(bomb_2,bombs.x,bombs.y,50,50,this);
}
if(bombs.cont>40){
g.drawImage(bomb_3,bombs.x,bombs.y,50,50,this);
}
}else{
BOMBv.remove(i);
}
}
//处理敌机s
for(int i=0;i
Enemy es;
es=(Enemy)EEv.elementAt(i);
if(es.y<(a.y-50)){
if(es.islive && !es.toleft && !es.toright){
g.drawImage(el_0,es.x,es.y,45,45,this);
}else if(es.toleft){
g.drawImage(el_0_l,es.x,es.y,50,50,this);
}else if(es.toright){
g.drawImage(el_0_r,es.x,es.y,50,50,this);
}
}else{
es.islive=false;
}
}
//处理hero
g.clipRect(hero_x,hero_y,70,70);
g.drawImage(hero,(hero_x-seq*1),hero_y,46,53,this);
}
public void run(){
int cont=0;
while(tracker.checkAll(true)==false){
try{
Thread.sleep(300);
}
catch(Exception e){
}
}
while(Game_star!=null){
//处理敌机s是否撞击hero
if(EEv.size()==0){
E_num=0;
}//清空敌机数组
if(cont!=0){
//移动条件下增加难度
if(E_num<=E_max){//满足条件则增加敌机
Enemy es;
es=new Enemy((int)(Math.random()*(a.x-50)),E_vel,E_mov,E_hit);
EEv.addElement(es);
E_num++;
}
for(int i=0;i
Enemy es;
es=(Enemy)EEv.elementAt(i);
if(es.y<(a.y-50) && es.islive){
es.hit(hero_x,hero_y);//监测碰撞
if(!es.islive){
Bomb bombs;
bombs=new Bomb(es.x,es.y);
BOMBv.addElement(bombs);
//System.out.println("YOU LOST");
hero_hp-=10;
}
if(es.islive){//移动未撞到的敌机
es.move(hero_x);
es.tofire();
if(es.tofire() && i%4==0 && es.y<(a.y-100)){
EnemyBullet ebs;
ebs=new EnemyBullet(es.x,es.y,hero_x,hero_y);
EBv.addElement(ebs);
}
}
}
else{
EEv.remove(i);
}//消除无效敌机
}
}
//处理子弹s是否击中
for(int i=0;i
PlayerBullet bs;
bs=(PlayerBullet)BBv.elementAt(i);
if(bs.y>-50 && bs.islive){//子弹存活
for(int j=0;j
Enemy es;
es=(Enemy)EEv.elementAt(j);
if(es.islive && bs.islive){//敌机存活
es.hit(bs.x,bs.y);
bs.hit(es.x,es.y);//监测碰撞
if(!es.islive){//添加爆炸
Sum++;
blastc=true;
Bomb bombs;
bombs=new Bomb(es.x,es.y);
BOMBv.addElement(bombs);
}
}
}
if(bs.islive){
bs.move();
}//未击中的子弹继续移动
}
else{
BBv.remove(i);
}//清除击中的子弹
}
//处理大爆
for(int i=0;i
Blast blast;
blast=(Blast)DBv.elementAt(i);
if(blast.islive){//大爆存活
for(int j=0;j
Enemy es;
es=(Enemy)EEv.elementAt(j);
if(es.islive && blast.islive){//敌机存活
es.hitblast(blast.x,blast.y);//监测碰撞
if(!es.islive){//添加爆炸
Sum++;
blastc=true;
Bomb bombs;
bombs=new Bomb(es.x,es.y);
BOMBv.addElement(bombs);
}
}
}
blast.grow();
}
else{
DBv.remove(i);
}//清除击中的子弹
}
//处理爆炸s
for(int i=0;i
Bomb bombs;
bombs=(Bomb)BOMBv.elementAt(i);
if(bombs.islive){
bombs.grow();
}
else{
BOMBv.remove(i);
}
}
//处理敌机子弹是否击中
for(int i=0;i
EnemyBullet ebs;
ebs=(EnemyBullet)EBv.elementAt(i);
ebs.hit(hero_x,hero_y);
//消除无效子弹
if(ebs.islive && ebs.y>-10 && ebs.y
ebs.move();
}
else if(!ebs.islive){
//System.out.println("HIT YOU");
EBv.remove(i);
hero_hp-=10;
}
else {
EBv.remove(i);
}
}
if(Sum%500==0&&Sum>0&&blastc){//符合条件增加大爆
blastnum++;
blastc=false;
}
cont++;
if(cont%3==0){
if(isblast){
DBmove(DBx,DBy);
}
if(isfire){
BBmove(BBx,BBy);
}
if(seq==0){
seq=1;
}
else{
seq=0;
}
cont=0;
}
repaint();
try{
Thread.sleep(20);
}
catch(Exception e){
}
if(y==0){
y=0;
}
else{
y++;
}
}
}
public void BBmove(int x,int y){
PlayerBullet pb;
pb=new PlayerBullet(x,y);
//保证不出界
if(BBx>=(a.x-45)){
BBx=a.x-45;
}
if(BBy>=(a.y-150)){
BBy=a.y-150;
}
BBv.addElement(pb);
}
//大爆的移动方法
public void DBmove(int x,int y){
Blast blast;
blast=new Blast(x,y);
//保证不出界
DBv.addElement(blast);
}
public void mouseDragged(MouseEvent e){
isfire=true;
BBx=hero_x+10;
BBy=hero_y;
hero_x=e.getX()-35;
hero_y=e.getY()-35;
//保证不出界
if(BBx>=(a.x-45)){
BBx=a.x-45;
}
if(BBy>=(a.y-150)){
BBy=a.y-150;
}
if(BBx<5){
BBx=5;
}
if(BBy<25){
BBy=25;
}
//限速
if((hero_x-hero_oldx)>15){
hero_x=hero_oldx+15;
}
if((hero_x-hero_oldx)<-15){
hero_x=hero_oldx-15;
}
if((hero_y-hero_oldy)>15){
hero_y=hero_oldy+15;
}
if((hero_y-hero_oldy)<-15){
hero_y=hero_oldy-15;
}
//保证不出界
if(hero_x>=(a.x-55)){
hero_x=a.x-55;
}
if(hero_y>=(a.y-110)){
hero_y=a.y-110;
}
if(hero_x<0){
hero_x=0;
}
if(hero_y<0){
hero_y=0;
}
hero_oldx=hero_x;
hero_oldy=hero_y;
}
public void mouseMoved(MouseEvent e){
hero_x=e.getX()-35;
hero_y=e.getY()-35;
if(hero_x>=(a.x-55)){
hero_x=a.x-55;
}
if(hero_y>=(a.y-110)){
hero_y=a.y-110;
}
if(hero_x<0){
hero_x=0;
}
if(hero_y<0){
hero_y=0;
}
if((hero_x-hero_oldx)>15){
hero_x=hero_oldx+15;
}
if((hero_x-hero_oldx)<-15){
hero_x=hero_oldx-15;
}
if((hero_y-hero_oldy)>15){
hero_y=hero_oldy+15;
}
if((hero_y-hero_oldy)<-15){
hero_y=hero_oldy-15;
}
hero_oldx=hero_x;
hero_oldy=hero_y;
}
public void mousePressed(MouseEvent e){
//如果GAMEOVER可以重新开始
if(e.getModifiers()==InputEvent.BUTTON1_MASK){
if(hero_hp<0){
if(this.Game_star!=null){
this.Game_star.stop();
this.Game_star=null;
//this.Game_star.destroy();
}
this.Game_star=new Thread(this);
Game_star.start();
Game_star.setPriority(7);
y=-(5*a.y);
hero_x=a.x/2-35;
hero_y=a.y-85;
hero_oldx=hero_x;
hero_oldy=hero_y;
hero_hp=300;
seq=0;
// dir=0;
Sum=0;
E_num=0;
E_max=9;
E_vel=7;
E_mov=90;
E_hit=97;
isfire=false;
isblast=false;
blastnum=10;
blastc=false;
EEv.removeAllElements();
BBv.removeAllElements();
EBv.removeAllElements();
BOMBv.removeAllElements();
DBv.removeAllElements();
}
else{
isfire=true;
BBx=hero_x+10;
BBy=hero_y;
//System.out.println(""+BBx+" "+BBy);
if(BBx>=(a.x-75)){
BBx=a.y-75;
}
if(BBy>=(a.y-150)){
BBy=a.y-150;
}
if(BBx<25){
BBx=25;
}
if(BBy<25){
BBy=25;
}
}
}
if(e.getModifiers()==InputEvent.BUTTON3_MASK){
if(blastnum>=1){
isblast=true;
DBx=hero_x-90;
DBy=hero_y-170;
EBv.removeAllElements();
blastnum--;
//System.out.println(""+blastnum);
}
}
}
public void mouseClicked(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
isfire=false;
isblast=false;
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
}
package lightning;
import java.awt.Toolkit;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Container;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import lightning.*;
public class Game extends JFrame{
int x,y;
MainPanel p1;
Game() {
x=Toolkit.getDefaultToolkit().getScreenSize().width/2;
y=Toolkit.getDefaultToolkit().getScreenSize().height;
//System.out.println(""+x+" "+y);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(x-100,y-100);
this.setLocation(x/2,0);
this.setResizable(false);
this.setTitle("Game");
this.setBackground(Color.BLACK);
this.setCursor(Cursor.CROSSHAIR_CURSOR);
Container cn=getContentPane();
p1=new MainPanel(this);
cn.add(p1,BorderLayout.CENTER);
}
public static void main(String[] args) {
Game w = new Game();
w.show();
}
}
package lightning;
public class EnemyBullet {
int x;
int y;
int vx;
int cont;
int vy;
boolean islive=true;
EnemyBullet(int x,int y,int a,int b) {
this.x=x;
this.y=y;
this.vy=15;
this.cont=0;
this.vx=2;
}
else{
this.vx=-2;
}
if(this.y
this.vy=7;
}
else{
this.vy=-7;
}
}
public void move(){
if(this.cont>=20){
this.cont=0;
}
this.cont++;
this.y+=this.vy;
this.x+=this.vx;
}
public void hit(int a,int b){
if(Math.abs((x+10)-(a+25))<28 && Math.abs((y+10)-(b+5))<28){
this.islive=false;
}
else{
this.islive=true;
}
}
}
package lightning;
public class PlayerBullet {
int x;
int y;
int v;
int cont;
boolean islive=true;
PlayerBullet(int x,int y) {
this.x=x;
this.y=y;
this.v=20;
this.cont=0;
}
public void move(){
if(this.cont>=7){
this.cont=0;
}
this.y-=this.v;
this.cont++;
}
public void hit(int a,int b){
if(Math.abs((x+25)-(a+25))<26 && Math.abs((y+25)-(b+25))<26){
this.islive=false;
}
else{
this.islive=true;
}
}
}
package lightning;
public class Enemy {
int x;
int y;
int r;
int f;
int vx;
int vy;
int cont;
boolean islive=true;
boolean toleft=false;
boolean toright=false;
public Enemy(int x,int vy,int r,int f) {
this.x=x;
this.y=-50;
this.vx=0;
this.vy=vy;
this.r=r;
this.f=f;
this.cont=0;
}
public void move(int a){
if(Math.random()*100>r){
if(a-this.x>50 && cont==0){
this.vx=3;
this.toright=true;
this.toleft=false;
}
else if(this.x-a>50 && cont==0){
this.vx=-3;
this.toright=false;
this.toleft=true;
}
this.cont++;
}
if(this.cont>2){
this.vx=0;
this.toright=false;
this.toleft=false;
this.cont=0;
}
this.x+=this.vx;
this.y+=this.vy;
}
public boolean tofire(){
if(Math.random()*100>f){
return true;
}
else{
return false;
}
}
public void hit(int a,int b){
if(Math.abs((x+25)-(a+25))<28 && Math.abs((y+25)-(b+25))<28){
this.islive=false;
}
else{
this.islive=true;
}
}
public void hitblast(int c,int d){
if(Math.abs((x+25)-(c+25))<200 && Math.abs((y+25)-(d+25))<100){
this.islive=false;
}
else{
this.islive=true;
}
}
}
package lightning;
class Blast {
int x;
int y;
int cont;
boolean islive=true;
Blast(int x,int y) {
this.x=x;
this.y=y;
this.cont=0;
}
public void grow(){
if(cont>21){
this.islive=false;
}
this.cont++;
this.y++;
}
}
package lightning;
class Bomb {
int x;
int y;
int cont;
boolean islive=true;
Bomb(int x,int y) {
this.x=x;
this.y=y;
this.cont=0;
}
public void grow(){
if(cont>61){
this.islive=false;
}
this.cont++;
this.y++;
}
}