Angry Birds
(Part 3)
Sketch.js:
const Engine = Matter.Engine;
const World = Matter.World;
const Bodies = Matter.Bodies;
const Constraint = Matter.Constraint;
var engine, world;
var box1;
function setup() {
createCanvas(1200, 400);
engine = Engine.create();
world = engine.world;
//First Floor
box1 = new Box(800, 320, 70, 70);
box2 = new Box(1000, 320, 70, 70);
pig1 = new Pig1(910, 350);
log1 = new Log(910, 270, 270, 90);
//Second Floor
box3 = new Box(826, 210, 70, 70);
box4 = new Box(990, 210, 70, 70);
pig2 = new Pig2(910, 190, 50, 50);
log2 = new Log(910, 100, 300, 90);
//Third Floor
box5 = new Box(890, 50, 70, 70);
log3 = new Log(900, 32, 150, 30);
log4 = new Log(960, 33, 150, -30);
constraintLog = new Log(230, 180, 80, 90);
bird = new Bird(200, 200);
platform = new Ground(150, 305, 300, 170);
var options = {
bodyA: bird.body,
bodyB: constraintLog.body,
stiffness: 0.04,
length: 10,
};
var chain = Constraint.create(options);
World.add(world, chain);
ground = new Ground(600, height, 1200, 20);
}
function preload() {
bgI = loadImage('sprites/bg.png');
}
function draw() {
background(bgI);
Engine.update(engine);
box1.display();
box2.display();
pig1.display();
log1.display();
box3.display();
box4.display();
pig2.display();
log2.display();
box5.display();
log3.display();
log4.display();
constraintLog.display();
bird.display();
platform.display();
strokeWeight(3);
line(
bird.body.position.x,
bird.body.position.y,
constraintLog.body.position.x,
constraintLog.body.position.y
);
ground.display();
}
0 Comments: