This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.pde
191 lines (186 loc) · 5.33 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
Game object by Vinh
*/
class Game {
Tile[][] map; //2D array of tiles for map
int score;
boolean gameOver;
Game() {
map = new Tile[col][row];
score = 0;
gameOver = false;
}
void display() {
for (int i = 0; i < col; i++) { // draws map
for (int j = 0; j < row; j++) {
map[i][j].display();
}
}
}
void interaction(float x, float y) { //if the player walks over...
if (map[int(x)][int(y)].type == 0) { //empty tile
death.pause();
death.rewind();
death.play(); //they die!
gameOver = true; //despair :C
} else if (map[int(x)][int(y)].type == 2) { //ice tile
if (knight.lastMove == 1) { //if lastMove is up
knight.moveUp();
} else if (knight.lastMove == 2) { //lastMove is right
knight.moveRight();
} else if (knight.lastMove == 3) { //lastMove is down
knight.moveDown();
} else if (knight.lastMove == 4) { //lastMove is left
knight.moveLeft();
}
} else if (map[int(x)][int(y)].type == 3) { //fire
death.pause();
death.rewind();
death.play(); //they die!
gameOver = true; //more despair :C
} else if (map[int(x)][int(y)].type == 4) { //web tile
knight.stuck = true; //oh no
if (!webbed.isPlaying()) {
webbed.pause();
webbed.rewind();
}
webbed.play(); //play the splash
tint(255, 100); //transparent
image(webOverlay, 0, 0, width, height); //display the web image
if (frameCount % 60 == 0) { //every second, it resets
map[int(x)][int(y)].type = 1; //change web to stone
knight.stuck = false; //no longer stuck
}
} else if (map[int(x)][int(y)].type == 5) { //coin tile
coinGet.pause();
coinGet.rewind();
coinGet.play(); //play the annoying sound
score+=100; //score up
map[int(x)][int(y)].type = 1; //change coin to stone
}
}
void timer() {
for (int i = 0; i < col; i++) { //check every map tile
for (int j = 0; j < row; j++) {
if (frameCount % 180 == 0) { //every 3 seconds
if (map[i][j].type == 3) { //if fire tile
map[i][j].type = 6; //switch to furnace tile
} else if (map[i][j].type == 6) { //if furnace tile
map[i][j].type = 3; //switch to fire tile
}
}
}
}
}
void build() {
if (randomMode) {
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
map[i][j] = new Tile(int(random(1, 7)), i, j); //set every tile to be randomly set
}
}
map[3][13].type = 1; //first tile is always stone
} else {
//reset map to empty space
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
map[i][j] = new Tile(0, i, j);
}
}
int mapChoice = int(random(3)); //choose between 3 layouts
switch(mapChoice) {
case 0:
map[3][13].type = 1; //handmade maps by Nick
map[3][12].type = 1;
map[3][11].type = 5;
map[2][11].type = 1;
map[3][10].type = 2;
map[2][10].type = 1;
map[1][10].type = 3;
map[1][9].type = 1;
map[1][8].type = 1;
map[2][8].type = 2;
map[3][8].type = 6;
map[4][8].type = 5;
map[4][7].type = 1;
map[4][6].type = 4;
map[4][5].type = 5;
map[5][5].type = 2;
map[3][5].type = 1;
map[2][5].type = 3;
map[2][4].type = 1;
map[3][4].type = 6;
map[2][3].type = 2;
map[2][2].type = 4;
map[3][2].type = 5;
map[3][1].type = 2;
map[3][0].type = 5;
break;
case 1:
map[3][13].type = 1;
map[4][13].type = 1;
map[3][12].type = 2;
map[4][12].type = 1;
map[5][12].type = 3;
map[6][12].type = 5;
map[4][11].type = 2;
map[4][10].type = 6;
map[5][10].type = 5;
map[3][10].type = 1;
map[3][9].type = 2;
map[4][9].type = 1;
map[6][8].type = 5;
map[5][8].type = 3;
map[4][8].type = 1;
map[3][8].type = 2;
map[4][7].type = 1;
map[4][6].type = 5;
map[3][6].type = 4;
map[2][6].type = 6;
map[1][6].type = 5;
map[3][5].type = 1;
map[2][4].type = 4;
map[3][4].type = 1;
map[2][3].type = 1;
map[3][3].type = 2;
map[4][3].type = 5;
map[5][3].type = 2;
map[4][2].type = 1;
map[4][1].type = 3;
map[4][0].type = 5;
break;
case 2:
map[3][13].type = 1;
map[3][12].type = 2;
map[4][12].type = 5;
map[2][12].type = 1;
map[1][12].type = 1;
map[3][11].type = 1;
map[4][11].type = 6;
map[1][11].type = 2;
map[1][10].type = 6;
map[1][9].type = 5;
map[1][8].type = 4;
map[2][8].type = 1;
map[3][8].type = 2;
map[4][8].type = 3;
map[5][8].type = 5;
map[2][7].type = 1;
map[2][6].type = 1;
map[3][6].type = 1;
map[3][5].type = 2;
map[4][5].type = 5;
map[5][5].type = 1;
map[6][5].type = 1;
map[4][4].type = 6;
map[3][4].type = 1;
map[6][4].type = 2;
map[6][3].type = 3;
map[6][2].type = 5;
map[6][1].type = 1;
map[6][0].type = 5;
break;
}
}
}
}