def levelUp(self): promijenjiva = False if self.ghost1.sakriven == True and self.ghost2.sakriven == True and self.ghost3.sakriven == True and self.ghost4.sakriven == True: promijenjiva = True if promijenjiva == True: if self.broj1 - 1 >= 1: self.broj1 -= 1 self.level = self.level + 1 text3 = "Level: " + (str(self.level)) self.label3.setText(text3) self.label3.setFont(QtGui.QFont('SansSerif', 15)) mapa = self.dots.tacka_pom.copy() self.dots.tacka = mapa self.tt = 0 self.ghost1 = g.Ghost(8, 10) self.ghost2 = g.Ghost(9, 10) self.ghost3 = g.Ghost(11, 10) self.ghost4 = g.Ghost(12, 10) self.ghost2.i = QImage('images/ghost1.png') self.ghost3.i = QImage('images/ghost2.png') self.ghost4.i = QImage('images/ghost3.png') zivot1 = self.player1.zivot zivot2 = self.player2.zivot bodovi1 = self.player1.poeni bodovi2 = self.player2.poeni self.player1 = p.Player() self.player1.id = 1 self.player1.zivot = zivot1 self.player1.poeni = bodovi1 if self.player1.zivot == 0: self.player1.game_over = True self.player2 = p.Player(20, 10) self.player2.id = 2 self.player2.zivot = zivot2 self.player2.poeni = bodovi2 self.player2.i = self.player2.i3 if self.player2.zivot == 0: self.player2.game_over = True self.opcija = False #bonuuus self.brojac = 0 self.brojac1 = 0
def capture(url, wait_for_text='', selector='body', viewport_size='800x450', filename='capture.png'): """see https://hub.docker.com/r/phuslu/ghost.py/""" import ghost logging.info('create ghost.py Session') session = ghost.Session(ghost.Ghost(), viewport_size=tuple( map(int, viewport_size.split('x')))) logging.info('open %r', url) session.open(url) if wait_for_text: logging.info('wait_for_text %r', wait_for_text) session.wait_for_text(wait_for_text) else: logging.info('wait_for_page_loaded') session.wait_for_page_loaded() if '/' not in filename: filename = '/data/' + filename logging.info('capture selector=%r to %r', selector, filename) session.capture_to(filename, selector=selector) os.chmod(filename, 0o666) htmlfile = os.path.splitext(filename)[0] + '.html' open(htmlfile, 'wb').write(session.content.encode('utf-8')) os.chmod(htmlfile, 0o666)
def update(self, screen, ball): """ Update screen background and draw bricks """ screen.fill((0, 0, 0)) pygame.draw.lines(screen, (200, 255, 200), False, [(0, 480), (0, 0), (639, 0), (639, 480)]) [b.update(screen) for b in self.bricks] for g in self.ghosts: g.update(screen) if g.timer < 1: self.ghosts.remove(g) # update shot if self.shot: self.shot.update(screen) if self.shot.y < -20: self.shot = None # and check for collisions in a copy of the list for i in self.bricks[:]: if i.overlap(ball): # we collided with ball, kill brick g = ghost.Ghost(i.x, i.y) self.bricks.remove(i) self.sound_brick.play() self.ghosts.append(g) ball.vy = -ball.vy ball.vx = -ball.vx ball.score = i.score
def test_ghost(): gh = ghost.Ghost() se = ghost.Session( gh, user_agent= "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36", wait_timeout=30, display=False, viewport_size=(5000, 1000), ignore_ssl_errors=True, plugins_enabled=True, java_enabled=True, download_images=False) print time.localtime() se.open( "https://jd.com", timeout=30, user_agent= "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" ) se.wait_for_page_loaded(30) """ try: se.wait_for_alert(30) except: pass def func(): return True """ print se.content print time.localtime()
def __setGhosts(self, gCords): ghosts = [] maxLength = len(self.maze) + len(self.maze[0]) for cord in gCords: ghosts += [ghost.Ghost(cord, random.randint(int(maxLength / 6), int(maxLength / 4)))] return ghosts
def start_ghost(): global game if game == None: global game_state game = "Ghost" game_state = ghost.Ghost() print("made Ghost") return question("Let's play Ghost! The first letter is " + game_state.first_turn()) return question("I misheard you. Please try again")
def test_blinky(self): gh = g.Ghost('blinky', 10, 10, 20, 20) self.assertEqual(gh.target, (-124, -16)) gh.target = (-100000, -100000000) field = f.Field('tests/lvl1.txt') gh.change_target(field, 7) self.assertEqual(gh.target, gh.default_target) gh.change_target(field, 0) self.assertEqual(gh.target, (field.hero.rect.x, field.hero.rect.y))
def test_free(self): gh = g.Ghost('blinky', 16, 16) gates = (16, 0) gh.free(gates) self.assertEqual(gh.target, (16, -32)) for i in range(8): gh.decide_direction([]) gh.update_move() gh.free(gates) self.assertEqual(gh.target, gh.default_target)
def test_pinky(self): gh = g.Ghost('pinky', 10, 10, 20, 20) self.assertEqual(gh.target, (176, -16)) gh.is_in_house = False gh.target = (-100000, -100000000) field = f.Field('tests/lvl1.txt') gh.change_target(field, 7) self.assertEqual(gh.target, gh.default_target) gh.change_target(field, 0) self.assertEqual(gh.target, (field.hero.rect.x + field.hero.xvel * 2, field.hero.rect.y + field.hero.yvel * 2))
def ghostCapture(web_timeout, screen_url, rep_fold, screen_name): # Try to get our screenshot and source code of the page # Write both out to disk if possible (if we can get one, we can get the other) ghost = screener.Ghost(wait_timeout=int(web_timeout), ignore_ssl_errors=True) logger = logging.getLogger('ghost') logger.disabled = True ghost_page, ghost_extra_resources = ghost.open(screen_url, auth=('none', 'none')) ghost.capture_to(rep_fold + "/screens/" + screen_name) return ghost_page, ghost_extra_resources
def test_scare(self): gh = g.Ghost('blinky', 16, 16) gh.target = (0, 0) self.assertEqual(gh.target, (0, 0)) gh.scared = True gh.update(f.Field('tests/lvl1.txt')) self.assertTrue(gh.scared) self.assertNotEqual(gh.target, (0, 0)) gh.alive = False gh.rect.x = gh.rect.y = 16 gh.update(f.Field('tests/lvl1.txt')) self.assertFalse(gh.scared)
def __init__(self, maze): """Constructor method of Main Class. It initialases all object needed for start the game board, coins, PacMan and ghosts. """ self.time_point = time() self.fps_no = 0 # board creating self.board = board.Board(maze) # PacMan player creating self.pacman = pacman.PacMan(14, 18) # Ghosts self.ghost1 = ghost.Ghost(14, 6, "N", (1.0, 0.0, 1.0)) self.ghost2 = ghost.Ghost(14, 6, "W", (1.0, 0.0, 0.0)) self.ghost3 = ghost.Ghost(14, 6, "E", (0.0, 1.0, 1.0)) self.ghosts = [self.ghost1, self.ghost2, self.ghost3]
def launch(self): self.field = field.Field(self.game.window, self.game.CELL_WIDTH) self.game.all = pygame.sprite.RenderUpdates() pacman.Pacman.container = self.game.all img = pacman.load_image("pacman.png") img = pygame.transform.scale(img, (self.game.CELL_WIDTH, self.game.CELL_WIDTH)) self.pacman = pacman.Pacman(pygame, Vector2D(100, 100), img, Vector2D(1, 0), 0) print(self.field.graph.keys()) self.ghosts.append(ghost.Ghost(1, self.field.graph, self.game.window, self.game.CELL_WIDTH)) self.ghosts.append(ghost.Ghost(2, self.field.graph, self.game.window, self.game.CELL_WIDTH)) self.ghosts.append(ghost.Ghost(3, self.field.graph, self.game.window, self.game.CELL_WIDTH)) self.ghosts.append(ghost.Ghost(0, self.field.graph, self.game.window, self.game.CELL_WIDTH)) self.game.all.update() self.game.all.draw(self.game.window) self.play()
def getRawData(year, month, place, zoom): g = ghost.Ghost() with g.start() as session: #page, extra_resources = session.open("https://jaitnium.github.io/popularLocationsDemo/flickrTest.html") #result, resources = session.evaluate("document.getElementById('displayBtn').innerHTML;"); #print(result) #sys.exit() page, extra_resources = session.open( "https://jaitnium.github.io/popularLocationsDemo/flickrTest.html") result, resources = session.evaluate( "getHotSpotJSON('2015', 'January', 'San Francisco', 15)") print(result) result, resources = session.wait_for_alert(100) #print(result) return result
def test_klyde(self): gh = g.Ghost('klyde', 10, 10, 20, 20) self.assertEqual(gh.target, (176, 36)) gh.is_in_house = False gh.target = (-100000, -100000000) field = f.Field('tests/lvl1.txt') gh.change_target(field, 7) self.assertEqual(gh.target, gh.default_target) gh.change_target(field, 0) self.assertEqual(gh.target, (field.hero.rect.x, field.hero.rect.y) if sqrt((gh.rect.x - field.hero.rect.x) * (gh.rect.x - field.hero.rect.x) + (gh.rect.y - field.hero.rect.y) * (gh.rect.y - field.hero.rect.y)) > 8 * 16 else gh.default_target)
def main(): logger.info('Initializing Ghost...') g = ghost.Ghost(GHOST_DEVICE_ID) g.settimeout(GHOST_DURATION) logger.info('Ready') while True: logger.info('Mounting the virtual device') hpc = hpfeeds.new(HPFEEDS_HOST, HPFEEDS_PORT, HPFEEDS_IDENT, HPFEEDS_SECRET) hpc.publish(HPFEEDS_STATUS_CHANNEL, create_status_update('mount')) hpc.close() g.run(onincident) logger.info('Virtual device removed') hpc = hpfeeds.new(HPFEEDS_HOST, HPFEEDS_PORT, HPFEEDS_IDENT, HPFEEDS_SECRET) hpc.publish(HPFEEDS_STATUS_CHANNEL, create_status_update('remove')) hpc.close() sleep(GHOST_INTERVAL)
def get_element_et_links(url): """Get the lxml element. :url: the webpage url :returns: the cleaned lxml element and all the webpage links """ if GHOST: ghost_object = ghost.Ghost(wait_timeout=120) ghost_object.open(url) ghost_object.wait_for_page_loaded() content = ghost_object.content.encode('utf8') element = fromstring(content) else: element = parse(url).getroot() links = [link for link in element.iterlinks()] element = clean_element(element) return element, links
__all__ = [ 'ContentItem', # tasks will be added by register_task_method() ] # ————————————————————————————————————————————————————————————————— start ghost if config.FEED_FETCH_GHOST_ENABLED: try: import ghost except: ghost = None # NOQA else: GHOST_BROWSER = ghost.Ghost() else: ghost = None # NOQA # Until we patch Ghost to use more than one Xvfb at the same time, # we are tied to ensure there is only one running at a time. global_ghost_lock = RedisExpiringLock('__ghost.py__') # ——————————————————————————————————————————————————————————— QuerySet patching def BaseItemQuerySet_empty_method(self): """ Patch BaseItemQuerySet to know how to return empty content. """ return self.filter(content_type__in=[None, CONTENT_TYPES.NONE])
def test_decision_not_collide(self): gh = g.Ghost('blinky', 10, 10, 20, 20) gh.target = (5, -5) gh.decide_direction([p.Platform(-20, -20)]) self.assertEqual(gh.current_dir, 'up')
def test_decision_collide(self): gh = g.Ghost('blinky', 16, 16) gh.target = (32, -16) gh.current_dir = 'down' gh.decide_direction([p.Platform(16, 0)]) self.assertEqual(gh.current_dir, 'right')
def main(): player = Player(pos=(startingWidth, startingHeight)) ghost1 = ghost.Ghost(player.board, dimension, width - (dimension * 1.5), height - (dimension * 1.5)) player.board.map[int((width - (dimension * 1.5)) // dimension)][int( (height - (dimension * 1.5)) // dimension)] = 4 #print(player.board.mapPrint()) playerEdit = Player(pos=(startingWidth, startingHeight)) newMap = playerEdit.board.map.copy() newPoints = playerEdit.board.maxPoints mode = 0 Ghosts = [ghost1] ghostX = [width - (dimension * 1.5)] ghostY = [height - (dimension * 1.5)] while 1: while 1 and mode == 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_w: player.up() if event.key == pygame.K_s: player.down() if event.key == pygame.K_a: player.left() if event.key == pygame.K_d: player.right() if event.key == pygame.K_ESCAPE: mode = 0 player.stop = 0 if player.stop == 0: player.playerMove() ghost1.playerMove() player.check() ghost1.check() if player.boardX == ghost1.boardX and player.boardY == ghost1.boardY: player.stop = 2 screen.fill(black) screen.blit(player.image, player.rect) player.draw() if ghost1.rotation == 1: screen.blit( pygame.transform.flip(ghost1.image, True, False), ghost1.rect) else: screen.blit(ghost1.image, ghost1.rect) pygame.display.set_caption("Pac-man: GAME") pygame.display.update() pygame.display.flip() #(player.board.mapPrint()) elif player.stop == 1: screen.blit(text5, (1, height / 2)) screen.blit(text6, (width / 8, height / 1.5)) pygame.display.update() pygame.display.flip() else: screen.blit(text4, (1, height / 2)) screen.blit(text6, (width / 8, height / 1.5)) pygame.display.update() pygame.display.flip() width1 = width / 2 width11 = width1 + width / 5 height1 = height / 4 height11 = height1 + height / 20 height2 = height / 3 height22 = height2 + height / 20 height3 = height / 3 * 2 height33 = height3 + height / 20 while 1 and mode == 0: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: if width1 <= mouse[0] <= width11 and height1 <= mouse[ 1] <= height11: mode = 1 player = Player(pos=(startingWidth, startingHeight)) ghost1 = ghost.Ghost(player.board, dimension, width - (dimension * 1.5), height - (dimension * 1.5)) player.board.map[int( (width - (dimension * 1.5)) // dimension)][int( (height - (dimension * 1.5)) // dimension)] = 4 player.board.maxPoints -= 1 if width1 <= mouse[0] <= width11 and height2 <= mouse[ 1] <= height22: mode = 2 tempPoints = playerEdit.board.maxPoints playerEdit.board.resetMap() newMap = playerEdit.board.map.copy() playerEdit = Player(pos=(startingWidth, startingHeight)) playerEdit.board.overwrite(newMap.copy()) playerEdit.board.changePosition( int(playerEdit.boardX), int(playerEdit.boardY)) playerEdit.board.maxPoints = tempPoints i = 0 for x in Ghosts: Ghosts[i] = ghost.Ghost(playerEdit.board, dimension, ghostX[i], ghostY[i]) playerEdit.board.map[int( (width - (dimension * 1.5)) // dimension)][int( (height - (dimension * 1.5)) // dimension)] = 4 i += 1 #print(len(Ghosts)) #ghost1 = ghost.Ghost(playerEdit.board, dimension, width - (dimension * 1.5), height - (dimension * 1.5)) #playerEdit.board.map[int((width - (dimension * 1.5)) // dimension)][int((height - (dimension * 1.5)) // dimension)] = 4 if width1 <= mouse[0] <= width11 and height3 <= mouse[ 1] <= height33: mode = 3 tempPoints = playerEdit.board.maxPoints playerEdit.board.resetMap() playerEdit = Player(pos=(startingWidth, startingHeight)) playerEdit.board.overwrite(newMap.copy()) playerEdit.board.maxPoints = tempPoints playerEdit.points = 0 #print(len(Ghosts)) mouse = pygame.mouse.get_pos() screen.fill(black) if width1 <= mouse[0] <= width11 and height1 <= mouse[ 1] <= height11: pygame.draw.rect( screen, color_light, [width / 2, height / 4, width / 5, height / 20]) else: pygame.draw.rect( screen, color_dark, [width / 2, height / 4, width / 5, height / 20]) if width1 <= mouse[0] <= width11 and height2 <= mouse[ 1] <= height22: pygame.draw.rect( screen, color_light, [width / 2, height / 3, width / 5, height / 20]) else: pygame.draw.rect( screen, color_dark, [width / 2, height / 3, width / 5, height / 20]) if width1 <= mouse[0] <= width11 and height3 <= mouse[ 1] <= height33: pygame.draw.rect(screen, color_light, [width / 2, height3, width / 5, height / 20]) else: pygame.draw.rect(screen, color_dark, [width / 2, height3, width / 5, height / 20]) screen.blit(text1, (width / 2 + 50, height / 4)) screen.blit(text2, (width / 2 + 50, height / 3)) screen.blit(text3, (width / 2, height3)) pygame.display.set_caption("Pac-man: MENU") pygame.display.update() pygame.display.flip() while 1 and mode == 2: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: playerEdit.board.changeElement(mouse[0] // dimension, mouse[1] // dimension) if event.type == pygame.MOUSEBUTTONDOWN and event.button == 3: if playerEdit.board.getElement(int(mouse[0] // dimension), int(mouse[1] // dimension)) == 4: for x in Ghosts: if x.boardX == int( mouse[0] // dimension) and x.boardY == int( mouse[1] // dimension): Ghosts.remove(x) playerEdit.board.map[int(mouse[0] // dimension)][int( mouse[1] // dimension)] = 1 playerEdit.board.maxPoints += 1 elif playerEdit.board.getElement( int(mouse[0] // dimension), int(mouse[1] // dimension)) == 1: Ghosts.append( ghost.Ghost( playerEdit.board, dimension, int((mouse[0] // dimension) * (dimension) + (dimension / 2)), int((mouse[1] // dimension) * (dimension) + (dimension / 2)))) ghostX.append( int((mouse[0] // dimension) * (dimension) + (dimension / 2))) ghostY.append( int((mouse[1] // dimension) * (dimension) + (dimension / 2))) playerEdit.board.map[int(mouse[0] // dimension)][int( mouse[1] // dimension)] = 4 if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: mode = 0 mouse = pygame.mouse.get_pos() screen.fill(black) screen.blit(playerEdit.image, playerEdit.rect) playerEdit.draw() for x in Ghosts: if x.rotation == 1: screen.blit(pygame.transform.flip(x.image, True, False), x.rect) else: screen.blit(x.image, x.rect) pygame.display.set_caption(" Pac-man: EDIT MAP") pygame.display.update() pygame.display.flip() while 1 and mode == 3: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_w: playerEdit.up() if event.key == pygame.K_s: playerEdit.down() if event.key == pygame.K_a: playerEdit.left() if event.key == pygame.K_d: playerEdit.right() if event.key == pygame.K_ESCAPE: mode = 0 playerEdit.stop = 0 if playerEdit.stop == 0: #print() playerEdit.playerMove() for x in Ghosts: x.playerMove() x.check() #ghost1.playerMove() playerEdit.check() ghost1.check() for x in Ghosts: if playerEdit.boardX == x.boardX and playerEdit.boardY == x.boardY: playerEdit.stop = 2 screen.fill(black) screen.blit(playerEdit.image, playerEdit.rect) playerEdit.draw() for x in Ghosts: if x.rotation == 1: screen.blit( pygame.transform.flip(x.image, True, False), x.rect) #print("ELLLEEEE") else: screen.blit(x.image, x.rect) #if ghost1.rotation == 1: # screen.blit(pygame.transform.flip(ghost1.image, True, False), ghost1.rect) #else: # screen.blit(ghost1.image, ghost1.rect) pygame.display.set_caption("Pac-man: GAME: edited map") pygame.display.update() pygame.display.flip() elif playerEdit.stop == 1: screen.blit(text5, (1, height / 2)) screen.blit(text6, (width / 8, height / 1.5)) pygame.display.update() pygame.display.flip() else: screen.blit(text4, (1, height / 2)) screen.blit(text6, (width / 8, height / 1.5)) pygame.display.update() pygame.display.flip()
import ghost from bs4 import BeautifulSoup g = ghost.Ghost() with g.start() as session: resources = session.open( 'https://www.rentomojo.com/bangalore/bikes-on-rent') #page, resources = ghost.wait_for_page_loaded() #wait_while_selector("rm-category__desc", timeout=None) session.wait_for_text('Honda Activa 3G', timeout=100) #session.wait_while_selector("div.rm-category__desc", timeout=None) #session.wait_timeout=50 html = session.content soup = BeautifulSoup(html, "html.parser") #print(soup) myContent = soup.find_all("div") print(len(myContent))
import pygame import player, map, ghost pygame.init() myfont = pygame.font.SysFont(None, 25) score = 0 screen = pygame.display.set_mode((570, 660)) done = False ghosts = [] ghosts.append(ghost.Ghost(270, 270)) ghosts.append(ghost.Ghost(270, 270)) ghosts.append(ghost.Ghost(270, 270)) ghosts.append(ghost.Ghost(240, 270)) player = player.Player() level = map.Map() map = level.getmap() clock = pygame.time.Clock() while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True pressed = pygame.key.get_pressed() if pressed[pygame.K_UP]: player.moveUp(map) if pressed[pygame.K_DOWN]:
def test_update(self): gh = g.Ghost('blinky', 16, 16) gh.image = None gh.update(f.Field('tests/lvl1.txt')) self.assertEqual(gh.image, gh.default_image)
# animation variables flash_text_counter = 0 gv.pacman_tick_counter = 0 # generating a screen gv.screen = pygame.display.set_mode(gv.screensize) pygame.display.set_caption("Daniel's PacMan") # create pacman and ghost objects gv.pacman = pm.Pacman([480, 200]) ghost_starting_positions = [[30, 30], [950, 30], [30, 450], [950, 450]] ghost_second_level_positions = [[30, 30], [950, 30], [30, 450], [950, 450]] ghost_third_level_positions = [[30, 30], [950, 30], [30, 450], [950, 450]] for ghost_type in range(4): gv.ghosts.append(gh.Ghost(ghost_type, ghost_starting_positions[ghost_type])) # create pellet lists ani.read_pellet_images() # menu loop while in_menu: gv.screen.fill((0, 0, 0)) if flash_text_counter == 0: flash_text_counter = 1 else: flash_text_counter = 0 ani.draw_hint(gv.screen) # showing the text # ordinary pygame loop which enables closing gv.keys_pressed = pygame.key.get_pressed() for event in pygame.event.get():
def __init__(self, parent): self.threads = [] self.pobjednik = 0 self.brojacZaSilu = 0 self.usporenjeIgraca = 0 self.usporenjeIgraca2 = 0 self.prikazanaSila = False self.vrijemePrikazavanja = ran.randrange(7, 15) self.vrijemeTrajanja = ran.randrange(5, 15) self.sila = f.Force() self.player1 = p.Player() self.player1.id = 1 self.player2 = p.Player(20, 10) self.player2.id = 2 self.player2.i = self.player2.i3 self.opcija = False #za bonus self.broj1 = 5 self.ghost1 = g.Ghost(8, 10) self.ghost2 = g.Ghost(9, 10) self.ghost3 = g.Ghost(11, 10) self.ghost4 = g.Ghost(12, 10) self.ghost2.id = 2 self.ghost3.id = 3 self.ghost4.id = 4 self.ghost1.id = 1 self.ghost2.i = QImage('images/ghost1.png') self.ghost3.i = QImage('images/ghost2.png') self.ghost4.i = QImage('images/ghost3.png') self.tt = 0 self.level = 1 self.broj = 10 #za timer self.pauza = False #p self.brojac1 = 0 #za uskoravanje duhova super().__init__(parent) self.resize(882, 924) self.shape = 10 self.dots = dot.Tacke() self.slika_pom = 1 # za mijenjanje slike text1 = "Poeni(1): 0 Zivot(1) : 3" self.label1 = QLabel(text1, self) self.label1.setFont(QtGui.QFont('SansSerif', 15)) self.label1.move(10, 930) text2 = "Poeni(2): 0 Zivot(2) : 3" self.label2 = QLabel(text2, self) self.label2.setFont(QtGui.QFont('SansSerif', 15)) self.label2.move(600, 930) self.radniBrojac = 0 text3 = "Level: 1" self.label3 = QLabel(text3, self) self.label3.setFont(QtGui.QFont('SansSerif', 15)) self.label3.move(400, 930) self.brojac = 0 #za timer self.brojac2 = 0 #za plejera 1 da li je skrenuo self.brojac3 = 0 #za plejera 2 da li je skrenuo self.player1.key = 0 self.player1.oldkey = 0 self.setFocusPolicy(Qt.StrongFocus) self.color1 = 0xFF0000 self.color2 = 0x000000 self.timer_interval = 10 self.scene = QGraphicsScene() self.scene.addItem(self.player1) self.scene.addItem(self.player2) self.timer = QBasicTimer() self.tiles = [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 3, 12, 12, 9, 12, 5, 10, 10, 10, 1, 10, 10, 10, 3, 12, 5, 10, 3, 12, 5, 10, 10, 1, 10, 10, 1, 10, 1, 10, 10, 10, 1, 10, 10, 10, 1, 10, 2, 12, 8, 10, 1, 10, 10, 1, 10, 10, 1, 10, 1, 10, 10, 10, 1, 10, 10, 10, 1, 10, 10, 10, 1, 10, 1, 10, 10, 6, 12, 12, 11, 12, 7, 12, 12, 12, 11, 12, 12, 12, 11, 12, 9, 12, 4, 10, 1, 10, 10, 1, 10, 10, 1, 10, 10, 10, 10, 10, 1, 10, 10, 10, 1, 10, 1, 10, 10, 10, 1, 10, 10, 1, 10, 10, 6, 12, 5, 10, 3, 12, 7, 12, 9, 12, 8, 10, 6, 12, 5, 10, 1, 10, 10, 1, 10, 10, 1, 10, 1, 10, 1, 10, 10, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 10, 2, 12, 12, 8, 10, 1, 10, 1, 10, 14, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 10, 10, 10, 10, 1, 10, 2, 12, 8, 10, 1, 10, 1, 10, 2, 12, 8, 10, 2, 12, 8, 10, 10, 10, 10, 10, 1, 10, 10, 10, 6, 20, 8, 10, 1, 10, 10, 10, 1, 10, 10, 10, 1, 10, 10, 10, 10, 10, 1, 10, 3, 12, 8, 10, 1, 10, 1, 10, 3, 12, 8, 10, 3, 12, 8, 10, 10, 3, 12, 12, 8, 10, 1, 10, 1, 10, 13, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 10, 1, 10, 10, 1, 10, 1, 10, 1, 10, 10, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 10, 1, 10, 10, 6, 12, 4, 10, 2, 12, 9, 12, 7, 12, 8, 10, 6, 12, 4, 10, 1, 10, 10, 1, 10, 10, 1, 10, 10, 10, 10, 10, 1, 10, 10, 10, 1, 10, 1, 10, 10, 10, 1, 10, 10, 6, 12, 12, 11, 12, 9, 12, 12, 12, 11, 12, 12, 12, 11, 12, 7, 12, 5, 10, 1, 10, 10, 1, 10, 10, 1, 10, 1, 10, 10, 10, 1, 10, 10, 10, 1, 10, 10, 10, 1, 10, 1, 10, 10, 1, 10, 10, 1, 10, 1, 10, 10, 10, 1, 10, 10, 10, 1, 10, 3, 12, 8, 10, 1, 10, 10, 2, 12, 12, 7, 12, 4, 10, 10, 10, 1, 10, 10, 10, 2, 12, 4, 10, 2, 12, 4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ]
def enter(boy, event): boy.frame = 0 boy.ghost = ghost.Ghost(boy.x, boy.y, boy.dir)
#206 #funkcja rysująca grę w aktualnym stanie (np po poruszeniu Pacmana) def redrawGame(): screen.blit(bg, (0, 0)) pacman.draw(screen, pacman.x + pacman.WalkCount_x, pacman.y + pacman.WalkCount_y, pacman.direction) draw_coins() ghost_1.draw(1, screen, ghost_1.x + ghost_1.WalkCount_x, ghost_1.y + ghost_1.WalkCount_y, ghost_1.direction) ghost_2.draw(2, screen, ghost_2.x + ghost_2.WalkCount_x, ghost_2.y + ghost_2.WalkCount_y, ghost_2.direction) ghost_3.draw(3, screen, ghost_3.x + ghost_3.WalkCount_x, ghost_3.y + ghost_3.WalkCount_y, ghost_3.direction) draw_text('Twój wynik: {}'.format(pacman.current_score), screen, [60, 0], 18, WHITE, START_FONT) pg.display.update() #Tworzymy postać Pacmana i przypisujemy go do pacman pacman = pacman.Pacman(30, 30, 1, 3, 0, 0, 0) #tworzymy przeciwników ghost_1 = ghost.Ghost(1, 270, 30, 2, 0, 0) ghost_2 = ghost.Ghost(2, 570, 600, 2, 0, 0) ghost_3 = ghost.Ghost(3, 570, 30, 2, 0, 0) #GłóWna pętla, w której wywołóujemy grę START_SCREEN() MainLoop()
from tile import Tile from player import Player import ghost import os import random import pygame pygame.init() screenWidth = 560 screenHeight = 620 rows = 31 cols = 28 scale = screenWidth // cols player = Player(13, 23, -1, 0) blinky = ghost.Ghost(13, 12, (255, 0, 0)) pinky = ghost.Ghost(14, 14, (255, 127, 255)) inky = ghost.Ghost(13, 13, (0, 255, 255)) clyde = ghost.Ghost(14, 13, (255, 155, 0)) mode = "c" counter = 0 win = pygame.display.set_mode((screenWidth, screenHeight + 50)) game = pygame.Surface((screenWidth, screenHeight)) pygame.display.set_caption("Pacman") font = pygame.font.SysFont("comicsans", 50) clock = pygame.time.Clock() background = pygame.image.load(os.path.join("pics", "pacman_background.png"))
def ready_game(): #global gameState #gameState = GAMESTATE_READY game_world.remove_objects_at_layer(game_world.LAYER_MONSTER) game_world.remove_all_item() f = open('monster.json', 'r') monster_data = json.load(f) f.close() f = open('room.json', 'r') room_data = json.load(f) f.close() monster_arr = None item_data = None # 방, 몬스터 정보 받기 for o in game_world.background_objects(): if o.GetID() == ID.ROOM: if roomNum == CAVE_0: monster_arr = monster_data['cave_0'] room_info = room_data['cave_0'] o.SetRoom(CAVE_0) elif roomNum == CAVE_1: monster_arr = monster_data['cave_1'] room_info = room_data['cave_1'] o.SetRoom(CAVE_1) elif roomNum == CAVE_2: monster_arr = monster_data['cave_2'] room_info = room_data['cave_2'] o.SetRoom(CAVE_2) elif roomNum == CAVE_3: monster_arr = monster_data['cave_3'] room_info = room_data['cave_3'] o.SetRoom(CAVE_3) elif roomNum == CABIN_0: monster_arr = monster_data['cabin_0'] room_info = room_data['cabin_0'] o.SetRoom(CABIN_0) elif roomNum == CABIN_1: monster_arr = monster_data['cabin_1'] room_info = room_data['cabin_1'] o.SetRoom(CABIN_1) elif roomNum == CABIN_2: monster_arr = monster_data['cabin_2'] room_info = room_data['cabin_2'] o.SetRoom(CABIN_2) elif roomNum == CABIN_3: monster_arr = monster_data['cabin_3'] room_info = room_data['cabin_3'] o.SetRoom(CABIN_3) break; for o in game_world.background_objects(): if o.GetID() == ID.ROOM: if not o.GetIsClear(): # 몬스터 생성 for d in monster_arr: if d["ID"] == ID.FLY: _monster = fly.Fly(d["x"], d["y"]) elif d["ID"] == ID.MEAT: _monster = meat.Meat(d["x"], d["y"]) elif d["ID"] == ID.HOPPER: _monster = hopper.Hopper(d["x"], d["y"]) elif d["ID"] == ID.GHOST: _monster = ghost.Ghost(d["x"], d["y"]) game_world.add_object(_monster, game_world.LAYER_MONSTER) # 아이템 미리 생성 item_data = item.Item(room_info["item"], 400, 150) game_world.add_object(item_data, game_world.LAYER_BG) break; # 문 생성 for o in game_world.background_objects(): if o.GetID() == ID.ROOM: o.SetDoor(room_info["left"], room_info["right"], room_info["up"], room_info["down"], room_info["stage"])