コード例 #1
0
ファイル: Game.py プロジェクト: nidycai/Alien-invasion-modify
 def __init__(self):
     self.settings = GameSettings()
     pygame.init()
     self.screen = pygame.display.set_mode(
         (self.settings.screen_width, self.settings.screen_height))
     self.screen_rect = self.screen.get_rect()
     pygame.display.set_caption('Alien Invasion')
コード例 #2
0
ファイル: game.py プロジェクト: Maxw21/Pacman_Portal
def run_game():
    # Initialize pygame, settings, and screen object.
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.mixer.init()
    pygame.init()
    game_settings = GameSettings()
    screen = pygame.display.set_mode((game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Pac Man Portal")

    # Open sprite sheet
    sprite_sheet = SpriteSheet(file_name='images/spritesheet.png')

    # Make the Play and Scores button.
    play_button = Button(screen=screen, msg="Play", order=0)
    score_button = Button(screen=screen, msg="High Scores", order=1)

    # Open high score file
    try:
        high_score_file = open("high_score_file.txt", "r+")
    except FileNotFoundError:
        high_score_file = open("high_score_file.txt", "w+")

    # Open maze layout file
    maze_file = open('mazelayout.txt', 'r')

    # Make sound manager
    sounds = Sounds()

    # Initialize game stats and scoreboard
    stats = GameStats(game_settings=game_settings)
    sb = Scoreboard(screen=screen, game_settings=game_settings, stats=stats, sprite_sheet=sprite_sheet,
                    high_score_file=high_score_file, sounds=sounds)

    # Initialize pacman
    pacman = Pacman(screen=screen, game_settings=game_settings, stats=stats, sb=sb,
                    image_list=sprite_sheet.pacman_image, death_anim_list=sprite_sheet.pacman_death_image,
                    sounds=sounds)

    # Initialize maze
    maze = Maze(screen=screen, game_settings=game_settings, maze_file=maze_file, sprite_sheet=sprite_sheet,
                pacman=pacman, sounds=sounds)

    # Initialize the event handler
    event_handler = EventHandler(pacman=pacman, play_button=play_button, score_button=score_button, stats=stats, sb=sb,
                                 maze=maze, sounds=sounds)

    # Initialize the display manager
    display = Display(screen=screen, game_settings=game_settings, stats=stats, sb=sb, sprite_sheet=sprite_sheet,
                      play_button=play_button, score_button=score_button, maze=maze, pacman=pacman,
                      event_handler=event_handler, sounds=sounds)

    # Start the main loop for the game
    while True:
        event_handler.check_events()
        if stats.game_active:
            pacman.update(maze=maze, display=display)
            maze.update_ghosts()
            maze.update_bullets()
            maze.update_portals()
        display.update_screen()
コード例 #3
0
def run_game():
    # Init game and create screen object
    pygame.init()
    settings = GameSettings()

    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    play_btn = Button(screen)
    stats = GameStats(settings)
    sb = ScoreBoard(settings, screen, stats)
    ship = Ship(screen, settings.ship_speed)
    bullets = Group()
    aliens = Group()

    gf.create_fleet(settings, screen, ship, aliens)

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

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

        gf.update_screen(settings, screen, stats, ship, bullets, aliens,
                         play_btn, sb)
コード例 #4
0
 def __init__(self):
     self.game_settings = GameSettings()
     self.size = width, height = self.game_settings.game_width, self.game_settings.game_height
     self.screen = pygame.display.set_mode(self.size)
     pygame.display.set_caption('Incremental Dungeon')
     self.town_panel_wrapper = TownWindow(0, self.game_settings)
     self.dungeon_panel_wrapper = DungeonWindow(0, self.game_settings,
                                                self.town_panel_wrapper)
コード例 #5
0
def run_game():
    pygame.init()
    gs = GameSettings()
    screen = gf.create_screen(gs.screen)
    ship = Ship(gs.ship, screen)
    bullets = Group()
    aliens = Group()

    gf.create_fleet(gs, screen, ship, aliens)

    while True:
        gf.check_events(gs, screen, ship, bullets, time)
        ship.update()
        gf.update_bullets(bullets)
        gf.update_screen(gs.screen, screen, ship, aliens, bullets)
コード例 #6
0
    def __init__(self):
        pygame.init()
        self.settings = GameSettings()

        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))

        # self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN)
        # self.settings.screen_width = self.screen.get_rect().width
        # self.settings.screen_height = self.screen.get_rect().height

        pygame.display.set_caption('Alien Invasion')

        self.stats = GameStats(self)
        self.ship = Ship(self)
        self.bullets = pygame.sprite.Group()
        self.aliens = pygame.sprite.Group()

        self._create_fleet()
        self.play_button = Button(self, "Play")
コード例 #7
0
def run_game():
    # Initialize game and create a screen object
    pygame.init()
    # create a GameSettings object to make screen
    gameSettings = GameSettings()
    # make a screen with provided dimensions
    screen = pygame.display.set_mode((gameSettings.screen_width, gameSettings.screen_height))
    pygame.display.set_caption("Alien Shooting Game")

    # Draw the SpaceShip
    spaceShip = Spaceship(screen)


    # main loop to control the game
    while True:
        # use screen.fill to fill in the background color
        screen.fill(gameSettings.background_color)
        spaceShip.draw()
        gf.events_check(spaceShip)
        spaceShip.update()
        gf.screen_update(screen = screen, gameSettings = gameSettings, spaceShip = spaceShip)
コード例 #8
0
def run_game():
    # Initialize game and create a screen object
    pygame.init()
    game_settings = GameSettings()
    game_stats = GameStats()
    screen = gf.initialize_screen(game_settings)
    turn_info = TurnInfo()
    player_turn_msg = PlayersTurn(game_settings, screen)
    move_allowed_msg = MoveNotAllowed(game_settings, screen)
    pawn_allowed_msg = PawnNotAllowed(game_settings, screen)
    player_win_msg = PlayerWin(game_settings, screen)

    # Make a list to store squares in.
    squares = []

    # Create the checker board out of a group of individual squares
    gf.create_checker_board(game_settings, screen, squares)

    # Create the pawn selector
    pawn_selector = PawnSelector(game_settings, screen)

    # Make a list to store pawns in.
    pawns = []

    # Initialize matrix of positions
    positions_matrix = []

    # Create the full set of pawns
    gf.create_pawns_set(game_settings, screen, pawns, positions_matrix)

    # Start the main loop for the game
    while True:
        if game_stats.game_active:
            gf.check_events(game_stats, turn_info, positions_matrix, pawns,
                            pawn_selector)
            gf.update_screen(game_settings, turn_info, screen, squares,
                             pawn_selector, pawns, player_turn_msg,
                             move_allowed_msg, pawn_allowed_msg,
                             player_win_msg)
コード例 #9
0
 def __init__(self):
     """ Init game object. """
     pygame.init()
     self.g_settings = GameSettings()
     self.surface = pygame.display.set_mode(
         (self.g_settings.window_width, self.g_settings.window_height))
     # surface part for game map
     self.game_screen = pygame.Rect(self.g_settings.game_positionx,
                                    self.g_settings.game_positiony,
                                    self.g_settings.game_width,
                                    self.g_settings.game_height)
     # surface part for score and statistic
     self.score_screen = pygame.Rect(self.g_settings.score_positionx,
                                     self.g_settings.score_positiony,
                                     self.g_settings.score_width,
                                     self.g_settings.score_height)
     # set window title
     pygame.display.set_caption(self.g_settings.game_title)
     # player rank
     self.p_tank = PlayerTank(self.surface, self.game_screen,
                              self.g_settings, md.UP,
                              self.g_settings.p_tank_centerx,
                              self.g_settings.p_tank_centery)
     # sprites group for bullets
     self.p_bullets = pygame.sprite.Group()
     self.e_bullets = pygame.sprite.Group()
     # sprites group for enemys tanks
     self.enemys = pygame.sprite.Group()
     self.enemy_tank = EnemyTank(self.surface, self.game_screen,
                                 self.g_settings, md.RIGHT, 25, 25)
     self.enemy_tank2 = EnemyTank(self.surface, self.game_screen,
                                  self.g_settings, md.LEFT, 225, 25)
     self.enemys.add(self.enemy_tank)
     self.enemys.add(self.enemy_tank2)
     # create wall
     self.walls = pygame.sprite.Group()
     # Start game loop
     self.loop()
コード例 #10
0
def run_program():

    pygame.init()
    game_settings = GameSettings()

    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Ant Intelligent")

    start_button = StartButton(game_settings, screen)

    ants = Group()
    foods = Group()

    ########################################################################
    ####					Function:Main Loop							####
    ########################################################################
    while True:
        gf.check_all_event(game_settings, start_button)

        if game_settings.game_active:
            pass

        gf.screen_update(game_settings, screen, start_button)
コード例 #11
0
    def __init__(self):
        """Initialize the game and create game resources"""
        pygame.init()
        self.settings = GameSettings()
        # Set up a clock that regulates the FPS of the game window
        self.clock = pygame.time.Clock()
        self.settings.vertical_momentum = 0

        drivers = ['directfb', 'fbcon', 'svgalib']

        found = False
        for driver in drivers:
            if not os.getenv('SDL_VIDEODRIVER'):
                os.putenv('SDL_VIDEODRIVER', driver)
            try:
                pygame.display.init()
            except pygame.error:
                print('Driver: {0} failed.'.format(driver))
                continue
            found = True
            break

        if not found:
            raise Exception('No suitable video driver found!')

        self.screen_window = pygame.display.set_mode((self.settings.screen_width,
                                                      self.settings.screen_height))
        pygame.display.set_caption("Alien Apocalypse")

        """Setting background color"""
        self.background_color = (0, 0, 255)

        # Initialize the attributes for the Mage class
        self.mage = Mage(self)
        self.walking_step = 6
        self.bullets = pygame.sprite.Group()
コード例 #12
0
def main():

    win_size = 1000
    game_settings = GameSettings()
    game_settings.window_height = win_size
    game_settings.window_width = win_size
    game_settings.map_height = win_size
    game_settings.map_width = win_size
    game_settings.zoom = 0.5

    game_settings.zoom_factor = 0.005

    pygame.init()
    win: pygame.Surface = pygame.display.set_mode(
        (game_settings.window_width, game_settings.window_height))

    g_field = GravitationalField(g=0.001)

    n_planets = 50

    g_objects: List[GravitationalObject] = [
        get_random_planet(game_settings,
                          g_field,
                          v_range=((0, 1), (0, 1)),
                          pos_range=((-10000, 10000), (-10000, 10000)),
                          density_range=(10000000, 100000000),
                          size_range=(50, 200)) for _ in range(n_planets)
    ]
    g_objects.append(
        MySpaceship(game_settings,
                    gravitational_field=g_field,
                    size=10,
                    m=np.array([10]),
                    colour=(0, 0, 100),
                    controls=default_controls))

    tick_time = 1 / game_settings.ticks_per_second * 1000

    while game_settings.is_running:
        win.fill((0, 0, 0))
        pygame.time.delay(int(tick_time))

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game_settings.is_running = False

        keys = pygame.key.get_pressed()

        font = pygame.font.SysFont("Courier New", 16)
        text_surface = font.render(
            f"camera pos: ({game_settings.camera_pos[0]: 0.2f},{game_settings.camera_pos[1]: 0.2f})\r"
            f"zoom: {game_settings.zoom: 0.2f}", True,
            game_settings.debug_text_colour)
        win.blit(text_surface, (10, 10))

        if keys[pygame.K_q]:
            game_settings.zoom *= 1 - game_settings.zoom_factor
        if keys[pygame.K_e]:
            game_settings.zoom *= 1 + game_settings.zoom_factor

        if keys[pygame.K_w]:
            game_settings.camera_pos[1] += 10
        if keys[pygame.K_s]:
            game_settings.camera_pos[1] -= 10
        if keys[pygame.K_a]:
            game_settings.camera_pos[0] += 10
        if keys[pygame.K_d]:
            game_settings.camera_pos[0] -= 10

        for obj in g_objects:
            obj.update_physics(obj.parse_controls(keys),
                               time_elapsed=tick_time)

            if type(obj) == MySpaceship:
                obj.centre()

            obj.draw(win)

        g_field.update(tick_time / 1000)
        pygame.display.flip()
コード例 #13
0
ファイル: app.py プロジェクト: bmartin5263/Uno_Basic
    def mainMenu():
        sys.stdout.write("\x1b[8;32;63t")
        sys.stdout.flush()
        gs = GameSettings()

        while True:

            print(drawMainMenu(gs))

            selection = str(input('\033[97mSelection: \033[92m'))
            while selection not in ['1', '2', '3', '4', '5']:
                gs.mainMenuError = "Invalid Selection"
                print(drawMainMenu(gs))
                selection = str(input('\033[97mSelection: \033[92m'))

            if selection == '1':
                if gs.canBegin():
                    gs.mainMenuError = ""
                    gs.finalizePlayers()
                    gs = playMatch(gs)
                else:
                    gs.mainMenuError = "Two Players Required to Begin"

            elif selection == '2':
                if gs.canAddPlayer():
                    gs.mainMenuError = ""
                    gs = addPlayer(gs)
                else:
                    gs.mainMenuError = "Max Number of Players Reached"

            elif selection == '3':
                if gs.canAddPlayer():
                    gs.mainMenuError = ""
                    gs = addComputer(gs)
                else:
                    gs.mainMenuError = "Max Number of Players Reached"

            elif selection == '4':
                if gs.canRemovePlayer():
                    gs.mainMenuError = ""
                    gs = removePlayer(gs)
                else:
                    gs.mainMenuError = "No Players to Remove"

            elif selection == '5':
                gs.mainMenuError = ""
                gs = settingsMenu(gs)

            else:
                raise BadInputError('Data Provided Has No Function')