1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
import {
victory,
getDebugInfo,
debugKey,
} from './control.js';
import Ship from './ship.js';
import Star from './star.js';
import Vec2 from './vec2.js';
import { drawSquare } from './util.js';
import { globalView } from './view.js';
var view;
class Cosmos {
pulses = [];
star;
player;
running;
dissipated;
dissipated_target;
dissipated_target_base = 50;
gravity = .008;
thresh_crit = 5.00;
max_size = (Math.min(gameCanvas.width, gameCanvas.height) / 2) + 100;
pulse_min_str = 7;
pulse_max_str = 20;
pulse_vel_base = 70.0;
angle = 1;
omega = 1.0;
init(difficulty) {
view = globalView();
const STRAD = 9;
const DIFFMUL = 3;
var starRadius = STRAD + difficulty * DIFFMUL;
this.star = new Star(starRadius, difficulty);
this.pulses = [];
this.player = Ship.AboveRadius(starRadius, this.max_size);
this.dissipated = 0;
this.dissipated_target = this.dissipated_target_base + 1 * (difficulty * 1.2);
this.omega = 1.0 + (0.2 * difficulty);
this.running = true;
}
stop() {
this.running = false;
// console.log('stop the world');
}
dissipate(energy) {
this.dissipated += energy;
debugKey('dissipated', this.dissipated);
}
update(dt) {
this.angle = (this.angle + this.omega * dt) % (2 * Math.PI);
this.player.update(dt);
this.star.update(dt);
this.pulses.forEach((p) => p.update(dt));
this.pulses = this.pulses.filter((p) => { return p.is_alive() });
if (this.dissipated > this.dissipated_target) {
victory();
}
}
render() {
ctx.fillStyle = "#151515";
ctx.strokeStyle = "#eeeeee";
ctx.fillRect(0,0, gameCanvas.width, gameCanvas.height);
this.star.render(ctx);
this.pulses.forEach((p) => p.render(ctx));
this.player.render(ctx);
// debugP.textContent = JSON.stringify(getDebugInfo());
// this.renderSpin();
}
renderSpin() {
ctx.fillStyle = "#ff1515";
ctx.strokeStyle = "#ff1515";
var p = view.project(new Vec2(Math.cos(this.angle),
Math.sin(this.angle)).scale(this.star.radius + 5));
drawSquare(ctx, p, 4);
var center = view.project(Vec2.zero());
var radius = center.sub(p).length();
ctx.beginPath();
ctx.arc(center.x, center.y, radius, -this.angle, -this.angle - 0.4, true);
ctx.stroke();
}
}
var theCosmos = new Cosmos();
var ctx = gameCanvas.getContext("2d");
window.cosmos = theCosmos;
function getCosmos() {
return theCosmos;
}
export {
Cosmos,
getCosmos,
}
|