-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgalaxyMap.ms
107 lines (89 loc) · 3.01 KB
/
galaxyMap.ms
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
import "importUtil"
ensureImport "sounds"
left = 0
bottom = 0
width = 550
height = 600
mapDistanceFactor = 7.5 // divide map distances by this to get light years!
planetColors = ["#51A1FB", "#FF8888", "#37C824"]
display(7).mode = displayMode.pixel; starsGfx = display(7)
display(6).mode = displayMode.pixel; underlayGfx = display(6)
display(5).mode = displayMode.pixel; mapGfx = display(5)
drawPlanet = function(p, hovered=false)
x = p.position.x; y = p.position.y
c = planetColors[p.status]
if hovered then c = color.lerp(c, color.white)
mapGfx.fillEllipse x-5, y-5, 11, 11, c
if p != targetPlanet then mapGfx.drawRect x-7, y-7, 15, 15, color.black
if p != fleet.planet then mapGfx.drawEllipse x-7, y-7, 15, 15, color.black
if p == targetPlanet then mapGfx.drawRect x-7, y-7, 15, 15, c
if p == fleet.planet then mapGfx.drawEllipse x-7, y-7, 15, 15, c
oldGfx = gfx; globals.gfx = mapGfx
font.printCentered p.name, x, y - 15, 1, c
globals.gfx = oldGfx
end function
drawUnderlay = function
underlayGfx.fillRect left, bottom, width, height, color.clear
for p in planets
for sat in p.incomingSats
t = (empire.year - sat.launchYear) / (sat.arriveYear - sat.launchYear)
p0 = mathUtil.lerp2d(sat.origin.position, p.position, t)
underlayGfx.line p0[0], p0[1], p.position.x, p.position.y, "#CCCCCC"
end for
end for
end function
animateWarp = function(fromPlanet, toPlanet, frameCallback)
duration = mathUtil.max(0.5, fromPlanet.distanceTo(toPlanet) / 20)
fromPos = fromPlanet.position
toPos = toPlanet.position
sounds.warp(duration).play
// Animate a line where the head reaches the target half a second
// or so early, and the tail leaves the source by the same delay.
delay = mathUtil.min(0.5, duration/2)
startTime = time
elapsed = 0
while elapsed < duration
headT = mathUtil.min(1, (time - startTime) / (duration - delay))
tailT = mathUtil.max(0, (time - delay - startTime) / (duration - delay))
headPos = mathUtil.lerp2d(fromPos, toPos, headT)
tailPos = mathUtil.lerp2d(fromPos, toPos, tailT)
underlayGfx.line headPos[0], headPos[1], tailPos[0], tailPos[1], "#FFFFCC"
if @frameCallback != null then frameCallback elapsed, duration
yield
underlayGfx.line headPos[0], headPos[1], tailPos[0], tailPos[1], color.clear
elapsed = time - startTime
end while
end function
drawStars = function
starsGfx.fillRect left, bottom, width, height, color.black
for i in range(500)
c = color.rgb(200+55*rnd, 200+55*rnd, 200+55*rnd)
starsGfx.setPixel left + width*rnd, bottom + height*rnd, c
end for
end function
drawPlanets = function
mapGfx.fillRect left, bottom, width, height, color.clear
for p in planets
drawPlanet p
end for
end function
drawAll = function
drawStars
drawPlanets
drawUnderlay
end function
planetUnderMouse = function
pos = {}
pos.x = mouse.x - left
pos.y = mouse.y - bottom
result = null
bestD = 0
for p in planets
d = mathUtil.distance(pos, p.position)
if d < 20 and (result == null or d < bestD) then
result = p
bestD = d
end if
end for
return result
end function