-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
executable file
·110 lines (93 loc) · 2.43 KB
/
main.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
import p5 from 'p5/lib/p5';
import "p5/lib/addons/p5.sound";
import {Bus} from './src/bus.js';
import {Road} from './src/road.js';
import {Spawner} from './src/spawner.js';
let bus;
let road;
let spawner;
let font;
let global = {
vel: 18,
velA: 0.00015,
objects: {
vel: {
min: 5,
max: 25,
}
}
};
let s = (sk) => {
sk.preload = () => {
font = sk.loadFont('AsapCondensed-Bold.ttf');
};
sk.windowResized = () => {
sk.resizeCanvas(window.innerWidth, window.innerHeight);
};
sk.setup = () => {
sk.createCanvas(window.innerWidth, window.innerHeight, sk.WEBGL);
bus = new Bus(sk);
road = new Road(sk,global);
spawner = new Spawner(sk,global);
};
sk.draw = () => {
sk.textFont(font);
sk.noStroke();
sk.background('#71C3FF');
sk.angleMode(sk.DEGREES)
sk.rotateX(50);
sk.fill('#B0E14E');
sk.plane(sk.width * 5, sk.height * 5);
road.update(sk,bus);
spawner.updateObjects(sk,bus);
bus.update(sk);
road.show(sk);
spawner.showObjects(sk);
bus.show(sk);
};
sk.keyReleased = () => {
if(typeof bus !== 'undefined')
bus.keyReleased(sk.keyCode);
}
};
console.log(document.querySelector('button.left'));
// CONTROLS (with DOM for mobile)
let controlLoop = null;
const controlLoopSpeed = 7;
const buttonLeft = document.querySelector('.control.left');
const buttonRight = document.querySelector('.control.right');
buttonLeft.ontouchstart = function(e) {
e.preventDefault();
e.stopPropagation();
if(typeof bus == 'object') {
clearInterval(controlLoop);
controlLoop = setInterval(function () {
bus.turnLeft();
}, controlLoopSpeed);
}
}
buttonLeft.ontouchend = (e) => {
e.preventDefault();
e.stopPropagation();
if(typeof bus == 'object') {
clearInterval(controlLoop);
}
}
buttonRight.ontouchstart = function(e) {
e.preventDefault();
e.stopPropagation();
if(typeof bus == 'object') {
clearInterval(controlLoop);
controlLoop = setInterval(function () {
bus.turnRight();
}, controlLoopSpeed);
}
}
buttonRight.ontouchend = (e) => {
e.preventDefault();
e.stopPropagation();
if(typeof bus == 'object') {
clearInterval(controlLoop);
}
}
const P5 = new p5(s);