I'm using Pygame to create a small game with few rectangle shapes. However, I want to learn more about classes, and I'm trying to use them. I'm very new to classes and inheritance, but I want to learn the best habits possible. I'm using Python 3.3.2.
import pygame
class Screen(object):
''' Creates main window and handles surface object. '''
def __init__(self, width, height):
self.WIDTH = width
self.HEIGHT = height
self.SURFACE = pygame.display.set_mode((self.WIDTH, self.HEIGHT), 0, 32)
class GameManager(object):
''' Handles game state datas and updates. '''
def __init__(self, screen):
self.screen = screen
pygame.init()
Window = Screen(800, 500)
Game = GameManager(Window)
I skipped a few functions to make it simpler. The thing that bothers me is that I've been told that I don't need GameManager
to be subclasses of Screen
. I was advised to use this implementation, but I find it very strange to use 'Window' as a parameter to GameManager
.
Do I need to use inheritance? Should I use super()
? Later on, I will have class Player
and I will need some of the attributes from the Screen
class. From the viewpoint of designing OO for a GUI game using Pygame.