xxxxxxxxxx
69
const {
Engine,
World,
MouseConstraint,
Mouse,
Constraint
} = Matter;
let BirdMass = 4;
let BoxBounciness = 0.5;
let BirdBounciness = 0.5;
let ground;
const boxes = [];
let bird;
let world, engine;
let mConstraint;
let slingshot;
function preload() {
bimg = loadImage("box.png");
dimg = loadImage("bird.png");
}
function setup() {
const canvas = createCanvas(600, 400);
engine = Engine.create();
world = engine.world;
ground = new Ground(width / 2, height - 10, width * 2, 20);
for (let i = 0; i < 3; i++) {
boxes[i] = new Box(450, 300 - i * 75, 50, 75);
}
bird = new Bird(150, 300, 25);
slingshot = new Slingshot(150, 300, bird.body);
const mouse = Mouse.create(canvas.elt);
const options = {
mouse: mouse
}
mConstraint = MouseConstraint.create(engine, options);
World.add(world, mConstraint);
}
function keyPressed() {
if (key = ' ') {
World.remove(world, bird.body);
bird = new Bird(150, 300, 25);
slingshot.attach(bird.body);
}
}
function mouseReleased() {
setTimeout(() => {
slingshot.fly();
}, 100);
}
function draw() {
background(0);
Matter.Engine.update(engine);
ground.show();
for (let box of boxes) {
box.show();
}
slingshot.show();
bird.show();
}