parent
680f087b25
commit
84d29842e6
Binary file not shown.
@ -0,0 +1,65 @@
|
||||
package com.demo.tank.coruse2;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Bullet {
|
||||
private int x, y;
|
||||
private Direction direction;
|
||||
private static final int SPEED = 5;
|
||||
private static final int WIDTH = 20;
|
||||
private static final int HEIGHT = 20;
|
||||
|
||||
public Bullet(int x, int y, Direction direction) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public void paint(Graphics g){
|
||||
Color color = g.getColor();
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(x, y, WIDTH, HEIGHT);
|
||||
g.setColor(color);
|
||||
move();
|
||||
}
|
||||
|
||||
private void move() {
|
||||
switch (direction){
|
||||
case UP: y -= SPEED;
|
||||
break;
|
||||
case DOWN: y += SPEED;
|
||||
break;
|
||||
case LEFT: x -= SPEED;
|
||||
break;
|
||||
case RIGHT: x += SPEED;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(Direction direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue