Now with kids mode
This commit is contained in:
117
ship.js
117
ship.js
@@ -1,15 +1,48 @@
|
||||
class Ship {
|
||||
constructor() {
|
||||
this.pos = createVector(width / 2, height / 2);
|
||||
constructor(safeSpawn = false) {
|
||||
if (safeSpawn) {
|
||||
this.pos = createVector(random(width), random(height));
|
||||
let safe = false;
|
||||
while (!safe) {
|
||||
safe = true;
|
||||
for (let asteroid of asteroids) {
|
||||
if (dist(this.pos.x, this.pos.y, asteroid.pos.x, asteroid.pos.y) < 100) {
|
||||
safe = false;
|
||||
this.pos = createVector(random(width), random(height));
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (let pizza of pizzas) {
|
||||
if (dist(this.pos.x, this.pos.y, pizza.pos.x, pizza.pos.y) < 100) {
|
||||
safe = false;
|
||||
this.pos = createVector(random(width), random(height));
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (let hamburger of hamburgers) {
|
||||
if (dist(this.pos.x, this.pos.y, hamburger.pos.x, hamburger.pos.y) < 100) {
|
||||
safe = false;
|
||||
this.pos = createVector(random(width), random(height));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.pos = createVector(width / 2, height / 2);
|
||||
}
|
||||
this.r = 20;
|
||||
this.heading = 0;
|
||||
this.rotation = 0;
|
||||
this.vel = createVector(0, 0);
|
||||
this.isBoosting = false;
|
||||
this.shieldActive = false;
|
||||
this.shieldEndTime = 0;
|
||||
this.shieldStart = 0;
|
||||
this.quadShotActive = false;
|
||||
this.quadShotEndTime = 0;
|
||||
this.quadShotStart = 0;
|
||||
}
|
||||
|
||||
boosting(b) {
|
||||
this.isBoosting = b;
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -17,12 +50,16 @@ class Ship {
|
||||
this.boost();
|
||||
}
|
||||
this.pos.add(this.vel);
|
||||
this.vel.mult(0.99); // Friction
|
||||
this.vel.mult(0.99);
|
||||
this.heading += this.rotation;
|
||||
if (this.shieldActive && millis() > this.shieldEndTime) {
|
||||
|
||||
// Check shield duration
|
||||
if (this.shieldActive && millis() - this.shieldStart > 10000) {
|
||||
this.shieldActive = false;
|
||||
}
|
||||
if (this.quadShotActive && millis() > this.quadShotEndTime) {
|
||||
|
||||
// Check quad shot duration
|
||||
if (this.quadShotActive && millis() - this.quadShotStart > 10000) {
|
||||
this.quadShotActive = false;
|
||||
}
|
||||
}
|
||||
@@ -38,54 +75,52 @@ class Ship {
|
||||
return d < this.r + obj.r;
|
||||
}
|
||||
|
||||
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;
|
||||
activateShield() {
|
||||
this.shieldActive = true;
|
||||
this.shieldStart = millis();
|
||||
}
|
||||
|
||||
activateQuadShot() {
|
||||
this.quadShotActive = true;
|
||||
this.quadShotStart = millis();
|
||||
}
|
||||
|
||||
setRotation(a) {
|
||||
this.rotation = a;
|
||||
}
|
||||
|
||||
boosting(b) {
|
||||
this.isBoosting = b;
|
||||
}
|
||||
|
||||
activateShield() {
|
||||
this.shieldActive = true;
|
||||
this.shieldEndTime = millis() + 10000; // 10 seconds
|
||||
}
|
||||
|
||||
activateQuadShot() {
|
||||
this.quadShotActive = true;
|
||||
this.quadShotEndTime = millis() + 10000; // 10 seconds
|
||||
}
|
||||
|
||||
show() {
|
||||
push();
|
||||
translate(this.pos.x, this.pos.y);
|
||||
rotate(this.heading + PI / 2);
|
||||
noFill();
|
||||
stroke(255);
|
||||
if (this.quadShotActive) {
|
||||
fill(0, 255, 0); // Green fill for quad-shot
|
||||
let quadTimeLeft = 10000 - (millis() - this.quadShotStart);
|
||||
if (quadTimeLeft < 2000) {
|
||||
let alpha = 255 * (1 + sin(millis() * 0.01)) / 2;
|
||||
fill(0, 255, 0, alpha);
|
||||
}
|
||||
}
|
||||
triangle(-this.r, this.r, this.r, this.r, 0, -this.r);
|
||||
if (this.shieldActive) {
|
||||
// Pulsing shield effect in last 2 seconds
|
||||
let timeLeft = (this.shieldEndTime - millis()) / 1000;
|
||||
let scaleFactor = this.shieldActive && timeLeft < 2 ? 1 + 0.1 * sin(millis() / 100) : 1;
|
||||
scale(scaleFactor);
|
||||
noFill();
|
||||
stroke(0, 255, 255); // Cyan shield
|
||||
stroke(0, 255, 255);
|
||||
let shieldTimeLeft = 10000 - (millis() - this.shieldStart);
|
||||
if (shieldTimeLeft < 2000) {
|
||||
let scaleFactor = 1 + 0.2 * sin(millis() * 0.01);
|
||||
scale(scaleFactor);
|
||||
}
|
||||
ellipse(0, 0, this.r * 2.5);
|
||||
}
|
||||
// Ship fill: green if quad-shot active, else black
|
||||
if (this.quadShotActive) {
|
||||
let timeLeft = (this.quadShotEndTime - millis()) / 1000;
|
||||
let alpha = this.quadShotActive && timeLeft < 2 ? map(sin(millis() / 100), -1, 1, 100, 255) : 255;
|
||||
fill(0, 255, 0, alpha);
|
||||
} else {
|
||||
fill(0);
|
||||
}
|
||||
stroke(255);
|
||||
triangle(-this.r, this.r, this.r, this.r, 0, -this.r);
|
||||
pop();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user