-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscript.js
101 lines (88 loc) · 2.62 KB
/
script.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
// Create Scene
const heightScreen = 700;
const widthScreen = 400;
const root = document.getElementById('root');
root.style.display = 'flex';
root.style.justifyContent = 'center';
root.style.alignItems = 'center';
const screen = document.createElement('div');
screen.style.position = "relative";
screen.style.width = `${widthScreen}px`;
screen.style.height = `${heightScreen}px`;
screen.style.border = "solid 1px black";
screen.style.background = "linear-gradient(to bottom, #94c5f8 1%,#a6e6ff 70%,#b1b5ea 100%)";
screen.style.overflow = "hidden";
// Create the platform
const heightPlatform = 20;
const platforms = [
{ top: 80, left: 10, width: 45 },
{ top: 150, left: 30, width: 45 },
{ top: 220, left: 50, width: 45 },
{ top: 290, left: 70, width: 45 },
{ top: 360, left: 90, width: 45 },
{ top: 430, left: 110, width: 45 },
{ top: 80, right: 10, width: 45 },
{ top: 150, right: 30, width: 45 },
{ top: 220, right: 50, width: 45 },
{ top: 290, right: 70, width: 45 },
{ top: 360, right: 90, width: 45 },
{ top: 430, right: 110, width: 45 },
];
function createPlatorm(d) {
const pf = document.createElement('div');
pf.style.position = "absolute";
pf.style.top = `${d.top}px`;
if (d.left) pf.style.left = `${d.left}px`
else pf.style.right = `${d.right}px`;
pf.style.width = `${d.width}px`;
pf.style.height = `${heightPlatform}px`;
pf.style.backgroundColor = 'grey';
pf.style.border = "2px solid black";
return pf;
}
// Create Tonneau
class Tonneau {
constructor(x) {
this.posX = x;
this.posY = 0;
this.intervalID = 0;
// Create tonneau
this.t = document.createElement('div');
this.t.style.position = "absolute";
this.t.style.top = `${this.posY}px`;
this.t.style.left = `${this.posX}px`;
this.t.style.width = "30px";
this.t.style.height = "22px";
this.t.style.backgroundColor = "brown";
this.t.style.border = "1px solid black";
this.t.style.borderRadius = "8px";
this.initialization();
}
initialization = () => {
this.intervalID = setInterval(() => {
this.posY += 5;
this.t.style.top = `${this.posY}px`;
this.detectionSurface();
}, 50);
}
getT() {
return this.t;
}
// TODO
detectionSurface = () => {
// If surface detected
//clearInterval(this.intervalID);
}
}
function generateTonneau() {
setInterval(() => {
const randomX = Math.floor(Math.random() * widthScreen);
const newT = new Tonneau(randomX);
screen.appendChild(newT.getT());
}, 2000);
}
// Append the platform
platforms.forEach(d => screen.appendChild(createPlatorm(d)))
root.appendChild(screen);
// Generate Tonneaux
generateTonneau();