User Tools

Site Tools


p5bg:bullet_game

This is an old revision of the document!


Bullet Game

Bullet Game is our near-end stage pygame 2d game framework example. We've already done at least 6 or 7 other games using pygame. So this will document the patterns we have learned.

We began by “just writing” a game, then the second part was refactoring the game. I wanted to make refactoring it's own project. What are the goals of this refactoring?

  • Refactoring
    • Encapsulation
    • Light Commentary (code commentary) ex. IN and OUT for functions.

The primary goal is encapsulation. So, we're going to break up the old main into several new classes.

PyGame Framework

The first part of this is the use of pygame framework. We'll describe the additions here.

Bullet Game

Here is the code we added, starting with main.py:

main.py

from Window import *
from Game import *

def main():
    window = Window()
    window.setCaption("Bullet Game")
    window.setSize(Screen.WIDTH, Screen.HEIGHT)
    window.setFont("assets/ps2p.ttf", 32)

    game = Game(window)
    game.start()

if __name__ == "__main__":
    main()
p5bg/bullet_game.1725439849.txt.gz · Last modified: 2024/09/04 08:50 by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki