plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
da83c16
— Peter John
2026-11-02T13:57:57+05:30
fix(kam): size the minimap colours up front; Array.push returns a new array
- plum-game/kam/Main.plum +16 -5
plum-game/kam/Main.plum
CHANGED
|
@@ -101,7 +101,11 @@ record Viewer(
|
|
|
101
101
|
terrain: Grid[Int],
|
|
102
102
|
rotation: Grid[Int],
|
|
103
103
|
objects: Grid[Int],
|
|
104
|
-
mini:
|
|
104
|
+
mini: Grid[Color])
|
|
105
|
+
|
|
106
|
+
# The minimap's colour storage: one cell per tile, sized up front (Array.push returns a new array).
|
|
107
|
+
fun miniColors(w: Int, h: Int) -> Grid[Color] =
|
|
108
|
+
Grid.filled(w, h, Color.Black)
|
|
105
109
|
|
|
106
110
|
export fun init() -> Viewer =
|
|
107
111
|
tileset := atlasLoad("Tileset")
|
|
@@ -112,20 +116,20 @@ export fun init() -> Viewer =
|
|
|
112
116
|
return Viewer(
|
|
113
117
|
cam: cam, ok: false, mapW: 1, mapH: 1, tileset: tileset, trees: trees,
|
|
114
118
|
terrain: Grid.filled(1, 1, 0), rotation: Grid.filled(1, 1, 0),
|
|
115
|
-
objects: Grid.filled(1, 1, 0), mini:
|
|
119
|
+
objects: Grid.filled(1, 1, 0), mini: miniColors(1, 1))
|
|
116
120
|
w := mapWidth(m)
|
|
117
121
|
h := mapHeight(m)
|
|
118
122
|
terrain := Grid.filled(w, h, 0)
|
|
119
123
|
rotation := Grid.filled(w, h, 0)
|
|
120
124
|
objects := Grid.filled(w, h, 0)
|
|
121
|
-
mini :=
|
|
125
|
+
mini := miniColors(w, h)
|
|
122
126
|
for y := range h
|
|
123
127
|
for x := range w
|
|
124
128
|
t := mapTerrain(m, x, y)
|
|
125
129
|
terrain.set(x, y, t)
|
|
126
130
|
rotation.set(x, y, mapRotation(m, x, y))
|
|
127
131
|
objects.set(x, y, mapObject(m, x, y))
|
|
128
|
-
mini.
|
|
132
|
+
mini.set(x, y, spriteColor(tileset, t + 1))
|
|
129
133
|
Viewer(
|
|
130
134
|
cam: cam, ok: true, mapW: w, mapH: h, tileset: tileset, trees: trees,
|
|
131
135
|
terrain: terrain, rotation: rotation, objects: objects, mini: mini)
|
|
@@ -191,7 +195,7 @@ fun drawMinimap(v: Viewer, sw: Float, sh: Float) =
|
|
|
191
195
|
for y := range v.mapH
|
|
192
196
|
for x := range v.mapW
|
|
193
197
|
drawRect(m.x + Float(x) * m.cell, m.y + Float(y) * m.cell, m.cell, m.cell,
|
|
194
|
-
v.mini.get(
|
|
198
|
+
v.mini.get(x, y))
|
|
195
199
|
vx := m.x + v.cam.x * m.cell / View.TileSize
|
|
196
200
|
vy := m.y + v.cam.y * m.cell / View.TileSize
|
|
197
201
|
vw := sw / v.cam.scale * m.cell / View.TileSize
|
|
@@ -256,3 +260,10 @@ test "a minimap click centres the camera"
|
|
|
256
260
|
c := Camera(x: 0.0, y: 0.0, scale: 2.0)
|
|
257
261
|
c.centerOn(w, 800.0, 600.0)
|
|
258
262
|
assert c.screenToWorld(Vec2(x: 400.0, y: 300.0)) == w
|
|
263
|
+
|
|
264
|
+
test "minimap colours are sized w*h up front"
|
|
265
|
+
g := miniColors(4, 3)
|
|
266
|
+
assert g.w * g.h == 12
|
|
267
|
+
g.set(3, 2, Color.White)
|
|
268
|
+
assert g.get(3, 2) == Color.White
|
|
269
|
+
assert g.get(0, 0) == Color.Black
|