【实例简介】
【实例截图】
【核心代码】
public void paintherobullets(Graphics g) {
for (int i = 0; i < herobullet.size(); i ) {
Herobullet hb = herobullet.get(i);
hb.draw(g);
}
}
@Override
public void keyTyped(KeyEvent e) {
}
// 键盘按下
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
up = true;
break;
case KeyEvent.VK_DOWN:
down = true;
break;
case KeyEvent.VK_LEFT:
left = true;
break;
case KeyEvent.VK_RIGHT:
right = true;
break;
case KeyEvent.VK_Z:
VK_Z = true;
break;
case KeyEvent.VK_X:
VK_X = true;
break;
case KeyEvent.VK_ENTER:
VK_ENTER = true;
break;
default:
break;
}
repaint();
}
// 键盘释放
@Override
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
up = false;
break;
case KeyEvent.VK_DOWN:
down = false;
break;
case KeyEvent.VK_LEFT:
left = false;
break;
case KeyEvent.VK_RIGHT:
right = false;
break;
case KeyEvent.VK_Z:
VK_Z = false;
break;
case KeyEvent.VK_X:
VK_X = false;
break;
case KeyEvent.VK_ENTER:
VK_ENTER = false;
break;
default:
break;
}
}
}