-
Notifications
You must be signed in to change notification settings - Fork 12
/
basic.js
27 lines (21 loc) · 837 Bytes
/
basic.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
(function() {
var colors = ['#006BA6', '#0496FF', '#FFBC42', '#D81159', '#8F2D56'];
var Bodies = Matter.Bodies;
Matter.use('matter-collision-events');
var boxA = Bodies.rectangle(400, 200, 80, 80, {
velocity: {
x: 12,
y: 10,
}
});
var boxB = Bodies.rectangle(450, 50, 80, 80);
boxA.render.fillStyle = colors[Math.floor(Math.random() * colors.length)];
boxB.render.fillStyle = colors[Math.floor(Math.random() * colors.length)];
boxB.onCollide(function(pair) {
console.log('BoxB got hit!', pair);
pair.bodyA.render.fillStyle = colors[Math.floor(Math.random() * colors.length)];
pair.bodyB.render.fillStyle = colors[Math.floor(Math.random() * colors.length)];
});
var ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
window.basicBodies = [boxA, boxB, ground];
})()