-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstract.js
38 lines (27 loc) · 1.21 KB
/
abstract.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
let canvasInstance = new gamid.graphics.Canvas(800, 800, 'white');
let canvas = canvasInstance.element;
// gamid.graphics.setBackgroundColor(canvas, 'red');
for (let i = 0; i < 30000; i++){
let square = new gamid.graphics.Square(1, 10, Math.random()*800, Math.random()*800, getRandomColor());
a = new gamid.controller.Keyboard(square, [87, 65, 83, 68]);
canvasInstance.addObject(square);
// square.speedX = 20;
// square.speedY = 20;
// a.setOnKeyUp(87, function(){square.speedY = 0});
a.setOnKeyDown(87, function(){square.speedY = -Math.random()*100; square.speedX = 0});
// a.setOnKeyUp(83, function(){square.speedY = 0});
a.setOnKeyDown(83, function(){square.speedY = Math.random()*100; square.speedX = 0});
// a.setOnKeyUp(65, function(){square.speedX = 0});
a.setOnKeyDown(65, function(){square.speedX = -Math.random()*100; square.speedY = 0});
// a.setOnKeyUp(68, function(){square.speedX = 0});
a.setOnKeyDown(68, function(){square.speedX = Math.random()*100; square.speedY = 0});
}
document.body.appendChild(canvas);
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}