-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
103 lines (97 loc) · 1.9 KB
/
sketch.js
File metadata and controls
103 lines (97 loc) · 1.9 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
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
fillVal = 126;
let timer = 40
let score_timer = timer
let x = 110
let y = 100
let score = 0
let timeLastUpdated = Date.now()
let timetemp = 0
let words = ['up', 'down', 'left', 'right'];
let directions = [1, 2, 3, 4];
let word = words[0];
let direction = directions[0];
// let scores = ['18/20', '19/20', '17/20'];
// let score = scores[0];
const TIME_BETWEEN = 2000;
function setup() {
createCanvas(1200, 1200);
frameRate(0.5);
}
function draw() {
if(timer > 0)
{
background(color(198, 221, 240));
textFont('Helvetica');
textSize(30);
text(timer, 50, 40);
strokeWeight(4);
stroke('#222222');
rectMode(CENTER);
rect(100*4,100*4,100*4,100*4);
strokeWeight(0);
stroke(51);
if(timer%2 == 0){
word = random(words);
direction = random(directions);
}
if (direction == 1) {
//right
if (keyCode === RIGHT_ARROW) {
score++;
// background(color(178, 230, 212));
}
x = 470;
y = 400;
}
if (direction == 2) {
//left
if (keyCode === LEFT_ARROW) {
score++;
// background(color(178, 230, 212));
}
x = 220;
y = 400;
}
if (direction == 3) {
//up
if (keyCode === UP_ARROW) {
score++;
// background(color(178, 230, 212));
}
x = 340;
y = 260;
}
if (direction == 4) {
//down
if (keyCode === DOWN_ARROW) {
score++;
// background(color(178, 230, 212));
}
x = 340;
y = 560;
}
textSize(50);
text(word, x, y);
}
if (timer == 0) {
textFont('Helvetica');
stroke(0);
textSize(30);
if (score < score_timer/2)
text("You can do better than that!\nYour score is:", 300, 680);
else {
if (score > score_timer/2)
score = score_timer/2;
text("Great job!\nYour score is:", 300, 680);
}
text(score, 480, 718);
text("/", 515, 718)
text(score_timer/2, 525, 718);
}
if (timer > 0) {
timer--;
}
if(timer == 0){
score = score;
}
}