-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.js
66 lines (49 loc) · 2.33 KB
/
random.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
let canvasInstance = new gamid.graphics.Canvas(800, 800, 'darkgreen');
let canvas = canvasInstance.element;
// gamid.graphics.setBackgroundColor(canvas, 'red');
for (let i = 0; i < 100; i++){
// let abc=['blue', 'red', 'yellow', 'green', 'gray']
let xxx = Math.random()*800
let yyy = Math.random()*800
let color = 'red'
let abc=['#009','yellow','yellow']
if (xxx >400) {
abc=['white', 'black']
}
// FIXME DÁ PRA CRIAR UM OBJETO SQUARE SEM UMA DAS POSIÇÕES X E Y (CORRIJAM) (OU É PQ FICA SEM COR, SEI LÁ)
// let square = new gamid.graphics.Square(2, 2, Math.random()*800, Math.random()*800, abc[Math.floor(Math.random()*abc.length)]);
let square = new gamid.graphics.Square(30, 30, xxx, yyy, 1, abc[Math.floor(Math.random()*abc.length)]);
let squarecollision = new gamid.physics.SquareCollision(square);
a = new gamid.controller.Keyboard(square, [87, 65, 83, 68, 73, 74, 75, 76]);
// = new gamid.controller.Keyboard(square, [73, 74, 75, 76]);
canvasInstance.addObject(square);
// square.speedX = 20;
// square.speedY = 20;
// a.setOnKeyUp(87, function(){square.speedY = 0});
if (xxx<400) {
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; });
} else {
a.setOnKeyDown(73, function(){square.speedY -= Math.random()*100;});
// a.setOnKeyUp(83, function(){square.speedY = 0});
a.setOnKeyDown(75, function(){square.speedY += Math.random()*100; });
// a.setOnKeyUp(65, function(){square.speedX = 0});
a.setOnKeyDown(74, function(){square.speedX -= Math.random()*100; });
// a.setOnKeyUp(68, function(){square.speedX = 0});
a.setOnKeyDown(76, 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;
}