parent
5606e45574
commit
e119a9798c
@ -0,0 +1,44 @@
|
||||
package com.msb;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @Author bingor
|
||||
* @Date 2022-09-30 14:33
|
||||
* @Description: 子弹类
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class Bullet extends Frame {
|
||||
|
||||
private int x, y;
|
||||
private DirEnum dir;
|
||||
public static final int WIDTH = 8;
|
||||
public static final int HEIGHT = 8;
|
||||
public static final int SPEED = 5;
|
||||
|
||||
public Bullet(int x, int y, DirEnum dir) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
Color color = g.getColor();
|
||||
g.setColor(Color.RED);
|
||||
g.fillOval(x, y, WIDTH, HEIGHT);
|
||||
g.setColor(color); //还原画笔原来的颜色
|
||||
moving();
|
||||
}
|
||||
|
||||
public void moving() {
|
||||
|
||||
switch (dir) {
|
||||
case UP: y -= SPEED; break;
|
||||
case DOWN: y += SPEED; break;
|
||||
case LEFT: x -= SPEED; break;
|
||||
case RIGHT: x += SPEED; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue