OK it's sort of done
This commit is contained in:
parent
e93fd30849
commit
1500d4ee55
@ -4,6 +4,9 @@ const HEIGHT = 800;
|
||||
const NCRITTERS = 10;
|
||||
const CLOSE = 20;
|
||||
const BOUNCE = 0.02;
|
||||
const STUN = 10;
|
||||
const MIN_RADIUS = 2;
|
||||
const HIDE_SPEED = 10.5;
|
||||
|
||||
const pointer = { x: 0, y: 0 };
|
||||
|
||||
@ -41,6 +44,16 @@ class Critter {
|
||||
}
|
||||
}
|
||||
update() {
|
||||
if( this.status === "hide" ) {
|
||||
if( this.tick > STUN ) {
|
||||
this.tick--;
|
||||
this.elt.setAttribute("r", this.tick + MIN_RADIUS);
|
||||
} else {
|
||||
this.hide_vec = Math.atan2(this.y - pointer.y, this.x - pointer.x);
|
||||
this.vx = Math.cos(this.hide_vec) * HIDE_SPEED;
|
||||
this.vy = Math.sin(this.hide_vec) * HIDE_SPEED;
|
||||
}
|
||||
}
|
||||
if( this.status === "collide" ) {
|
||||
this.tick--;
|
||||
if( this.tick === 0 ) {
|
||||
@ -91,9 +104,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if( lights === "on" ) {
|
||||
lights = "off";
|
||||
dark.setAttribute("fill-opacity", "0.8");
|
||||
for( const c of critters ) {
|
||||
c.status = "go";
|
||||
}
|
||||
} else {
|
||||
lights = "on";
|
||||
dark.setAttribute("fill-opacity", "0");
|
||||
for( const c of critters ) {
|
||||
c.status = "hide";
|
||||
c.tick = Math.random() * 10 + 15;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user