def __init__(self): pygame.init() pygame.mixer.pre_init(44100, 16, 2, 4096) self.settings = Settings() self.settings.start_intro_music() self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height)) pygame.display.set_caption("Pacman Portal") self.clock = pygame.time.Clock() self.radius = 1 self.start = 1 self.end = 10 self.begin = pygame.time.get_ticks() self.wait = 800 self.startup = Start(self.screen, self.settings) self.stats = Stats(self.settings) self.sb = Scoreboard(self.settings, self.screen, self.stats) self.maze = Maze(self.screen, mazefile='images/pacman_portal_maze.txt', brickfile='square', orangeportalfile='portal_orange', blueportalfile='portal_blue', shieldfile='shield', pointfile='point_pill', gatefile="gate") self.pacman = Pacman(self.screen, mazefile='images/pacman_portal_maze.txt') self.red = Red(self.screen, mazefile='images/pacman_portal_maze.txt') self.blue = Blue(self.screen, mazefile='images/pacman_portal_maze.txt') self.orange = Orange(self.screen, mazefile='images/pacman_portal_maze.txt') self.pink = Pink(self.screen, mazefile='images/pacman_portal_maze.txt') self.inc = 0
def create_ghost(self): self.red = Red(self.screen, self.stats, self.pacman, self.sb, self.maze) self.red.centerx = self.screen_rect.left - 100 self.red.rect.centery = self.screen_rect.centery self.red.index = 4 self.blue = Blue(self.screen, self.stats, self.pacman) self.blue.centerx = self.screen_rect.left - 125 self.blue.rect.centery = self.screen_rect.centery self.blue.index = 4 self.orange = Orange(self.screen, self.stats, self.pacman) self.orange.centerx = self.screen_rect.left - 150 self.orange.rect.centery = self.screen_rect.centery self.orange.index = 4 self.pink = Pink(self.screen, self.stats, self.pacman) self.pink.centerx = self.screen_rect.left - 175 self.pink.rect.centery = self.screen_rect.centery self.pink.index = 4
def __init__(self): pygame.init() self.screen = pygame.display.set_mode((735, 800)) pygame.display.set_caption("Pac-man") self.settings = Settings() self.radius = 1 self.start = 2 self.end = 10 self.begin = pygame.time.get_ticks() self.wait = 800 self.stats = Stats(self.settings) self.pb = Button(self.screen) self.maze = Maze(self.screen, 'images/maze.txt', 'images/cube0.png', 'images/gate0.png', 'images/dot0.png') self.sb = Scoreboard(self.settings, self.screen, self.stats, self.maze, self.pb) self.player = Player(self.settings, self.screen, self.stats, self.sb, self.maze) self.red = Red(self.screen, self.stats, self.player, self.sb, self.maze) self.blue = Blue(self.screen, self.stats, self.player) self.orange = Orange(self.screen, self.stats, self.player) self.pink = Pink(self.screen, self.stats, self.player) self.menu = Menu(self.screen, self.stats, self.sb, self.pb, self.maze)
class OrangeWidget(QtOpenGL.QGLWidget): def __init__(self, parent=None): super(OrangeWidget, self).__init__(parent) self.camera = MayaCamera() self.timer = QtCore.QTime() self.reset_fps() @property def fps(self): return 1000.0 * self.frames / max(1, self.timer.elapsed()) def reset_fps(self): self.frames = 0 self.timer.start() def cleanup(self): self.orange = None def initializeGL(self): self.cleanup() self.orange = Orange() self.orange.set_camera_xform(self.camera.view_matrix_inv.data()) log.info('OpenGL %s' % glGetString(GL_VERSION)) def paintGL(self): fb = self.orange.render() self.drawTexture(QtCore.QRectF(-1,-1,2,2), fb) glFinish() self.update() self.frames += 1 def resizeGL(self, width, height): glViewport(0, 0, width, height) self.camera.aspect = float(width) / height def mousePressEvent(self, event): self.last_pos = event.posF() def mouseMoveEvent(self, event): dxy = event.posF() - self.last_pos dx = dxy.x() / self.width() dy = dxy.y() / self.height() if event.buttons() & QtCore.Qt.LeftButton: self.camera.rotate(dx, dy) elif (event.buttons() & Qt.MidButton) or event.modifiers(): self.camera.pan(dx, dy) elif event.buttons() & QtCore.Qt.RightButton: self.camera.zoom(dx, dy) self.orange.set_camera_xform(self.camera.view_matrix_inv.data()) self.last_pos = event.posF() def wheelEvent(self, event): self.camera.zoom(event.delta() / 360.0, 0.0) self.orange.set_camera_xform(self.camera.view_matrix_inv.data())
class OrangeWidget(QtOpenGL.QGLWidget): def __init__(self, parent=None): super(OrangeWidget, self).__init__(parent) self.camera = MayaCamera() self.timer = QtCore.QTime() self.reset_fps() @property def fps(self): return 1000.0 * self.frames / max(1, self.timer.elapsed()) def reset_fps(self): self.frames = 0 self.timer.start() def cleanup(self): self.orange = None def initializeGL(self): self.cleanup() self.orange = Orange() self.orange.set_camera_xform(self.camera.view_matrix_inv.data()) log.info('OpenGL %s' % glGetString(GL_VERSION)) def paintGL(self): fb = self.orange.render() self.drawTexture(QtCore.QRectF(-1, -1, 2, 2), fb) glFinish() self.update() self.frames += 1 def resizeGL(self, width, height): glViewport(0, 0, width, height) self.camera.aspect = float(width) / height def mousePressEvent(self, event): self.last_pos = event.posF() def mouseMoveEvent(self, event): dxy = event.posF() - self.last_pos dx = dxy.x() / self.width() dy = dxy.y() / self.height() if event.buttons() & QtCore.Qt.LeftButton: self.camera.rotate(dx, dy) elif (event.buttons() & QtCore.Qt.MidButton) or event.modifiers(): self.camera.pan(dx, dy) elif event.buttons() & QtCore.Qt.RightButton: self.camera.zoom(dx, dy) self.orange.set_camera_xform(self.camera.view_matrix_inv.data()) self.last_pos = event.posF() def wheelEvent(self, event): self.camera.zoom(event.delta() / 360.0, 0.0) self.orange.set_camera_xform(self.camera.view_matrix_inv.data())
def initializeGL(self): self.cleanup() self.orange = Orange() self.orange.set_camera_xform(self.camera.view_matrix_inv.data()) log.info('OpenGL %s' % glGetString(GL_VERSION))
class Menu: def __init__(self, screen, stats, sb, play_button, maze): self.settings = Settings() self.screen = screen self.screen_rect = screen.get_rect() self.button = play_button self.stats = stats self.sb = sb self.maze = maze self.menu_color = (0, 0, 0) self.text_color = (250, 250, 210) self.font = pygame.font.SysFont(None, 150) self.title = "Pac-man" self.prep_screen() def prep_screen(self): self.title_image = self.font.render(self.title, True, self.text_color, self.menu_color) self.title_image_rect = self.title_image.get_rect() self.title_image_rect.centerx = self.screen_rect.centerx self.title_image_rect.centery = self.screen_rect.top + 100 self.create_pacman() self.create_ghost() def draw_menu(self): self.screen.fill((0, 0, 0)) self.screen.blit(self.title_image, self.title_image_rect) self.button.draw_button() self.animate_pacman() self.animate_ghost() def create_pacman(self): self.pacman = Player(self.settings, self.screen, self.stats, self.sb, self.maze) self.pacman.centerx = self.screen_rect.left self.pacman.rect.centery = self.screen_rect.centery self.pacman.index = 4 def create_ghost(self): self.red = Red(self.screen, self.stats, self.pacman, self.sb, self.maze) self.red.centerx = self.screen_rect.left - 100 self.red.rect.centery = self.screen_rect.centery self.red.index = 4 self.blue = Blue(self.screen, self.stats, self.pacman) self.blue.centerx = self.screen_rect.left - 125 self.blue.rect.centery = self.screen_rect.centery self.blue.index = 4 self.orange = Orange(self.screen, self.stats, self.pacman) self.orange.centerx = self.screen_rect.left - 150 self.orange.rect.centery = self.screen_rect.centery self.orange.index = 4 self.pink = Pink(self.screen, self.stats, self.pacman) self.pink.centerx = self.screen_rect.left - 175 self.pink.rect.centery = self.screen_rect.centery self.pink.index = 4 def animate_pacman(self): self.pacman.screen_animate() self.pacman.blitme() def animate_ghost(self): self.red.screen_animate() self.red.blitme() self.blue.screen_animate() self.blue.blitme() self.orange.screen_animate() self.orange.blitme() self.pink.screen_animate() self.pink.blitme()
class Game: BLACK = (0, 0, 0) def __init__(self): pygame.init() pygame.mixer.pre_init(44100, 16, 2, 4096) self.settings = Settings() self.settings.start_intro_music() self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height)) pygame.display.set_caption("Pacman Portal") self.clock = pygame.time.Clock() self.radius = 1 self.start = 1 self.end = 10 self.begin = pygame.time.get_ticks() self.wait = 800 self.startup = Start(self.screen, self.settings) self.stats = Stats(self.settings) self.sb = Scoreboard(self.settings, self.screen, self.stats) self.maze = Maze(self.screen, mazefile='images/pacman_portal_maze.txt', brickfile='square', orangeportalfile='portal_orange', blueportalfile='portal_blue', shieldfile='shield', pointfile='point_pill', gatefile="gate") self.pacman = Pacman(self.screen, mazefile='images/pacman_portal_maze.txt') self.red = Red(self.screen, mazefile='images/pacman_portal_maze.txt') self.blue = Blue(self.screen, mazefile='images/pacman_portal_maze.txt') self.orange = Orange(self.screen, mazefile='images/pacman_portal_maze.txt') self.pink = Pink(self.screen, mazefile='images/pacman_portal_maze.txt') self.inc = 0 def __str__(self): return 'Game(Pacman Portal), maze=' + str(self.maze) + ')' def open_portal(self, x, y, color): for r in range(self.start, self.end): pygame.gfxdraw.circle(self.screen, x, y, r, color) now = pygame.time.get_ticks() if now < self.begin + self.wait: self.inc = 1 elif now < self.begin + 4 * self.wait: self.inc = 0 else: self.inc = -1 self.start += self.inc self.start = max(1, self.start) self.end += self.inc def play(self): clock = pygame.time.Clock() eloop = EventLoop(finished=False) while not eloop.finished: eloop.check_events(self.screen, self.pacman, self.startup) if self.startup.playing: pygame.mixer.music.stop() if not self.settings.flag_chomp: self.settings.chomp_music() self.settings.flag_chomp = True self.settings.chomp_music() self.pacman.update(self.maze, self.settings, self.stats, self.sb, self.red, self.blue, self.orange, self.pink) self.red.update(self.maze, self.settings, self.stats, self.pacman, self.startup, self.blue, self.pink, self.orange, self.sb) self.blue.update(self.maze, self.settings, self.stats, self.pacman, self.startup, self.red, self.pink, self.orange, self.sb) self.orange.update(self.maze, self.settings, self.stats, self.pacman, self.startup, self.blue, self.pink, self.red, self.sb) self.pink.update(self.maze, self.settings, self.stats, self.pacman, self.startup, self.blue, self.red, self.orange, self.sb) self.update_screen() clock.tick(155) def update_screen(self): if not self.startup.playing: self.startup.draw_bg() self.startup.draw_button() else: self.screen.fill(Game.BLACK) self.maze.blitme() self.pacman.blitme() self.red.blitme() self.blue.blitme() self.orange.blitme() self.pink.blitme() self.open_portal(100, 100, (240, 100, 20)) self.sb.show_score() pygame.display.flip()
class Game: def __init__(self): pygame.init() self.screen = pygame.display.set_mode((735, 800)) pygame.display.set_caption("Pac-man") self.settings = Settings() self.radius = 1 self.start = 2 self.end = 10 self.begin = pygame.time.get_ticks() self.wait = 800 self.stats = Stats(self.settings) self.pb = Button(self.screen) self.maze = Maze(self.screen, 'images/maze.txt', 'images/cube0.png', 'images/gate0.png', 'images/dot0.png') self.sb = Scoreboard(self.settings, self.screen, self.stats, self.maze, self.pb) self.player = Player(self.settings, self.screen, self.stats, self.sb, self.maze) self.red = Red(self.screen, self.stats, self.player, self.sb, self.maze) self.blue = Blue(self.screen, self.stats, self.player) self.orange = Orange(self.screen, self.stats, self.player) self.pink = Pink(self.screen, self.stats, self.player) self.menu = Menu(self.screen, self.stats, self.sb, self.pb, self.maze) def open_portal(self, x, y, color): for r in range(self.start, self.end): pygame.gfxdraw.circle(self.screen, x, y, r, color) now = pygame.time.get_ticks() if now < self.begin + self.wait: self.inc = 1 elif now < self.begin + 4 * self.wait: self.inc = 0 else: self.inc = -1 self.start += self.inc self.start = max(1, self.start) self.end += self.inc def play(self): clock = pygame.time.Clock() eloop = EventLoop(finished=False) self.menu.prep_screen() while not eloop.finished: eloop.check_events(self.settings, self.screen, self.stats, self.sb, self.player, self.pb, self.maze) if self.stats.game_active: self.player.update(self.maze) self.red.update() self.blue.update() self.orange.update() self.pink.update() self.display_game() clock.tick(20) def display_game(self): self.screen.fill((0, 0, 0)) self.maze.blitme() self.open_portal(365, 550, (240, 100, 20)) self.player.blitme() self.red.blitme() self.blue.blitme() self.orange.blitme() self.pink.blitme() self.sb.show_score() if not self.stats.game_active: self.menu.draw_menu() if self.stats.HS_active: self.display_HS_menu() pygame.display.flip() def display_HS_menu(self): self.screen.fill((0, 0, 0)) self.sb.prep_list() self.sb.display_list()
from orange import Orange from person import Person person = Person('Andrei', 25) orange = Orange("Citruc", 12, 'orange', 1.2, True, person, 36) print(orange.buyer.print_name()) print(f'Today {orange.buyer.print_name()} bought {orange.amount} oranges for {round(orange.full_price())}kr') orange.change_price(40) print(f"Ooops! New price for 1kg! {orange.price}kr")