Example #1
0
def main():
    #backgrounds, screen, clock, song, font = setup()
    backgrounds, background_size = setup_backgrounds("far", "sand",
                                                     "foreground")
    font = setup_displays("main_theme", "Pixeled.ttf")
    clock = setup_clock()
    screen = setup_screen(background_size)

    menu(backgrounds, screen, clock)

    #a list of all sprites
    all_sprites_list = pygame.sprite.Group()
    sharks = pygame.sprite.Group()
    sushis = pygame.sprite.Group()

    #objects
    fish = Fish()
    shark = Shark()
    sushi = Sushi()

    #add sprites to lists
    all_sprites_list.add(fish)
    all_sprites_list.add(shark)
    all_sprites_list.add(sushi)
    sharks.add(shark)
    sushis.add(sushi)

    timer = 1
    #run until sys.exit() is detected
    while True:
        #print(len(sharks))
        if (timer % 150 == 0):
            #print(len(sharks))
            #make a new shark and add to the lists
            shark = Shark()
            sharks.add(shark)
            all_sprites_list.add(shark)
        elif (timer % 225 == 0):
            sushi = Sushi()
            sushis.add(sushi)
            all_sprites_list.add(sushi)
        timer += 1

        pressed_key = pygame.key.get_pressed()

        check_for_quit(pressed_key)
        draw_background(screen, backgrounds)
        animate(fish, sharks, sushis, all_sprites_list, font, pressed_key,
                backgrounds, screen)
        check_off_screen(sharks, sushis)

        #afterwards, display the new screen after updates are finalized
        pygame.display.flip()
        clock.tick(FPS)
Example #2
0
    def spawn_enemies(self):
        spawns = self.level.get_spawns()
        if spawns[Level.SHARKS]:
            # Make a new shark
            self.sharks.append(Shark())
            self.shark_sprites.add(self.sharks[-1])

        if spawns[Level.PIRATES]:
            # Make a new pirate ship
            self.pirates.append(Pirateboat())
            self.pirate_sprites.add(self.pirates[-1])

        if spawns[Level.MINES]:
            self.mines.append(Mine())
            self.mine_sprites.add(self.mines[-1])

        if spawns[Level.SEAGULLS]:
            self.seagulls.append(Seagull())
            self.seagull_sprites.add(self.seagulls[-1])

        if spawns[Level.TITANIC]:
            self.titanic = Titanic()
            self.titanic_sprite.add(self.titanic)

        if spawns[Level.POWERUPS]:
            self.powerups.append(Powerup())
            self.powerup_sprites.add(self.powerups[-1])
Example #3
0
 def spawn(self, grid, creature_type):
     spawned = False
     while not spawned:
         x = random.randint(0, HEIGHT - 1)
         y = random.randint(0, WIDTH - 1)
         if grid[x][y] == 0:
             spawned = True
     if creature_type == "fish":
         grid[x][y] = 1
         fish = Fish(x, y)
     elif creature_type == "shark":
         grid[x][y] = 2
         shark = Shark(x, y)
Example #4
0
 def spawn_creature(self, grid, creature_type):
     """Randomly choose beginning location of creatures."""
     spawned = False
     while not spawned:
         x = random.randint(0, HEIGHT - 1)
         y = random.randint(0, WIDTH - 1)
         if grid[x][y] == 0:
             spawned = True
     if creature_type == "fish":
         grid[x][y] = 1
         fish = Fish(x, y)
     elif creature_type == "shark":
         grid[x][y] = 2
         shark = Shark(x, y)
Example #5
0
    def __init__(self, player, level, background, platform, creatures_list,
                 shark_list, bubble_number, shell_number, diver_x):
        # Lists of sprites used in all levels.
        self.platform_list = None
        self.treasure_list = None
        self.enemy_list = None
        self.shark_list = None
        # Background
        self.background = None
        # How far world has been scrolled right
        self.world_shift = 0
        self.platform_list = pygame.sprite.Group()
        self.treasure_list = pygame.sprite.Group()
        self.bubbles_list = pygame.sprite.Group()
        self.enemy_list = pygame.sprite.Group()
        self.shark_list = pygame.sprite.Group()
        self.floor = pygame.sprite.Group()
        self.level = level
        self.player = player
        self.background = pygame.image.load(background).convert()
        self.background.set_colorkey
        self.level_limit = -11500
        self.creature = creatures_list
        self.shark = shark_list
        self.diver_x = diver_x
        self.bubble_number = bubble_number
        self.shell_number = shell_number
        """
        looping through a list of variables to add items
        """
        for creature in self.creature:
            cr = Creatures(creature, self)
            self.enemy_list.add(cr)

        for shark in self.shark:
            sr = Shark(shark, self)
            self.enemy_list.add(sr)

        for treasure in range(self.shell_number):
            tr = Treasure(self)
            self.treasure_list.add(tr)

        for bubble in range(self.bubble_number):
            bu = Bubbles(self)
            self.bubbles_list.add(bu)

        self.floor.add(SpriteOnScreen(platform, 0, 0))
Example #6
0
def main():
    width = 1000
    height = 1000
    blue_color = (97, 159, 182)
    black_color = (0, 0, 0)

    # adding music
    pygame.mixer.init()
    # sound = pygame.mixer.Sound('music/baby_shark_soundtrack.wav')

    pygame.init()
    screen = pygame.display.set_mode((width, height))
    pygame.display.set_caption('Flappy Baby Daddy Shark')
    clock = pygame.time.Clock()

    # Adding image files
    seaweed_image = pygame.image.load('images/seaweed.png').convert_alpha()
    upper_seaweed_image = pygame.image.load(
        'images/upper_seaweed.png').convert_alpha()
    sharky_image = pygame.image.load(
        'images/daddy_shark_110px.png').convert_alpha()

    # Adding flappybabyshark and seaweed characters:
    seaweed = SeaWeed(seaweed_image, 1000, 600, 1)
    upper_seaweed = UpperSeaWeed(upper_seaweed_image, 1000, -600, 1)
    shark = Shark(100, 500)
    #shark.move = [pygame.K_LEFT, pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN]
    # shark.vx = 5
    # shark.vy = 5

    # shark_group = pygame.sprite.Group()
    # shark_group.add(shark)

    seaweed_group = Group()
    seaweed_group.add(seaweed, upper_seaweed)
    all_sprites = pygame.sprite.Group()
    all_sprites.add(shark)

    # Game loop/Event handling
    stop_game = False
    while not stop_game:
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                # sound.play()
                stop_game = True

        # draw stuff
        BackGround = Background('images/bbsharktitle.jpg', [0, 0])
        screen.fill([255, 255, 255])
        screen.blit(BackGround.image, BackGround.rect)
        font = pygame.font.Font(None, 50)
        text = font.render('Click to play', True, black_color)
        screen.blit(text, (395, 750))

        pygame.display.update()
        clock.tick(60)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            elif event.type == pygame.KEYDOWN:
                print(event.key)
                if event.key == 275:  # right arrow key number
                    shark.should_move("right")
                elif event.key == 276:
                    shark.should_move("left")
                elif event.key == 273:
                    shark.should_move("up")
                elif event.key == 274:
                    shark.should_move("down")
            elif event.type == pygame.KEYUP:  # the user released a key
                if event.key == 275:
                    shark.should_move("right", False)
                elif event.key == 276:
                    shark.should_move("left", False)
                elif event.key == 273:
                    shark.should_move("up", False)
                elif event.key == 274:
                    shark.should_move("down", False)
                else:
                    print(event.key)

        # Game logic

        # Draw background
        screen.fill(blue_color)

        seaweed.display(screen)
        upper_seaweed.display(screen)
        seaweed.update_position(width, height)
        upper_seaweed.update_position(width, height)

        #Shark
        if pygame.sprite.spritecollideany(shark, seaweed_group):
            shark.kill()

        # shark.render(screen, sharky_image)
        for entity in all_sprites:
            screen.blit(entity.image, [entity.x, entity.y])

        shark.draw_me(width, height)
        shark.update_me(width, height)

        # print("shark", shark.x, shark.y)
        # print("seaweed", seaweed.x, seaweed.y)
        # print("upper seaweed", upper_seaweed.x, upper_seaweed.y)

        # collision
        if pygame.sprite.spritecollideany(shark, seaweed_group):
            shark.kill()
            print('DEAD')

        pygame.display.update()
        clock.tick(60)
    pygame.quit()
Example #7
0
pygame.init()

game_area = GameArea(int(round(utils.WIDTH * 0.8)), int(round(utils.HEIGHT * 0.8)))

game_area_start = game_area_start_width, game_area_start_height = (int(round(utils.WIDTH * 0.1)), int(round(utils.HEIGHT * 0.05)))

active_background = Background("assets"+os.sep+"water.jpg", utils.ORIGIN)
gray_background = Background("assets"+os.sep+"water_gy.jpg", utils.ORIGIN)

screen = pygame.display.set_mode(utils.SIZE)

active_background.scale(game_area.getDim())
gray_background.scale(game_area.getDim())

shark = Shark("assets"+os.sep+"shark-fin.png", game_area.getRect().bottomright[0]/2, game_area.getRect().bottomright[1]/2-utils.PLAYER_LINE_WIDTH, pygame.K_RIGHT, game_area.getDim())

boat = Boat("assets"+os.sep+"ship.png", game_area.getRect().bottomright[0]/2, game_area.getRect().bottomright[1], pygame.K_RIGHT)

direction_list = deque([])

dead = False

while not dead:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            dead = True
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key in utils.DIRECTIONS:
                if event.key not in direction_list: