Best game ever
This commit is contained in:
46
hamburger.js
Normal file
46
hamburger.js
Normal file
@@ -0,0 +1,46 @@
|
||||
class Hamburger {
|
||||
constructor(pos, r) {
|
||||
this.pos = pos.copy();
|
||||
this.r = r ? r / 2 : random(20, 30);
|
||||
this.vel = p5.Vector.random2D();
|
||||
this.vel.mult(random(1, 3));
|
||||
}
|
||||
|
||||
update() {
|
||||
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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user