omnipython-apps 0.1.4.dev8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. apps/__init__.py +5 -0
  2. apps/about/__init__.py +257 -0
  3. apps/about/app.json +1 -0
  4. apps/about/credits.py +12 -0
  5. apps/about/facts.py +398 -0
  6. apps/about/fonts/OFL.txt +93 -0
  7. apps/about/fonts/latin1_14.bin +0 -0
  8. apps/about/fonts/latin1_16.bin +0 -0
  9. apps/about/fonts/latin1_24.bin +0 -0
  10. apps/about/fonts/latin1_32.bin +0 -0
  11. apps/about/fonts/latin1_40.bin +0 -0
  12. apps/backline/__init__.py +58 -0
  13. apps/backline/app.json +1 -0
  14. apps/backline/app.py +475 -0
  15. apps/backline/art.py +717 -0
  16. apps/backline/ask.py +781 -0
  17. apps/backline/box.py +502 -0
  18. apps/backline/cast.py +137 -0
  19. apps/backline/desk/__init__.py +329 -0
  20. apps/backline/desk/editor.py +331 -0
  21. apps/backline/desk/grid.py +154 -0
  22. apps/backline/desk/look.py +169 -0
  23. apps/backline/desk/pedals.py +102 -0
  24. apps/backline/desk/perform.py +157 -0
  25. apps/backline/desk/prompt.py +210 -0
  26. apps/backline/desk/strip.py +159 -0
  27. apps/backline/desk_main.py +226 -0
  28. apps/backline/engine.py +622 -0
  29. apps/backline/floor.py +509 -0
  30. apps/backline/footswitch.py +119 -0
  31. apps/backline/glyphs.py +82 -0
  32. apps/backline/kits.py +428 -0
  33. apps/backline/midipedal.py +362 -0
  34. apps/backline/page_data.py +413 -0
  35. apps/backline/parts.py +145 -0
  36. apps/backline/pedal.py +107 -0
  37. apps/backline/remote.py +134 -0
  38. apps/backline/songs/ballad_68.json +1 -0
  39. apps/backline/songs/bossa.json +1 -0
  40. apps/backline/songs/country_train.json +1 -0
  41. apps/backline/songs/funk.json +1 -0
  42. apps/backline/songs/metal.json +1 -0
  43. apps/backline/songs/pop.json +1 -0
  44. apps/backline/songs/rock.json +1 -0
  45. apps/backline/songs/shuffle.json +1 -0
  46. apps/battery/__init__.py +101 -0
  47. apps/battery/app.json +1 -0
  48. apps/bit_world/act_deck.py +683 -0
  49. apps/bit_world/act_game.py +762 -0
  50. apps/bit_world/act_pet.py +1032 -0
  51. apps/bit_world/app.json +1 -0
  52. apps/bit_world/bit_output.py +45 -0
  53. apps/bit_world/bit_palette.py +503 -0
  54. apps/bit_world/bit_sound.py +431 -0
  55. apps/bit_world/bit_sprites.py +632 -0
  56. apps/bit_world/bit_world.py +534 -0
  57. apps/btreceiver/__init__.py +690 -0
  58. apps/btreceiver/app.json +1 -0
  59. apps/btreceiver/chime.py +155 -0
  60. apps/btreceiver/demo.py +529 -0
  61. apps/btreceiver/screen.py +633 -0
  62. apps/camera/__init__.py +316 -0
  63. apps/camera/app.json +1 -0
  64. apps/card/__init__.py +113 -0
  65. apps/card/app.json +1 -0
  66. apps/cast/__init__.py +631 -0
  67. apps/cast/app.json +1 -0
  68. apps/cast/receivers.py +193 -0
  69. apps/chess/__init__.py +18 -0
  70. apps/chess/app.json +1 -0
  71. apps/chess/app.py +922 -0
  72. apps/chess/art.py +323 -0
  73. apps/chess/ble.py +411 -0
  74. apps/chess/engine.py +925 -0
  75. apps/chess/game.py +327 -0
  76. apps/chess/net.py +261 -0
  77. apps/clock/__init__.py +38 -0
  78. apps/clock/app.json +1 -0
  79. apps/detect/__init__.py +214 -0
  80. apps/detect/app.json +1 -0
  81. apps/fmsynth/__init__.py +41 -0
  82. apps/fmsynth/algorithms.py +61 -0
  83. apps/fmsynth/app.json +1 -0
  84. apps/fmsynth/app.py +355 -0
  85. apps/fmsynth/editor.py +206 -0
  86. apps/fmsynth/engine.py +257 -0
  87. apps/fmsynth/meters.py +262 -0
  88. apps/fmsynth/midi.py +375 -0
  89. apps/fmsynth/panel_view.py +1071 -0
  90. apps/fmsynth/patches/fmsynth-01.syx +0 -0
  91. apps/fmsynth/settings.py +138 -0
  92. apps/fmsynth/voice.py +398 -0
  93. apps/gamepad/__init__.py +685 -0
  94. apps/gamepad/app.json +1 -0
  95. apps/gamepad/pad.py +94 -0
  96. apps/gamepad/watch.py +352 -0
  97. apps/hidden/__init__.py +72 -0
  98. apps/hidden/app.json +1 -0
  99. apps/home/__init__.py +483 -0
  100. apps/home/app.json +1 -0
  101. apps/home/main.py +36 -0
  102. apps/homeassistant/__init__.py +213 -0
  103. apps/homeassistant/api.py +104 -0
  104. apps/homeassistant/app.json +1 -0
  105. apps/huey/__init__.py +287 -0
  106. apps/huey/acting.py +184 -0
  107. apps/huey/actor.py +194 -0
  108. apps/huey/app.json +1 -0
  109. apps/huey/client.py +125 -0
  110. apps/huey/servers.py +121 -0
  111. apps/huey/settings.example.json +8 -0
  112. apps/huey/settings.py +97 -0
  113. apps/huey/turn.py +504 -0
  114. apps/huey/voice.py +217 -0
  115. apps/info/__init__.py +810 -0
  116. apps/info/app.json +1 -0
  117. apps/lora/__init__.py +62 -0
  118. apps/lora/app.json +1 -0
  119. apps/manifest.py +71 -0
  120. apps/medialink_baby_monitor/__init__.py +222 -0
  121. apps/medialink_baby_monitor/app.json +1 -0
  122. apps/medialink_doorbell/__init__.py +251 -0
  123. apps/medialink_doorbell/app.json +1 -0
  124. apps/medialink_hands_free/__init__.py +217 -0
  125. apps/medialink_hands_free/app.json +1 -0
  126. apps/medialink_surveillance_camera/__init__.py +258 -0
  127. apps/medialink_surveillance_camera/app.json +1 -0
  128. apps/medialink_video_doorbell/__init__.py +289 -0
  129. apps/medialink_video_doorbell/app.json +1 -0
  130. apps/medialink_videophone/__init__.py +273 -0
  131. apps/medialink_videophone/app.json +1 -0
  132. apps/medialink_walkie_talkie/__init__.py +228 -0
  133. apps/medialink_walkie_talkie/app.json +1 -0
  134. apps/midicontroller/__init__.py +774 -0
  135. apps/midicontroller/app.json +1 -0
  136. apps/midicontroller/links.py +421 -0
  137. apps/midicontroller/surface.py +343 -0
  138. apps/midiengine/__init__.py +977 -0
  139. apps/midiengine/app.json +1 -0
  140. apps/midiengine/banks.py +85 -0
  141. apps/midiengine/midiin.py +165 -0
  142. apps/midiengine/player.py +392 -0
  143. apps/midiengine/umidiparser.py +1413 -0
  144. apps/mp3/__init__.py +240 -0
  145. apps/mp3/app.json +1 -0
  146. apps/perch/__init__.py +119 -0
  147. apps/perch/app.json +1 -0
  148. apps/perch/huey.py +481 -0
  149. apps/perch/huey_props.py +386 -0
  150. apps/perch/huey_shift.py +42 -0
  151. apps/perch/huey_views.py +296 -0
  152. apps/perch/scene_bench.py +680 -0
  153. apps/perch/scene_coast.py +479 -0
  154. apps/perch/scene_desk.py +492 -0
  155. apps/perch/stage.py +1274 -0
  156. apps/perch/vec.py +366 -0
  157. apps/repl/__init__.py +325 -0
  158. apps/repl/app.json +1 -0
  159. apps/roku/__init__.py +156 -0
  160. apps/roku/app.json +1 -0
  161. apps/rokucam/__init__.py +362 -0
  162. apps/rokucam/app.json +1 -0
  163. apps/security/__init__.py +261 -0
  164. apps/security/app.json +1 -0
  165. apps/settings/__init__.py +221 -0
  166. apps/settings/app.json +1 -0
  167. apps/shell/__init__.py +33 -0
  168. apps/shell/app.json +1 -0
  169. apps/spotify/__init__.py +669 -0
  170. apps/spotify/app.json +1 -0
  171. apps/spotify/screen.py +82 -0
  172. apps/steps/__init__.py +58 -0
  173. apps/steps/app.json +1 -0
  174. apps/stompbox/__init__.py +31 -0
  175. apps/stompbox/app.json +1 -0
  176. apps/stompbox/app.py +668 -0
  177. apps/stompbox/boards.json +20 -0
  178. apps/stompbox/effects.py +241 -0
  179. apps/stompbox/engine.py +340 -0
  180. apps/stompbox/footswitch.py +331 -0
  181. apps/stompbox/inputs.py +449 -0
  182. apps/stompbox/meter.py +72 -0
  183. apps/stompbox/outputs.py +135 -0
  184. apps/stompbox/pedals.txt +45 -0
  185. apps/stompbox/presets.py +106 -0
  186. apps/stompbox/styles.py +135 -0
  187. apps/stompbox/ui.py +817 -0
  188. apps/stompbox/wavfile.py +73 -0
  189. apps/synthstation/__init__.py +20 -0
  190. apps/synthstation/app.json +1 -0
  191. apps/synthstation/audio.py +397 -0
  192. apps/synthstation/catalog.py +50 -0
  193. apps/synthstation/meters.py +136 -0
  194. apps/synthstation/midi.py +380 -0
  195. apps/synthstation/pads.py +177 -0
  196. apps/synthstation/parts.py +128 -0
  197. apps/synthstation/station.py +1069 -0
  198. apps/system/__init__.py +11 -0
  199. apps/system/app.json +1 -0
  200. apps/touchcal/__init__.py +324 -0
  201. apps/touchcal/app.json +1 -0
  202. apps/touchcal/fit.py +262 -0
  203. apps/wake/__init__.py +268 -0
  204. apps/wake/app.json +1 -0
  205. apps/wake/feed.py +155 -0
  206. apps/watch/__init__.py +355 -0
  207. apps/watch/app.json +1 -0
  208. apps/watch/faces.py +35 -0
  209. apps/watch/wheel.py +157 -0
  210. apps/weather/__init__.py +278 -0
  211. apps/weather/app.json +1 -0
  212. apps/weather/icons.py +172 -0
  213. apps/weather/sizing.py +71 -0
  214. apps/weather/zippad.py +172 -0
  215. omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
  216. omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
  217. omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
  218. omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,762 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Act 2: Bioluminescent Sky Ruins (Parallax 2D Game Engine Showcase).
6
+
7
+ Demonstrates a 4-layer parallax scrolling action-platformer built entirely with
8
+ pygraphics FrameBuffer blits and primitives, featuring jetpack physics,
9
+ animated crystal pickups, patrol drones, plasma bolts, particle bursts, floating
10
+ score popups, and a seamless attract-mode autopilot.
11
+
12
+ Needs: pygraphics, bit_palette, bit_sprites.
13
+ """
14
+
15
+ from array import array
16
+
17
+ from bit_palette import (
18
+ KEY,
19
+ ABYSS,
20
+ ABYSS_RGB,
21
+ AMBER,
22
+ AQUA_GLOW,
23
+ BRONZE,
24
+ CORAL,
25
+ CREAM,
26
+ CYAN,
27
+ DARK_MOSS,
28
+ DEEP_SLATE,
29
+ DEEP_TEAL,
30
+ EMERALD,
31
+ FOREST,
32
+ GOLD,
33
+ ICE_CYAN,
34
+ LIME_GLOW,
35
+ MAGENTA,
36
+ MIST,
37
+ MOSS,
38
+ NEON_PINK,
39
+ NIGHT,
40
+ NIGHT_RGB,
41
+ ORANGE,
42
+ SILVER,
43
+ SLATE,
44
+ STEEL,
45
+ SUN_YELLOW,
46
+ TEAL,
47
+ VOID,
48
+ VOID_RGB,
49
+ WHITE,
50
+ copy_frame,
51
+ draw_pixel_panel,
52
+ isin,
53
+ make_canvas,
54
+ make_fb,
55
+ paint_gradient,
56
+ restore_rects,
57
+ rng_int,
58
+ )
59
+
60
+ # Moving things keep their positions in fixed point, FX_ONE to a pixel, and timers count
61
+ # whole ms, so a frame does its arithmetic in small ints and boxes no floats.
62
+ FX = 12
63
+ FX_ONE = 1 << FX
64
+
65
+
66
+ # A value in pixels as a fixed-point int, rounded to nearest.
67
+ def _fx(v):
68
+ return int(v * FX_ONE + (0.5 if v >= 0 else -0.5))
69
+
70
+
71
+ # A fixed-point value as whole pixels, truncated toward zero like int().
72
+ def _px(v):
73
+ return v >> FX if v >= 0 else -((-v) >> FX)
74
+
75
+
76
+ # Text drawn once into its own frame, then blitted with the sprite key each frame. A
77
+ # label made chars wide can be redrawn in place with _relabel for any text that fits.
78
+ def _label(text, col, chars=0):
79
+ w = max(chars, len(text)) * 8
80
+ lbl = make_canvas(bytearray(w * 16), w, 8)
81
+ _relabel(lbl, text, col)
82
+ return lbl
83
+
84
+
85
+ def _relabel(lbl, text, col):
86
+ lbl.fill(KEY)
87
+ lbl.text(text, 0, 0, col)
88
+
89
+
90
+ # Popups and HUD numbers fit in this many characters.
91
+ LABEL_CHARS = 16
92
+ # Popup labels are reused in turn; one more than the popups on screen at once.
93
+ POPUP_LABELS = 7
94
+ # Particle lists are reused, and no more than this many are on screen.
95
+ MAX_PARTICLES = 36
96
+
97
+
98
+ # Parallax layer speeds as percentages of the scroll speed: islands, citadel, ruins, floor.
99
+ LAYER_RATES = (10, 22, 50, 100)
100
+
101
+ # A burst's upward drift, 0.8 pixels a frame.
102
+ _BURST_LIFT = _fx(0.8)
103
+
104
+
105
+ class SkyRuinsAct:
106
+ """Render and simulate Act 2: Bioluminescent Sky Ruins 2D Action Game."""
107
+
108
+ # *background* is a (bytearray, FrameBuffer) pair from make_fb at the panel's size to
109
+ # draw the static scene into; left as None, the act makes its own.
110
+ def __init__(self, layout, sprites, sound, background=None):
111
+ self.lay = layout
112
+ self.sprites = sprites
113
+ self.sound = sound
114
+ self.phase = 0
115
+ # Scroll, bolt and popup speeds in fixed-point pixels a second.
116
+ self.scroll_speed = (95 if layout.compact else 135) << FX
117
+ self._bolt_speed = (220 if layout.compact else 290) << FX
118
+ self._popup_speed = 28 << FX
119
+ # Each parallax layer's offset into its repeat span, and how many spans it has passed.
120
+ if layout.compact:
121
+ spans = (220, 140, 110, 40)
122
+ else:
123
+ spans = (310, 190, 156, 56)
124
+ self._layer_span = array("i", [sp << FX for sp in spans])
125
+ self._layer_pos = array("i", [0] * 4)
126
+ self._layer_idx = array("i", [0] * 4)
127
+
128
+ w = layout.w
129
+ sy = layout.scene_y
130
+ sh = layout.scene_h
131
+ self.ground_y = sy + sh - (42 if layout.compact else 56)
132
+ self.hud_y = sy + 6
133
+ self.hud_h = 22 if layout.compact else 26
134
+
135
+ # Hero physics state.
136
+ # hero_y and hero_vy are fixed point; hero_vy and gravity are per frame.
137
+ self.hero_x = int(w * 0.20)
138
+ self.hero_y = (self.ground_y - sprites.bit_game_r.h) << FX
139
+ self.hero_vy = 0
140
+ self._gravity = _fx(0.46 if layout.compact else 0.56)
141
+ self._jump_vy = _fx(-7.6 if layout.compact else -9.4)
142
+ self._jet_kick = _fx(5.2 if layout.compact else 6.4)
143
+ self._jet_max = _fx(-8.2)
144
+ self._fire_range = _fx(w * 0.68)
145
+ self.on_ground = True
146
+ self.jet_cooldown = 0
147
+ self.fire_cooldown = 0
148
+
149
+ # Arcade score, crystal count, combo multiplier, and screen shake.
150
+ self.score = 1250
151
+ self.crystals_collected = 12
152
+ self.combo = 1
153
+ # The HUD's numbers and texts, formatted again only when the numbers change.
154
+ self._hud_texts = None
155
+ self._hud_labels = (
156
+ _label("", WHITE, LABEL_CHARS),
157
+ _label("", WHITE, LABEL_CHARS),
158
+ _label("", WHITE, LABEL_CHARS),
159
+ )
160
+ self._popup_labels = [_label("", WHITE, LABEL_CHARS) for _ in range(POPUP_LABELS)]
161
+ self._next_popup = 0
162
+ self._spare_particles = [[0, 0, 0, 0, 0, 0] for _ in range(MAX_PARTICLES + 1)]
163
+ self.combo_timer = 0
164
+ self.shake_timer = 0
165
+
166
+ # Touch/mouse virtual arcade button rectangles at bottom corners.
167
+ btn_w = 104 if layout.compact else 136
168
+ btn_h = 24 if layout.compact else 30
169
+ btn_y = sy + sh - btn_h - 6
170
+ self.btn_jump = (layout.pad, btn_y, btn_w, btn_h)
171
+ self.btn_fire = (w - layout.pad - btn_w, btn_y, btn_w, btn_h)
172
+ # The fixed HUD and button labels, and where the button labels sit, centred.
173
+ self._lbl_jet = _label("JET:RDY", LIME_GLOW)
174
+ j_txt = "JUMP" if layout.compact else "JUMP / JET"
175
+ f_txt = "FIRE" if layout.compact else "FIRE PLASMA"
176
+ self._lbl_jump = _label(j_txt, WHITE)
177
+ self._lbl_fire = _label(f_txt, GOLD)
178
+ self._jump_at = (layout.pad + ((btn_w - len(j_txt) * 8) >> 1), btn_y + ((btn_h - 8) >> 1))
179
+ self._fire_at = (
180
+ w - layout.pad - btn_w + ((btn_w - len(f_txt) * 8) >> 1),
181
+ btn_y + ((btn_h - 8) >> 1),
182
+ )
183
+
184
+ # World entities: platforms, crystals, drones, bolts, particles, popups.
185
+ self.platforms = []
186
+ self.crystals = []
187
+ self.drones = []
188
+ self.bolts = []
189
+ self.particles = []
190
+ self.popups = []
191
+ self._seed_world()
192
+
193
+ # Pre-render the sky gradient, ringed planet, and distant stars into sky_fb.
194
+ self.sky_buf, self.sky_fb = background or make_fb(w, layout.h, VOID)
195
+ self.sky_view = memoryview(self.sky_buf)
196
+ # The part of the scene draw_changes copies back: everything above the floor.
197
+ self._scene_rects = [(0, sy, w, self.ground_y + 3 - sy)]
198
+ self._build_sky_backdrop()
199
+
200
+ # Platforms are [x, y, width], crystals [x, y, active], drones [x, y, phase] and bolts
201
+ # [x, y]: x in fixed point, y in pixels. Particles are [x, y, vx, vy, color, ms left] with
202
+ # position and per-frame velocity in fixed point; popups are [x, y, label, color, ms left].
203
+ # Populate initial platforms, crystals, and patrol drones across the screen.
204
+ def _seed_world(self):
205
+ w = self.lay.w
206
+ step = int(w * 0.36)
207
+ for i in range(4):
208
+ px = int(w * 0.25) + i * step
209
+ pw = 88 if self.lay.compact else 128
210
+ py = self.ground_y - (52 if (i & 1) == 0 else 86)
211
+ if self.lay.compact:
212
+ py = self.ground_y - (40 if (i & 1) == 0 else 66)
213
+ self.platforms.append([px << FX, py, pw])
214
+ self.crystals.append([(px + (pw >> 1)) << FX, py - 24, True])
215
+ for i in range(2):
216
+ dx = int(w * 0.55) + i * int(w * 0.48)
217
+ dy = self.ground_y - (38 if i == 0 else 74)
218
+ self.drones.append([dx << FX, dy, i * 64])
219
+
220
+ # Pre-render the twilight sky gradient, starfield, and ringed solarpunk moon.
221
+ def _build_sky_backdrop(self):
222
+ fb = self.sky_fb
223
+ lay = self.lay
224
+ w = lay.w
225
+ sy = lay.scene_y
226
+ sky_h = self.ground_y - sy
227
+
228
+ paint_gradient(fb, 0, sy, w, sky_h, VOID_RGB, NIGHT_RGB, step=3)
229
+ paint_gradient(
230
+ fb,
231
+ 0,
232
+ sy + (sky_h >> 1),
233
+ w,
234
+ sky_h - (sky_h >> 1),
235
+ NIGHT_RGB,
236
+ (14, 58, 74),
237
+ step=3,
238
+ )
239
+
240
+ # Draw fixed background stars.
241
+ for i in range(36):
242
+ sx = (i * 73 + 19) % w
243
+ sy_star = sy + 28 + ((i * 41 + 11) % max(16, int(sky_h * 0.55)))
244
+ col = WHITE if (i % 5) == 0 else (AQUA_GLOW if (i & 1) else STEEL)
245
+ fb.pixel(sx, sy_star, col)
246
+
247
+ # Draw a large ringed planet/moon in the upper right sky.
248
+ px = int(w * 0.78)
249
+ py = sy + int(sky_h * 0.28)
250
+ pr = 22 if lay.compact else 32
251
+ fb.ellipse(px, py, pr * 2, pr >> 2, TEAL, False)
252
+ fb.ellipse(px, py, pr, pr, GOLD, True)
253
+ fb.ellipse(px - (pr >> 2), py - (pr >> 3), pr - 3, pr - 3, SUN_YELLOW, True)
254
+ fb.ellipse(px + (pr >> 2), py + 2, pr - 4, pr - 4, NIGHT, True)
255
+ fb.ellipse(px, py, pr * 2 + 2, (pr >> 2) + 1, AQUA_GLOW, False)
256
+
257
+ # Trigger a hero jump or mid-air jetpack thrust.
258
+ def jump(self):
259
+ if self.on_ground:
260
+ self.hero_vy = self._jump_vy
261
+ self.on_ground = False
262
+ self.sound.sfx_jump()
263
+ self._spawn_jet_particles(6)
264
+ elif self.jet_cooldown <= 0 and self.hero_y > (self.lay.scene_y + 42) << FX:
265
+ self.hero_vy = max(self._jet_max, self.hero_vy - self._jet_kick)
266
+ self.jet_cooldown = 180
267
+ self.sound.sfx_jump()
268
+ self._spawn_jet_particles(5)
269
+
270
+ # Fire a glowing plasma bolt from Bit's emitter.
271
+ def fire(self):
272
+ if self.fire_cooldown > 0 or len(self.bolts) >= 5:
273
+ return
274
+ self.fire_cooldown = 220
275
+ hero = self.sprites.bit_game_r
276
+ bx = (self.hero_x + hero.w - 4) << FX
277
+ by = _px(self.hero_y) + (hero.h >> 1) - (self.sprites.bolt.h >> 1)
278
+ self.bolts.append([bx, by])
279
+ self.sound.sfx_laser()
280
+
281
+ # Spawn glowing thruster exhaust particles beneath Bit.
282
+ def _spawn_jet_particles(self, count=4):
283
+ hero = self.sprites.bit_game_r
284
+ cx = (self.hero_x + (hero.w >> 1)) << FX
285
+ cy = (_px(self.hero_y) + hero.h - 4) << FX
286
+ for _ in range(count):
287
+ # vx = -2.2 - r * 0.1 and vy = 1.0 + r * 0.15 pixels a frame.
288
+ vx = -(((22 + rng_int(0, 15)) * FX_ONE + 5) // 10)
289
+ vy = ((100 + rng_int(0, 15) * 15) * FX_ONE + 50) // 100
290
+ col = AQUA_GLOW if rng_int(0, 1) else GOLD
291
+ self._add_particle(cx, cy, vx, vy, col, 450)
292
+
293
+ # Spawn a radial pixel burst at fixed-point (cx, cy) when a crystal or a drone goes.
294
+ def _spawn_burst(self, cx, cy, colors, count=10):
295
+ for i in range(count):
296
+ ang = (i * 256) // count
297
+ # 4.2 pixels a frame outward, 0.8 upward.
298
+ vx = (isin(ang + 64) * 168 + 5) // 10
299
+ vy = (isin(ang) * 168 + 5) // 10 - _BURST_LIFT
300
+ col = colors[i % len(colors)]
301
+ self._add_particle(cx, cy, vx, vy, col, 550)
302
+
303
+ # Start a particle in a reused list, retiring the oldest when the screen is full.
304
+ def _add_particle(self, x, y, vx, vy, col, life_ms):
305
+ parts = self.particles
306
+ if len(parts) >= MAX_PARTICLES:
307
+ self._spare_particles.append(parts.pop(0))
308
+ p = self._spare_particles.pop()
309
+ p[0] = x
310
+ p[1] = y
311
+ p[2] = vx
312
+ p[3] = vy
313
+ p[4] = col
314
+ p[5] = life_ms
315
+ parts.append(p)
316
+
317
+ # Spawn a rising text popup (e.g. "+100" or "BOOM +250") at fixed-point (x, y).
318
+ def _spawn_popup(self, x, y, text, col=GOLD):
319
+ lbl = self._popup_labels[self._next_popup]
320
+ self._next_popup = (self._next_popup + 1) % POPUP_LABELS
321
+ _relabel(lbl, text, col)
322
+ self.popups.append([x, y, lbl, col, 750])
323
+ if len(self.popups) > 6:
324
+ self.popups.pop(0)
325
+
326
+ # Handle pointer down inside the Sky Ruins scene;Left side jumps, Right side fires.
327
+ def on_pointer_down(self, x, y):
328
+ jx, jy, jw, jh = self.btn_jump
329
+ fx, fy, fw, fh = self.btn_fire
330
+ if jx <= x < jx + jw and jy <= y < jy + jh:
331
+ self.jump()
332
+ return True
333
+ if fx <= x < fx + fw and fy <= y < fy + fh:
334
+ self.fire()
335
+ return True
336
+ if x < (self.lay.w >> 1):
337
+ self.jump()
338
+ else:
339
+ self.fire()
340
+ return True
341
+
342
+ # Advance scrolling world, hero physics, collisions, and attract-mode AI.
343
+ def update(self, dt, auto_mode=True):
344
+ if dt <= 0.0:
345
+ dt = 0.016
346
+ elif dt > 0.08:
347
+ dt = 0.08
348
+ dt_ms = int(dt * 1000.0 + 0.5)
349
+
350
+ self.phase = (self.phase + 6) & 0xFF
351
+ dx = (self.scroll_speed * dt_ms + 500) // 1000
352
+ self._scroll_layers(dx)
353
+ self.jet_cooldown = max(0, self.jet_cooldown - dt_ms)
354
+ self.fire_cooldown = max(0, self.fire_cooldown - dt_ms)
355
+ self.shake_timer = max(0, self.shake_timer - dt_ms)
356
+
357
+ if self.combo_timer > 0:
358
+ self.combo_timer -= dt_ms
359
+ if self.combo_timer <= 0:
360
+ self.combo = 1
361
+
362
+ # Attract-mode AI autopilot: aim for crystals, jump gaps, and blast drones.
363
+ if auto_mode:
364
+ self._run_autopilot()
365
+
366
+ # Hero vertical gravity and ground/platform landing.
367
+ hero_w = self.sprites.bit_game_r.w
368
+ hero_h = self.sprites.bit_game_r.h
369
+ prev_bottom = self.hero_y + (hero_h << FX)
370
+ self.hero_y += self.hero_vy
371
+ self.hero_vy += self._gravity
372
+ self.on_ground = False
373
+
374
+ # Check landing on elevated rune platforms when descending.
375
+ if self.hero_vy >= 0:
376
+ new_bottom = self.hero_y + (hero_h << FX)
377
+ left = (self.hero_x + 6) << FX
378
+ right = (self.hero_x + hero_w - 6) << FX
379
+ for plat in self.platforms:
380
+ px, py, pw = plat
381
+ if (
382
+ right > px
383
+ and left < px + (pw << FX)
384
+ and prev_bottom <= (py + 8) << FX
385
+ and new_bottom >= py << FX
386
+ ):
387
+ self.hero_y = (py - hero_h) << FX
388
+ self.hero_vy = 0
389
+ self.on_ground = True
390
+ break
391
+
392
+ # Check landing on main mossy ruin floor.
393
+ if self.hero_y + (hero_h << FX) >= self.ground_y << FX:
394
+ self.hero_y = (self.ground_y - hero_h) << FX
395
+ self.hero_vy = 0
396
+ self.on_ground = True
397
+
398
+ # Emit subtle jetpack trail while airborne.
399
+ if not self.on_ground and (self.phase & 12) == 0:
400
+ self._spawn_jet_particles(1)
401
+
402
+ # Scroll platforms and recycle off-screen ones on the right.
403
+ w = self.lay.w
404
+ for plat in self.platforms:
405
+ plat[0] -= dx
406
+ if plat[0] + (plat[2] << FX) < -(20 << FX):
407
+ plat[0] = (w + rng_int(20, 80)) << FX
408
+ plat[1] = self.ground_y - rng_int(
409
+ 38 if self.lay.compact else 50,
410
+ 68 if self.lay.compact else 92,
411
+ )
412
+ self.crystals.append([plat[0] + ((plat[2] >> 1) << FX), plat[1] - 24, True])
413
+
414
+ # Scroll crystals and test hero pickup collisions.
415
+ crys_w = self.sprites.crystals[0].w
416
+ crys_h = self.sprites.crystals[0].h
417
+ hero_cx = self.hero_x + (hero_w >> 1)
418
+ hero_cy = _px(self.hero_y) + (hero_h >> 1)
419
+ i = len(self.crystals) - 1
420
+ while i >= 0:
421
+ c = self.crystals[i]
422
+ c[0] -= dx
423
+ if c[0] < -(30 << FX) or not c[2]:
424
+ self.crystals.pop(i)
425
+ elif (
426
+ abs(_px(c[0]) - hero_cx) < (hero_w >> 1) + (crys_w >> 1)
427
+ and abs(c[1] - hero_cy) < (hero_h >> 1) + (crys_h >> 1)
428
+ ):
429
+ c[2] = False
430
+ pts = 100 * self.combo
431
+ self.score += pts
432
+ self.crystals_collected += 1
433
+ self.combo = min(8, self.combo + 1)
434
+ self.combo_timer = 3200
435
+ self.sound.sfx_crystal()
436
+ self._spawn_burst(c[0], c[1] << FX, (AQUA_GLOW, ICE_CYAN, NEON_PINK, GOLD), 8)
437
+ self._spawn_popup(c[0], (c[1] - 8) << FX, f"+{pts}", AQUA_GLOW)
438
+ self.crystals.pop(i)
439
+ i -= 1
440
+
441
+ # Scroll sentinel drones, a little faster than the floor.
442
+ drone_w = self.sprites.drones[0].w
443
+ drone_h = self.sprites.drones[0].h
444
+ drone_dx = dx * 118 // 100
445
+ for d in self.drones:
446
+ d[0] -= drone_dx
447
+ d[2] = (d[2] + 5) & 0xFF
448
+ if d[0] < -(40 << FX):
449
+ d[0] = (w + rng_int(40, 140)) << FX
450
+ d[1] = self.ground_y - rng_int(
451
+ 32 if self.lay.compact else 40, 74 if self.lay.compact else 96
452
+ )
453
+
454
+ # Advance plasma bolts and check drone hits.
455
+ bolt_dx = (self._bolt_speed * dt_ms + 500) // 1000
456
+ bolt_w = self.sprites.bolt.w << FX
457
+ bolt_h = self.sprites.bolt.h
458
+ bi = len(self.bolts) - 1
459
+ while bi >= 0:
460
+ b = self.bolts[bi]
461
+ b[0] += bolt_dx
462
+ hit = False
463
+ for d in self.drones:
464
+ dy_bob = d[1] + ((isin(d[2]) * 8) >> 10)
465
+ if (
466
+ b[0] + bolt_w >= d[0]
467
+ and b[0] <= d[0] + (drone_w << FX)
468
+ and b[1] + bolt_h >= dy_bob
469
+ and b[1] <= dy_bob + drone_h
470
+ ):
471
+ hit = True
472
+ pts = 250 * self.combo
473
+ self.score += pts
474
+ self.combo = min(8, self.combo + 1)
475
+ self.combo_timer = 3200
476
+ self.shake_timer = 140
477
+ self.sound.sfx_boom()
478
+ self._spawn_burst(
479
+ d[0] + ((drone_w >> 1) << FX),
480
+ (dy_bob + (drone_h >> 1)) << FX,
481
+ (CORAL, ORANGE, GOLD, WHITE),
482
+ 12,
483
+ )
484
+ self._spawn_popup(d[0], (dy_bob - 6) << FX, f"BOOM +{pts}", GOLD)
485
+ d[0] = (w + rng_int(60, 160)) << FX
486
+ break
487
+ if hit or b[0] > (w + 20) << FX:
488
+ self.bolts.pop(bi)
489
+ bi -= 1
490
+
491
+ # Update particles and floating score popups.
492
+ pi = len(self.particles) - 1
493
+ while pi >= 0:
494
+ p = self.particles[pi]
495
+ p[0] += p[2]
496
+ p[1] += p[3]
497
+ p[5] -= dt_ms
498
+ if p[5] <= 0:
499
+ self._spare_particles.append(self.particles.pop(pi))
500
+ pi -= 1
501
+
502
+ rise = (self._popup_speed * dt_ms + 500) // 1000
503
+ ui = len(self.popups) - 1
504
+ while ui >= 0:
505
+ pop = self.popups[ui]
506
+ pop[1] -= rise
507
+ pop[4] -= dt_ms
508
+ if pop[4] <= 0:
509
+ self.popups.pop(ui)
510
+ ui -= 1
511
+
512
+ # Move each parallax layer by its share of dx, wrapping its offset at its span.
513
+ def _scroll_layers(self, dx):
514
+ pos = self._layer_pos
515
+ idx = self._layer_idx
516
+ span = self._layer_span
517
+ for k in range(4):
518
+ p = pos[k] + dx * LAYER_RATES[k] // 100
519
+ while p >= span[k]:
520
+ p -= span[k]
521
+ idx[k] += 1
522
+ pos[k] = p
523
+
524
+ # Steer Bit automatically in attract mode to collect crystals and blast drones.
525
+ def _run_autopilot(self):
526
+ hero_h = self.sprites.bit_game_r.h
527
+ hero_cy = self.hero_y + ((hero_h >> 1) << FX)
528
+ hx = self.hero_x << FX
529
+
530
+ # Fire at any drone in front of Bit on a similar vertical band.
531
+ for d in self.drones:
532
+ dist_x = d[0] - hx
533
+ if (24 << FX) < dist_x < self._fire_range:
534
+ if abs(((d[1] + 12) << FX) - hero_cy) < (28 << FX):
535
+ self.fire()
536
+ elif dist_x < (95 << FX) and (d[1] << FX) > self.hero_y - (18 << FX):
537
+ self.jump()
538
+
539
+ # Jump toward upcoming elevated crystals.
540
+ for c in self.crystals:
541
+ dist_x = c[0] - hx
542
+ if (16 << FX) < dist_x < (110 << FX) and (c[1] << FX) < self.hero_y - (10 << FX):
543
+ self.jump()
544
+ break
545
+
546
+ # Render all 4 parallax layers, sprites, particles, and arcade HUD.
547
+ def draw(self, fb, draw_obj=None, st=None):
548
+ copy_frame(fb, self.sky_fb)
549
+ self._draw_scene(fb)
550
+ if st is not None:
551
+ st.sig = {}
552
+
553
+ # Repaint the scene down to the foreground floor, which paints itself in full.
554
+ def draw_changes(self, fb, draw_obj, st):
555
+ lay = self.lay
556
+ restore_rects(fb, self.sky_view, self._scene_rects, lay.w, lay.h)
557
+ self._draw_scene(fb)
558
+
559
+ # Paint every parallax layer, entity and HUD element over the sky.
560
+ def _draw_scene(self, fb):
561
+ shake_y = rng_int(-2, 2) if self.shake_timer > 0 else 0
562
+
563
+ self._draw_sky_islands(fb, shake_y)
564
+ self._draw_far_citadel(fb, shake_y)
565
+ self._draw_mid_ruins(fb, shake_y)
566
+ self._draw_foreground_ground(fb, shake_y)
567
+ self._draw_platforms_and_entities(fb, shake_y)
568
+ self._draw_hud(fb)
569
+
570
+ # Draw Layer 0.5 (0.10x speed): Floating solarpunk sky islands with waterfalls.
571
+ def _draw_sky_islands(self, fb, shake_y):
572
+ w = self.lay.w
573
+ span = 220 if self.lay.compact else 310
574
+ offs = self._layer_pos[0] >> FX
575
+ x = -offs + 28
576
+ idx = self._layer_idx[0]
577
+ while x < w + span:
578
+ iy = self.lay.scene_y + (56 if self.lay.compact else 78) + ((idx * 19) % 28) + shake_y
579
+ iw = 56 if self.lay.compact else 84
580
+ # Mossy island cap and tapered floating rock spire below.
581
+ fb.fill_rect(x, iy, iw, 6, MOSS)
582
+ fb.hline(x + 2, iy, iw - 4, LIME_GLOW)
583
+ fb.fill_rect(x + 6, iy + 6, iw - 12, 8, SLATE)
584
+ fb.fill_rect(x + 16, iy + 14, iw - 32, 8, DEEP_SLATE)
585
+ # Ancient obelisk and cascading bioluminescent waterfall.
586
+ ox = x + (iw >> 1) - 4
587
+ fb.fill_rect(ox, iy - 16, 8, 16, STEEL)
588
+ fb.pixel(ox + 4, iy - 19, AQUA_GLOW)
589
+ fall_h = 22 + ((idx * 7) % 12)
590
+ fb.vline(ox + 2, iy + 6, fall_h, CYAN)
591
+ fb.vline(ox + 3, iy + 6, fall_h, AQUA_GLOW)
592
+ x += span
593
+ idx += 1
594
+
595
+ # Draw Layer 1 (0.22x speed): Distant silhouetted solarpunk spires and bio-domes.
596
+ def _draw_far_citadel(self, fb, shake_y):
597
+ w = self.lay.w
598
+ base_y = self.ground_y + shake_y
599
+ span = 140 if self.lay.compact else 190
600
+ offs = self._layer_pos[1] >> FX
601
+ x = -offs
602
+ idx = self._layer_idx[1]
603
+ while x < w + span:
604
+ tower_h = (54 if self.lay.compact else 78) + ((idx * 29) % 38)
605
+ tw = 28 if self.lay.compact else 38
606
+ ty = base_y - tower_h
607
+ fb.fill_rect(x + 12, ty, tw, tower_h, DEEP_SLATE)
608
+ fb.ellipse(x + 12 + (tw >> 1), ty, tw >> 1, 10, DEEP_TEAL, True)
609
+ fb.vline(x + 12 + (tw >> 1), ty - 16, 16, CYAN)
610
+ # Lit spire windows.
611
+ fb.fill_rect(x + 12 + (tw >> 1) - 2, ty + 8, 4, tower_h - 16, AQUA_GLOW)
612
+ x += span
613
+ idx += 1
614
+
615
+ # Draw Layer 2 (0.50x speed): Midground mossy stone arches and glowing vines.
616
+ def _draw_mid_ruins(self, fb, shake_y):
617
+ w = self.lay.w
618
+ base_y = self.ground_y + shake_y
619
+ span = 110 if self.lay.compact else 156
620
+ offs = self._layer_pos[2] >> FX
621
+ x = -offs
622
+ idx = self._layer_idx[2]
623
+ arch_h = 46 if self.lay.compact else 68
624
+ pillar_w = 16 if self.lay.compact else 22
625
+ while x < w + span:
626
+ ay = base_y - arch_h
627
+ # Stone lintel and twin pillars.
628
+ fb.fill_rect(x, ay, span - 14, 10, SLATE)
629
+ fb.hline(x, ay, span - 14, MOSS)
630
+ fb.fill_rect(x + 4, ay + 10, pillar_w, arch_h - 10, DEEP_SLATE)
631
+ fb.fill_rect(x + span - 18 - pillar_w, ay + 10, pillar_w, arch_h - 10, DEEP_SLATE)
632
+ # Hanging bioluminescent vines swaying gently in the breeze.
633
+ sway = (isin(self.phase + idx * 37) * 3) >> 10
634
+ vx1 = x + (span >> 1) - 8 + sway
635
+ vh1 = 18 + ((idx * 13) % 16)
636
+ fb.vline(vx1, ay + 10, vh1, EMERALD)
637
+ fb.fill_rect(vx1 - 1, ay + 10 + vh1, 3, 3, LIME_GLOW)
638
+ x += span
639
+ idx += 1
640
+
641
+ # Draw Layer 3 (1.00x speed): Foreground mossy ruin floor with glowing cyan runes.
642
+ def _draw_foreground_ground(self, fb, shake_y):
643
+ w = self.lay.w
644
+ gy = self.ground_y + shake_y
645
+ gh = (self.lay.scene_y + self.lay.scene_h) - gy
646
+ if gh <= 0:
647
+ return
648
+ fb.fill_rect(0, gy, w, gh, ABYSS)
649
+ fb.fill_rect(0, gy, w, 6, FOREST)
650
+ fb.hline(0, gy, w, EMERALD)
651
+ fb.hline(0, gy + 1, w, LIME_GLOW)
652
+
653
+ tile_w = 40 if self.lay.compact else 56
654
+ offs = self._layer_pos[3] >> FX
655
+ tx = -offs
656
+ while tx < w:
657
+ fb.vline(tx, gy + 6, gh - 6, NIGHT)
658
+ fb.rect(tx + 8, gy + 12, tile_w - 16, 10, DEEP_TEAL)
659
+ fb.hline(tx + 12, gy + 16, tile_w - 24, CYAN)
660
+ tx += tile_w
661
+
662
+ # Draw platforms, crystals, patrol drones, Bit, plasma bolts, and particles.
663
+ def _draw_platforms_and_entities(self, fb, shake_y):
664
+ # Elevated mossy rune platforms.
665
+ for px, py, pw in self.platforms:
666
+ ix = _px(px)
667
+ iy = py + shake_y
668
+ fb.fill_rect(ix, iy, pw, 12, SLATE)
669
+ fb.fill_rect(ix + 2, iy + 2, pw - 4, 8, DEEP_SLATE)
670
+ fb.hline(ix, iy, pw, LIME_GLOW)
671
+ fb.hline(ix + 1, iy + 1, pw - 2, EMERALD)
672
+ fb.hline(ix + 8, iy + 6, pw - 16, AQUA_GLOW)
673
+
674
+ # Spinning 4-frame bioluminescent crystals with soft radial alpha glow.
675
+ cframe = (self.phase >> 4) % len(self.sprites.crystals)
676
+ csprite = self.sprites.crystals[cframe]
677
+ for cx, cy, active in self.crystals:
678
+ if active:
679
+ ccx = _px(cx)
680
+ bob = (isin(self.phase + ccx) * 4) >> 10
681
+ ccy = cy + bob + shake_y
682
+ self.sprites.draw_glow(fb, ccx, ccy, AQUA_GLOW, large=True)
683
+ csprite.draw_center(fb, ccx, ccy)
684
+
685
+ # Hovering sentinel patrol drones.
686
+ dframe = (self.phase >> 3) % len(self.sprites.drones)
687
+ dsprite = self.sprites.drones[dframe]
688
+ for dx, dy, dphase in self.drones:
689
+ bob = (isin(dphase) * 8) >> 10
690
+ dsprite.draw(fb, _px(dx), dy + bob + shake_y)
691
+
692
+ # Plasma bolts with alpha glow halo.
693
+ for bx, by in self.bolts:
694
+ ibx = _px(bx)
695
+ iby = by + shake_y
696
+ self.sprites.draw_glow(fb, ibx + (self.sprites.bolt.w >> 1), iby + 4, ICE_CYAN, large=False)
697
+ self.sprites.bolt.draw(fb, ibx, iby)
698
+ fb.hline(ibx - 10, iby + 4, 10, AQUA_GLOW)
699
+
700
+ # Hero Bit sprite + jetpack flame when airborne.
701
+ hy = _px(self.hero_y) + shake_y
702
+ self.sprites.bit_game_r.draw(fb, self.hero_x, hy)
703
+ if not self.on_ground:
704
+ flame = self.sprites.flames[(self.phase >> 2) % len(self.sprites.flames)]
705
+ flame.draw(
706
+ fb,
707
+ self.hero_x + (self.sprites.bit_game_r.w >> 1) - (flame.w >> 1),
708
+ hy + self.sprites.bit_game_r.h - 4,
709
+ )
710
+
711
+ # Particle bursts and thruster sparks.
712
+ for p in self.particles:
713
+ fb.fill_rect(_px(p[0]), _px(p[1]) + shake_y, 3, 3, p[4])
714
+
715
+ # Floating score/combo text popups.
716
+ for pop in self.popups:
717
+ fb.blit(pop[2], _px(pop[0]), _px(pop[1]) + shake_y, KEY)
718
+
719
+ # Render the top arcade score bar and bottom tactile JUMP / FIRE touch pads.
720
+ def _draw_hud(self, fb):
721
+ w = self.lay.w
722
+ pad = self.lay.pad
723
+ draw_pixel_panel(
724
+ fb, pad, self.hud_y, w - pad * 2, self.hud_h, ABYSS, CYAN, ICE_CYAN
725
+ )
726
+ ty = self.hud_y + ((self.hud_h - 8) >> 1)
727
+ texts = self._hud_texts
728
+ if (
729
+ texts is None
730
+ or texts[0] != self.score
731
+ or texts[1] != self.crystals_collected
732
+ or texts[2] != self.combo
733
+ ):
734
+ score_lbl, crys_lbl, combo_lbl = self._hud_labels
735
+ _relabel(score_lbl, f"SCORE {self.score:06d}", WHITE)
736
+ _relabel(crys_lbl, f"CRYSTALS:{self.crystals_collected:02d}", AQUA_GLOW)
737
+ _relabel(combo_lbl, f"COMBO x{self.combo}", GOLD if self.combo > 1 else SILVER)
738
+ texts = self._hud_texts = (
739
+ self.score,
740
+ self.crystals_collected,
741
+ self.combo,
742
+ score_lbl,
743
+ crys_lbl,
744
+ combo_lbl,
745
+ int(w * 0.36),
746
+ int(w * 0.62),
747
+ )
748
+ fb.blit(texts[3], pad + 10, ty, KEY)
749
+ fb.blit(texts[4], texts[6], ty, KEY)
750
+ fb.blit(texts[5], texts[7], ty, KEY)
751
+ if not self.lay.compact:
752
+ fb.blit(self._lbl_jet, w - pad - 68, ty, KEY)
753
+
754
+ # Tactile arcade touch controls at the bottom-left and bottom-right.
755
+ jx, jy, jw, jh = self.btn_jump
756
+ fx, fy, fw, fh = self.btn_fire
757
+ draw_pixel_panel(fb, jx, jy, jw, jh, DEEP_TEAL, AQUA_GLOW, WHITE)
758
+ draw_pixel_panel(fb, fx, fy, fw, fh, NIGHT, CORAL, GOLD)
759
+ x, y = self._jump_at
760
+ fb.blit(self._lbl_jump, x, y, KEY)
761
+ x, y = self._fire_at
762
+ fb.blit(self._lbl_fire, x, y, KEY)