📄 mainpanel.java
字号:
}
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<BBv.size();i++){
PlayerBullet bs;
bs=(PlayerBullet)BBv.elementAt(i);
if(bs.y>-50 && bs.islive){//子弹存活
for(int j=0;j<EEv.size();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<DBv.size();i++){
Blast blast;
blast=(Blast)DBv.elementAt(i);
if(blast.islive){//大爆存活
for(int j=0;j<EEv.size();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);
}
}
}
/* for(int j=0;j<EEv.size();j++){
EnemyBullet ebs;
ebs=(EnemyBullet)EBv.elementAt(j);
if(ebs.islive && blast.islive){//敌机存活
ebs.hitblast(blast.x,blast.y);//监测碰撞
/* if(!ebs.islive){
EBv.remove(i);
}*/
// }
// }
blast.grow();
}
else{
DBv.remove(i);
}//清除击中的子弹
}
//处理爆炸s
for(int i=0;i<BOMBv.size();i++){
Bomb bombs;
bombs=(Bomb)BOMBv.elementAt(i);
if(bombs.islive){
bombs.grow();
}
else{
BOMBv.remove(i);
}
}
//处理敌机子弹是否击中
for(int i=0;i<EBv.size();i++){
EnemyBullet ebs;
ebs=(EnemyBullet)EBv.elementAt(i);
ebs.hit(hero_x,hero_y);
//消除无效子弹
if(ebs.islive && ebs.y>-10 && ebs.y<a.y-10 && ebs.x>0 && ebs.x<a.x-10){
ebs.move();
}
else if(!ebs.islive){
//System.out.println("HIT YOU");
EBv.remove(i);
hero_hp-=10;
}
else {
EBv.remove(i);
}
}
//System.out.println(""+Sum);
//blastnum=Sum%500;
//System.out.println(""+blastnum);
if(Sum%500==0&&Sum>0&&blastc){ //符合条件增加大爆
blastnum++;
blastc=false;
//System.out.println(""+blastnum);
}
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);
//保证不出届
/*if(BBx>=(a.x-75)){
BBx=a.x-75;
}
if(BBx>=(a.y-150)){
BBy=a.y-150;
}*/
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=1;
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) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -