-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblizzard.js
44 lines (34 loc) · 1.39 KB
/
blizzard.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
let canvasInstance = new gamid.graphics.Canvas(800, 800, 'black');
let canvas = canvasInstance.element;
// gamid.graphics.setBackgroundColor(canvas, 'red');
for (let i = 0; i < 1000; i++){
let square = new gamid.graphics.Square(1, 10, Math.random()*800, Math.random()*800, 1, 'cyan');
let a = new gamid.controller.Keyboard(square, [87, 65, 83, 68]);
let squarecollision = new gamid.physics.SquareCollision(square);
squarecollision.afterCollision = function(object, collided){
collided.width +=0.01;
collided.height +=0.01;
object.width +=0.01;
object.height +=0.01;
}
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;});
// a.setOnKeyUp(83, function(){square.speedY = 0});
a.setOnKeyDown(83, function(){square.speedY += Math.random()*100; });
// a.setOnKeyUp(65, function(){square.speedX = 0});
a.setOnKeyDown(65, function(){square.speedX -= Math.random()*100; });
// a.setOnKeyUp(68, function(){square.speedX = 0});
a.setOnKeyDown(68, function(){square.speedX += Math.random()*100; });
}
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;
}