Example #1
0
    def set(self):
        self.font = pygame.font.Font(None, 100)
        self.surface = pygame.Surface(
            (setting.screen_width, setting.screen_height))
        self.rect = self.surface.get_rect()
        self.text_color = (128, 20, 0)
        self.idle_avarage = 1

        if globals.player.health > 0:
            self.sprite = animation.Animate('end_game.png',
                                            setting.screen_rect)
            globals.game.window.blit(self.sprite.get_surface(),
                                     setting.screen_rect)

        else:
            # Paint background as transparent
            self.surface.fill((0, 0, 0))
            center = self.surface.get_rect().center

            ellipse_rect = pygame.Rect(
                (0, 0, setting.screen_width // 2, setting.screen_height // 4))
            ellipse_rect.center = center
            ellipse = pygame.draw.ellipse(self.surface, self.text_color,
                                          ellipse_rect, 10)

            text = self.font.render("GAME OVER", True, self.text_color)
            text_rect = text.get_rect()
            text_rect.center = center
            self.surface.blit(text, text_rect)

            # Make surface transparent and copy unto display surface
            self.surface.set_colorkey((0, 0, 0))
            self.surface.set_alpha(255)

            globals.game.window.blit(self.surface, self.rect)

        pygame.display.flip()

        end = False
        while not end:
            globals.game.clock.tick(setting.frame_rate)

            # Check for user input
            event_list = pygame.event.get()
            for event in event_list:
                if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    globals.game.player_input.stop = True
                    end = True
Example #2
0
    def __init__(self):
        # Load resources
        music = common.load_music('Test1.ogg')
        next_level_sound = common.load_sound('level3.ogg')

        background_sprite = animation.Animate(
            'sky4.jpg', (0, 0, setting.screen_width, setting.screen_height))
        player_sprite = animation.Animate('a1a1_rocket2.png',
                                          (500, 500, 80, 80))
        player_shot_sprite = animation.Animate('shot.png', (0, 0, 10, 10))
        city_sprite = animation.Animate('city7.png', (10, 580, 80, 80))
        alien_sprite = animation.Animate("ufo3.png", (0, 0, 100, 50), 5, -1,
                                         (0, 0, 100, 50))
        alien_bomb_sprite = animation.Animate('bomb.png', (0, 0, 40, 40))
        alien_shot_sprite = animation.Animate('alien_shot.png')
        level_sprite = animation.Animate(
            'level1.png', (0, 0, setting.screen_width, setting.screen_height))

        player_dead_sound = common.load_sound('big_bang.wav')
        player_shot_sound = common.load_sound('shot.wav')
        city_dead_sound = common.load_sound('city_explosion.wav')
        alien_dead_sound = common.load_sound('small_bang.wav')
        alien_shot_sound = common.load_sound('small_shoot_sound.wav')

        self.objects = [
            {
                'next_level': {
                    'sound': next_level_sound,
                    'sprite': level_sprite,
                    'intro_time': 2,
                    'intro_effect': 'slide_down',
                    'hold_time': 2,
                    'outtro_time': 1,
                    'outtro_effect': 'slide_down'
                }
            },
            {
                'music': music
            },
            {
                'background': {
                    'color': pygame.Color('dodgerblue1'),
                    'sprite': background_sprite,
                }
            },
            {
                'player': {
                    'rect': (500, 500, 80, 80),
                    'sprite': player_sprite,
                    'boundary': (0, 300, 1000, 360),
                    'speed': 10,
                    'sound': player_dead_sound,
                    'shoot_sound': player_shot_sound,
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': 90,
                        'speed': 5,
                        'sprite': player_shot_sprite,
                        'sound': player_shot_sound,
                    },
                }
            },
            {
                'city': {
                    'rect': (10, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (100, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (190, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (280, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (370, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (460, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (550, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (640, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (730, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (820, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (910, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'city': {
                    'rect': (1000, 580, 80, 80),
                    'sprite': city_sprite,
                    'sound': city_dead_sound
                }
            },
            {
                'alien': {
                    'rect': (800, 30, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 2,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 5,
                        'sprite': alien_shot_sprite
                    },
                }
            },
            {
                'alien': {
                    'rect': (900, 30, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 1,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 5,
                        'sprite': alien_shot_sprite
                    },
                }
            },
            {
                'alien': {
                    'rect': (600, 90, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 1,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 5,
                        'sprite': alien_shot_sprite
                    },
                }
            },
            {
                'alien': {
                    'rect': (500, 30, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 1,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 5,
                        'sprite': alien_shot_sprite
                    },
                }
            },
            {
                'alien': {
                    'rect': (100, 30, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 1,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 5,
                        'sprite': alien_shot_sprite
                    },
                }
            },
            {
                'alien': {
                    'rect': (200, 30, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 1,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 5,
                        'sprite': alien_shot_sprite
                    },
                }
            },
            {
                'alien': {
                    'rect': (350, 90, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 1,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 5,
                        'sprite': alien_shot_sprite
                    },
                }
            },
            {
                'alien': {
                    'rect': (750, 30, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 1,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 5,
                        'sprite': alien_shot_sprite
                    },
                }
            },
            {
                'alien': {
                    'rect': (400, 90, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 1,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 5,
                        'sprite': alien_shot_sprite
                    },
                }
            },
        ]
Example #3
0
    def __init__(self):
        # Load resources
        music = common.load_music('Test1.ogg')
        next_level_sound = False

        background_sprite = animation.Animate(
            'sky.jpg', (0, 0, setting.screen_width, setting.screen_height))
        player_sprite = animation.Animate('player.png', (500, 500, 80, 80))
        player_shot_sprite = animation.Animate('shot.png', (0, 0, 10, 10))
        city_sprite = animation.Animate('city.png', (0, 0, 80, 80))
        alien_sprite = animation.Animate("alien-{index}.png", (0, 0, 100, 50))
        alien_bomb_sprite = animation.Animate('bomb.png', (0, 0, 40, 40))
        alien_shot_sprite = animation.Animate('alien_shot.png')
        level_sprite = animation.Animate(
            'level1.png', (0, 0, setting.screen_width, setting.screen_height))

        player_dead_sound = common.load_sound('big_bang.wav')
        player_shot_sound = common.load_sound('shot.wav')
        city_dead_sound = common.load_sound('city_explosion.wav')
        alien_dead_sound = False  #common.load_sound('small_bang.wav')
        alien_shot_sound = False  #common.load_sound('small_shoot_sound.wav')

        self.objects = [
            {
                'background': {
                    'color': pygame.Color('dodgerblue1'),
                    'sprite': '',
                }
            },
            {
                'player': {
                    'rect': (500, 500, 80, 80),
                    'sprite': player_sprite,
                    'boundary': (0, 300, 1000, 360),
                    'speed': 10,
                    'sound': player_dead_sound,
                    'shoot_sound': player_shot_sound,
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': 90,
                        'speed': 5,
                        'sprite': player_shot_sprite,
                        'sound': player_shot_sound,
                    },
                }
            },
            {
                'alien': {
                    'rect': (800, 30, 100, 50),
                    'sprite': alien_sprite,
                    'boundary': (0, 0, 1000, 200),
                    'speed': 2,
                    'direction': 180,
                    'move_pattern': 'horisontal',
                    'sound': alien_dead_sound,
                    'shoot_sound': alien_shot_sound,
                    'bomb': {
                        'rect': (0, 0, 40, 40),
                        'direction': -90,
                        'speed': 1,
                        'sprite': alien_bomb_sprite
                    },
                    'shot': {
                        'rect': (0, 0, 10, 10),
                        'direction': -90,
                        'speed': 3,
                        'sprite': alien_shot_sprite
                    },
                }
            },
        ]