xxxxxxxxxx
59
var Engine = Matter.Engine,
Runner = Matter.Runner,
World = Matter.World,
Bodies = Matter.Bodies,
Composite = Matter.Composite;
// create an engine
var engine;
var world;
var ball;
var obstacle;
function setup() {
createCanvas(500, 500);
engine = Engine.create();
world = engine.world;
Runner.run(engine);
ball = new Ball(100, 100, 60)
obstacle = new Obstacle(100,200,90)
}
function draw() {
background(220);
ball.show()
obstacle.show()
}
function Ball(x, y, r) {
this.body = Bodies.circle(x, y, r / 2);
World.add(world, this.body);
this.show = function () {
var pos = this.body.position;
circle(pos.x, pos.y, r);
};
}
function Obstacle(x, y, r) {
this.body = Bodies.circle(x, y, r / 2, { isStatic: true });
this.r = r;
World.add(world, this.body);
this.show = function () {
var pos = this.body.position;
var angle = this.body.angle;
//push();
//translate(pos.x, pos.y);
//rotate(angle)
circle(x, y, r);
//pop();
//console.log(pos.x,pos.y,this.w,this.h)
};
}