예제 #1
0
def main():
	try:
		pygame.init()
		disp = pygame.display.set_mode((800, 600), False, False)
		pygame.display.set_caption("rock, paper, and scissors")
	except pygame.error:
		print "Pygame failed to initialize"

	try:
		tiles = pygame.image.load(src + "images/ssp_trans.png")
	except pygame.error:
		print "Failed to read game data"
	clk = pygame.time.Clock()
	exit_game = False
	startscreen = StartScreen(disp, clk, tiles)
	gamescreen = GameScreen(disp, clk, tiles)
	while not exit_game:
		ret = startscreen.run()
		exit_game = ret[0]
		if exit_game:
			break

		exit_game = gamescreen.run(ret[1])
	pygame.quit()
	return 1
예제 #2
0
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
    startScreen = StartScreen(screen, gamesettings)
    showgamestats = GameStats(screen, gamesettings)

    # Grouping blocks and pellets
    blocks = Group()
    powerpills = Group()
    shield = Group()
    portal = Group()

    thepacman = Pacman(screen, gamesettings)

    # Making the ghosts
    redghost = Ghosts(screen, "red")
    cyanghost = Ghosts(screen, "cyan")
    orangeghost = Ghosts(screen, "orange")
    pinkghost = Ghosts(screen, "pink")

    startScreen.makeScreen(screen)
    gf.readFile(screen, blocks, shield, powerpills, portal)

    screen.fill(BLACK)
    while True:
        screen.fill(BLACK)
        showgamestats.blitstats()
        gf.check_events(thepacman)
        gf.check_collision(thepacman, blocks, powerpills, shield)
        thepacman.update()
        for block in blocks:
            block.blitblocks()
        for theshield in shield:
            theshield.blitshield()
        for pill in powerpills:
            pill.blitpowerpills()
        for theportal in portal:
            theportal.blitportal()
        thepacman.blitpacman()
        redghost.blitghosts()
        cyanghost.blitghosts()
        orangeghost.blitghosts()
        pinkghost.blitghosts()

        pygame.display.flip()
예제 #3
0
파일: qmpcapp.py 프로젝트: jmechnich/qmpc
 def initStartScreen(self):
     self.startscreen = StartScreen(self)
     self.startscreen.clicked.connect(self.connectActivated)
     if have_maemo:
         menu = QMenuBar(self.startscreen)
         menu.addAction(self.actionConnect)
         menu.addAction(self.actionPrefs)
예제 #4
0
def run_game():
    # Initialize pygame, settings, and screen object.
    pygame.init()
    ai_settings = Settings()
    clock = pygame.time.Clock()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Space Invaders")

    # Make the Play button.
    play_button = Button(screen, "Play")

    # Start Screen
    start_screen = StartScreen(ai_settings, screen, play_button)

    # Create an instance to store game statistics, and a scoreboard.
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    # Make Start Screen
    start_screen.make_screen(ai_settings, screen)

    # Make a ship, a group of bullets, and a group of aliens.
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

    # Create the fleet of aliens.
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)

        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens,
                         bullets, play_button)

        clock.tick(240)
예제 #5
0
    def runit(self):
        menu = Menu(self.screen)
        hs_screen = HighScoreScreen(self.screen, self.score)
        intro_seq = StartScreen(self.screen)
        e_loop = Event(loop_running=True, actions={pygame.MOUSEBUTTONDOWN: menu.check_buttons})

        while e_loop.loop_running:
            self.clock.tick(60)
            e_loop.check_events()
            self.screen.fill(PacmanPortal.black)
            if not menu.hs_screen:
                intro_seq.update()
                intro_seq.blit()
                menu.update()
                menu.blit()
            else:
                hs_screen.blit()
                hs_screen.check_done()
            if menu.ready_to_play:
                pygame.mixer.music.stop()
                self.play_game()
                for g in self.ghosts:
                    g.reset_speed()
                menu.ready_to_play = False
                self.score.save_high_scores()
                hs_screen.prep_images()
                hs_screen.position()
            pygame.display.flip()
예제 #6
0
    def __init__(self, ai_settings, screen, msg):
        """Create the play button."""
        self.startup = StartScreen(screen, ai_settings)
        self.ai_settings = ai_settings
        self.screen = screen
        self.screen_rect = screen.get_rect()

        # Set the dimensions and properties of the button
        self.width, self.height = 200, 50
        self.button_color = (0, 255, 0)
        self.text_color = (0, 255, 255)
        self.black = (0, 0, 0)
        self.font = pygame.font.SysFont(None, 48)

        # Build the button's rect object and center it
        self.rect = pygame.Rect(0, 0, self.width, self.height)
        self.rect.center = self.screen_rect.center
        self.rect.y = self.rect.y + self.screen_rect.height / 4 - self.ai_settings.SIZE

        # The button message needs to be prepped only once
        self.msg_image, self.msg_image_rect = None, None
        self.prep_msg(msg)
예제 #7
0
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("Space Invaders")
    pygame.mixer.music.load("sounds/loop.mp3")
    play_button = Button(ai_settings, screen, "Play")
    start_screen = StartScreen(ai_settings, screen, play_button)
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    start_screen.makescreen(ai_settings)
    ship = Ship(ai_settings, screen)
    bullets = Group()
    lazers = Group()
    aliens = Group()
    bunkers = pygame.sprite.Group(make_bunker(ai_settings, screen, 0),
                                  make_bunker(ai_settings, screen, 1),
                                  make_bunker(ai_settings, screen, 2),
                                  make_bunker(ai_settings, screen, 3))
    gf.create_fleet(ai_settings, screen, aliens)
    pygame.mixer.music.play(-1, 0.0)
    # Start the main loop for the game.
    gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                     lazers, play_button, bunkers)
    while True:
        pygame.time.delay(15)
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, aliens, bullets)
            gf.update_bullets_lazers(ai_settings, lazers, bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets, lazers)
            gf.update_screen(ai_settings, screen, stats, sb, ship, aliens,
                             bullets, lazers, play_button, bunkers)
예제 #8
0
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()
예제 #9
0
파일: qmpcapp.py 프로젝트: jmechnich/qmpc
class QMPCApp(QObject):
    __images__ = {
        'background':           "images/background.png",
    }
    
    __icons__  = {
        'homeButton':           "general_backspace",
        'volumeButton':         "general_speaker",
        'settingsButton':       "keyboard_menu",
        'prevButton':           "/etc/hildon/theme/mediaplayer/Back.png",
        'prevButtonPressed':    "/etc/hildon/theme/mediaplayer/BackPressed.png",
        'playButton':           "/etc/hildon/theme/mediaplayer/Play.png",
        'pauseButton':          "/etc/hildon/theme/mediaplayer/Pause.png",
        'stopButton':           "/etc/hildon/theme/mediaplayer/Stop.png",
        'stopButtonPressed':    "/etc/hildon/theme/mediaplayer/StopPressed.png",
        'nextButton':           "/etc/hildon/theme/mediaplayer/Forward.png",
        'nextButtonPressed':    "/etc/hildon/theme/mediaplayer/ForwardPressed.png",
        'repeatButton':         "/etc/hildon/theme/mediaplayer/Repeat.png",
        'repeatButtonPressed':  "/etc/hildon/theme/mediaplayer/RepeatPressed.png",
        'shuffleButton':        "/etc/hildon/theme/mediaplayer/Shuffle.png",
        'shuffleButtonPressed': "/etc/hildon/theme/mediaplayer/ShufflePressed.png",
    }

    def __init__(self):
        super(QMPCApp,self).__init__()
        self.mw = None
        self.initData()
        self.initMPD()
        self.initActions()
        self.initGUI()
        QTimer.singleShot(100,self.deferredStart)

    def deferredStart(self):
        if self.data.autoconnect: self.connectMPD()

    def initData(self):
        self.selectedServerName = None
        self.data = DataModel()
        self.data.loadSettings()
        self.imagehelper = ImageHelper(images=self.__images__,
                                       icons=self.__icons__)
        QApplication.instance().aboutToQuit.connect(self.data.saveSettings)

    def initActions(self):
        self.actionPlayer = QAction("Player", self)
        self.actionPlayer.triggered.connect(
            lambda: self.showWidget(self.player))
        self.actionPlaylist = QAction("Playlist",self)
        self.actionPlaylist.triggered.connect(
            lambda: self.showWidget(self.playlist))
        self.actionBrowser = QAction("Browser",self)
        self.actionBrowser.triggered.connect(
            lambda: self.showWidget(self.browser))

        self.actionOutputs = QAction("Outputs",self)
        self.actionOutputs.triggered.connect(self.showOutputs)
        self.actionStats = QAction("Statistics",self)
        self.actionStats.triggered.connect(self.showStats)
        self.actionPrefs = QAction("Preferences",self)
        self.actionPrefs.triggered.connect(self.showPrefs)
        self.actionConnect = QAction("Connect",self)
        self.actionConnect.triggered.connect(self.connectActivated)

    def initGUI(self):
        self.initStartScreen()
        self.initWidgets()
        
        if not have_maemo:
            self.mw     = QMainWindow()
            menu        = self.mw.menuBar()
            menufile    = menu.addMenu("&File")
            menuwindows = menu.addMenu("&Windows")
            self.mw.statusBar()
            menuwindows.addAction(self.actionPlayer)
            menuwindows.addAction(self.actionPlaylist)
            menuwindows.addAction(self.actionBrowser)
            menuwindows.addAction(self.actionOutputs)
            menuwindows.addAction(self.actionStats)
            menufile.addAction(self.actionConnect)
            menufile.addAction(self.actionPrefs)
            menufile.addSeparator()
            menufile.addAction("&Quit", QApplication.quit)
       
        self.setConnectionState(False)

    def initStartScreen(self):
        self.startscreen = StartScreen(self)
        self.startscreen.clicked.connect(self.connectActivated)
        if have_maemo:
            menu = QMenuBar(self.startscreen)
            menu.addAction(self.actionConnect)
            menu.addAction(self.actionPrefs)
            
    def initWidgets(self):
        # create subwidgets
        self.player   = Player(self)
        self.playlist = Playlist(self)
        self.browser  = Browser(self)
        if have_maemo:
            # build Maemo stack hierarchy
            self.playlist.setParent(self.player)
            self.browser.setParent(self.player)
            for w in [ self.player, self.playlist, self.browser ]:
                w.setAttribute( Qt.WA_Maemo5StackedWindow)
                w.setWindowFlags( w.windowFlags() | Qt.Window)

            # add menu bar
            menu = QMenuBar(self.player)
            menu.addAction(self.actionPlaylist)
            menu.addAction(self.actionBrowser)
            menu.addAction(self.actionStats)
            menu.addAction(self.actionOutputs)
            menu.addAction(self.actionPrefs)
            menu.addAction(self.actionConnect)
        else:
            self.stack = QStackedWidget()
            for w in [ self.player, self.playlist, self.browser ]:
                w.setParent(self.stack)
                self.stack.addWidget(w)

    def switchView(self, connected):
        if have_maemo:
            if connected:
                self.player.show()
                self.startscreen.hide()
            else:
                self.startscreen.show()
        else:
            cw = self.mw.centralWidget()
            if cw:
                cw.setParent(None)
                cw.hide()
            if connected:
                self.mw.setCentralWidget(self.stack)
                self.stack.show()
                self.showWidget(self.player)
            else:
                self.mw.setCentralWidget(self.startscreen)
                self.startscreen.show()
            self.mw.show()

    def showWidget(self,widget):
        if not have_maemo:
            self.stack.setCurrentWidget(widget)
        widget.show()

    def connectActivated(self):
        if self.actionConnect.text() == "Connect":
            self.connectMPD()
        else:
            self.disconnectMPD()

    def initMPD(self):
        self.mpd = MPDWrapper()
        self.mpdtimer = None
    
    def connectMPD(self,reconnect=False):
        selected = self.data.selectedServer()
        if not len(selected):
            InformationBox.information( self.mw, "Select server to connect")
            self.showPrefs()

        selected = self.data.selectedServer()
        if len(selected):
            name, address, port = selected
            try:
                if not reconnect:
                    InformationBox.information(
                        self.mw, "Connecting to <b>%s</b>" % name)
                    QApplication.processEvents()
                self.mpd.timeout = 10
                self.mpd.connect( str(address), int(port))
                if not reconnect:
                    InformationBox.information(
                        self.mw, "Connected to <b>%s</b>" % name)
                    QApplication.processEvents()
                    self.setConnectionState(True)
                    self.selectedServerName = name
                self.mpdtimer = self.startTimer(5000)
            except socket.timeout, e:
                self.setConnectionState(False)
                InformationBox.information( self.mw, "%s: %s" %(name,e))
                QApplication.processEvents()
            except socket.gaierror, e:
                self.setConnectionState(False)
                InformationBox.information( self.mw, "%s: %s" %(name,e[1]))
                QApplication.processEvents()
            except socket.error, e:
                self.setConnectionState(False)
                InformationBox.information( self.mw, "%s: %s" %(name,e[1]))
                QApplication.processEvents()