-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
60 lines (50 loc) · 934 Bytes
/
sketch.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
let unicorn;
let uImg;
let tImg;
let bImg;
let trains = [];
function preload() {
const options = {
probabilityThreshold: 0.95
};
uImg = loadImage('unicorn.png');
tImg = loadImage('train.png');
bImg = loadImage('background.jpg');
}
function mousePressed() {
trains.push(new Train());
}
function setup() {
createCanvas(800, 450);
unicorn = new Unicorn();
}
function gotCommand(error, results) {
if (error) {
console.error(error);
}
console.log(results[0].label, results[0].confidence);
if (results[0].label == 'up') {
unicorn.jump();
}
}
function keyPressed() {
if (key == ' ') {
unicorn.jump();
}
}
function draw() {
if (random(1) < 0.005) {
trains.push(new Train());
}
background(bImg);
for (let t of trains) {
t.move();
t.show();
if (unicorn.hits(t)) {
console.log('game over');
noLoop();
}
}
unicorn.show();
unicorn.move();
}