packaging

This commit is contained in:
rhiannon morris 2023-08-16 20:52:56 +02:00
parent 2a44d4e25b
commit 0db170c269
2 changed files with 34 additions and 17 deletions

View file

@ -1,5 +1,6 @@
from st3m.reactor import Responder
from st3m.run import run_responder
from st3m.application import Application, ApplicationContext
from st3m.run import run_view
import os.path
UP = 0
LEFT = 1
@ -16,8 +17,9 @@ def dir_str(dir):
elif dir == RIGHT:
return 'right'
def image_path(dir, step):
return f"/flash/sprites/{dir_str(dir)}{str(step + 1)}.png"
def image_path(direction, step):
dir = os.path.dirname(__file__)
return f"{dir}/sprites/{dir_str(direction)}{str(step + 1)}.png"
class Random:
@ -34,11 +36,11 @@ class Random:
return self.next() & 3
def delay(self):
return Box.TURN_DELAY_BASE + self.next()
return Quox.TURN_DELAY_BASE + self.next()
# screen coords range ±120 each side
class Box(Responder):
class Quox(Application):
STEP_DELAY = 250
TURN_DELAY_BASE = 1400
MOVE_DELAY = 100
@ -47,13 +49,15 @@ class Box(Responder):
LEFT = -90
RIGHT = 70
def __init__(self):
def __init__(self, app_ctx):
super().__init__(app_ctx)
self.random = Random()
self.choose_direction()
self.choose_turn_delay()
self.step = 0
self.step_delay = Box.STEP_DELAY
self.move_delay = Box.MOVE_DELAY
self.step_delay = Quox.STEP_DELAY
self.move_delay = Quox.MOVE_DELAY
self.x = -10
self.y = -10
@ -87,7 +91,7 @@ class Box(Responder):
ctx = ctx.rgb(.1, .6, .3)
else:
ctx = ctx.rgb(.1, .3, .6)
ctx.rectangle(0, 0, *Box.coord(self.direction)).fill()
ctx.rectangle(0, 0, *Quox.coord(self.direction)).fill()
def text(self, ctx):
msg = f"{self.x}, {self.y}"
@ -96,6 +100,7 @@ class Box(Responder):
ctx.rgb(1, 1, 1).move_to(0, -100).text(msg)
def think(self, state, Δ):
super().think(state, Δ)
self.update_delay(Δ)
def update_delay(self, Δ):
@ -107,10 +112,10 @@ class Box(Responder):
self.choose_direction()
self.choose_turn_delay(old_delay)
if self.step_delay <= 0:
self.step_delay = Box.STEP_DELAY
self.step_delay = Quox.STEP_DELAY
self.step = (self.step + 1) & 3
if self.move_delay <= 0:
self.move_delay += Box.MOVE_DELAY
self.move_delay += Quox.MOVE_DELAY
self.move()
def choose_direction(self):
@ -120,10 +125,10 @@ class Box(Responder):
self.turn_delay = self.random.delay() + subtract
def at_edge(self):
return ((self.direction == UP and self.y <= Box.TOP) or
(self.direction == DOWN and self.y >= Box.BOTTOM) or
(self.direction == LEFT and self.x <= Box.LEFT) or
(self.direction == RIGHT and self.x >= Box.RIGHT))
return ((self.direction == UP and self.y <= Quox.TOP) or
(self.direction == DOWN and self.y >= Quox.BOTTOM) or
(self.direction == LEFT and self.x <= Quox.LEFT) or
(self.direction == RIGHT and self.x >= Quox.RIGHT))
def flip_direction(self):
if self.direction == UP:
@ -148,4 +153,5 @@ class Box(Responder):
elif self.direction == RIGHT:
self.x += 5
run_responder(Box())
if __name__ == '__main__':
run_view(Quox(ApplicationContext()))

11
flow3r.toml Normal file
View file

@ -0,0 +1,11 @@
[app]
name = "stompy quox"
menu = "Apps"
[entry]
class = "Quox"
[metadata]
author = "niss"
license = "just do whatever."
url = "https://git.rhiannon.website/rhi/qflow3r"