This commit is contained in:
rhiannon morris 2023-08-16 19:51:55 +02:00
parent d928e2b09b
commit 5925a4c857
17 changed files with 24 additions and 38 deletions

62
main.py
View file

@ -6,6 +6,19 @@ LEFT = 1
DOWN = 2 DOWN = 2
RIGHT = 3 RIGHT = 3
def dir_str(dir):
if dir == UP:
return 'back'
elif dir == LEFT:
return 'left'
elif dir == DOWN:
return 'front'
elif dir == RIGHT:
return 'right'
def image_path(dir, step):
return f"/flash/sprites/{dir_str(dir)}{str(step + 1)}.png"
class Random: class Random:
def __init__(self): def __init__(self):
@ -25,41 +38,8 @@ class Random:
# screen coords range ±120 each side # screen coords range ±120 each side
TRANSPARENT = (1, 0, 1)
def to_image(str):
cols = {
' ': TRANSPARENT,
'#': (0, 0, 0),
'%': (.6, .6, .6),
'*': (.26, .26, .26),
':': (0, .41, 0),
"'": (.87, .87, .87),
'.': (.87, .87, 0),
}
lines = str.strip().split('\n')
lmap = lambda f, xs: list(map(f, xs))
return lmap(lambda l: lmap(lambda c: cols[c], l), lines)
quox_left_1 = to_image("""
% *
% % * %*% * :#
%%%% %%% *%%*%%* ::%
%%#%%% *%%*%%*%* :#
%%'%%% *%%*%*%* :#
%%%%%%: *%*%** ::%
%% %%#:::*%**%*: :##
%%::::::%*::::%
##:::::::::::##
%:::%#%:::%#%
#*:::##*:::#
##***::#***::###
##.%%:##.%%:##
""")
class Box(Responder): class Box(Responder):
STEP_DELAY = 500 STEP_DELAY = 250
TURN_DELAY_BASE = 1400 TURN_DELAY_BASE = 1400
def __init__(self): def __init__(self):
@ -71,14 +51,18 @@ class Box(Responder):
def draw(self, ctx): def draw(self, ctx):
self.clear(ctx) self.clear(ctx)
self.rect(ctx)
# self.text(ctx) # self.text(ctx)
self.image(ctx)
def clear(self, ctx): def clear(self, ctx):
ctx.rgb(0, 0, 0) \ ctx.rgb(0, 0, 0) \
.rectangle(-120, -120, 240, 240) \ .rectangle(-120, -120, 240, 240) \
.fill() .fill()
def image(self, ctx):
path = image_path(self.direction, self.step)
ctx.image(path, -10, -10, -1, -1)
@staticmethod @staticmethod
def coord(d): def coord(d):
if d == UP: if d == UP:
@ -98,8 +82,10 @@ class Box(Responder):
ctx.rectangle(0, 0, *Box.coord(self.direction)).fill() ctx.rectangle(0, 0, *Box.coord(self.direction)).fill()
def text(self, ctx): def text(self, ctx):
ctx.rgb(1, 1, 1) \ msg = f"{self.turn_delay}; {self.step_delay}; {self.direction}; {self.step}"
.move_to(0, 0).text(str(self.delay) + '; ' + str(self.direction)) ctx.font_size = 16.0
ctx.text_align = ctx.CENTER
ctx.rgb(1, 1, 1).move_to(0, -100).text(msg)
def think(self, state, Δ): def think(self, state, Δ):
self.update_delay(Δ) self.update_delay(Δ)
@ -113,7 +99,7 @@ class Box(Responder):
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 = Box.STEP_DELAY
self.step = (self.step + 1) & 4 self.step = (self.step + 1) & 3
def choose_direction(self): def choose_direction(self):
self.direction = self.random.direction() self.direction = self.random.direction()

BIN
sprites/back1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 833 B

BIN
sprites/back2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 823 B

BIN
sprites/back3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 804 B

BIN
sprites/back4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 B

BIN
sprites/front1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

BIN
sprites/front2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

BIN
sprites/front3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

BIN
sprites/front4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

BIN
sprites/left1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 873 B

BIN
sprites/left2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

BIN
sprites/left3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 873 B

BIN
sprites/left4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 858 B

BIN
sprites/right1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

BIN
sprites/right2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

BIN
sprites/right3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

BIN
sprites/right4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 937 B