xxxxxxxxxx
72
class Sleigh {
constructor(x, y, img) {
this.x = x;
this.y = y;
this.speed = 0.5; // Adjust the sleigh's speed
this.img = img;
this.presents = []; // Array to store present details
}
move() {
// Implement your sleigh's movement logic here
this.x += this.speed;
// Wrap the sleigh around the canvas if it goes off-screen
if (this.x > width) {
this.x = -100; // Reset the sleigh's position to the left of the canvas
}
}
display() {
// Draw your sleigh using the provided image
image(this.img, this.x, this.y, 200, 200);
// Check if it's time to drop presents
if (frameCount % 60 === 0) {
this.dropPresent();
}
// Update and display the presents
for (let i = this.presents.length - 1; i >= 0; i--) {
const present = this.presents[i];
present.y += present.speed; // Move the present down
// Draw your present using shapes or images
fill(255, 0, 255);
rect(present.x, present.y, 20, 20); // Example: A pink rectangle for the present
// Remove the present from the array when it's out of sight
if (present.y > height) {
this.presents.splice(i, 1);
}
}
}
dropPresent() {
// Store present details (position and speed) in the array
this.presents.push({
x: this.x + 100, // Adjust as needed
y: this.y + 200, // Adjust as needed
speed: 3, // Adjust the fall speed
});
}
}
let sleigh;
function preload() {
sl = loadImage('sleigh.png');
}
function setup() {
createCanvas(600, 600);
sleigh = new Sleigh(0, height / 4, sl); // Initialize the sleigh
}
function draw() {
background(220);
sleigh.move(); // Move the sleigh
sleigh.display(); // Display the sleigh
}