Pygame is a cross-platform set of Python modules desighned for writing games. It include Compluter graphics and sound libraries designed to be used with the Python programming language.

Let’s begin create our FPS game using the pygame library

pip install pygame

The initial structure of the project will consist of five files

  • main.py
  • player.py
  • object_renderer.py
  • raycasting.py
  • settings.py
  • map.py

Initial Setup

settings.py

# game settings
RES = WIDTH, HEIGHT = 1600, 900
FPS = 60

main.py

import pygame as pg
import sys
from settings import *

class Game:
    def __init__(self):
        pg.init()
        self.screen = pg.display.set_mode(RES)
        self.clock = pg.time.Clock()

    def new_game(self):
        pass

    def update(self):
        pg.display.flip()
        self.clock.tick(FPS)
        pg.display.set_caption(f'{self.clock.get_fps() : .1f}')

    def draw(self):
        self.screen.fill('black')

    def check_events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
                pg.quit()
                sys.exit()

    def run(self):
        while True:
            self.check_events()
            self.update()
            self.draw()


if __name__ == '__main__':
    game = Game()
    game.run()

image

Reference

Understaning and Implementation about RayCasting