Return to repo list

tzed

Simple story-driven open world 2D CRPG.
Return to HMagellan.com

commit 5e082e72fb8dabc2bc095f3cc456143f62c23cee
parent 26be36a3edf52c4b5495859ee572f032d28dd258
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri,  4 Jun 2021 22:53:43 -0500

most basic window func

Diffstat:
Mmain.py | 7++++++-
Asrc/envvars.py | 4++++
Msrc/game.py | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/main.py b/main.py @@ -1,4 +1,9 @@ import pygame from src import game -g1 = game.Game() +pygame.mixer.pre_init(44100, -16, 4, 1024) +pygame.init() + +if __name__ == "__main__": + g1 = game.Game() + g1.mainloop() diff --git a/src/envvars.py b/src/envvars.py @@ -0,0 +1,4 @@ +# Game settings +SCREEN_WIDTH = 1024 +SCREEN_HEIGHT = 768 +FRAMERATE = 60 diff --git a/src/game.py b/src/game.py @@ -1,8 +1,65 @@ import pygame +from .envvars import * + +########### +# game.py # +########### + +# This file contains: +# 1. The 'Game' object, which represents the entire game application. class Game(object): """ - Generic game object. + Game is the object that represents the entire running + game application. Everything is a subcomponent of and + subordinate to the Game object, and there is only ever + a single instance of Game. """ + def __init__(self): - pass + + # Basic values + self.on = True + + # Mode values + self.state_mode = None + self.control_mode = None + + # Pygame objects + self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) + self.frame_clock = pygame.time.Clock() + + def shift_frames(self, framerate = FRAMERATE): + """ + Shift to the next frame of the game at the specified + framerate. + """ + self.frame_clock.tick(framerate) + + def update_game(self): + """ + Update the game elements, the screen, and any other + objects. + """ + + # First, fill the screen + self.screen.fill((0, 0, 0)) + + # Last, update the screen + pygame.display.update() + + def quit_game(self): + """ + Safely move the game into a quitting state. + """ + self.on = False + + def mainloop(self): + """ + The main game loop. Run once to start the game. Also + safely handles shutting down if the game is turned off. + """ + while self.on: + self.shift_frames() + self.update_game() + pygame.quit()