-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGame.pde
175 lines (164 loc) · 4.74 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
HashMap<String, Float> timers;
boolean paused = false;
boolean gameover = false;
boolean newGame = true;
public void drawMainBar() {
PImage left = getImage("main_bar_bg_left");
PImage right = getImage("main_bar_bg_right");
drawImage(left,0,0);
for (int x=0;x<gameWidth-right.width-left.width;x++) {
drawImage(getImage("main_bar_bg_center"),left.width+x,0);
}
drawImage(right,gameWidth-right.width,0);
drawImage(getImage("main_bar_score"),1,0);
PImage highScore = getImage("main_bar_highscore");
drawImage(highScore,gameWidth-highScore.width-3,0);
}
public void drawGameBackground() {
background(36,182,255);
drawMainBar();
}
public void makeGameBoard() {
board = new GameBoard(3,15);
}
public void game(float time) {
if (gameStateChanged) {
drawGameBackground();
// Create the game board
makeGameBoard();
int nextPlayerSize = int(TILESIZE * getMaximumShapeSize().x);
gameWidth = board.getRightEdge()+nextPlayerSize+(TILESIZE * 4);
gameHeight = board.getBottomEdge();
updateGameSize();
timers = new HashMap<String, Float>();
timers.put("keyLeft",0f);
timers.put("keyRight",0f);
timers.put("keyDown",0f);
timers.put("gameStart1",0f);
timers.put("gameStart2",0f);
timers.put("gameStart3",0f);
}
if (!gameover && !newGame && !paused) {
if (isKeyDown("left")) {
timers.put("keyLeft",timers.get("keyLeft")+time);
if (timers.get("keyLeft")>500) {
board.player.move(-1,0);
}
}
if (isKeyDown("right") && timers.get("keyRight")>200) {
timers.put("keyRight",timers.get("keyRight")+time);
if (timers.get("keyRight")>500) {
board.player.move(1,0);
}
}
if (isKeyDown("up") && !wasKeyDown("up")) {
Shape p = board.player;
if (p.blocks.length>0) {
p.shift();
}
}
for (HashMap.Entry<String,Boolean> entry : keysDown.entrySet()) {
wereKeysDown.put(entry.getKey(),false);
wereKeysDown.put(entry.getKey(),entry.getValue());
}
timers.put("keyDown",timers.get("keyDown")+time);
board.player.checkCollisions();
scoreFont.update(time);
comboFont.update(time);
// If this is a new high score
// Update save file
if (score>config.getInt("highScore")) {
config.set("highScore", score);
config.save();
}
}
else if (gameover) {
board.fillUp(time);
}
/*else if (newGame) {
if (timers.get("gameStart1")==0) {
playSound("ready");
}
timers.put("gameStart1",timers.get("gameStart1")+time);
if (timers.get("gameStart1")>1000 && timers.get("gameStart2")==0) {
playSound("set");
}
if (timers.get("gameStart1")>1000 && timers.get("gameStart3")==0) {
timers.put("gameStart2",timers.get("gameStart2")+time);
if (timers.get("gameStart2")>1000) {
playSound("go");
}
}
if (timers.get("gameStart2")>1000) {
timers.put("gameStart3",timers.get("gameStart3")+time);
if (timers.get("gameStart3")>750) {
newGame();
}
}
}*/
if (!paused) {
board.update(time);
}
drawGameBackground();
board.display();
if (paused) {
drawImageCenter("paused",
int(board.getVisibleCenter().x),
int(board.getVisibleCenter().y)
);
}
drawImageStack(time);
scoreFont.write(str(score),65,4);
scoreFont.write(str(config.getInt("highScore")),gameWidth-3,4);
sim.update(time);
sim.display();
comboFont.display();
/*if (newGame) {
if (timers.get("gameStart1")<1000 && timers.get("gameStart2")==0) {
drawImageCenter("ready_txt",
int(board.getVisibleCenter().x),
int(board.getVisibleCenter().y)
);
}
else if (timers.get("gameStart2")<1000) {
drawImageCenter("set_txt",
int(board.getVisibleCenter().x),
int(board.getVisibleCenter().y)
);
}
else if (timers.get("gameStart3")<1000) {
drawImageCenter("set_txt",
int(board.getVisibleCenter().x),
int(board.getVisibleCenter().y)
);
}
}*/
}
public void gameOver() {
newGame = true;
gameover = false;
level = 0;
score = 0;
board.setNextPlayer(null);
config.save();
}
public void newGame() {
if (newGame) {
newGame = false;
// Redraw the score bar
drawMainBar();
// Clear the board
board.reset();
score = 0;
// Create the next player
board.setNextPlayer(randomShape());
nextPlayer();
// Reset the speed back to the original speed
speed = initspeed;
level = 0;
score = 0;
timers.put("gameStart1",0f);
timers.put("gameStart2",0f);
timers.put("gameStart3",0f);
}
}