Compare commits
6 Commits
77406db737
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
4d32ff6f5a
|
|||
| dee653ca31 | |||
| 32aa61533c | |||
| 214edfbe3a | |||
| 1b84249f47 | |||
| 89241c2939 |
29
__main__.py
29
__main__.py
@ -7,8 +7,7 @@ import attr
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# TODO: Auto install game requirements
|
# TODO: Add Discord rich presence
|
||||||
# TODO: If a game is specified, only install those requirements
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
log = logging.getLogger('PainJamLauncher')
|
log = logging.getLogger('PainJamLauncher')
|
||||||
@ -54,8 +53,6 @@ for path in os.listdir('../'):
|
|||||||
|
|
||||||
log.debug(f'Loaded game {gameID}')
|
log.debug(f'Loaded game {gameID}')
|
||||||
|
|
||||||
run = True
|
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
# I'm sorry, I prefer object-oriented programming. So sue me.
|
# I'm sorry, I prefer object-oriented programming. So sue me.
|
||||||
@ -79,18 +76,18 @@ class Launcher:
|
|||||||
os.chdir(game.path)
|
os.chdir(game.path)
|
||||||
# Load the games game.py file.
|
# Load the games game.py file.
|
||||||
spec = importlib.util.spec_from_file_location(game.id, os.path.join(game.path, 'game.py'))
|
spec = importlib.util.spec_from_file_location(game.id, os.path.join(game.path, 'game.py'))
|
||||||
foo = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(foo)
|
spec.loader.exec_module(module)
|
||||||
# Initialise the games Game class, then set the
|
# Initialise the games Game class, then set the
|
||||||
# current game to that.
|
# current game to that.
|
||||||
self.currentGame = foo.Game(self.gameSurface)
|
self.currentGame = module.Game(self.gameSurface)
|
||||||
# Set the window title to the games name
|
# Set the window title to the games name
|
||||||
pygame.display.set_caption(game.name)
|
pygame.display.set_caption(game.name)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if self.gameRunning:
|
if self.gameRunning:
|
||||||
self.currentGame.onEvent(event)
|
self.currentGame._onEvent(event)
|
||||||
|
|
||||||
# CTRL+ESC
|
# CTRL+ESC
|
||||||
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE and event.mod == 64):
|
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE and event.mod == 64):
|
||||||
@ -101,7 +98,7 @@ class Launcher:
|
|||||||
os.chdir(originalCWD)
|
os.chdir(originalCWD)
|
||||||
pygame.display.set_caption('Pain Jam Launcher')
|
pygame.display.set_caption('Pain Jam Launcher')
|
||||||
# If we launched directly into a game
|
# If we launched directly into a game
|
||||||
if args.gameID != None:
|
if args.gameID is not None:
|
||||||
# Exit the launcher when we exit the game
|
# Exit the launcher when we exit the game
|
||||||
self.running = False
|
self.running = False
|
||||||
else:
|
else:
|
||||||
@ -111,23 +108,23 @@ class Launcher:
|
|||||||
elif event.type == pygame.KEYDOWN:
|
elif event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_1:
|
if event.key == pygame.K_1:
|
||||||
self.loadGame(games['russianRoulette'])
|
self.loadGame(games['russianRoulette'])
|
||||||
|
|
||||||
if self.gameRunning:
|
if self.gameRunning:
|
||||||
self.currentGame.update()
|
self.currentGame._update()
|
||||||
self.screen.blit(self.currentGame.surf, (0, 0))
|
self.screen.blit(self.currentGame._surf, (0, 0))
|
||||||
else:
|
else:
|
||||||
self.screen.fill((0, 0, 0))
|
self.screen.fill((0, 0, 0))
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
self.clock.tick(args.fpsCap)
|
self.clock.tick(args.fpsCap)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def gameRunning(self):
|
def gameRunning(self):
|
||||||
return self.currentGame != None
|
return self.currentGame is not None
|
||||||
|
|
||||||
launcher = Launcher()
|
launcher = Launcher()
|
||||||
if args.gameID != None:
|
if args.gameID is not None:
|
||||||
launcher.loadGame(games[args.gameID])
|
launcher.loadGame(games[args.gameID])
|
||||||
while launcher.running:
|
while launcher.running:
|
||||||
launcher.update()
|
launcher.update()
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
pygame-ce
|
pygame-ce
|
||||||
|
pishock
|
||||||
attrs
|
attrs
|
||||||
Reference in New Issue
Block a user