Skip to content

Commit 386d226

Browse files
committed
implement bullet
1 parent 1a5dedd commit 386d226

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

src/main/java/bwapi/Bullet.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,74 @@
11
package bwapi;
22

3+
import JavaBWAPIBackend.Client.GameData.BulletData;
34
import bwapi.point.Position;
45
import bwapi.types.BulletType;
56

67
public class Bullet {
7-
private final int id;
8+
private final BulletData bulletData;
9+
private final Game game;
810

9-
Bullet(int id) {
10-
this.id = id;
11+
Bullet(final BulletData bulletData, final Game game) {
12+
this.bulletData = bulletData;
13+
this.game = game;
1114
}
1215

1316
public int getID() {
14-
return id;
17+
return bulletData.id();
1518
}
1619

1720
public boolean exists() {
18-
return false;
21+
return bulletData.exists();
1922
}
2023

2124
public Player getPlayer() {
22-
return null;
25+
return game.getPlayer(bulletData.player());
2326
}
2427

2528
public BulletType getType() {
26-
return null;
29+
return BulletType.bulletTypes.get(bulletData.type());
2730
}
2831

2932
public Unit getSource() {
30-
return null;
33+
return game.getUnit(bulletData.source());
3134
}
3235

3336
public Position getPosition() {
34-
return null;
37+
return new Position(bulletData.positionX(), bulletData.positionY());
3538
}
3639

3740
public double getAngle() {
38-
return -1;
41+
return bulletData.angle();
3942
}
4043

4144
public double getVelocityX() {
42-
return -1;
45+
return bulletData.velocityX();
4346
}
4447

4548
public double getVelocityY() {
46-
return -1;
49+
return bulletData.velocityY();
4750
}
4851

4952
public Unit getTarget() {
50-
return null;
53+
return game.getUnit(bulletData.target());
5154
}
5255

5356
public Position getTargetPosition() {
54-
return null;
57+
return new Position(bulletData.positionX(), bulletData.positionY());
5558
}
5659

5760
public int getRemoveTimer() {
58-
return -1;
61+
return bulletData.removeTimer();
5962
}
6063

6164
public boolean isVisible() {
62-
return false;
65+
return isVisible(game.self());
6366
}
6467

65-
public boolean isVisible(Player player) {
66-
return false;
68+
public boolean isVisible(final Player player) {
69+
return bulletData.isVisible(player.getID());
6770
}
6871

69-
7072
public boolean equals(Object that){
7173
if(!(that instanceof Bullet)) return false;
7274
return getID() == ((Bullet)that).getID();

src/main/java/bwapi/Game.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,17 @@ public Collection<Unit> getAllUnits() {
5959
6060
public List<Unit> getStaticNeutralUnits();
6161
62-
public List<Bullet> getBullets();
62+
*/
63+
public Collection<Bullet> getBullets() {
64+
//TODO cache this in onFrame
65+
final List<Bullet> bullets = new ArrayList<>();
66+
for (int i=0; i < gameData.bulletCount(); i++) {
67+
bullets.add(new Bullet(gameData.bullet(i), this));
68+
}
69+
return bullets;
70+
}
6371

72+
/*
6473
public List<Position> getNukeDots();
6574
*/
6675

src/main/java/bwapi/types/BulletType.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package bwapi.types;
22

3+
import java.util.Arrays;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
import java.util.stream.Collectors;
7+
38
public enum BulletType {
49
Melee(0),
510

@@ -46,6 +51,10 @@ public enum BulletType {
4651
None(209),
4752
Unknown(210);
4853

54+
public static Map<Integer, BulletType> bulletTypes = Arrays.stream(BulletType.values())
55+
.collect(Collectors.toMap(v-> v.id, v -> v));
56+
57+
4958
private int id;
5059

5160
BulletType(int id){

0 commit comments

Comments
 (0)