49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
class Hamburger {
|
|
constructor(pos, r) {
|
|
this.pos = pos.copy();
|
|
this.r = r ? r / 2 : random(20, 30);
|
|
this.baseVel = p5.Vector.random2D();
|
|
this.speed = window.kidMode ? random(0.5, 1.5) : random(1, 3);
|
|
this.vel = this.baseVel.copy().mult(this.speed);
|
|
}
|
|
|
|
update() {
|
|
this.speed = window.kidMode ? random(0.5, 1.5) : random(1, 3);
|
|
this.vel = this.baseVel.copy().mult(this.speed);
|
|
this.pos.add(this.vel);
|
|
}
|
|
|
|
edges() {
|
|
if (this.pos.x > width + this.r) this.pos.x = -this.r;
|
|
else if (this.pos.x < -this.r) this.pos.x = width + this.r;
|
|
if (this.pos.y > height + this.r) this.pos.y = -this.r;
|
|
else if (this.pos.y < -this.r) this.pos.y = height + this.r;
|
|
}
|
|
|
|
hits(bullet) {
|
|
let d = dist(this.pos.x, this.pos.y, bullet.pos.x, bullet.pos.y);
|
|
return d < this.r;
|
|
}
|
|
|
|
show() {
|
|
push();
|
|
translate(this.pos.x, this.pos.y);
|
|
// Rotate to align with velocity
|
|
let angle = atan2(this.vel.y, this.vel.x);
|
|
rotate(angle);
|
|
// Draw hamburger image (10 points)
|
|
if (hamburgerImg) {
|
|
imageMode(CENTER);
|
|
let scaleFactor = (this.r * 2) / hamburgerImg.width; // Scale to match radius
|
|
scale(scaleFactor);
|
|
image(hamburgerImg, 0, 0);
|
|
} else {
|
|
// Fallback if image fails to load
|
|
fill(200, 150, 100); // Brighter brown for hamburger
|
|
stroke(255);
|
|
ellipse(0, 0, this.r * 2);
|
|
console.log('Hamburger image not loaded, using fallback');
|
|
}
|
|
pop();
|
|
}
|
|
} |