#!/usr/bin/env python3 import pygame as pg import pacman_sprite import pacman as m_pacman # m_ for module to avoid conflicts from physic_motor import PhysicMotor import pacmap as m_pacmap import sys pg.init() class Screen: def __init__(self, size, pacmap: m_pacmap.Map, physic_motor: PhysicMotor, pacman: m_pacman.Pacman): self.screen = pg.display.set_mode(size) # self.screen.set_caption("Pacman") self.physic_motor = physic_motor self.pacman = pacman self.pacman_sprite = pacman_sprite.PacmanSprite(size[0]/28) self.clock = pg.time.Clock() self.max_fps = 30 self.loop() def user_events(self): key = pg.key.get_pressed() if key[pg.K_UP]: pacman.change_dir(m_pacman.direction.up) if key[pg.K_DOWN]: pacman.change_dir(m_pacman.direction.down) if key[pg.K_LEFT]: pacman.change_dir(m_pacman.direction.left) if key[pg.K_RIGHT]: pacman.change_dir(m_pacman.direction.right) def refresh(self): """refresh/redraw all""" pass def create_maze_surface(self): pass def loop(self): while 1: for event in pg.event.get(): if event.type == pg.QUIT: sys.exit() self.user_events() self.physic_motor.move_all() self.refresh() self.clock.tick(max_fps) if __name__ == '__main__': pacman = m_pacman.Pacman((1,1)) pacmap = m_pacmap.Map(maze_img_file="../pacmap_maze_1.png") phys_motor = PhysicMotor(pacmap, pacman) screen = Screen((280, 310), pacmap, phys_motor, pacman)