Window Class
Base Window
class. All other Window
s will inherit
this class.
Import statements
These are the other classes or files that this one depends on.
Variables
window
PyGame window instance that manages sprites drawn on the screen, etc.
background_color
List of three integers holding RGB values of the screen's background colour.
clock
Instance of pygame's time's Clock
. Used to limit FPS to 60.
running
True or false value that, when set to false, quits the game.
Functions
initfunction
Initialises pygame
with a screen size of 640x480. Sets the window title to the project's name, but this cannot be changed at runtime (you must use pygame's display's set_title("name")
instead). Sets up a background colour fill of white; this variable can be changed at runtime. Sets up a pygame Clock
to limit FPS to 60.
display_screen
Called manually once everything has been set up ready for the screen to be launched. Normally this can just be called at the end of the initfunction
of a class inheriting this one (usually called the project name, with Window
appended).
Inside a while
loop (with the condition that variable my running
is true
), calls the functions named after the events since the last frame, e.g. the KEYDOWN
event calls the key_down
function on itself. It then fills the background with its background_color
, flips the display on-screen and limits the frames to 60FPS using its Clock
.
set_screen_title(title)
Never automatically called. Pass in variable title
to this function to change the name of the window.
press_quit
Called when the user presses the 'X' button. Does nothing; it is left for the inherit
ing class to implement.
quit_game
Unloads pygame. Other unloading code should also be overriden here.
key_down(event)
Called when a key is pressed. Does nothing; it is left for the inherit
ing class to implement.