-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
245 lines (219 loc) · 14.6 KB
/
Copy pathProgram.cs
File metadata and controls
245 lines (219 loc) · 14.6 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace winformWowSignal
{
internal static class Program { [STAThread] static void Main() { Application.Run(new SanctuaryMonitor()); } }
public class Moon
{
public string Name; public float Radius, Speed, Size, X, Y;
public Moon(string n, float r, float s, float sz) { Name = n; Radius = r; Speed = s; Size = sz; }
}
public class Planet
{
public string Name; public float Radius, Speed, Size, X, Y; public Color Color;
public bool IsDestroyed = false; public List<Moon> Moons = new List<Moon>();
public Planet(string n, float r, float s, float sz, Color c) { Name = n; Radius = r; Speed = s; Size = sz; Color = c; }
}
public class Ship
{
public string Name; public PointF Pos; public float Angle; public Color ShipColor; public bool IsFiring;
public Ship(string n, PointF p, Color c) { Name = n; Pos = p; ShipColor = c; }
}
public class Particle
{
public float X, Y, VX, VY; public Color Col; public int Life;
public Particle(float x, float y, float vx, float vy, Color c) { X = x; Y = y; VX = vx; VY = vy; Col = c; Life = 500; }
}
public class SanctuaryMonitor : Form
{
private bool[,] grid;
private int cellSize = 4, rows, cols;
private System.Windows.Forms.Timer timer;
private string[] wowChars = { "6", "E", "Q", "U", "J", "5" };
private Color[] pulseColors = { Color.LightBlue, Color.OrangeRed, Color.Yellow, Color.DeepSkyBlue, Color.MediumPurple, Color.DarkSlateBlue };
private long globalTicks = 0;
private PointF atlasPos, atlasVel, enkiPos;
private List<Planet> planets = new List<Planet>();
private List<Ship> fleet = new List<Ship>();
private List<PointF> asteroids = new List<PointF>();
private List<Particle> debris = new List<Particle>();
private bool enkiActive, sunDestroyed, rebirthTriggered, swiftActive, laserActive, tractorActive;
private float timeStep = 4550.0f, enkiSize = 0, swiftAngle;
private int weaponTimer = 0, missionState = 0, targetIndex = 0;
private Random rnd = new Random();
public SanctuaryMonitor()
{
this.DoubleBuffered = true; this.BackColor = Color.Black;
this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized;
cols = Screen.PrimaryScreen.Bounds.Width / cellSize; rows = Screen.PrimaryScreen.Bounds.Height / cellSize;
grid = new bool[cols, rows];
InitializeSystem();
ResetShips();
for (int i = 0; i < 400; i++) asteroids.Add(new PointF((float)(rnd.NextDouble() * Math.PI * 2), rnd.Next(290, 390)));
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) grid[x, y] = rnd.Next(100) < 12;
timer = new System.Windows.Forms.Timer { Interval = 30 };
timer.Tick += (s, e) => { UpdateLife(); UpdatePhysics(); Invalidate(); };
timer.Start();
}
private void InitializeSystem()
{
planets.Add(new Planet("SUN", 0, 0, 65, Color.Gold));
planets.Add(new Planet("MERCURY", 85, 0.012f, 5, Color.Silver));
planets.Add(new Planet("VENUS", 130, 0.008f, 9, Color.SandyBrown));
var earth = new Planet("EARTH", 185, 0.005f, 10, Color.RoyalBlue);
earth.Moons.Add(new Moon("LUNA", 25, 0.04f, 4)); planets.Add(earth);
var mars = new Planet("MARS", 260, 0.003f, 8, Color.OrangeRed);
mars.Moons.Add(new Moon("PHOBOS", 12, 0.07f, 2)); planets.Add(mars);
var jup = new Planet("JUPITER", 440, 0.0015f, 32, Color.Peru);
jup.Moons.Add(new Moon("EUROPA", 38, 0.10f, 5)); planets.Add(jup);
planets.Add(new Planet("SATURN", 580, 0.001f, 26, Color.Khaki));
planets.Add(new Planet("PLUTO", 880, 0.0004f, 4, Color.Thistle));
}
private void ResetShips()
{
atlasPos = new PointF(-1300, 700); atlasVel = new PointF(0.15f, -0.01f);
fleet.Add(new Ship("SWIFT", new PointF(100, 100), Color.DeepSkyBlue));
fleet.Add(new Ship("MUSK", new PointF(250, 250), Color.OrangeRed));
fleet.Add(new Ship("ENLIL", new PointF(Width - 100, 100), Color.MediumPurple));
fleet.Add(new Ship("ANU", new PointF(100, Height - 100), Color.Gold));
fleet.Add(new Ship("ISHTAR", new PointF(Width - 100, Height - 100), Color.LimeGreen));
}
private void UpdateLife()
{
bool[,] next = new bool[cols, rows];
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++)
{
int n = 0;
for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++)
{
if (i == 0 && j == 0) continue;
if (grid[(x + i + cols) % cols, (y + j + rows) % rows]) n++;
}
if (grid[x, y]) next[x, y] = (n == 2 || n == 3); else next[x, y] = (n == 3);
}
grid = next;
}
private void UpdatePhysics()
{
globalTicks++; timeStep += 1.0f; weaponTimer = (weaponTimer + 1) % 90;
float cx = Width / 2, cy = Height / 2;
// 1. 3I SLOW SWEEP
float dxS = cx - atlasPos.X, dyS = cy - atlasPos.Y;
float distS = (float)Math.Sqrt(dxS * dxS + dyS * dyS);
if (!sunDestroyed)
{
float g = Math.Min(45000.0f / (distS * distS + 900), 0.18f);
atlasVel.X += (dxS / distS) * g; atlasVel.Y += (dyS / distS) * g;
}
else { atlasVel.X += 0.01f; atlasVel.Y -= 0.01f; }
atlasPos.X += atlasVel.X; atlasPos.Y += atlasVel.Y;
// 2. CELESTIALS
foreach (var p in planets)
{
if (p.Name.Contains("SUN") || p.Name.Contains("STAR")) { p.X = cx; p.Y = cy; continue; }
p.X = cx + (float)Math.Cos(timeStep * p.Speed) * p.Radius;
p.Y = cy + (float)Math.Sin(timeStep * p.Speed) * p.Radius;
foreach (var m in p.Moons)
{
m.X = p.X + (float)Math.Cos(timeStep * m.Speed) * m.Radius;
m.Y = p.Y + (float)Math.Sin(timeStep * m.Speed) * m.Radius;
}
}
// 3. COMBAT & MISSIONS
if (globalTicks > 1200 && !enkiActive)
{
Ship sShip = fleet.Find(s => s.Name == "SWIFT");
Planet ven = planets.Find(p => p.Name == "VENUS"), ear = planets.Find(p => p.Name == "EARTH");
PointF sTarget = new PointF(0, 0);
switch (missionState)
{
case 0:
sTarget = new PointF(ear.Moons[0].X, ear.Moons[0].Y); tractorActive = true;
if (Dist(sShip.Pos, sTarget) < 15) { ear.Moons.Clear(); ven.Moons.Add(new Moon("LUNA", 30, 0.08f, 4)); missionState = 1; }
break;
case 1:
sTarget = new PointF(ven.X, ven.Y); tractorActive = true;
if (Dist(sShip.Pos, sTarget) < 15) { ven.Radius = 55; ven.Speed = 0.04f; missionState = 2; targetIndex = 0; }
break;
case 2:
int[] pIdx = { 3, 1, 4, 6, 7 };
if (targetIndex < pIdx.Length)
{
var p = planets[pIdx[targetIndex]]; sTarget = new PointF(p.X, p.Y); laserActive = (weaponTimer < 30);
if (Dist(sShip.Pos, sTarget) < 15) { p.IsDestroyed = true; TriggerExplosion(p.X, p.Y, p.Color); targetIndex++; }
}
else missionState = 3; break;
case 3:
sTarget = new PointF(planets.Find(p => p.Name == "JUPITER").X, planets.Find(p => p.Name == "JUPITER").Y); laserActive = false; tractorActive = false;
if (Dist(sShip.Pos, sTarget) < 15) { enkiActive = true; enkiPos = new PointF(Width + 300, cy); }
break;
}
for (int i = 0; i < fleet.Count; i++)
{
var s = fleet[i]; var next = fleet[(i + 1) % fleet.Count];
PointF t = (s.Name == "SWIFT") ? sTarget : (rebirthTriggered ? new PointF(planets[1].X, planets[1].Y) : next.Pos);
float d = Dist(s.Pos, t);
if (d > (s.Name == "SWIFT" ? 2 : 120))
{
float ang = (float)Math.Atan2(t.Y - s.Pos.Y, t.X - s.Pos.X);
s.Angle = ang; s.Pos.X += (float)Math.Cos(ang) * 3.5f; s.Pos.Y += (float)Math.Sin(ang) * 3.5f;
}
s.IsFiring = (weaponTimer < 30 && d < 350 && !rebirthTriggered && s.Name != "SWIFT");
}
}
if (enkiActive)
{
enkiSize = Math.Min(enkiSize + 2, 220); enkiPos.X -= 3.5f;
if (!sunDestroyed && Dist(enkiPos, new PointF(cx, cy)) < 180) { sunDestroyed = true; rebirthTriggered = true; CreateNeoSystem(); }
}
foreach (var d in debris) { float dx = cx - d.X, dy = cy - d.Y, dist = (float)Math.Sqrt(dx * dx + dy * dy); d.VX += (dx / dist) * (7000f / (dist * dist + 500)); d.VY += (dy / dist) * (7000f / (dist * dist + 500)); d.X += d.VX; d.Y += d.VY; d.Life--; }
debris.RemoveAll(d => d.Life <= 0);
}
private void CreateNeoSystem() { planets.Clear(); debris.Clear(); asteroids.Clear(); planets.Add(new Planet("NEW STAR", 0, 0, 70, Color.DeepSkyBlue)); for (int i = 0; i < 4; i++) { var p = new Planet("NEO-" + (i + 1), 160 + (i * 100), 0.005f, 12, Color.LimeGreen); p.Moons.Add(new Moon("S-" + (i + 1), 24, 0.05f, 4)); planets.Add(p); } }
private float Dist(PointF a, PointF b) { return (float)Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2)); }
private void TriggerExplosion(float x, float y, Color c) { for (int j = 0; j < 60; j++) debris.Add(new Particle(x, y, (float)(rnd.NextDouble() - 0.5) * 18, (float)(rnd.NextDouble() - 0.5) * 18, c)); }
protected override void OnPaint(PaintEventArgs e)
{
int curIdx = (int)((globalTicks / 15) % wowChars.Length); Color activePulse = pulseColors[curIdx];
int cx = Width / 2, cy = Height / 2;
using (SolidBrush b = new SolidBrush(Color.FromArgb(70, activePulse)))
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) if (grid[x, y]) e.Graphics.FillRectangle(b, x * cellSize, y * cellSize, cellSize - 1, cellSize - 1);
if (!sunDestroyed) { e.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(120, Color.OrangeRed)), cx - 40, cy - 40, 80, 80); e.Graphics.FillEllipse(Brushes.Gold, cx - 30, cy - 30, 60, 60); }
foreach (var ast in asteroids) if (!sunDestroyed) e.Graphics.FillRectangle(Brushes.DimGray, cx + (float)Math.Cos(ast.X + timeStep * 0.0005f) * ast.Y, cy + (float)Math.Sin(ast.X + timeStep * 0.0005f) * ast.Y, 1, 1);
foreach (var p in planets)
{
if (p.IsDestroyed || (p.Name == "SUN" && sunDestroyed)) continue;
e.Graphics.FillEllipse(new SolidBrush(p.Color), p.X - p.Size / 2, p.Y - p.Size / 2, p.Size, p.Size);
e.Graphics.DrawString(p.Name, new Font("Consolas", 8, FontStyle.Bold), new SolidBrush(p.Color), p.X + 10, p.Y - 10);
foreach (var m in p.Moons) { e.Graphics.FillEllipse(Brushes.Silver, m.X - 2, m.Y - 2, 4, 4); e.Graphics.DrawString(m.Name, new Font("Consolas", 6), Brushes.Silver, m.X + 5, m.Y - 5); }
}
foreach (var s in fleet)
{
GraphicsState st = e.Graphics.Save(); e.Graphics.TranslateTransform(s.Pos.X, s.Pos.Y); e.Graphics.RotateTransform(s.Angle * 57.29f);
e.Graphics.FillPolygon(new SolidBrush(s.ShipColor), new PointF[] { new PointF(14, 0), new PointF(-10, -10), new PointF(-10, 10) });
e.Graphics.DrawString(s.Name, new Font("Consolas", 8, FontStyle.Bold), new SolidBrush(s.ShipColor), 10, -15); e.Graphics.Restore(st);
if (s.IsFiring) e.Graphics.DrawLine(new Pen(s.ShipColor, 2), s.Pos.X, s.Pos.Y, s.Pos.X + (float)Math.Cos(s.Angle) * 300, s.Pos.Y + (float)Math.Sin(s.Angle) * 300);
}
if (enkiActive)
{
GraphicsState enS = e.Graphics.Save(); e.Graphics.TranslateTransform(enkiPos.X, enkiPos.Y);
PointF[] hull = { new PointF(-enkiSize / 2, 0), new PointF(enkiSize / 4, -enkiSize / 4), new PointF(enkiSize / 2, -enkiSize / 8), new PointF(enkiSize / 2, enkiSize / 8), new PointF(enkiSize / 4, enkiSize / 4) };
e.Graphics.FillPolygon(Brushes.DarkSlateGray, hull); e.Graphics.DrawString("ENKI", new Font("Consolas", 12, FontStyle.Bold), Brushes.Red, -20, -50); e.Graphics.Restore(enS);
}
GraphicsState astState = e.Graphics.Save(); e.Graphics.TranslateTransform(atlasPos.X, atlasPos.Y); e.Graphics.RotateTransform((float)Math.Atan2(atlasVel.Y, atlasVel.X) * 57.29f);
e.Graphics.FillRectangle(Brushes.White, -18, -4, 36, 8); e.Graphics.DrawString("3I/ATLAS", new Font("Consolas", 8, FontStyle.Bold), Brushes.White, 15, -15); e.Graphics.Restore(astState);
Rectangle hud = new Rectangle(10, Height - 460, 540, 450); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(230, 0, 0, 0)), hud);
using (Font f = new Font("Consolas", 8))
{
e.Graphics.DrawString($"WOW! SIG: [ {wowChars[curIdx]} ]", new Font("Consolas", 10, FontStyle.Bold), new SolidBrush(activePulse), 20, Height - 450);
int y = Height - 420;
foreach (var s in fleet) { e.Graphics.DrawString($"{s.Name}: {s.Pos.X:F0}, {s.Pos.Y:F0}", f, new SolidBrush(s.ShipColor), 20, y); y += 15; }
foreach (var p in planets) { if (planets.IndexOf(p) < 4) { e.Graphics.DrawString($"{p.Name}: {p.X:F0}, {p.Y:F0}", f, new SolidBrush(p.Color), 20, y); y += 15; foreach (var m in p.Moons) { e.Graphics.DrawString($" > {m.Name}: {m.X:F0}, {m.Y:F0}", f, Brushes.Silver, 20, y); y += 15; } } }
e.Graphics.DrawString($"SWIFT MISSION: {Math.Max(0, 40 - (int)(globalTicks / 30))}s", f, Brushes.Lime, 20, Height - 50);
}
}
}
}