plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
f28e296
— Peter John
2026-11-02T17:32:06+05:30
Orb Run: additive orb glow; scene demo: minimap rendered into a texture
- plum-examples/game.plum +4 -1
- plum-examples/scene.plum +34 -3
plum-examples/game.plum
CHANGED
|
@@ -259,7 +259,10 @@ export fun draw(w: World) =
|
|
|
259
259
|
drawStars(w)
|
|
260
260
|
for i := range w.orbs.length()
|
|
261
261
|
orb := w.orbs.at(i)
|
|
262
|
+
blendMode(Blend.Add)
|
|
262
|
-
drawCircle(orb.x, orb.y,
|
|
263
|
+
drawCircle(orb.x, orb.y, 26.0, Color(r: 0.35, g: 0.22, b: 0.0, a: 0.5))
|
|
264
|
+
drawCircle(orb.x, orb.y, 17.0, Color(r: 0.6, g: 0.4, b: 0.05, a: 0.5))
|
|
265
|
+
blendMode(Blend.Normal)
|
|
263
266
|
sprite(w, 1, frameOf(w.clock + Float(i) * 0.1, 4, 8.0), orb.x, orb.y, 0.0, Color.White)
|
|
264
267
|
for i := range w.mines.length()
|
|
265
268
|
mine := w.mines.at(i)
|
plum-examples/scene.plum
CHANGED
|
@@ -25,6 +25,9 @@ primitive Layout =
|
|
|
25
25
|
CenterX = 400.0
|
|
26
26
|
CenterY = 300.0
|
|
27
27
|
Cell = 16.0
|
|
28
|
+
MapW = 160
|
|
29
|
+
MapH = 120
|
|
30
|
+
MapScale = 0.2
|
|
28
31
|
Planets = 4
|
|
29
32
|
|
|
30
33
|
# Everything `update` and `draw` need. `bodies` and `names` are parallel (every
|
|
@@ -38,7 +41,8 @@ record Sky(
|
|
|
38
41
|
label: Node,
|
|
39
42
|
selected: Int,
|
|
40
43
|
clock: Float,
|
|
41
|
-
paused: Bool
|
|
44
|
+
paused: Bool,
|
|
45
|
+
map: Int)
|
|
42
46
|
|
|
43
47
|
# Gives the node a behaviour that turns it `speed` radians per second.
|
|
44
48
|
fun spun(n: Node, speed: Float) -> Node =
|
|
@@ -72,7 +76,7 @@ fun newSky(sheet: Int) -> Sky =
|
|
|
72
76
|
label := Node.text("Click a planet", 24.0, Color.White).at(16.0, 12.0)
|
|
73
77
|
sky := Sky(
|
|
74
78
|
stage: stage, bodies: List[Node](), halos: List[Node](), names: List[Str](),
|
|
75
|
-
sun: sun, label: label, selected: -1, clock: 0.0, paused: false)
|
|
79
|
+
sun: sun, label: label, selected: -1, clock: 0.0, paused: false, map: -1)
|
|
76
80
|
# faint orbit rings, added first so every body draws (and is hit) above them
|
|
77
81
|
for i := range Layout.Planets
|
|
78
82
|
r := 90.0 + Float(i) * 60.0
|
|
@@ -143,7 +147,9 @@ fun tick(sky: Sky, dt: Float) =
|
|
|
143
147
|
# --- host glue ---
|
|
144
148
|
|
|
145
149
|
export fun init() -> Sky =
|
|
146
|
-
newSky(textureLoad("sprites.png"))
|
|
150
|
+
sky := newSky(textureLoad("sprites.png"))
|
|
151
|
+
sky.map = textureCreate(Layout.MapW, Layout.MapH)
|
|
152
|
+
sky
|
|
147
153
|
|
|
148
154
|
export fun update(sky: Sky, dt: Float) =
|
|
149
155
|
if isKeyPressed(Key.Space)
|
|
@@ -155,9 +161,34 @@ export fun update(sky: Sky, dt: Float) =
|
|
|
155
161
|
p := sky.stage.screenToStage(m.x, m.y)
|
|
156
162
|
clickAt(sky, p.x, p.y)
|
|
157
163
|
|
|
164
|
+
# Redraws the minimap texture (every body as a dot, the selected one highlighted)
|
|
165
|
+
# and shows it in the bottom-right corner of the screen.
|
|
166
|
+
fun drawMinimap(sky: Sky) =
|
|
167
|
+
if sky.map < 0
|
|
168
|
+
return
|
|
169
|
+
k := Layout.MapScale
|
|
170
|
+
w := Float(Layout.MapW)
|
|
171
|
+
h := Float(Layout.MapH)
|
|
172
|
+
renderTarget(sky.map)
|
|
173
|
+
clear(Color(r: 0.05, g: 0.1, b: 0.2, a: 0.85))
|
|
174
|
+
drawRect(0.0, 0.0, w, 1.0, Color.White)
|
|
175
|
+
drawRect(0.0, h - 1.0, w, 1.0, Color.White)
|
|
176
|
+
drawRect(0.0, 0.0, 1.0, h, Color.White)
|
|
177
|
+
drawRect(w - 1.0, 0.0, 1.0, h, Color.White)
|
|
178
|
+
drawCircle(Layout.CenterX * k, Layout.CenterY * k, 5.0, Color.Yellow)
|
|
179
|
+
for i := range sky.bodies.length()
|
|
180
|
+
c := centerOf(sky, i)
|
|
181
|
+
dot := Color(r: 0.6, g: 0.8, b: 1.0, a: 1.0)
|
|
182
|
+
if i == sky.selected
|
|
183
|
+
dot = Color.Yellow
|
|
184
|
+
drawCircle(c.x * k, c.y * k, 2.0, dot)
|
|
185
|
+
renderTarget(-1)
|
|
186
|
+
drawTexture(sky.map, screenWidth() - w - 8.0, screenHeight() - h - 8.0, Color.White)
|
|
187
|
+
|
|
158
188
|
export fun draw(sky: Sky) =
|
|
159
189
|
clear(Color.Black)
|
|
160
190
|
sky.stage.draw()
|
|
191
|
+
drawMinimap(sky)
|
|
161
192
|
|
|
162
193
|
# --- tests ---
|
|
163
194
|
|