diff -ruN a/lib/cnst.py b/lib/cnst.py --- a/lib/cnst.py +++ b/lib/cnst.py @@ -6,11 +6,11 @@ IROTATE = 64 #FPS = 10 -TITLE = "Barbie Seahorse Adventures" #"Barbie Seahorse Adventures" #"Bubble Kong" # #"The Volcanic Rollercoaster Ride!" +TITLE = "Seahorse Adventures" #"Barbie Seahorse Adventures" #"Bubble Kong" # #"The Volcanic Rollercoaster Ride!" SCALE2X = False #use the scale2x scaler to make things look hi-res LOWRES = False #keep it in 320x240 mode -FULL = True # +FULL = False # #INIT_BORDER = 100 #DEINIT_BORDER = 200 diff -ruN a/lib/main.py b/lib/main.py --- a/lib/main.py +++ b/lib/main.py @@ -6,6 +6,7 @@ directory. ''' +import asyncio import sys import os @@ -93,8 +94,8 @@ pygame.font.init() - f_main = data.filepath(os.path.join('fonts','04B_20__.TTF')) - f_scale = 0.35 + f_main = data.filepath(os.path.join('fonts','Silkscreen-Regular.ttf')) + f_scale = 0.5 #f_main = data.filepath(os.path.join('fonts','04B_25__.TTF')) #f_scale = 0.75 #f_main = data.filepath(os.path.join('fonts','04B_11__.TTF')) @@ -300,7 +301,7 @@ -def main(): +async def main(): #print("Hello from your game's main()") #print(data.load('sample.txt').read()) @@ -342,7 +343,10 @@ from . import level l = level.Level(g,fname,engine.Quit(g)) - g.run(l) + while True: + await g.run(l) + # nothing to quit to on a web page: back to the menu + l = menu.Menu(g) if not gamerzilla is None: gamerzilla.GamerzillaQuit() pygame.quit() diff -ruN a/lib/menu.py b/lib/menu.py --- a/lib/menu.py +++ b/lib/menu.py @@ -95,7 +95,7 @@ y += 12 - text = 'www.imitationpickles.org' + text = 'THE OLDE BATTLEAXE & FRIENDS' c = (0x00,0x00,0x00) img = fnt.render(text,1,c) x = (SW-img.get_width())//2 diff -ruN a/lib/pgu/engine.py b/lib/pgu/engine.py --- a/lib/pgu/engine.py +++ b/lib/pgu/engine.py @@ -1,7 +1,9 @@ """a state engine. """ +import asyncio import pygame from pygame.locals import * +from . import timer as _timer class State: """Template Class -- for a state. @@ -88,7 +90,7 @@ return 0 - def run(self,state,screen=None): + async def run(self,state,screen=None): """Run the state engine, this is a infinite loop (until a quit occurs).
Game.run(state,screen=None)
@@ -106,6 +108,8 @@ while not self.quit: self.loop() + # wait for the next frame without keeping the browser busy + await asyncio.sleep(_timer.Timer.pending_wait / 1000.0) def loop(self): s = self.state diff -ruN a/lib/pgu/timer.py b/lib/pgu/timer.py --- a/lib/pgu/timer.py +++ b/lib/pgu/timer.py @@ -9,6 +9,8 @@
Timer(fps)
""" + pending_wait = 0 + def __init__(self,fps): if fps == 0: self.tick = self._blank @@ -25,11 +27,13 @@
Timer.tick()
""" + # (web version: the engine sleeps for pending_wait milliseconds instead of blocking here) self.ct = pygame.time.get_ticks() if self.ct < self.nt: - pygame.time.wait(self.nt-self.ct) + Timer.pending_wait = self.nt-self.ct self.nt+=self.wait else: + Timer.pending_wait = 0 self.nt = pygame.time.get_ticks()+self.wait diff -ruN a/main.py b/main.py --- a/main.py +++ b/main.py @@ -0,0 +1,8 @@ +import asyncio + +# pygbag reads the imports of this file to install pygame-ce before the game's own modules load +import pygame + +from lib import main + +asyncio.run(main.main())