Esempio n. 1
0
def run_game():
    #initialize game & screen objectt
    pygame.init()  #called the pygame init constructor
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    #set the background code
    #the screen object is called a surface
    #On that surface we'll keep our elements
    pygame.display.set_caption("What the Fart!")
    #Object creation of items on the screen
    butt = Butt(screen)
    #creating a group of noses using sprite.Group()
    noses = Group()
    #create a group of aliens
    bullets = Group()
    #creating group of bullets
    gf.create_fleet(settings, screen, noses)
    while True:
        x = gf.check_events(butt, bullets, screen)
        #checks the events in for loop get_events()
        butt.update()
        #updating the butt positions
        gf.bullet_update(butt, bullets, x)
        #creating and updating bullets
        gf.rm_oldbullet(bullets)
        #removing old bullets from the sprite group
        gf.update_noses(noses)
        #update noses and their movement
        gf.check_collisions(bullets, noses, settings, screen)
        #collision between noses and bullet farts
        gf.update_surface(settings, butt, bullets, noses, x, screen)
Esempio n. 2
0
def run_game():
    """Initialize the game, settings and create a screen object."""
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Snake")

    # Create an instance to store game statistics.
    stats = GameStats(settings)

    # Make a group of food and snake rects.
    food = Group()
    snake_body = Group()

    # An array to hold snake pieces for removing later.
    snake_list = []

    # Create the snake body.
    gf.create_snake_body(screen, settings, snake_body, snake_list)

    # Start the main loop for the game.
    while True:
        gf.check_events(food, screen, settings)
        gf.check_collisions(food, screen, settings, snake_list, stats)

        if stats.game_active:
            gf.move_snake(food, screen, settings, snake_body, snake_list)
            gf.check_snake_food(food, screen, settings)

        gf.update_screen(food, screen, settings, snake_body)

        sleep(settings.speed)
Esempio n. 3
0
def main():

    pyg.init() # Init pygame and make a window, the player, and the tiles
    pyg.display.set_caption("Pew Pew Game")
    window = pyg.display.set_mode((1200, 800)) # Tile Dimensions: 60x40
    player = Player(window)
    enemies = Group()
    enemy = Enemy(window)
    enemies.add(enemy)
    walls = Group()
    lavas = Group()
    gf.init_tiles(window, walls, lavas)

    while True:
        gf.fade_to_black(window)
        gf.check_events(player)
        player.move()
        gf.check_collisions(player, walls, lavas, enemies, window)
        gf.update_screen(window, player, walls, lavas, enemies)
Esempio n. 4
0
enemies.add(enemy)
enemies.add(enemy2)
enemies.add(enemy3)

pygame.display.set_caption("My Game")

# Loop until the user clicks the close button.
done = False

# Used to manage how fast the screen updates
clock = pygame.time.Clock()

# -------- Main Program Loop -----------
while not done:

    # --- Check events; If user quits, exit main program loop
    done = gf.check_events(settings, screen, player, bullets)

    # --- Game logic should go here
    gf.update_everything(player, bullets, enemies)
    gf.check_collisions(settings, sb, bullets, enemies)
    gf.check_bullets_pos(bullets)

    # --- Draw all objects to the screen
    gf.update_screen(screen, sb, player, enemies, bullets)

    # --- Limit to 60 frames per second
    clock.tick(60)

# Close the window and quit.
pygame.quit()
Esempio n. 5
0
def run_game():

    #Create some groups of objects
    game_objects = Group()
    bullets = Group()
    aliens = Group()
    buttons = Group()
    
    #Initialize game settings
    game_settings = Settings()
    
    #Initialize game statistics
    game_stats = Stats()
    
    #Pygame initiation, and establish screen  
    pygame.init()
    screen = pygame.display.set_mode((game_settings.screen_width, 
                        game_settings.screen_height))
    pygame.display.set_caption(game_settings.screen_title)
    
    #Create background object
    background = Background(screen, game_settings)
    game_objects.add(background)
    
    #Create ship object
    ship = Ship(screen, game_settings)
    game_objects.add(ship)
    
    #Create fleet of aliens then add them to game objects and aliens groups
    gf.create_fleet(screen, game_settings, game_objects, aliens)
    
    #Create buttons then ass them to game_objects and buttons groups
    gf.create_start_buttons(screen, game_settings, game_objects, buttons)
    
    #Create clock object
    clock = Clock()
    
    #Some statistics labels
    level = Label(screen, "level: " + str(game_stats.level), 10, 10)
    game_objects.add(level)

    ammo = Label(screen, "ammo: " + str(ship.game_settings.ammo), 200, 10)
    game_objects.add(ammo)

    points = Label(screen, "score: " + str(game_stats.points), 400, 10)
    game_objects.add(points)

    #Update screen           
    gf.update_screen(game_objects)

    while True:
        if len(aliens) == 0:
            game_stats.level += 1
            game_settings.alien_speed_factor += 1
            game_settings.ammo = game_settings.ammo + game_settings.initial_ammo
            #Create fleet of aliens then add them to game objects and aliens groups
            gf.create_fleet(screen, game_settings, game_objects, aliens)
        
        #Check events key down or key up
        gf.check_events(game_stats, game_objects, ship, bullets, buttons)
    
        level.text = "level: " + str(game_stats.level)
        ammo.text = "ammo: " + str(ship.game_settings.ammo)
        points.text = "score: " + str(game_stats.points)
        
        if game_stats.game_started:
            #Check collisions
            gf.check_collisions(screen, game_settings, game_stats, game_objects, ship, aliens, bullets, buttons)
        
            #Update screen           
            gf.update_screen(game_objects)

        #Wait certain time to achieve 40fps 
        clock.tick(40)
Esempio n. 6
0
def run_game():
    pygame.init()

    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.mixer.init()
    pygame.mixer.music.load('songs/8bit_bgm.wav')
    pygame.mixer.music.play(-1)

    svv_settings = Settings()
    stats = GameStats(svv_settings)

    screen = pygame.display.set_mode(
        (svv_settings.screen_width, svv_settings.screen_height))
    pygame.display.set_caption("SPIDEY VS VENOM")

    play_button = Button(svv_settings, screen, "Click to Play")

    s_hb = HB(screen, 0, (255, 0, 0))
    v_hb = HB(screen, 1, (0, 0, 255))
    s_i_hb = HB_I(screen, 0)
    v_i_hb = HB_I(screen, 1)

    spidey = Spidey(svv_settings, screen)
    venom = Venom(svv_settings, screen)

    bullets = Group()
    venom_bullets = Group()
    vomit_bullets = Group()

    while True:

        if not stats.spidey_died and not stats.venom_died:
            gf.check_health_bar(s_hb, v_hb, stats)

            if stats.spidey_died or stats.venom_died:
                play_button = GO(screen, stats)

        if stats.spidey_died or stats.venom_died:
            play_button.update_image()

        gf.check_events(svv_settings, screen, stats, play_button, spidey,
                        bullets, venom, venom_bullets, vomit_bullets)
        gf.update_screen(svv_settings, screen, spidey, stats, play_button,
                         bullets, venom, venom_bullets, vomit_bullets,
                         (s_hb, v_hb), (s_i_hb, v_i_hb))

        if stats.game_active == False:
            s_hb.reset_health_bar()
            v_hb.reset_health_bar()

            spidey.center_spidey()
            venom.center_venom()

        if stats.game_active:
            stats.spidey_died = False
            stats.venom_died = False

            spidey.intro()
            venom.intro()

            if spidey.mask_on and venom.mask_on == True:
                spidey.update()
                venom.update()

                bullets.update()
                venom_bullets.update()
                vomit_bullets.update()

                gf.update_bullets(bullets, venom_bullets, vomit_bullets)
                gf.check_collisions(venom, spidey, venom_bullets,
                                    vomit_bullets, bullets, s_hb, v_hb)

        pygame.display.flip()
# Make an enemy.
gf.spawn_enemies(settings, screen, enemies, enemy_bullets)

pygame.display.set_caption("My Game")

# Loop until the user clicks the close button.
done = False

# Used to manage how fast the screen updates
clock = pygame.time.Clock()

# -------- Main Program Loop -----------
while not done:

    # --- Check events; If user quits, exit main program loop
    done = gf.check_events(settings, screen, player, bullets)

    # --- Game logic should go here
    gf.update_everything(player, bullets, enemies, enemy_bullets)
    gf.check_collisions(settings, screen, sb, bullets, enemies, enemy_bullets)
    gf.check_bullets_pos(bullets)

    # --- Draw all objects to the screen
    gf.update_screen(screen, sb, player, enemies, bullets, enemy_bullets)

    # --- Limit to 60 frames per second
    clock.tick(60)

# Close the window and quit.
pygame.quit()
Esempio n. 8
0
def run_game():
    # Initialize game and create a screen object.
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    pygame.display.set_caption("Pong")

    # Start screen
    start = Start(screen)

    # Draw line
    line = Line(screen)

    # Draw right side paddle
    right = VerticalPaddle(screen)
    right.rect.centery = right.screen_rect.centery
    right.rect.right = right.screen_rect.right

    # Draw Right top paddle
    right_top = HorizontalPaddle(screen)
    right_top.rect.top = right_top.screen_rect.top
    right_top.rect.centerx = right_top.screen_rect.centerx * 1.5

    # Draw Right bottom paddle (align to right top paddle)
    right_bot = HorizontalPaddle(screen)
    right_bot.rect.bottom = right_bot.screen_rect.bottom
    right_bot.rect.centerx = right_top.rect.centerx

    # Draw left side paddle
    left = CPUVerticalPaddle(screen)
    left.rect.centery = left.screen_rect.centery
    left.rect.left = left.screen_rect.left

    # Draw CPU top paddle
    left_top = CPUHorizontalPaddle(screen)
    left_top.rect.top = left_top.screen_rect.top
    left_top.rect.centerx = left_top.screen_rect.centerx / 2

    # Draw CPU bottom paddle
    left_bot = CPUHorizontalPaddle(screen)
    left_bot.rect.bottom = left_bot.screen_rect.bottom
    left_bot.rect.centerx = right_top.rect.centerx

    # Draw ball
    ball = Ball(screen)
    ball.rect.centerx = ball.screen_rect.centerx
    ball.rect.centery = ball.screen_rect.centery

    # Make game active to false
    ball.game_active = False

    # Start the main loop for the game
    while True:
        gf.check_events(right, right_top, ball, screen)

        if ball.start_active:
            start.start_blit(screen)
            start.start_update(ball)

        if ball.game_active:
            gf.update_screen(screen, line, right, right_top, right_bot, left,
                             left_top, left_bot, ball, start)
            right.update()
            right_top.update()
            left.update(ball, start)
            left_top.update(ball, start)
            gf.check_ball(ball)
            gf.check_collisions(ball, right, right_top, right_bot, left,
                                left_top, left_bot)