Skip to content
Snippets Groups Projects

clouds: move to Badge menu, use IMU and bundle_path

Merged pippin requested to merge pippin/clouds_use_bundle_path_imu_and_move_to_badge_menu into main
All threads resolved!
2 files
+ 21
7
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -6,7 +6,8 @@ from ctx import Context
class Cloud:
def __init__(self, x: float, y: float, z: float) -> None:
def __init__(self, path: str, x: float, y: float, z: float) -> None:
self.path = path
self.x = x
self.y = y
self.z = z
@@ -14,10 +15,10 @@ class Cloud:
def draw(self, ctx: Context) -> None:
x = self.x / self.z * 120
y = self.y / self.z * 120
width = 200.0 / self.z * 120
height = 100.0 / self.z * 120
width = 200.0 / self.z * 160
height = 100.0 / self.z * 160
ctx.image(
"/flash/sys/apps/clouds/cloud.png",
self.path,
x - width / 2,
y - height / 2,
width,
@@ -29,11 +30,15 @@ class Clouds(Application):
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self.clouds = []
+1
bundle_path = getattr(app_ctx, "bundle_path")
if bundle_path == "":
bundle_path = "/flash/sys/apps/clouds"
for i in range(10):
self.clouds.append(
Cloud(
bundle_path + "/cloud.png",
((random.getrandbits(16) - 32767) / 32767.0) * 200,
((random.getrandbits(16)) / 65535.0) * 50 - 5,
((random.getrandbits(16)) / 65535.0) * 60 - 10,
((random.getrandbits(16)) / 65535.0) * 200 + 5,
)
)
@@ -41,9 +46,18 @@ class Clouds(Application):
def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms)
for c in self.clouds:
c.z -= 40 * delta_ms / 1000.0
c.x -= (delta_ms / 1000.0) * ins.imu.acc[1] * 10
c.z -= (delta_ms / 1000.0) * (ins.imu.acc[2] - 5) * 20
# wrap x and z coordinates around
if c.z < 10:
c.z = 300
elif c.z > 300:
c.z = 10
if c.x < -200:
c.x = 200
elif c.x > 200:
c.x = -200
self.clouds = sorted(self.clouds, key=lambda c: -c.z)
def draw(self, ctx: Context) -> None:
Loading