forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColour_Game.js
169 lines (147 loc) · 2.63 KB
/
Colour_Game.js
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
/*
@title: Colour_Game
@author: Thuvaragan
Instructions:
Press J if you see BLUE
Press L if you see GREEN
Press A if you see BLACK
The colour of the square is in random order.
Each time you press the correct button for the corresponding colour, you receive a point.
Game over if you click the wrong button.
Try to get as many points as you can!
Press Run again to restart
*/
// setup
const blue = "b";
const green = "g";
const black = "r";
setLegend(
[ blue, bitmap`
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555`],
[ green, bitmap`
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD`],
[ black, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`]
);
setMap(map`
.`);
let gameOver = false;
let currentColour = -1;
function changeColour(colour) {
currentColour = colour;
clearTile(0, 0);
if(colour == 0) {
addSprite(0, 0, blue);
}
if(colour == 1) {
addSprite(0, 0, green);
}
if(colour == 2) {
addSprite(0, 0, black);
}
}
let timer = 60;
changeColour(Math.floor(Math.random() * 3));
let score = 0;
function endGame() {
gameOver = true;
addText("Game Over", {
x: 5,
y: 5,
color: color`2`
});
}
function gameLoop() {
if(!gameOver) {
// timer
addText(timer.toString(), {
x: 3,
y: 1,
color: color`2`
});
timer -= 1;
//score
addText("Score: " + score.toString(), {
x: 8,
y: 14,
color: color`2`
});
if(timer < 0) {
endGame();
}
}
}
setInterval(gameLoop, 1000);
// User Input
onInput("j", () => {
// blue
if(currentColour == 0) {
score += 1;
} else {
endGame();
}
changeColour(Math.floor(Math.random() * 3));
});
onInput("l", () => {
// green
if(currentColour == 1) {
score += 1;
} else {
endGame();
}
changeColour(Math.floor(Math.random() * 3));
});
onInput("a", () => {
// black
if(currentColour == 2) {
score += 1;
} else {
endGame();
}
changeColour(Math.floor(Math.random() * 3));
});