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