diff -ruN a/main.py b/main.py --- a/main.py 1969-12-31 21:00:00.000000000 -0300 +++ b/main.py 2026-11-04 22:57:34.068568920 -0300 @@ -0,0 +1,11 @@ +import pygame +import asyncio +import os +import sys + +mainpath = os.path.abspath(os.path.dirname(__file__)) +sys.path.append(mainpath) +sys.path.append(os.path.join(mainpath, "src")) +import bb_main + +asyncio.run(bb_main.main(mainpath)) diff -ruN a/run_game.py b/run_game.py --- a/run_game.py 2026-11-04 22:57:26.309241854 -0300 +++ b/run_game.py 1969-12-31 21:00:00.000000000 -0300 @@ -1,12 +0,0 @@ -#!/usr/bin/python - -""" -run_game.py: Used to run game -""" - -import sys, os -mainpath = os.path.abspath(os.path.dirname(sys.argv[0])) -sys.path.append(mainpath) -sys.path.append(os.path.join(mainpath,"src")) -import main -main.main(mainpath) diff -ruN a/src/bb_main.py b/src/bb_main.py --- a/src/bb_main.py 1969-12-31 21:00:00.000000000 -0300 +++ b/src/bb_main.py 2026-11-04 22:57:34.068354254 -0300 @@ -0,0 +1,61 @@ +#!/usr/bin/python + +""" +main.py: Main entry point for game +""" + +from builtins import range + +import os +import pygame +from pygame.locals import * +from gamedirector import * + +import resources +import game + +# Start +async def main(mainpath): + + # Initialise pygame + pygame.init() + pygame.mixer.init() + + # on the web the page keeps the /saves folder in the browser + savefile = '/saves/saved_progress.txt' if os.path.isdir('/saves') else os.path.join(mainpath,'data','saved_progress.txt') + + # start up director + framerate = 30 + screen_res = (800,600) + window_title = "Pyweek27: Breakout Blue (Team Chimera)" + dir = GameDirector(window_title, screen_res, framerate) + + # Load resources + resources.init(mainpath,screen_res) + + # Load game scenes + maingame = game.MainGame(dir, screen_res) + maingame.savepath = savefile + dir.addscene('maingame', maingame) + + pausescene = game.PauseScreen(dir, screen_res) + dir.addscene('pausescene', pausescene) + maingame.h_pausescene = pausescene + pausescene.h_maingame = maingame + + titlescene = game.TitleScreen(dir, screen_res) + titlescene.savepath = savefile + titlescene.h_maingame = maingame + dir.addscene('titlescene', titlescene) + + cutscene = game.CutScene(dir, screen_res) + dir.addscene('cutscene', cutscene) + + # start up director + #dir.change_scene('maingame', [True, 'testbig003']) + #dir.change_scene('maingame', [True, 'level3']) + #dir.change_scene('titlescene', []) + dir.change_scene('cutscene', ['team_chimera','none','titlescene',[]]) + #dir.change_scene('cutscene', ['news002','tense_chase','titlescene',[]]) + await dir.loop() + diff -ruN a/src/gamedirector.py b/src/gamedirector.py --- a/src/gamedirector.py 2026-11-04 22:57:26.339529642 -0300 +++ b/src/gamedirector.py 2026-11-04 22:57:34.067985462 -0300 @@ -4,6 +4,8 @@ gamedirector.py: classes for running the game using a director/scene structure """ +import asyncio +import time import pygame from pygame.locals import * @@ -19,9 +21,14 @@ self.frame = 0 self.timesincestart = 0 - def loop(self): + async def loop(self): + last = time.time() while not self.quit_flag: - self.time = self.clock.tick(self.fps) + # frame limiter for the browser: the page needs control back every frame + await asyncio.sleep(max(0.0, 1.0 / self.fps - (time.time() - last))) + now = time.time() + self.time = max(1, int((now - last) * 1000)) + last = now self.framerate = 1000.0/self.time self.frame = self.frame + 1 self.timesincestart = self.timesincestart + self.time @@ -51,7 +58,7 @@ def change_scene(self, scenename, switchtoargs): if scenename is None: - self.quit() + pass # the web page has nowhere to quit to else: self.scene = self.scenelist[scenename] self.scene.on_switchto(switchtoargs) diff -ruN a/src/main.py b/src/main.py --- a/src/main.py 2026-11-04 22:57:26.347171505 -0300 +++ b/src/main.py 1969-12-31 21:00:00.000000000 -0300 @@ -1,58 +0,0 @@ -#!/usr/bin/python - -""" -main.py: Main entry point for game -""" - -from builtins import range - -import os -import pygame -from pygame.locals import * -from gamedirector import * - -import resources -import game - -# Start -def main(mainpath): - - # Initialise pygame - pygame.init() - pygame.mixer.init() - - # start up director - framerate = 30 - screen_res = (800,600) - window_title = "Pyweek27: Breakout Blue (Team Chimera)" - dir = GameDirector(window_title, screen_res, framerate) - - # Load resources - resources.init(mainpath,screen_res) - - # Load game scenes - maingame = game.MainGame(dir, screen_res) - maingame.savepath = os.path.join(mainpath,'data','saved_progress.txt') - dir.addscene('maingame', maingame) - - pausescene = game.PauseScreen(dir, screen_res) - dir.addscene('pausescene', pausescene) - maingame.h_pausescene = pausescene - pausescene.h_maingame = maingame - - titlescene = game.TitleScreen(dir, screen_res) - titlescene.savepath = os.path.join(mainpath,'data','saved_progress.txt') - titlescene.h_maingame = maingame - dir.addscene('titlescene', titlescene) - - cutscene = game.CutScene(dir, screen_res) - dir.addscene('cutscene', cutscene) - - # start up director - #dir.change_scene('maingame', [True, 'testbig003']) - #dir.change_scene('maingame', [True, 'level3']) - #dir.change_scene('titlescene', []) - dir.change_scene('cutscene', ['team_chimera','none','titlescene',[]]) - #dir.change_scene('cutscene', ['news002','tense_chase','titlescene',[]]) - dir.loop() -