xxxxxxxxxx
50
class Platform {
constructor({ x, y, Yangle }) {
this.x = x;
this.y = y;
this.width = 40;
this.height = 200;
this.speed = 1;
this.angle = 1.45;
this.Yangle = Yangle;
}
move() {
this.y = this.y + this.speed;
// each frame im increasing the direction by 1
if (this.y > width || this.y < 0) {
// || means or
this.speed = this.speed * -1;
}
}
draw() {
rectMode(CENTER);
rotateX(this.angle);
rect(this.x, this.y, this.width, this.height);
}
}
let plat;
function setup() {
createCanvas(710, 400, WEBGL);
plat = [
new Platform({ x: 0, y: 300, Yangle: 0 }),
new Platform({ x: -50, y: 100, Yangle: 1.15 }),
];
}
function draw() {
background(200);
// plat.move();
// plat.draw();
plat.forEach((plat) => {
plat.move();
plat.draw();
});
}