pyGhost/game.py
import pygameimport numpy as np from pyGhost.player import Playerfrom pyGhost.room import Room # Initialize and create the screenpygame.init()SCREEN = pygame.display.set_mode((1400, 800), pygame.FULLSCREEN)screen_rect = SCREEN.get_rect() # Title and iconpygame.display.set_caption('pyGhost')ICON = pygame.image.load('pyGhost/icons/map.png')pygame.display.set_icon(ICON) # ConstsDISTANCE = 1.8 def show_object(obj, position): SCREEN.blit(obj, position) class Game: def __init__(self): self.running = False self.player = Player(screen_rect) # Build room self.room = Room(SCREEN, None) Function `run` has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. def run(self): # Game loop player_x_change = 0 player_y_change = 0 self.running = True while self.running: # Background color set SCREEN.fill((0, 0, 0)) self.room.show_room() for event in pygame.event.get(): if event.type == pygame.QUIT: self.running = False elif event.type == pygame.KEYDOWN: if event.key in [pygame.K_ESCAPE, pygame.K_q]: self.running = False if event.key == pygame.K_LEFT: player_x_change = -DISTANCE if event.key == pygame.K_RIGHT: player_x_change = DISTANCE if event.key == pygame.K_DOWN: player_y_change = DISTANCE if event.key == pygame.K_UP: player_y_change = -DISTANCE elif event.type == pygame.KEYUP:Similar blocks of code found in 2 locations. Consider refactoring. if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: player_x_change = 0Similar blocks of code found in 2 locations. Consider refactoring. if event.key == pygame.K_UP or event.key == pygame.K_DOWN: player_y_change = 0 self.player.move(player_x_change, player_y_change, self.room.walls) show_object(self.player.figure, self.player.position) pygame.display.update()