1
1
import time
2
2
import array
3
3
import _stage
4
- import struct
5
4
6
5
7
6
FONT = (b'\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 '
131
130
132
131
def color565 (r , g , b ):
133
132
"""Convert 24-bit RGB color to 16-bit."""
134
- return (b & 0xf8 ) << 8 | (g & 0xfc ) << 3 | r >> 3
133
+ return (r & 0xf8 ) << 8 | (g & 0xfc ) << 3 | b >> 3
135
134
136
135
137
136
def collide (ax0 , ay0 , ax1 , ay1 , bx0 , by0 , bx1 = None , by1 = None ):
@@ -399,11 +398,11 @@ class Stage:
399
398
"""
400
399
buffer = bytearray (512 )
401
400
402
- def __init__ (self , display_bus , fps = 6 ):
401
+ def __init__ (self , display , fps = 6 ):
403
402
self .layers = []
404
- self .display_bus = display_bus
405
- self .width = 128
406
- self .height = 128
403
+ self .display = display
404
+ self .width = display . width
405
+ self .height = display . height
407
406
self .last_tick = time .monotonic ()
408
407
self .tick_delay = 1 / fps
409
408
@@ -416,26 +415,15 @@ def tick(self):
416
415
else :
417
416
self .last_tick = time .monotonic ()
418
417
419
- def _block (self , x0 , y0 , x1 , y1 ):
420
- x0 += 3
421
- x1 += 3
422
- y0 += 2
423
- y1 += 2
424
- xpos = struct .pack ('>HH' , x0 , x1 )
425
- self .display_bus .send (0x2a , xpos )
426
- ypos = struct .pack ('>HH' , y0 , y1 )
427
- self .display_bus .send (0x2b , ypos )
428
- self .display_bus .send (0x2c , b'' )
429
-
430
418
def render_block (self , x0 = 0 , y0 = 0 , x1 = None , y1 = None ):
431
419
"""Update a rectangle of the screen."""
432
420
if x1 is None :
433
421
x1 = self .width
434
422
if y1 is None :
435
423
y1 = self .height
436
424
layers = [l .layer for l in self .layers ]
437
- self ._block (x0 , y0 , x1 - 1 , y1 - 1 )
438
- _stage .render (x0 , y0 , x1 , y1 , layers , self .buffer , self .display_bus )
425
+ self .display . block (x0 , y0 , x1 - 1 , y1 - 1 )
426
+ _stage .render (x0 , y0 , x1 , y1 , layers , self .buffer , self .display . bus )
439
427
440
428
def render_sprites (self , sprites ):
441
429
"""Update the spots taken by all the sprites in the list."""
@@ -447,7 +435,7 @@ def render_sprites(self, sprites):
447
435
y1 = max (1 , min (self .height , max (sprite .py , int (sprite .y )) + 16 ))
448
436
if x0 == x1 or y0 == y1 :
449
437
continue
450
- self ._block (x0 , y0 , x1 - 1 , y1 - 1 )
438
+ self .display . block (x0 , y0 , x1 - 1 , y1 - 1 )
451
439
_stage .render (x0 , y0 , x1 , y1 , layers , self .buffer ,
452
- self .display_bus )
440
+ self .display . bus )
453
441
sprite ._updated ()
0 commit comments