This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.pde
94 lines (72 loc) · 2.14 KB
/
Game.pde
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class Game extends CWorld {
public static final int STAGE_OFFSET = 32;
public static final int BUY_TOWER = 0;
public static final int UPGRADE_TOWER = 1;
public static final int SELL_TOWER = 2;
private Player player;
private SpawnWaveButton SpawnWaveButton;
private WaveSequence waveSeq;
private Stage stage;
private Combat combat;
Game(String stageId) {
stage = new Stage(stageId, this);
stage.setOffset(0, Game.STAGE_OFFSET);
player = new Player(stage.getInitialGold(), this);
}
void setup() {
stage.setup();
waveSeq = new WaveSequence(stage.getWavedataArray(), stage.getPath(), this);
new SpawnWaveButton(stage.getPath().getSpawnpoint(), this);
}
void postUpdate() {
if (waveSeq.hasNotStarted()) return;
if (player.isAlive()) {
if (waveSeq.areAllCreepsDead()) {
// Wins.
transitionTo(new RatingCalculation(player.getHp()));
}
} else {
// Loses.
transitionTo(new GameOver());
}
// XXX: Auto populate all nodes with arrow towers for testing.
// for (Node node : stage.getNodes().getObjects()) {
// player.buyTower(Tower.ICE, node);
// }
}
void draw() {
background(Utils.VERY_DARK_VIOLET);
// Manually draw non-Beings.
player.drawStats();
stage.drawMap();
// TODO: stage.drawForeground() and stage.drawBackground() would allow for beings to be displayed behind objectsr
super.draw();
}
void buyTower(int type, Node node) {
player.buyTower(type, node);
}
void dmgPlayer() {
player.receiveDmg();
}
void rewardPlayer(int amount) {
player.gainGold(amount);
}
void startWaveSeq() {
waveSeq.start();
combat = new Combat(player.getTowers(), player.getGuards(), waveSeq.getCreeps(), this);
}
public Path getPath() {
return stage.getPath();
}
private class SpawnWaveButton extends TextButton {
private Game game;
public SpawnWaveButton(PVector spawnpoint, Game game) {
super((int) spawnpoint.x, (int) spawnpoint.y + 60, "Spawn wave", game);
this.game = game;
}
protected void _onClick() {
game.startWaveSeq();
game.delete(this);
}
}
}