def __init__(self, settings, screen, stats, nodes, stars, update_score, red, pink, orange, blue): super(Pacman, self).__init__() self.screen = screen self.screen_rect = screen.get_rect() self.settings = settings self.stats = stats self.stars = stars self.nodes = nodes self.update_score = update_score self.node = nodes.nodeList[6] self.red = red self.pink = pink self.orange = orange self.blue = blue self.images = self.frames('right') self.timer = Timer(self.images, wait=50) self.image = self.images[self.timer.frame_index()] self.rect = self.image.get_rect() self.eat_star = pygame.mixer.Sound('music/pacman_chomp.wav') self.eat_super_star = pygame.mixer.Sound('music/pacman_eatfruit.wav') self.open_portal = False self.curr_portal = 0 self.portal_a = Portal(self.settings, self.screen, self.rect.x, self.rect.y, 'orange') self.portal_b = Portal(self.settings, self.screen, self.rect.x, self.rect.y, 'blue') self.portal_init = False self.portals = [self.portal_a, self.portal_b]
def __init__(self): pygame.init() self.screen = pygame.display.set_mode((716, 793 + 60)) pygame.display.set_caption("Pacman Portal") self.bricks = Group() self.shields = Group() self.powerpills = Group() self.qpills = Group() self.maze = Maze(self.screen, self.bricks, self.shields, self.powerpills, self.qpills, brickfile='square', mazefile='images/pacmanportalmaze.txt', shieldfile='shield', powerpill='powerpill') self.increase = False self.scoreboard = Scorebord(self.screen, self) self.pacman = Pacman(self.screen, self.scoreboard, self) self.play_button = Button(self.screen, "PLAY GAME", 80 / 100) self.score_button = Button(self.screen, "HIGH SCORES", 90 / 100) self.menu = Menu() self.audio = Audio() self.fruit = Fruit(self.screen) self.blinky = Blinky(self.screen, self.pacman, self.scoreboard) self.inky = Inky(self.screen, self.pacman, self.scoreboard) self.pinky = Pinky(self.screen, self.pacman, self.scoreboard) self.clyde = Clyde(self.screen, self.pacman, self.scoreboard) self.oportal = Portal('o', self.pacman) self.bportal = Portal('b', self.pacman) self.active = False self.pause = False
def update_portals(self): """Check if portals need to be closed.""" portal_position = None if self.create_blue_portal: for portal in self.portals.sprites(): if portal.indicator == 0: portal.closing_portal = True else: portal_position = portal.position portal.other_portal = self.blue_bullet_position new_portal = Portal(screen=self.screen, image_list=self.sprite_sheet.blue_portal, position=self.blue_bullet_position, indicator=0, other_portal=portal_position) self.portals.add(new_portal) self.create_blue_portal = False if self.create_red_portal: for portal in self.portals.sprites(): if portal.indicator == 1: portal.closing_portal = True else: portal_position = portal.position portal.other_portal = self.red_bullet_position new_portal = Portal(screen=self.screen, image_list=self.sprite_sheet.red_portal, position=self.red_bullet_position, indicator=1, other_portal=portal_position) self.portals.add(new_portal) self.create_red_portal = False self.portals.update()
def checkpacmanportals(settings, screen, blocks, portals, portal_bullet): if settings.portal_passed: for portal in portals.sprites(): portals.remove(portal) settings.active_portals = 0 settings.portal_passed = False for bullet in portal_bullet.sprites(): if checkobjectwallcollisions(bullet, blocks, settings): settings.active_portals += 1 if settings.active_portals != 3: portal = None if settings.active_portals == 1: portal = Portal(screen, 1) portal.draw_portal(bullet.colx - 3, bullet.coly - 3) elif settings.active_portals == 2: portal = Portal(screen, 2) portal.draw_portal(bullet.colx - 3, bullet.coly - 3) for block in blocks.sprites(): if (portal.rect.x + 3) == block.rect.x and ( portal.rect.y + 3) == block.rect.y: if settings.active_portals == 1: block.type = "blockp1" elif settings.active_portals == 2: block.type = "blockp2" portal_bullet.remove(bullet) portals.add(portal) else: settings.active_portals -= 1
def create_portals(self, wall): x1 = self.laser.rect.centerx - (self.laser.velocity.x * 13) y1 = self.laser.rect.centery - (self.laser.velocity.y * 13) x2, y2 = self.game.WIDTH - x1 - 2, y1 + 2 # create portals and open self.game.portals = [ Portal(self.game, x1, y1, ['g5452', 'g5520', 'g5627', 'g5402-4']), Portal(self.game, x2, y2, ['g5452', 'g5520', 'g5627', 'g5402-4']) ] for p in self.game.portals: if not p.isopen: p.open(self.game) self.game.portals[0].draw() self.game.portals[1].draw()
def run_game(): pygame.init() pygame.display.set_caption("Portal") user32 = ctypes.windll.user32 screenSize = (user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)) screen = pygame.display.set_mode((screenSize), pygame.FULLSCREEN) settings = Settings(screenSize) settings.g_speed = settings.g_speed / 65 portais = Group() portal_inicial = Portal(settings, screen, None) portais.add(portal_inicial) ball = Ball(settings, screen) while True: check_events(ball) ball.update() screen.fill(settings.bg_color) for portal in portais: portal.check_collision(settings, screen, ball, portais) portal.draw_portal() pygame.draw.line(screen, (255, 255, 255), [0, settings.bottom], [settings.screen_width, settings.bottom], 5) ball.draw_ball() pygame.display.flip()
def test_portal(): res = [] res.append("=============================") res.append("1. Portal") portalSoup = request.makeGet("http://ufm.edu/Portal") por = Portal(portalSoup) return res
def new(self): self.all_sprites = pg.sprite.Group() self.platforms = pg.sprite.Group() self.saws = pg.sprite.Group() plts_conf, plr_conf, saw_conf, fl_saw_conf, prtl_conf = self.create_level( levels.level1) self.player = Player(*plr_conf, self) self.all_sprites.add(self.player) for plt in plts_conf: p = Platform(*plt) self.all_sprites.add(p) self.platforms.add(p) for saw in saw_conf: s = Saw(*saw) self.all_sprites.add(s) self.saws.add(s) for fl_saw in fl_saw_conf: s = FlyingSaw(*fl_saw, self.platforms) self.all_sprites.add(s) self.saws.add(s) self.portal = Portal(*prtl_conf) self.all_sprites.add(self.portal) self.run()
def fire_orange_portal(self): if not self.orange_active: port_loc = self.pac_man.find_portal_spot() self.oport = Portal(self.screen, 'orange') self.oport.rect.centerx = port_loc[0] self.oport.rect.centery = port_loc[1] self.active_ports.add(self.oport) self.orange_active = True
def portal(result): res = [] res.append("=============================") res.append("1. Portal") portalSoup = request.makeGet("http://ufm.edu/Portal") por = Portal(portalSoup) portalArray = por.init() #print(portalArray) res = res + portalArray return res
def __init__(self): pygame.init() self.settings = Settings() self.settings.reset() self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height)) self.intro = Intro(self.screen, self.settings) self.menu = Menu(self.screen, self.settings) pygame.display.set_caption("Pacman Portal") self.maze = Maze(self.screen, mazefile='pacmap.txt') self.pacman = Pacman(self.screen) self.dashboard = Dashboard(self.screen) self.portal_enter = Portal("Enter", self.screen, self.settings) self.portal_exit = Portal("Exit", self.screen, self.settings) scoresheet = open('scoresheet.txt', 'r') self.settings.score_high = int(scoresheet.read())
def get_portal(self): if self.curr_portal == 0: portal_color = 'orange' self.portal_a = Portal(self.settings, self.screen, self.rect.x, self.rect.y, portal_color) self.portals.insert(0, self.portal_a) self.portal_a.open(self) self.portal_a.blitme() self.portal_a.image_rect.centerx = self.rect.centerx + 20 self.portal_a.image_rect.centery = self.rect.centery self.curr_portal += 1 self.portal_init = True else: portal_color = 'blue' self.portal_b = Portal(self.settings, self.screen, self.rect.x, self.rect.y, portal_color) self.portals.insert(1, self.portal_b) self.portal_b.open(self) self.portal_b.blitme() self.portal_b.image_rect.centerx = self.rect.centerx + 20 self.portal_b.image_rect.centery = self.rect.centery self.curr_portal = 0 self.portal_init = True
def readPortalsFromJsonFile(portalsFile): lstPortals = [] with open(portalsFile, 'r') as json_file: data = json.load(json_file) for p in data: portal = Portal() portal.setCity(p["city"]) portal.setUrl(p["url"]) portal.setCoord(p["coord"]) portal.setCategorization(p["categorization"]) portal.setPlatform(p["platform"]) portal.setCategories(p['categories']) lstPortals.append(portal) return lstPortals[:5]
def _add_random_artifact(self, context, brick): if context.portal is None: if random() <= 1 / len(context.bricks): context.portal = Portal(brick.y, brick.x) return if random() <= 0.1: context.artifacts.append(Life(brick.y, brick.x)) return if random() <= 0.3: context.artifacts.append(SuperBombArtifact(brick.y, brick.x)) return if random() <= 0.3: context.artifacts.append(Point(brick.y, brick.x)) return if random() <= 0.4: context.monsters.append(Monster(context.board, context.user, 1, brick.y, brick.x)) return
def enter(): global guy, bg, wall, map, death, portal, clear, deathcount deathcount = 0 guy = Guy() portal = Portal() map = create_map() bg = Background() death = Death() clear = Clear() guy.set_bg(bg) bg.set_guy(guy) death.set_bg(bg) death.set_guy(guy) clear.set_bg(bg) clear.set_guy(guy) portal.set_bg(bg) for wall in map: wall.set_bg(bg)
def readFile(screen, blocks, shield, powerpills, portal): file = open("images/otherpacmanportalmaze.txt", "r") contents = file.read() line = '' all_lines = [] for chars in contents: if chars != '\n': line += chars else: all_lines.append(line) line = '' i = 0 j = 0 for rows in all_lines: for chars in rows: if chars == 'X': new = Blocks(screen) new.rect.x, new.rect.y = 13 * i, 13 * j blocks.add(new) elif chars == 'd': thepowerpill = Powerpills(screen) thepowerpill.rect.x, thepowerpill.rect.y = 13 * i, 13 * j powerpills.add(thepowerpill) elif chars == 'o': theshield = Shield(screen) theshield.rect.x, theshield.rect.y = 13 * i, 13 * j shield.add(theshield) # This is where the horizontal portal is supposed to be elif chars == 'h': pass # Vertical portal? elif chars == 'P': theportal = Portal(screen) theportal.rect.x, theportal.rect.y = 13 * i, 13 * j portal.add(theportal) pass i += 1 i = 0 j += 1
def new(self): # Создание нового уровня self.all_sprites = pg.sprite.Group( ) # Создание группы для всех спрайтов self.platforms = pg.sprite.Group() # Создание группы для платформ self.saws = pg.sprite.Group() # Создание группы для пил # Взятие двумерного кортежа настроек платформ и кортежа настроек игрока plts_conf, sws_cong, fl_sws_conf, plr_conf, prtl_conf = self.create_level( levels.level1) self.player = Player( *plr_conf, self ) # Создание игрока раскрыв кортеж настроек игрока и передав ссылку на игру self.all_sprites.add(self.player) # Добавление игрока в группу for plt in plts_conf: # Для каждого кортежа настроек в двумерном кортеже p = Platform( *plt ) # Создаем платформу по координатам раскрывая кортеж настроек # Добавляем платформу в группы self.all_sprites.add(p) self.platforms.add(p) for saw in sws_cong: # Для каждого кортежа настроек в двумерном кортеже s = Saw( *saw) # Создаем пилу по координатам раскрывая кортеж настроек # Добавляем платформу в группы self.all_sprites.add(s) self.saws.add(s) for saw in fl_sws_conf: # Для каждого кортежа настроек в двумерном кортеже s = FlyingSaw(*saw, self.platforms) # Создание летающей пилы # Добавляем летающую пилу в группы self.all_sprites.add(s) self.saws.add(s) self.portal = Portal(*prtl_conf) self.all_sprites.add(self.portal) self.run() # Запускаем уровень
def __init__(self): pygame.init() # declares all and sets classes, data, groups self.pac = Group() self.points = Group() self.pills = Group() self.fruits = Group() self.ghosts = Group() self.delay = 0 self.count = 0 self.timer = random.randint(3000, 5001) self.timer2 = 4500 self.settings = Settings() self.stats = GameStats(self.settings) self.screen = pygame.display.set_mode( (self.settings.screen_width, self.settings.screen_height)) pygame.display.set_caption("Pacman Portal") self.point = Point(self.screen, self.settings) self.maze = Maze(self.screen, self.settings, self.pac, self.points, self.pills, self.fruits, mazefile='images/maze.txt', brickfile='square') self.portal = Portal(self.screen, self.settings) self.pacman = Pacman(self.screen, self.settings, self.maze, self.portal, self.stats) self.sb = Scoreboard(self.settings, self.screen, self.stats, self.maze, self.portal) self.play_button = Startup(self.screen, self.settings, 'Play') self.score_button = HighScores(self.screen, "High Scores", self.settings) self.back_button = HighScores(self.screen, "Back (B)", self.settings)
def readPortalsFromJsonFile(portalsFile, platform=None): lstPortals = [] with open(portalsFile, 'r') as json_file: data = json.load(json_file) for p in data: portal = Portal() portal.setCity(p["city"]) portal.setUrl(p["url"]) portal.setCoord(p["coord"]) portal.setCategorization(p["categorization"]) portal.setPlatform(p["platform"]) portal.setCategories(p['categories']) lstPortals.append(portal) if platform is None: return lstPortals platform_portals = [] for portal in lstPortals: if (portal.getPlatform() == platform): platform_portals.append(portal) return platform_portals
def run_game(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("PacMan Portal") spritesheet1 = SpriteSheet('PacManNGhost.png', screen) spritesheet2 = SpriteSheet('MoreStuff.png', screen) spritesheet3 = SpriteSheet('Ghost.png', screen) title = Title(ai_settings, screen) ghostpoints = GhostPoints(screen, spritesheet1, spritesheet3) play_button = Button(ai_settings, screen, "Play", ai_settings.screen_width / 2, ai_settings.screen_height * 2 / 3) score_button = Button(ai_settings, screen, "High Scores", ai_settings.screen_width / 2, ai_settings.screen_height * 2 / 3 + 100) score = Score(ai_settings, screen, spritesheet1) pacman = Pacman(ai_settings, screen, spritesheet1) red_ghost = RedGhost(ai_settings, screen, spritesheet1) green_ghost = GreenGhost(ai_settings, screen, spritesheet3) orange_ghost = OrangeGhost(ai_settings, screen, spritesheet3) pink_ghost = PinkGhost(ai_settings, screen, spritesheet3) red_portal = Portal(ai_settings, screen, spritesheet2) blue_portal = Portal(ai_settings, screen, spritesheet2) left_hitbox = LeftHitbox(ai_settings, pacman) right_hitbox = RightHitbox(ai_settings, pacman) up_hitbox = UpHitbox(ai_settings, pacman) down_hitbox = DownHitbox(ai_settings, pacman) blocks = Group() g_blocks = Group() dots = Group() power_dots = Group() bullets = Group() side_portals = SidePortals(ai_settings, screen) fruit = Fruit(ai_settings, screen, spritesheet1) time = 1 maze = Maze(ai_settings, screen, spritesheet2, blocks, g_blocks, dots, power_dots) while True: timer = pygame.time.Clock() timer.tick(60) time += 1 if time == 61: time = 1 gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) gf.check_events(ai_settings, screen, spritesheet2, play_button, score_button, pacman, bullets) if ai_settings.game_on: pygame.mouse.set_visible(False) maze.reset_maze(spritesheet2, dots, power_dots) pacman.reset_pacman() red_ghost.reset_ghost() green_ghost.reset_ghost() orange_ghost.reset_ghost() pink_ghost.reset_ghost() fruit.reset_fruit() fruit.fruit_count = 0 bullets.empty() red_portal.reset_portal(pacman) blue_portal.reset_portal(pacman) score.reset_score() score.prep_lives() score.prep_score() score.prep_high_score() score.prep_level() gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) maze.pre_game_draw() sleep(5) while ai_settings.game_on: timer.tick(60) time += 1 if time == 61: time = 1 pacman.cooldown() red_ghost.cooldown() green_ghost.cooldown() orange_ghost.cooldown() pink_ghost.cooldown() gf.check_events(ai_settings, screen, spritesheet2, play_button, score_button, pacman, bullets) if pacman.active: gf.check_collisions(ai_settings, score, pacman, blocks, g_blocks, dots, power_dots, left_hitbox, right_hitbox, up_hitbox, down_hitbox, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, green_ghost, orange_ghost, pink_ghost) score.extra_life() if not pacman.active and score.lives > 0: score.lives -= 1 score.prep_lives() pacman.reset_pacman() red_ghost.reset_ghost() green_ghost.reset_ghost() orange_ghost.reset_ghost() pink_ghost.reset_ghost() fruit.reset_fruit() fruit.fruit_count = 0 bullets.empty() red_portal.reset_portal(pacman) blue_portal.reset_portal(pacman) sleep(3) gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) maze.pre_game_draw() sleep(5) elif not pacman.active and score.lives == 0: sleep(3) ai_settings.game_on = False pygame.mouse.set_visible(True) for x in range(0, len(score.high_score_list)): if score.points > score.high_score_list[x]: score.high_score_list.insert(x, score.points) score.high_score_list.pop() break high_score_file = open("High_Scores.txt", "w") for x in range(0, len(score.high_score_list) - 1): high_score_file.write( str(score.high_score_list[x]) + "\n") high_score_file.write(str(score.high_score_list[8])) high_score_file.close() print(list(map(str, score.high_score_list))) pacman.update_pacman() red_ghost.update_ghost(pacman) green_ghost.update_ghost(pacman) orange_ghost.update_ghost(pacman) pink_ghost.update_ghost(pacman) for bullet in bullets: bullet.update_bullet() left_hitbox.update_hitbox(pacman) right_hitbox.update_hitbox(pacman) up_hitbox.update_hitbox(pacman) down_hitbox.update_hitbox(pacman) red_portal.expire_portal(pacman) blue_portal.expire_portal(pacman) fruit.update_fruit() gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) if len(dots) == 0 and len(power_dots) == 0: gf.end_level(ai_settings, screen, time, spritesheet2, score, title, play_button, score_button, pacman, maze, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) elif ai_settings.score_on: while ai_settings.score_on: gf.check_events(ai_settings, screen, spritesheet2, play_button, score_button, pacman, bullets) gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost)
import os import subprocess import uuid import shutil import time import requests from portal import Portal portal = Portal(os.getenv("PORTAL_URL"), os.getenv("PORTAL_ID_MATRIX"), os.getenv("PORTAL_TOKEN_MATRIX")) CAMERA_WAKE = 2 @portal.on_request() def on_request(data): ffmpeg = subprocess.Popen([ "ffmpeg", "-i", "/dev/video0", "-video_size", "1280x720", "matrix/recording.mkv" ], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) time.sleep(CAMERA_WAKE) print("Recording started")
def __init__(self): pg.init() # Initialize pygame self.BG_COLOR = (0, 0, 0) # Set background to black self.screen = pg.display.set_mode( (Game.WIDTH, Game.HEIGHT)) # Set window dimensions pg.display.set_caption('Pac-Man') # Set name of the game # ****************** # *** Animations *** # ****************** self.CLOCK = pg.time.Clock() # Universal animation clock self.img_index = Timer(3) # Pac-man Animations self.last_img_index = self.img_index.frame_index() self.enemy_img_index = Timer(2) # Enemy Animations self.last_enemy_img_index = self.enemy_img_index.frame_index() self.enemy_scatter_index = TimerDual(2, 4) self.sprite_store = SpriteStore() # Instance for retrieving sprites portal_sprites = [] # Portal Animations for sprite in self.sprite_store.portal: # Fill list with unscaled images portal_sprites.append(pg.transform.scale(sprite, (20, 20))) self.portal_img_index = Timer(6) # ******************** # *** Game Objects *** # ******************** self.graph = Graph(self) # Graph (Map) obj self.pacman = Pacman(self, self.sprite_store.pacman, self.graph) # Pac-man obj self.portal1 = Portal(self, portal_sprites) # Portal One obj self.portal2 = Portal(self, portal_sprites) # Portal Two obj self.portals = [self.portal1, self.portal2] # List of Portal obj's self.blinky = Enemy(self, self.sprite_store.blinky, self.graph) # 1. Blinky obj (Enemy00) self.pinky = Enemy(self, self.sprite_store.pinky, self.graph) # 2. Pinky obj (Enemy01) self.clyde = Enemy(self, self.sprite_store.clyde, self.graph) # 3. Clyde obj (Enemy02) self.inkey = Enemy(self, self.sprite_store.inkey, self.graph) # 4. Inkey obj (Enemy03) self.enemies = [] # List of Enemy obj's self.enemies.append(self.blinky) # Add enemies to list self.enemies.append(self.pinky) self.enemies.append(self.clyde) self.enemies.append(self.inkey) self.bg = Background('images/map.png', (0, 60)) # Background Image obj self.small_logo = self.sprite_store.get_small_logo() self.big_logo = self.sprite_store.get_bigger_logo() # ********************** # *** Initialization *** # ********************** self.pacman.rect.centerx = self.graph.nodes[ 65].x # Set Pac-man to node 65 self.pacman.rect.centery = self.graph.nodes[65].y self.pacman.adj_node = self.graph.nodes[65] self.initialize_enemies() self.pellets = Group() for pellet in self.graph.pellets: self.pellets.add(pellet) self.score = 0 self.high_score = 0 self.win = False self.last_key = None # Last key the user inputted self.start_screen = True self.initial_start = True self.is_paused = False self.game_over = False self.new_life = False self.has_game_started = False # buttons self.play_button = True self.play_button_rect = None self.hs_show = False self.hs_button = True self.hs_button_rect = None self.back_button = False self.back_button_rect = None self.last_flip = pg.time.get_ticks() self.show = True self.debug_game_state() # define the RGB value for white, # green, blue colour . self.white = (255, 255, 255) self.green = (0, 255, 0) self.blue = (0, 0, 128) # ************************ # ********* U.I. ********* # ************************ self.pac_life_icon = self.sprite_store.pac_life self.cherry_icon = self.sprite_store.fruits[0] self.sound_icon = pg.image.load(r'images/sound_icon.png') self.load_high_score() # Load high scores # ************************ # ******** Sounds ******** # ************************ pg.mixer.init() # If you want more channels, change 8 to a desired number. 8 is the default number of channel pg.mixer.set_num_channels(8) self.voice = pg.mixer.Channel(5) self.portal = pg.mixer.Channel(6) # This is the sound channel self.eating_sound = pg.mixer.Sound('sounds/chomp.wav') self.death_sound = pg.mixer.Sound('sounds/pacman_death.wav') self.beginning_music = pg.mixer.Sound('sounds/beginning.wav') self.portal_shoot = pg.mixer.Sound('sounds/portal_shoot.wav') self.tp_sound = pg.mixer.Sound('sounds/tp.wav') self.eat_ghost_sound = pg.mixer.Sound('sounds/pacman_eat_ghost.wav') pg.mixer.music.load('sounds/pkmn_trainer_victory_cut_for_loop.wav') spac_imgs = self.sprite_store.get_pacman_sprites( ) # L indices -- 0, 1, 2 // R indices -- 0, 3, 4 self.starter_pacman = [] for img in spac_imgs: self.starter_pacman.append(pg.transform.scale(img, (48, 48))) self.starter_pacman_rect = self.starter_pacman[0].get_rect() self.starter_pacman_rect.centerx = -48 self.starter_pacman_rect.centery = 430 # ALL GHOSTS: L indices -- 4, 5 // R indices -- 0, 1 sblinky_imgs = self.sprite_store.get_blinky_sprites() self.starter_blinky = [] for img in sblinky_imgs: self.starter_blinky.append(pg.transform.scale(img, (48, 48))) self.starter_blinky_rect = self.starter_blinky[0].get_rect() self.starter_blinky_rect.centerx = -144 self.starter_blinky_rect.centery = 430 spinky_imgs = self.sprite_store.get_pinky_sprites() self.starter_pinky = [] for img in spinky_imgs: self.starter_pinky.append(pg.transform.scale(img, (48, 48))) self.starter_pinky_rect = self.starter_pinky[0].get_rect() self.starter_pinky_rect.centerx = -199 self.starter_pinky_rect.centery = 430 sclyde_imgs = self.sprite_store.get_clyde_sprites() self.starter_clyde = [] for img in sclyde_imgs: self.starter_clyde.append(pg.transform.scale(img, (48, 48))) self.starter_clyde_rect = self.starter_clyde[0].get_rect() self.starter_clyde_rect.centerx = -254 self.starter_clyde_rect.centery = 430 sinkey_imgs = self.sprite_store.get_inkey_sprites() self.starter_inkey = [] for img in sinkey_imgs: self.starter_inkey.append(pg.transform.scale(img, (48, 48))) self.starter_inkey_rect = self.starter_inkey[0].get_rect() self.starter_inkey_rect.centerx = -309 self.starter_inkey_rect.centery = 430 running_away = self.sprite_store.get_ghost_running_away_sprites() self.starter_running_away = [] for img in running_away: self.starter_running_away.append(pg.transform.scale(img, (48, 48))) self.starter_entities = [] self.starter_entities.append( [self.starter_blinky, self.starter_blinky_rect]) self.starter_entities.append( [self.starter_pinky, self.starter_pinky_rect]) self.starter_entities.append( [self.starter_clyde, self.starter_clyde_rect]) self.starter_entities.append( [self.starter_inkey, self.starter_inkey_rect]) self.starter_right = True
import json from portal import Portal from api_ckan import obter_metadados_datasets ##################################################################### ########## Lendo todos os portais do arquivo portals.json ########### ##################################################################### lstPortals = [] portalsFile = "portals.json" with open(portalsFile, 'r') as json_file: data = json.load(json_file) for p in data: portal = Portal() portal.setCity(p["city"]) portal.setUrl(p["url"]) portal.setCoord(p["coord"]) portal.setCategorization(p["categorization"]) portal.setPlatform(p["platform"]) portal.setCategories(p['categories']) lstPortals.append(portal) #################################################################### ###### Obtendo portais que utilizam o CKAN como plataforma ######### #################################################################### ckan_portals = [] for portal in lstPortals:
def __init__(self, screen, mazefile, stats, clock): self.screen = screen self.stats = stats self.clock = clock self.radio = pygame.mixer self.radio.init() self.filename = mazefile with open(self.filename, 'r') as f: self.rows = f.readlines() self.maze_obj = [] size = Maze.BRICK_SIZE self.brick = Image(screen, 'brick', size, size) self.default_ports = pygame.sprite.Group() self.def_port_list = [] self.lport = Portal(self.screen, 'blue') self.rport = Portal(self.screen, 'orange') self.pac_dots = pygame.sprite.Group() self.pac_dot = Pacdot(screen, pygame.image.load('images/pacdot.png')) self.pac_dot.image = pygame.transform.scale(self.pac_dot.image, (8, 8)) self.power_dots = pygame.sprite.Group() self.power = Pacdot(screen, pygame.image.load('images/pacdot.png')) self.power.image = pygame.transform.scale(self.power.image, (15, 15)) self.shield = Image(screen, 'shield', size, size) self.pac_man = Pacman(screen, self) self.blinky = Ghost(screen, self, 'blinky') self.pinky = Ghost(screen, self, 'pinky') self.inky = Ghost(screen, self, 'inky') self.clyde = Ghost(screen, self, 'clyde') self.ghosts = pygame.sprite.Group() self.fruit = None self.fruits = pygame.sprite.Group() self.deltax = self.deltay = Maze.BRICK_SIZE # used for menu purposes self.title = None self.title_rect = None self.start_button = None self.scores_button = None # end of menu items # used for sounds self.intro = self.radio.Sound('sounds/intro.wav') self.ambient = self.radio.Sound('sounds/ambient.wav') self.eatdot = self.radio.Sound('sounds/eatdot.wav') self.eatghost = self.radio.Sound('sounds/eatghost.wav') self.powersound = self.radio.Sound('sounds/power.wav') self.death = self.radio.Sound('sounds/death.wav') self.gameover = self.radio.Sound('sounds/gameover.wav') self.ambient_playing = False self.power_playing = False # end of sounds self.lives_counter = pygame.sprite.Group() self.lives_sprites = [] self.active_ports = pygame.sprite.Group() self.bport = None self.oport = None self.blue_active = False self.orange_active = False self.build()
def Game(): pygame.init() gamesettings = Settings() screen = pygame.display.set_mode( (gamesettings.screen_width, gamesettings.screen_height)) pygame.display.set_caption("Pacman Portal") # Start screen showgamestats = GameStats(screen, gamesettings) startScreen = StartScreen(screen, gamesettings, showgamestats) # Grouping blocks and pellets and ghosts blocks = Group() powerpills = Group() shield = Group() portals = Group() ghosts = Group() intersections = Group() fruit = Fruit(screen) thepacman = Pacman(screen, gamesettings) # Making the ghosts redghost = Ghosts(screen, "red") cyanghost = Ghosts(screen, "cyan") orangeghost = Ghosts(screen, "orange") pinkghost = Ghosts(screen, "pink") ghosts.add(redghost) ghosts.add(cyanghost) ghosts.add(orangeghost) ghosts.add(pinkghost) # Making the two portals orange = Portal(screen, "orange") blue = Portal(screen, "blue") portals.add(orange) portals.add(blue) startScreen.makeScreen(screen, gamesettings) fruit.fruitReset() gf.readFile(screen, blocks, shield, powerpills, intersections) frames = 0 # for the victory fanfare and death animation # play intro chime playIntro = True screen.fill(BLACK) while True: if (gamesettings.game_active): pygame.time.Clock().tick(120) #120 fps lock screen.fill(BLACK) showgamestats.blitstats() gf.check_events(thepacman, powerpills, gamesettings, orange, blue) gf.check_collision(thepacman, blocks, powerpills, shield, ghosts, intersections, showgamestats, gamesettings, fruit, orange, blue) for block in blocks: block.blitblocks() for theshield in shield: theshield.blitshield() for pill in powerpills: pill.blitpowerpills() for portal in portals: portal.blitportal() for ghost in ghosts: ghost.blitghosts() ghost.update() if (ghost.DEAD): ghost.playRetreatSound() elif (ghost.afraid): ghost.playAfraidSound( ) # if ghosts are afraid, loop their sound for intersection in intersections: intersection.blit() fruit.blitfruit() thepacman.blitpacman() thepacman.update() if (len(powerpills) == 0): gamesettings.game_active = False gamesettings.victory_fanfare = True if (playIntro and pygame.time.get_ticks() % 200 <= 50): mixer.Channel(2).play( pygame.mixer.Sound('sounds/pacman_beginning.wav')) pygame.time.wait(4500) playIntro = False elif (gamesettings.victory_fanfare): if (frames <= 120): for block in blocks: block.color = ((255, 255, 255)) block.blitblocks() elif (frames <= 240): for block in blocks: block.color = ((0, 0, 255)) block.blitblocks() elif (frames <= 360): for block in blocks: block.color = ((255, 255, 255)) block.blitblocks() elif (frames <= 480): for block in blocks: block.color = ((0, 0, 255)) block.blitblocks() else: gamesettings.game_active = True gamesettings.victory_fanfare = False thepacman.resetPosition() for ghost in ghosts: ghost.resetPosition() ghost.speed += 1 showgamestats.level += 1 fruit.fruitReset() gf.readFile(screen, blocks, shield, powerpills, intersections) frames = 0 pygame.time.wait(1000) frames += 1 elif (thepacman.DEAD): thepacman.deathAnimation(frames) frames += 1 if (frames > 600): gamesettings.game_active = True thepacman.DEAD = False thepacman.resetPosition() for ghost in ghosts: ghost.resetPosition() frames = 0 pygame.time.wait(1000) if (showgamestats.num_lives < 0): #reset game and save score screen.fill(BLACK) pygame.time.wait(2000) gamesettings.game_active = False thepacman.resetPosition() for ghost in ghosts: ghost.resetPosition() ghost.speed = 1 showgamestats.num_lives = 3 showgamestats.save_hs_to_file() showgamestats.score = 0 showgamestats.level = 1 fruit.fruitReset() playIntro = True # reset the chime gf.readFile(screen, blocks, shield, powerpills, intersections) startScreen.makeScreen(screen, gamesettings) pygame.display.flip()
import os from flask import request, current_app, render_template, abort from flask_debugtoolbar import DebugToolbarExtension from flask.ext.admin import Admin from portal import blueprint, Page, Portal from portal.editing import PortalFileAdmin app = Portal(__name__) app.config['SECRET_KEY'] = '3294038' app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False app.debug = True toolbar = DebugToolbarExtension(app) # Required by the portal app.config['PAGES_DIR'] = os.path.join(app.root_path, 'pages') app.register_blueprint(blueprint) admin = Admin(app, 'Portal Admin', template_mode='bootstrap3') admin.add_view(PortalFileAdmin(app.root_path, '/', name='Files')) print "portal running on port 5000" app.run()
import os import time from portal import Portal portal = Portal( os.getenv("PORTAL_URL"), os.getenv("PORTAL_ID_ECHO"), os.getenv("PORTAL_TOKEN_ECHO") ) @portal.on_request() def on_request(data): print(data) time.sleep(5) return {"title": data, "description": "Echo portal, made with <3 by breq!"} portal.run()
score_table = HighScoreTable(screen) # used to control fps clock = pygame.time.Clock() # max fps MAX_PFS = 30 # game intro object intro = GameIntro(screen, play_button, high_score_button, ai_settings) score_board = Scoreboard(ai_settings, screen, stats, score_table) fruit = Fruit(0, 0, 19, 19, pac.maze, screen, stats, pac) portal = Portal(screen, pac, pac.rect.x, pac.rect.y, 32, 32, os.getcwd() + '/images/invis_portal.png') fire = False def gameloop(): # temporary fix for variables will create classes and clean the code global fire while not stats.game_exit: # debugging # print(str(pac.rect.x) + ", " + str(pac.rect.y)) # print(pac.stats.score) # print(pac.stats.pacman_left) while stats.game_over or stats.intro: time.sleep(0.01)