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 23:27:39.232396677 -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 dp_main + +asyncio.run(dp_main.main(mainpath)) diff -ruN a/run_game.py b/run_game.py --- a/run_game.py 2026-11-04 23:27:13.674652980 -0300 +++ b/run_game.py 1969-12-31 21:00:00.000000000 -0300 @@ -1,13 +0,0 @@ -#!/usr/bin/python - -# run_game.py: run the game from here - -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/dp_main.py b/src/dp_main.py --- a/src/dp_main.py 1969-12-31 21:00:00.000000000 -0300 +++ b/src/dp_main.py 2026-11-04 23:27:39.227947327 -0300 @@ -0,0 +1,53 @@ +#!/usr/bin/python + +# main.py + +import os + +import pygame +from pygame.locals import * +from gamedirector import * + +import resources +import titles +import cutscene +import game + +# Start +async def main(mainpath): + + # Initialise pygame + pygame.init() + pygame.mixer.init() + + # start up director + framerate = 30 + window_size = (800,600) + window_title = 'Dark Physics' + dir = GameDirector(window_title, window_size, framerate) + + resources.init(mainpath, window_size) + + # Scenes + titlescreen = titles.TitleScreen(dir, window_size) + dir.addscene('titlescreen', titlescreen) + + cutscenes = cutscene.CutScene(dir, window_size) + dir.addscene('cutscene', cutscenes) + + maingame = game.MainGame(dir, window_size) + dir.addscene('maingame', maingame) + + scuff = game.ScuffleScene(dir, window_size) + dir.addscene('scuff', scuff) + + # Start it up + dir.change_scene('titlescreen', []) + #dir.change_scene('maingame', ['LT001']) + #dir.change_scene('maingame', ['seminar1']) + #dir.change_scene('cutscene', ['final']) + #dir.change_scene('scuff', []) + await dir.loop() + + + \ No newline at end of file diff -ruN a/src/gamedirector.py b/src/gamedirector.py --- a/src/gamedirector.py 2026-11-04 23:27:13.818536054 -0300 +++ b/src/gamedirector.py 2026-11-04 23:27:39.210279926 -0300 @@ -2,6 +2,8 @@ # gamedirector.py: director/scene structure +import asyncio +import time import pygame from pygame.locals import * @@ -20,10 +22,14 @@ self.frame = 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.frame = self.frame + 1 # Get quit events @@ -47,7 +53,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 23:27:13.822099201 -0300 +++ b/src/main.py 1969-12-31 21:00:00.000000000 -0300 @@ -1,53 +0,0 @@ -#!/usr/bin/python - -# main.py - -import os - -import pygame -from pygame.locals import * -from gamedirector import * - -import resources -import titles -import cutscene -import game - -# Start -def main(mainpath): - - # Initialise pygame - pygame.init() - pygame.mixer.init() - - # start up director - framerate = 30 - window_size = (800,600) - window_title = 'Dark Physics' - dir = GameDirector(window_title, window_size, framerate) - - resources.init(mainpath, window_size) - - # Scenes - titlescreen = titles.TitleScreen(dir, window_size) - dir.addscene('titlescreen', titlescreen) - - cutscenes = cutscene.CutScene(dir, window_size) - dir.addscene('cutscene', cutscenes) - - maingame = game.MainGame(dir, window_size) - dir.addscene('maingame', maingame) - - scuff = game.ScuffleScene(dir, window_size) - dir.addscene('scuff', scuff) - - # Start it up - dir.change_scene('titlescreen', []) - #dir.change_scene('maingame', ['LT001']) - #dir.change_scene('maingame', ['seminar1']) - #dir.change_scene('cutscene', ['final']) - #dir.change_scene('scuff', []) - dir.loop() - - - \ No newline at end of file