Exemplo n.º 1
0
def game_state(screen):
    """
    0 = main menu
    1 = playing
    2 = game over
    """
    current_game_state = 0

    if current_game_state == 0:
        GameMenu.run(screen)
        print('Changed game state')
        current_game_state = 1

    if current_game_state == 1:
        GameGame.run(screen)
Exemplo n.º 2
0
 def get_tiles_by_apps(apps):
     tiles = []
     for app in apps:
         filename = os.path.join(Nvstream.BOXARTDIR,
                                 "{0}.png".format(app.id))
         tile = GameMenu.Tile(app.title, filename)
         if not os.path.isfile(filename):
             t = Nvstream.BoxArtThread(self.moonlight.ip, app.id,
                                       gm.draw_tile, tile)
             t.start()
         tiles.append(tile)
     return tiles
Exemplo n.º 3
0
    def loadStream(self):
        self.loaded = 3
        gm = GameMenu.GameMenu(self.screen)
        apps = Nvstream.get_apps(self.moonlight.ip)
        if not apps:
            return self.loadPair()

        def get_tiles_by_apps(apps):
            tiles = []
            for app in apps:
                filename = os.path.join(Nvstream.BOXARTDIR,
                                        "{0}.png".format(app.id))
                tile = GameMenu.Tile(app.title, filename)
                if not os.path.isfile(filename):
                    t = Nvstream.BoxArtThread(self.moonlight.ip, app.id,
                                              gm.draw_tile, tile)
                    t.start()
                tiles.append(tile)
            return tiles

        gm.set_itens(get_tiles_by_apps(apps))
        out = gm.start()

        if out:
            self.menu.setColors(bg=(0, 0, 0))
            self.menu.msg("Stream starting")
            proc = self.moonlight.stream(out)
            while True:
                line = proc.stdout.readline()
                if not line:
                    break
                print(line)
                self.menu.msg("Stream starting", desc=line.rstrip())
                time.sleep(0.25)
            self.menu.msg("Please wait", desc="Waiting for process to end")
            proc.wait()
            self.menu.setColors()
            return self.loadMainMenu()
        else:
            return self.loadMainMenu()
Exemplo n.º 4
0
def main(team_blue, team_red, language):
    pygame.init()
    pygame.mixer.init()

    health_font = pygame.font.SysFont("monospace", 12)
    name_font = pygame.font.SysFont("monospace", 12)
    team_health_font = pygame.font.SysFont("monospace", 22, bold=True)
    time_font = pygame.font.SysFont("monospace", 30, bold=True)

    screen_x = constants.SCREEN_WIDTH
    screen_y = constants.SCREEN_HEIGHT
    speed = 0
    screen = pygame.display.set_mode((screen_x, screen_y))
    pygame.display.set_caption("Ormstunga")
    won = False
    RedWin = False
    BlueWin = False
    # Starting weapon of choice
    g_menu = GunMenu.GunMenu
    img = g_menu.BAZOOKA

    player_list = []

    for p in team_blue:
        player = worm.Worm(language)
        player.team = 'BLUE'
        player.name = p
        player_list.insert(random.randint(0, len(team_blue)), player)

    for p in team_red:
        player = worm.Worm(language)
        player.team = 'RED'
        player.name = p
        player_list.insert(random.randint(0, len(team_red)), player)
    red_team = Team.Team([x for x in player_list if x.team == 'RED'])
    blue_team = Team.Team([x for x in player_list if x.team == 'BLUE'])

    red_team_logo = pygame.transform.scale(
        pygame.image.load('Pics/Menu/team_red_logo.png'), (100, 24))
    blue_team_logo = pygame.transform.scale(
        pygame.image.load('Pics/Menu/team_blue_logo.png'), (100, 24))
    red_team_wins = pygame.transform.scale(pygame.image.load('Pics/rtw.png'),
                                           (500, 200))
    blue_team_wins = pygame.transform.scale(pygame.image.load('Pics/btw.png'),
                                            (500, 200))
    play_again = pygame.transform.scale(
        pygame.image.load('Pics/play_again.png'), (155, 47))

    active_sprite_list = pygame.sprite.Group()
    #background = pygame.Surface(screen.get_size())
    current_level = LandScape.LandScape01(player_list)
    for man in player_list:
        if man.team == 'BLUE':
            man.rect.x = random.randint(1100, 1200)
        else:
            man.rect.x = random.randint(250, 400)
        man.rect.y = 50 - man.rect.height
        man.level = current_level
        man.aim = aim.Aim(man)
        active_sprite_list.add(man)
        active_sprite_list.add(man.aim)

    clock = pygame.time.Clock()

    team_played = True

    red_team_cycle = itertools.cycle(red_team.members)
    blue_team_cycle = itertools.cycle(blue_team.members)

    player = get_player(red_team_cycle, blue_team_cycle, team_played)
    player.is_playing = True
    player.start_time = pygame.time.get_ticks()
    team_played = not team_played
    PlayerDel = False

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

        for RedWorm in red_team.members:
            if RedWorm.life <= 0 and player_list != []:
                player_list.remove(RedWorm)
                RedWorm.kill()
                RedWorm.aim.kill()
                PlayerDel = True

        for BlueWorm in blue_team.members:
            if BlueWorm.life <= 0 and player_list != []:
                player_list.remove(BlueWorm)
                BlueWorm.kill()
                BlueWorm.aim.kill()
                PlayerDel = True

        if PlayerDel:
            pl_team = player.team
            if pl_team == 'BLUE':
                blue_team.update([x for x in player_list if x.team == 'BLUE'])
                blue_team_cycle = itertools.cycle(blue_team.members)
                team_played = True
            else:
                red_team.update([x for x in player_list if x.team == 'RED'])
                red_team_cycle = itertools.cycle(red_team.members)
                team_played = False
            player = get_player(red_team_cycle, blue_team_cycle, team_played)
            player.is_playing = True
            team_played = not team_played
            player.start_time = pygame.time.get_ticks()
            PlayerDel = False

        active_sprite_list.update()
        current_level.update()
        current_level.draw(screen)
        active_sprite_list.draw(screen)

        time = time_font.render(str(int(player.time)), 2, (255, 255, 0))
        screen.blit(time, (20, 680))

        red_team_health = team_health_font.render(str(red_team.team_health), 2,
                                                  (255, 255, 255))
        blue_team_health = team_health_font.render(str(blue_team.team_health),
                                                   2, (255, 255, 255))

        screen.blit(red_team_health, ((screen_x / 2) - 30, 30))
        screen.blit(blue_team_health, ((screen_x / 2) + 30, 30))

        screen.blit(red_team_logo, ((screen_x / 2) - 140, 30))
        screen.blit(blue_team_logo, ((screen_x / 2) + 78, 30))

        for players in player_list:
            if players.is_playing:
                pn = name_font.render(str(players.name), 2, (255, 255, 255))
                screen.blit(pn, (players.rect.x, players.rect.y - 40))
            else:
                if players.team == 'BLUE':
                    pn = name_font.render(str(players.name), 2, (0, 0, 255))
                    screen.blit(pn, (players.rect.x, players.rect.y - 40))
                else:
                    pn = name_font.render(str(players.name), 2, (255, 0, 0))
                    screen.blit(pn, (players.rect.x, players.rect.y - 40))

            health = health_font.render(str(players.life), 2, (255, 255, 255))
            screen.blit(health, (players.rect.x, players.rect.y - 20))
        if not won:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    player.go_left()
                if event.key == pygame.K_RIGHT:
                    player.go_right()
                if event.key == pygame.K_SPACE:
                    player.jump()
                if event.key == pygame.K_UP:
                    player.aim.go_up()
                if event.key == pygame.K_DOWN:
                    player.aim.go_down()
                if event.key == pygame.K_1:
                    img = g_menu.BAZOOKA
                    player.current_gun = g_menu.BAZOOKA
                if event.key == pygame.K_2:
                    img = g_menu.GRENADE
                    player.current_gun = g_menu.GRENADE
                if event.key == pygame.K_3:
                    img = g_menu.HOLYBOMB
                    player.current_gun = g_menu.HOLYBOMB
                # shoot on keypad 0 down
                if event.key == pygame.K_KP0:
                    red_team.update(
                        [x for x in player_list if x.team == 'RED'])
                    blue_team.update(
                        [x for x in player_list if x.team == 'BLUE'])
                    b = False
                    if len(red_team.members) > 0 and len(
                            blue_team.members) > 0:
                        keys = pygame.key.get_pressed()
                        f = True
                        while keys[pygame.K_KP0] and f:
                            speed += 0.00005
                            for e in pygame.event.get():
                                if e.type == pygame.KEYUP:
                                    player.bullet = Bullets.Bullet(
                                        active_sprite_list, player, language)
                                    player.bullet.shoot(speed)
                                    active_sprite_list.add(player.bullet)
                                    player.is_playing = False
                                    player = get_player(
                                        red_team_cycle, blue_team_cycle,
                                        team_played)
                                    player.is_playing = True
                                    team_played = not team_played
                                    player.start_time = pygame.time.get_ticks()
                                    f = False
                                    speed = 0
                                    break
                    else:
                        if len(blue_team.members) == 0:
                            won = True
                            RedWin = True
                        if len(red_team.members) == 0:
                            won = True
                            BlueWin = True
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT and player.change_x < 0:
                    player.stop()
                if event.key == pygame.K_RIGHT and player.change_x > 0:
                    player.stop()

            # Stop if player time is over
            player.time = turntime - (pygame.time.get_ticks() -
                                      player.start_time) / 1000
            if player.time <= 0:
                player.is_playing = False
                player = get_player(red_team_cycle, blue_team_cycle,
                                    team_played)
                team_played = not team_played
                player.is_playing = True
                player.start_time = pygame.time.get_ticks()

            # Dying
            if int(player.rect.y) > screen_y and player_list != []:
                player_list.remove(player)
                player.kill
                player.aim.kill
                pl_team = player.team
                if not won:
                    if pl_team == 'BLUE':
                        blue_team.update(
                            [x for x in player_list if x.team == 'BLUE'])
                        blue_team_cycle = itertools.cycle(blue_team.members)
                        team_played = True
                    else:
                        red_team.update(
                            [x for x in player_list if x.team == 'RED'])
                        red_team_cycle = itertools.cycle(red_team.members)
                        team_played = False
                    player = get_player(red_team_cycle, blue_team_cycle,
                                        team_played)
                    player.is_playing = True
                    team_played = not team_played
                    player.start_time = pygame.time.get_ticks()

            if len(blue_team.members) == 0:
                won = True
                RedWin = True
            if len(red_team.members) == 0:
                won = True
                BlueWin = True

        mouse = pygame.mouse.get_pos()

        if RedWin:
            screen.blit(red_team_wins, ((screen_x / 2) - 250, 200))
            screen.blit(play_again, ((screen_x / 2) - 77.5, 400))
            if (screen_x / 2) - 77.5 < mouse[0] < (
                    screen_x / 2) + 77.5 and 400 < mouse[1] < 447:
                if pygame.mouse.get_pressed()[0]:
                    GameMenu.game_menu()
        elif BlueWin:
            screen.blit(blue_team_wins, ((screen_x / 2) - 250, 200))
            screen.blit(play_again, ((screen_x / 2) - 77.5, 400))
            if (screen_x / 2) - 77.5 < mouse[0] < (
                    screen_x / 2) + 77.5 and 400 < mouse[1] < 447:
                if pygame.mouse.get_pressed()[0]:
                    GameMenu.game_menu()

        screen.blit(img.value, (screen_x - img.value.get_width(),
                                screen_y - img.value.get_height()))

        pygame.display.flip()

        clock.tick(60)
Exemplo n.º 5
0
                won = True
                BlueWin = True

        mouse = pygame.mouse.get_pos()

        if RedWin:
            screen.blit(red_team_wins, ((screen_x / 2) - 250, 200))
            screen.blit(play_again, ((screen_x / 2) - 77.5, 400))
            if (screen_x / 2) - 77.5 < mouse[0] < (
                    screen_x / 2) + 77.5 and 400 < mouse[1] < 447:
                if pygame.mouse.get_pressed()[0]:
                    GameMenu.game_menu()
        elif BlueWin:
            screen.blit(blue_team_wins, ((screen_x / 2) - 250, 200))
            screen.blit(play_again, ((screen_x / 2) - 77.5, 400))
            if (screen_x / 2) - 77.5 < mouse[0] < (
                    screen_x / 2) + 77.5 and 400 < mouse[1] < 447:
                if pygame.mouse.get_pressed()[0]:
                    GameMenu.game_menu()

        screen.blit(img.value, (screen_x - img.value.get_width(),
                                screen_y - img.value.get_height()))

        pygame.display.flip()

        clock.tick(60)


if __name__ == "__main__":
    GameMenu.game_menu()
Exemplo n.º 6
0
#! /usr/bin/python3

import pygame
import GameView
import GameController
import GameMenu
import GameModel

if __name__ == "__main__":
    pygame.mixer.pre_init(44100, -16, 2, 4096)
    pygame.mixer.init()
    pygame.init()
    gameModel = GameModel.GameModel()
    gameMenu = GameMenu.GameMenu()
    gameView = GameView.GameView(gameMenu.screen, gameModel)
    gameController = GameController.GameController(gameView, gameMenu)
    gameController.main_menu()
Exemplo n.º 7
0
def play():
	game = GameMenu(my_screen, menu_items)
	start=game.run()
	while start:
	#create screen
		my_screen.blit(image, [0, 0])	
		pygame.display.set_caption('Remember the Pattern')
		gameLevel=1
		life=3
		while gameLevel<10:

			#show current level
			level_str='Level '+ str(gameLevel)
			my_text=my_font.render(level_str,True,(255,255,255))
			my_screen.blit(image, [0, 0])
			my_screen.blit(my_text, centerFont(my_screen,my_text))
			pygame.display.update()
			pygame.time.delay(2000)
			my_screen.blit(image, [0, 0])
			printlife(my_screen,life)
			
			#create and display pattern
			pattern_size=getPatternSize(gameLevel)
			block_number=getBlockNumber(gameLevel)
			patternlist = patternInitiation.initiatePattern(my_screen,HORIZ,VERT,block_number,pattern_size)
			my_screen.blit(image, [0, 0])
			printlife(my_screen,life)
		
			#ask user and show user input interface
			buttonlist=playscreen.initiateGameScreen(my_screen,HORIZ,VERT,block_number,pattern_size)
			
			#compare the input with the initial pattern and show a message based on the result
			flag=True
			for i in range(0,block_number-1):
				if not patternlist[i]==buttonlist[i].getIsPressed():
					flag=False
					break
			if flag:	
				my_text=my_font.render('CORRECT!',True,(255,255,255))
				gameLevel+=1
			else:
				my_text=my_font.render('Level Failed',True,(255,255,255))
				life-=1
			if life==0:
				my_text=my_font.render('Game Over!',True,(255,255,255))
				my_screen.blit(image, [0, 0])
				my_screen.blit(my_text, centerFont(my_screen,my_text))
				pygame.display.update()
				pygame.time.delay(2000)
				break
	
			#show message on screen
			my_screen.blit(image, [0, 0])
			my_screen.blit(my_text, centerFont(my_screen,my_text))
			pygame.display.update()
			pygame.time.delay(2000)
		
		#show menu after finishing the game
		my_screen.blit(image, [0, 0])
		pygame.display.set_caption('Game Menu')
		game = GameMenu(my_screen, menu_items)
		start=game.run()
		
	else:
		#say bye
		my_text=my_font.render('BYE!!',True,(255,255,255))
		my_screen.blit(image, [0, 0])
		my_screen.blit(my_text, centerFont(my_screen,my_text))
		pygame.display.update()
		pygame.time.delay(4000)
Exemplo n.º 8
0
def play():
    game = GameMenu(my_screen, menu_items)
    start = game.run()
    while start:
        #create screen
        my_screen.blit(image, [0, 0])
        pygame.display.set_caption('Remember the Pattern')
        gameLevel = 1
        life = 3
        while gameLevel < 10:

            #show current level
            level_str = 'Level ' + str(gameLevel)
            my_text = my_font.render(level_str, True, (255, 255, 255))
            my_screen.blit(image, [0, 0])
            my_screen.blit(my_text, centerFont(my_screen, my_text))
            pygame.display.update()
            pygame.time.delay(2000)
            my_screen.blit(image, [0, 0])
            printlife(my_screen, life)

            #create and display pattern
            pattern_size = getPatternSize(gameLevel)
            block_number = getBlockNumber(gameLevel)
            patternlist = patternInitiation.initiatePattern(
                my_screen, HORIZ, VERT, block_number, pattern_size)
            my_screen.blit(image, [0, 0])
            printlife(my_screen, life)

            #ask user and show user input interface
            buttonlist = playscreen.initiateGameScreen(my_screen, HORIZ, VERT,
                                                       block_number,
                                                       pattern_size)

            #compare the input with the initial pattern and show a message based on the result
            flag = True
            for i in range(0, block_number - 1):
                if not patternlist[i] == buttonlist[i].getIsPressed():
                    flag = False
                    break
            if flag:
                my_text = my_font.render('CORRECT!', True, (255, 255, 255))
                gameLevel += 1
            else:
                my_text = my_font.render('Level Failed', True, (255, 255, 255))
                life -= 1
            if life == 0:
                my_text = my_font.render('Game Over!', True, (255, 255, 255))
                my_screen.blit(image, [0, 0])
                my_screen.blit(my_text, centerFont(my_screen, my_text))
                pygame.display.update()
                pygame.time.delay(2000)
                break

            #show message on screen
            my_screen.blit(image, [0, 0])
            my_screen.blit(my_text, centerFont(my_screen, my_text))
            pygame.display.update()
            pygame.time.delay(2000)

        #show menu after finishing the game
        my_screen.blit(image, [0, 0])
        pygame.display.set_caption('Game Menu')
        game = GameMenu(my_screen, menu_items)
        start = game.run()

    else:
        #say bye
        my_text = my_font.render('BYE!!', True, (255, 255, 255))
        my_screen.blit(image, [0, 0])
        my_screen.blit(my_text, centerFont(my_screen, my_text))
        pygame.display.update()
        pygame.time.delay(4000)
Exemplo n.º 9
0
                    ghost.nextxtile, ghost.nextytile = ghosts.BlueGHLoc
                    ghost.xtile, ghost.ytile = ghosts.BlueGHLoc
                elif ghost.ghostColor == 'O':
                    ghost.nextxtile, ghost.nextytile = ghosts.OrangeGHLoc
                    ghost.xtile, ghost.ytile = ghosts.OrangeGHLoc

                # Update ghost's location in pixels
                ghost.xloc = ghost.xtile * TileLen
                ghost.yloc = ghost.ytile * TileLen

                ghost.drawGhost()
                ghost.mode = None
                ghost.eatenbypacman = True

            else:
                # The pacman was eaten by the ghost
                # the pacman's life - 1, if 0, game over
                print('Eaten')
                self.PacMan.lives -= 1
                pygame.time.wait(3000)
                self.events.PacManLives(self.PacMan, self.gameScreen,
                                        self.gamemap, self.ghostdict,
                                        self.fruits, self.game_start_time)
                self.events.restart_lvl(self.PacMan, self.gameScreen,
                                        self.gamemap, self.ghostdict,
                                        self.fruits)


if __name__ == "__main__":
    GameMenu()