幸运 |
@Override |
public void mouseExited(MouseEvent e) { |
if (state==RUNNING) { |
state=PAUSE; |
} |
} |
|
@Override |
public void mouseEntered(MouseEvent e) { |
if (state==PAUSE) { |
state=RUNNING; |
} |
} |
|
|
}; |
this .addMouseMotionListener(l); |
this .addMouseListener(l); |
Timer timer= new Timer(); |
timer.schedule( new TimerTask() { |
private int runTimes= 0 ; |
@Override |
public void run() { |
if (state==RUNNING) { |
runTimes++; |
if (runTimes% 40 == 0 ) { |
nextOne(); |
} |
for ( int i= 0 ;i<flyers.length;i++) { |
flyers[i].step(); |
} |
if (runTimes% 15 == 0 ) { |
shoot(); |
} |
for ( int i= 0 ;i<bullets.length;i++) { |
bullets[i].step(); |
} |
hero.step(); |
bang(); |
hit(); |
outOfBounds(); |
} |
repaint(); |
} |
|
}, 5 , 5 ); |
} |
|
@Override |
public void paint(Graphics g) { |
|
g.drawImage(background, 0 , 0 , null ); //super.paint(arg0); |
|
paintHero(g); |
|
paintFlyers(g); |
|
paintBullets(g); |
|
paintScore_Life(g); |
|
if (state==START) { |
g.drawImage(start, 0 , 0 , null ); |
} else if (state==PAUSE){ |
g.drawImage(pause, 0 , 0 , null ); |
} else if (state==GAME_OVER) { |
g.drawImage(gameover, 0 , 0 , null ); |
} |
} |
public void paintHero(Graphics g) { |
g.drawImage(hero.image,hero.x,hero.y, null ); |
} |
public void paintFlyers(Graphics g) { |