summaryrefslogtreecommitdiff
path: root/2026/games/crm148/star.js
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-08-26 23:47:59 -0400
committerLLLL Colonq <llll@colonq>2026-08-26 23:47:59 -0400
commit0d2d8cd897e94bd94e0b3ae7c6ce9aa580a44a0a (patch)
treee9039d1c3aedca515d6cb499451d4b73aca4f5fd /2026/games/crm148/star.js
parent242943e5b023ce40eb3be826c418a478d4672f78 (diff)
Add a_tension_span
Diffstat (limited to '2026/games/crm148/star.js')
-rw-r--r--2026/games/crm148/star.js79
1 files changed, 0 insertions, 79 deletions
diff --git a/2026/games/crm148/star.js b/2026/games/crm148/star.js
deleted file mode 100644
index 78173a8..0000000
--- a/2026/games/crm148/star.js
+++ /dev/null
@@ -1,79 +0,0 @@
-
-import { getCosmos } from './cosmos.js';
-import { globalView } from './view.js';
-import Vec2 from './vec2.js';
-import Color from './color.js';
-import Pulse from './pulse.js';
-
-var cosmos;
-
-export default class Star {
- pos = Vec2.zero();
- radius;
-
- difficulty_mult = 0.2;
- growth_base = 3;
-
- pulses = [];
- state = 'state_glowing';
-
- energy = 5;
- growth_rate;
-
- constructor(radius, difficulty) {
- cosmos = getCosmos();
- this.radius = radius;
- const diff_adjust = 1.0 + difficulty * this.difficulty_mult;
- this.growth_rate = this.growth_base + diff_adjust;
- }
-
- update(dt) {
- this.energy += dt * this. growth_rate;
- if (this[this.state]) {
- this[this.state](dt);
- }
- }
-
- state_glowing(dt) {
- if (this.energy > cosmos.thresh_crit) {
- this.state = 'state_critical';
- }
- }
-
- // Multiply the energy by a random value
- // If the result is over the threshold, dump that energy into a pulse
- state_critical(dt) {
- var rand = 0.1 + 0.8 * Math.random();
- var strength = Math.min(rand * this.energy, cosmos.pulse_max_str);
- if (strength > cosmos.pulse_min_str) {
- this.energy -= strength;
- cosmos.pulses.push(Pulse.StrengthPulse(this.radius, strength));
- }
- }
-
- getColor() {
- var color = Color.StarColor;
- switch (this.state) {
- case 'state_glowing':
- color = Color.interpolate(Color.StarDim,
- Color.StarBright,
- this.energy / cosmos.thresh_crit);
- break;
- case 'state_critical':
- color = Color.StarBright;
- break;
- }
- return color.to_string();
- }
-
- render(ctx) {
- const view = globalView();
- var s_pos = view.project(this.pos);
- var surface_vec = view.project(new Vec2(this.radius, this.pos.y));
- var s_rad = surface_vec.x - s_pos.x;
- ctx.fillStyle = this.getColor();
- ctx.beginPath();
- ctx.arc(s_pos.x, s_pos.y, s_rad, 0, 2 * Math.PI);
- ctx.fill();
- }
-}