-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.java
More file actions
77 lines (63 loc) · 1.99 KB
/
Player.java
File metadata and controls
77 lines (63 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package data;
import java.util.ArrayList;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import static helpers.Artist.*;
import GameObjects.Tower;
import GameObjects.TowerType;
public class Player {
private TileGrid grid;
private TileType[] types;
private int index;
private WaveController waveController;
private ArrayList<Tower> towerList;
private ArrayList<Enemy> enemyList;
public Player(TileGrid grid, WaveController waveController, ArrayList<Enemy> enemies) {
this.grid = grid;
this.types = new TileType[3];
this.index = 0;
this.waveController = waveController;
this.towerList = new ArrayList<Tower>();
this.enemyList = enemies;
this.types[0] = TileType.Path;
this.types[1] = TileType.Water;
this.types[2] = TileType.Ground;
}
public void setTile() {
grid.SetTile((int) Math.floor(Mouse.getX() / 64), (int) Math.floor((HEIGHT - Mouse.getY() - 1) / 64),
types[index]);
}
public void update() {
for (Tower t : towerList) {
t.update();
}
// Mouse Input.
if (Mouse.isButtonDown(0)) {
towerList.add(new Tower("fkghhg", grid.GetTile((int) Math.floor(Mouse.getX() / 64), (int) Math.floor((HEIGHT - Mouse.getY() - 1) / 64)), TowerType.BasicSquirt, this.enemyList));
}
// Keyboard Input.
while (Keyboard.next()) {
if (Keyboard.getEventKey() == Keyboard.KEY_RIGHT && Keyboard.getEventKeyState()) {
moveIndex();
}
if (Keyboard.getEventKey() == Keyboard.KEY_RIGHT && Keyboard.getEventKeyState()) {
moveIndex();
}
if (Keyboard.getEventKey() == Keyboard.KEY_T && Keyboard.getEventKeyState()) {
towerList.add(new Tower("fkghhg", grid.GetTile(18, 9), TowerType.BasicSquirt, this.enemyList));
}
}
}
private void moveIndex() {
index++;
if (index > types.length - 1) {
index = 0;
}
}
public ArrayList<Tower> getTowerList() {
return towerList;
}
public void setTowerList(ArrayList<Tower> towerList) {
this.towerList = towerList;
}
}