bullet.java
来自「简易的坦克程序」· Java 代码 · 共 61 行
JAVA
61 行
import java.awt.*;
public class bullet{
private int xPos;
private int yPos;
private Rectangle bullet;
private int direction;
private int Speed;
private int bulletpower;
public bullet(int a, int b, int c, int d, int e){
xPos = a;
yPos = b;
direction = c;
Speed = d;
bulletpower = e;
}
public void draw(Graphics g) {
g.setColor(Color.lightGray);
if(direction == 0 || direction == 1)
g.fillRect(xPos-1, yPos-4, 3, 9);
if(direction == 2 || direction == 3)
g.fillRect(xPos-4, yPos-1, 9, 3);
}
public void move(){
if(direction == 0)
yPos = yPos - Speed;
if(direction == 1)
yPos = yPos + Speed;
if(direction == 2)
xPos = xPos - Speed;
if(direction == 3)
xPos = xPos + Speed;
}
public Rectangle getbulletborder(){
if(direction == 0)
bullet = new Rectangle(xPos-2, yPos-5, 5, 11);
if(direction == 1)
bullet = new Rectangle(xPos-2, yPos-5, 5, 11);
if(direction == 2)
bullet = new Rectangle(xPos-5, yPos-2, 11, 5);
if(direction == 3)
bullet = new Rectangle(xPos-5, yPos-2, 11, 5);
return bullet;
}
public Point getbulletposition(){
return new Point(xPos, yPos);
}
public int getbulletpower(){
return bulletpower;
}
public int getbulletdirection(){
return direction;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?