Exemplo n.º 1
0
    def __init__(self, screen, on_next):
        super(OnWinScene, self).__init__(screen, on_next,
                                         './assets/ganar_nivel.ogg')
        self.loop = False

        mantillin_sprites = SpriteSheet("mantillin").load_strip(
            (432, 0, 108, 121.5), 1)
        hearts_sprites = SpriteSheet("hearts_un").load_strip((0, 0, 51, 48), 6)

        self.mantillin = sprite.Group([
            Particle(mantillin_sprites,
                     (SCREEN_WIDTH / 2 - mantillin_sprites[0].get_width() / 8,
                      SCREEN_HEIGHT / 3 + mantillin_sprites[0].get_height()),
                     0, 0, 0),
            Particle(
                hearts_sprites,
                (SCREEN_WIDTH / 2 + 1.25 * hearts_sprites[0].get_width(),
                 SCREEN_HEIGHT / 3 + 1.5 * hearts_sprites[0].get_height()), 0,
                0, 0)
        ])

        self.text_title = HeadingFont(60).render("YOU WON", True,
                                                 (3, 169, 244))
        self.text_continue = PixelFont(26).render("press enter to continue",
                                                  True, (255, 255, 255))
        self.star = image.load("assets/star.png").convert_alpha()
Exemplo n.º 2
0
    def __init__(self, bullet_image_list):
        bullet_velocity = 800
        sprite_sheet_1 = SpriteSheet("resources/images/Sprite Sheet1.png")
        image_list = [
            sprite_sheet_1.imageAt(pygame.Rect(966, 332, 35, 21)),
            sprite_sheet_1.imageAt(pygame.Rect(471, 93, 102, 40))
        ]
        gun_x_position = 7.0
        gun_y_position = 0.0
        delay = 1
        damage = 5
        ammo = 30
        max_ammo = 30
        reload_time = 2.0
        accuracy = .07
        width = 35
        height = 21
        look_left_offset = -16

        Gun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo,
                     reload_time, accuracy, image_list, gun_x_position,
                     gun_y_position, width, height, look_left_offset)

        ServerShotgun.__init__(self)

        self.bullet_image_list = bullet_image_list
Exemplo n.º 3
0
    def __init__(self, bullet_image_list):

        sprite_sheet_1 = SpriteSheet("resources/images/Sprite Sheet1.png")
        image_list = [
            sprite_sheet_1.imageAt(pygame.Rect(732, 316, 58, 30)),
            sprite_sheet_1.imageAt(pygame.Rect(811, 315, 84, 40))
        ]

        reload_time = 2
        accuracy = .1
        damage = 10
        ammo = 30
        max_ammo = 30
        delay = .8
        bullet_velocity = 1000
        width = 58
        height = 30
        look_left_offset = 16
        gun_x_position = -9.0
        gun_y_position = -13.0

        Gun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo,
                     reload_time, accuracy, image_list, gun_x_position,
                     gun_y_position, width, height, look_left_offset)

        ServerPistol.__init__(self)
        self.bullet_image_list = bullet_image_list
    def __init__(self, start_position, ready=False):
        MenuObject.__init__(self, start_position)

        self.ready = False if not ready else True

        # Import ready status indicator images.
        ready_status_indicator_sheet = SpriteSheet('resources/images/ready_status_indicators.png')
        ready_status_image_list = [ready_status_indicator_sheet.imageAt(pygame.Rect(0, 0, 15, 15)),
                                   ready_status_indicator_sheet.imageAt(pygame.Rect(15, 0, 15, 15))]
        self.image_list = ready_status_image_list
    def __init__(self, always_visible=False, x_offset=0, y_offset=0, box_width=None, box_height=None, max_chars=65,
                 player_heads_up_display=None, screen=None):
        self.screen = screen
        self.always_visible = always_visible
        self.max_chars = max_chars
        self.view_offset = 0  # The part of the text log you're viewing.  0 is the most recent on the bottom.

        # These values move the ChatBox from it's default position at the bottom left hand corner of the screen.
        self.x_offset = x_offset
        self.y_offset = y_offset

        self.hidden = not self.always_visible  # while this is true the ChatBox shouldn't be displayed.
        self.alpha = 255
        self.delaying_to_fade = False
        self.is_fading = False  # while this is true, the ChatBox text is fading to transparency.
        self.fade_delay = 3  # seconds after the ChatBox is deselected until the text starts to fade.
        self.fade_time = 2  # seconds that it fades for after the fadeDelay
        self.last_deselect_time = 0  # time that the fade process started.
        self.last_fade_start_time = 0
        self.selected = False
        self.fade_proportion = 0  # This will hold the proportion to convert the time to terms of opacity (0-255)
        self.font = pygame.font.SysFont('arial', 12)

        self.cursor_blink_time = 1.5  # the cursor will change every half of this number
        self.last_cursor_blink = 0
        self.cursor_is_blinking = False
        self.cursor_surface = self.font.render("|", True, [255, 255, 255])

        self.text_content = []  # list of strings. lower index = older
        self.input = None  # a string of input to send to the textBox.
        self.surface_content = []  # a list of surface slices. lower index = older
        self.border_offset = 14  # offset text by ten pixels to account for the border of the chatBox
        self.blit_dict = {}
        self.alpha_blit_dict = {}

        temp_sprite_sheet = SpriteSheet("resources/images/Sprite Sheet1.png")
        self.box_image = temp_sprite_sheet.imageAt(pygame.Rect(5, 15, 370, 135))
        # this image is cursed to never change color.
        self.unfocused_image = temp_sprite_sheet.imageAt(pygame.Rect(6, 158, 368, 130))
        if box_width is not None and box_height is not None:
            self.box_image = pygame.transform.scale(self.box_image, (box_width, box_height))
            self.unfocused_image = pygame.transform.scale(self.box_image, (box_width, box_height))
        self.image = self.box_image  # everything will be blit onto here.

        self.shift_is_pressed = False

        if hasattr(globals, 'online_game'):
            self.last_message_received = 0
            self.get_new_messages_thread = RepeatTask(1, self.get_new_messages)
            self.get_new_messages_thread.start()

        self.player_heads_up_display = player_heads_up_display
        self.last_paused = datetime.now()
    def __init__(self, start_position, ready=False):
        MenuObject.__init__(self, start_position)

        self.ready = False if not ready else True

        # Import ready status indicator images.
        ready_status_indicator_sheet = SpriteSheet(
            'resources/images/ready_status_indicators.png')
        ready_status_image_list = [
            ready_status_indicator_sheet.imageAt(pygame.Rect(0, 0, 15, 15)),
            ready_status_indicator_sheet.imageAt(pygame.Rect(15, 0, 15, 15))
        ]
        self.image_list = ready_status_image_list
Exemplo n.º 7
0
 def save(self):
     primary_images = [card.image for card in self.cards]
     secondary_images = [
         image for c in self.cards for image in c.secondary_images
     ]
     filename = os.path.join(SPRITE_SHEET_OUTPUT_DIR, self.name)
     if os.path.exists(filename):
         shutil.rmtree(filename)
     os.mkdir(filename)
     SpriteSheet.create_sprite_sheets(filename, "deck", primary_images)
     if secondary_images:
         SpriteSheet.create_sprite_sheets(filename, "secondary",
                                          secondary_images)
Exemplo n.º 8
0
    def __init__(self):
        sprites = SpriteSheet("pecha").load_strip((0, 0, 109, 85), 4)
        super(Pechatron, self).__init__(sprites, (SCREEN_WIDTH / 2, SCREEN_HEIGHT * .2), 0.1)

        self.movement_vectors = [(1, 0)]
        self.max_life = 100
        self.life = 100
Exemplo n.º 9
0
class Sprite(pygame.sprite.Sprite):
    def __init__(self, image):
        #initialize the class with the base class
        pygame.sprite.Sprite.__init__(self)
        self.size = 50
        try:
            self.ss = SpriteSheet(image)
            self.image = self.ss.image_at((0, 0, 32, 32), (255, 0, 255))
            self.image.convert()
            self.image = pygame.transform.scale(self.image, [self.size] * 2)
        except:
            self.image = pygame.Surface([self.size] * 2)
            self.image.fill((0, 0, 0))
        # print self.image
        self.speed = self.size
        # self.image.fill((255, 255, 255))

        self.keys = [K_UP, K_DOWN, K_LEFT, K_RIGHT]
        self.rect = self.image.get_rect()

    def update(self, actions):
        # if actions: print '----'
        # self.rect.y += 1

        for action in actions:
            if action.key in self.keys:
                if action.key == K_UP:
                    self.rect.y -= self.speed
                elif action.key == K_DOWN:
                    self.rect.y += self.speed
                elif action.key == K_LEFT:
                    self.rect.x -= self.speed
                elif action.key == K_RIGHT:
                    self.rect.x += self.speed
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
    def load_shields(self):
        sprites = SpriteSheet("shields").load_strip((0, 0, 87, 84), 4)

        return [
            Shield([sprites[i]],
                   (.20 * (i + 1) * SCREEN_WIDTH, SCREEN_HEIGHT * 0.75))
            for i in range(len(sprites))
        ]
Exemplo n.º 12
0
class Shield(Entity):
    """Shield which is placed between the user and the alien horde.

    Arguments:
        position (tuple {int, int}): The position to place the shield.
        groups (pygame.sprite.Group): All the groups this entity will be in.

    Attributes:
        image (pygame.Surface): The current image which represents the sprite.
        rect (pygame.Rect): The rect used for placing the sprite.
        mask (pygame.mask.Mask): The mast for the image.
    """
    shield = SpriteSheet.sprite(SHIELD)

    def __init__(self, position, *groups):
        super().__init__(*groups)
        self.image = copy(self.shield).convert_alpha()
        self.rect = self.image.get_rect()
        self.mask = pygame.mask.from_surface(self.image)

        self.rect.topleft = position

    def take_damage(self, bullets):
        """Take damage from the bullets on the display.

        Arguments:
            bullets (pygame.sprite.Group): The groups which contains bullets.
        """
        for bullet in bullets:
            try:
                pos_x, pos_y = pygame.sprite.collide_mask(self, bullet)
                bullet.kill()
                self.dirty = 1
            except TypeError:
                continue

            destroy_rect = pygame.Rect((pos_x - 4, pos_y, 8, 8))
            self.image.fill((0, 0, 0, 0), destroy_rect)

            for _ in range(10):
                destroy_x = randint(pos_x - 4, pos_x + 4)
                destroy_y = randint(pos_y - 4, pos_y + 4)
                destroy_rect = (destroy_x - 2, destroy_y, 4, 4)
                self.image.fill((0, 0, 0, 0), destroy_rect)

            for _ in range(20):
                destroy_x = randint(pos_x - 8, pos_x + 8)
                destroy_y = randint(pos_y - 8, pos_y + 8)
                destroy_rect = (destroy_x - 1, destroy_y, 2, 2)
                self.image.fill((0, 0, 0, 0), destroy_rect)

            for _ in range(30):
                destroy_x = randint(pos_x - 12, pos_x + 12)
                destroy_y = randint(pos_y - 12, pos_y + 12)
                destroy_rect = pygame.Rect((destroy_x - 0.5, destroy_y, 1, 1))
                self.image.fill((0, 0, 0, 0), destroy_rect)

            self.mask = pygame.mask.from_surface(self.image)
    def __init__(self, parent, start_position=Vector2(0.0, 0.0)):
        self.width = globals.screen.get_width()
        self.height = globals.screen.get_height()
        self.font = pygame.font.SysFont('arial', 12)

        UIFrame.__init__(self, start_position, self.width, self.height, parent)
        #WorldObject.__init__(self, start_position, self.screen_size_x, self.screen_size_y, velocity, image_list)

        #self.pause_menu = PauseMenu(font, self.screen_size_x, self.screen_size_y, screen)

        # # Make a chat box.
        # self.chat_box = ChatBox(player_heads_up_display=self)

        # Load sprite sheets.
        self.health = 0
        self.max_health = 0
        crosshair_sheet = SpriteSheet("resources/images/Crosshair Sheet.png")
        sprite_sheet = SpriteSheet("resources/images/Sprite Sheet1.png")

        # Load crosshair.
        self.crosshair = BlitData(
            crosshair_sheet.imageAt(pygame.Rect(176, 158, 46, 48)))

        # load health bar info
        self.hp_overlay = BlitData(
            sprite_sheet.imageAt(pygame.Rect(652, 373, 290, 90)), (0, 0))
        self.hp_bar = BlitData(
            sprite_sheet.imageAt(pygame.Rect(722, 485, 213, 40)), (64, 22))
        self.mana_bar = BlitData(
            sprite_sheet.imageAt(pygame.Rect(722, 529, 146, 20)), (68, 65),
            (0, 0, 159, 20))

        # set colorkey so black pixels will be transparent
        # self.image.set_colorkey(BLACK)  # set black to transparent
        # self.image.fill(BLACK)

        # ammo and weapon data
        self.ammo_string = "send me text"
        self.weapon_string = "send me text"
        self.ammo_string_surface = self.font.render(self.ammo_string, True,
                                                    [255, 255, 255])
        self.weapon_string_surface = self.font.render(self.weapon_string, True,
                                                      [255, 255, 255])
        self.ammo_blit = BlitData(self.ammo_string_surface,
                                  (globals.screen.get_width() / 1.16,
                                   globals.screen.get_height() / 1.11))
        self.weapon_blit = BlitData(self.weapon_string_surface,
                                    (globals.screen.get_width() / 1.16,
                                     globals.screen.get_height() / 1.066))
        # order this list in which one you want blit first.  top picture = last in the list.
        #self.blit_list = [self.hp_overlay, self.hp_bar, self.ammo_blit, self.weapon_blit, self.crosshair]
        self.blit_list = [
            self.hp_overlay, self.hp_bar, self.mana_bar, self.ammo_blit,
            self.weapon_blit, self.crosshair
        ]
Exemplo n.º 14
0
    def __init__(self, image):
        #initialize the class with the base class
        pygame.sprite.Sprite.__init__(self)
        self.size = 50
        try:
            self.ss = SpriteSheet(image)
            self.image = self.ss.image_at((0, 0, 32, 32), (255, 0, 255))
            self.image.convert()
            self.image = pygame.transform.scale(self.image, [self.size] * 2)
        except:
            self.image = pygame.Surface([self.size] * 2)
            self.image.fill((0, 0, 0))
        # print self.image
        self.speed = self.size
        # self.image.fill((255, 255, 255))

        self.keys = [K_UP, K_DOWN, K_LEFT, K_RIGHT]
        self.rect = self.image.get_rect()
Exemplo n.º 15
0
    def __init__(self, name, x, y, animation_speed=200):
        super().__init__()

        self.sprite_sheet = SpriteSheet(f'{name}.png')
        self.image = pygame.image.load('cell.png')
        self.rect = self.image.get_rect()
        self.position = [x, y]
        self.feet = pygame.Rect(0, 0, self.rect.width * 0.5, 12)

        # vie
        self.health = 100
        self.max_health = 100

        # animation
        self.old_position = self.position
        self.current_animation_index = 0
        self.animation_speed = animation_speed
        self.cooldown = 0
        self.speed = 1
Exemplo n.º 16
0
    def __init__(self, bullet_image_list):
        #load image for bigbertha
        image_list = []  # override gun's image list
        sprite_sheet_1 = SpriteSheet("resources/images/Sprite Sheet1.png")
        image_list.append(sprite_sheet_1.imageAt(pygame.Rect(726, 131, 146, 34)))
        image_list.append(sprite_sheet_1.imageAt(pygame.Rect(726, 187, 146, 34)))
        bullet_velocity = 1100
        delay = .8
        damage = 420
        ammo = 10
        max_ammo = 10
        reload_time = 1.5
        accuracy = 0.2

        Gun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, image_list)

        ServerGrenadeLauncher.__init__(self)

        self.bullet_image_list = bullet_image_list
Exemplo n.º 17
0
    def __init__(self):
        """ Constructor function """

        # Call the parent's constructor
        super(Player, self).__init__()

        # Create an image of the block, and fill it with a color.
        # This could also be an image loaded from the disk.
        width = 40
        height = 80 #60

        sprite_sheet = SpriteSheet("walk_red2.png")
        #sprite_sheet = SpriteSheet("p1_walk.png")
        # Load all the right facing images into a list
        self.image = sprite_sheet.get_image(0, 0, 40, 80)

        self.walking_frames_r = []
        self.walking_frames_l = []
        for i in range(10):
            image = sprite_sheet.get_image(i * 40, 0, 40, 80)
            self.walking_frames_r.append(image)
            image = sprite_sheet.get_image(i * 40, 80, 40, 80)
            self.walking_frames_l.append(image)

        self.imageFrame = 0
        self.image = self.walking_frames_r[self.imageFrame]

        #self.image = pygame.Surface([width, height])
        self.rect = self.image.get_rect()
        #self.image.fill(RED)

        # Set a referance to the image rect.
        self.rect = self.image.get_rect()

        # Set speed vector of player
        self.change_x = 0
        self.change_y = 0
        self.goLeft = False

        # List of sprites we can bump against
        self.level = None
        self.onAir = False
Exemplo n.º 18
0
    def __init__(self, icon_filename, surface):
        self.button_names = (RUN, STOP, SAVE, LOAD, CHANGE_COLOR)
        self.surface = surface
        self.button_count = 5
        self.button_size = 16
        self.button_margin = 2
        width = ((self.button_size * self.button_count) +
                 (self.button_margin * (self.button_count + 1)))
        height = self.button_size + self.button_margin * 2
        self.tray_size = (width, height)
        self.top_left = [(surface.get_size()[X] - width - 3),
                         (surface.get_size()[Y] - height) - 3]
        self.tray = pygame.Rect(self.top_left, self.tray_size)

        self.sprites = SpriteSheet(icon_filename)
        # the icons don't use alpha transparency - bg color is fixed
        #self.up_buttons = self.sprites.load_strip(
        #    pygame.Rect(0, 0, self.button_size, self.button_size),
        #    self.button_count)
        #self.down_buttons = self.sprites.load_strip(
        #    pygame.Rect(self.button_size * self.button_count, 0,
        #                self.button_size, self.button_size),
        #    self.button_count)
        self.buttons = {}
        up_pos = [0, 0]
        down_pos = [self.button_size * self.button_count, 0]
        size = (self.button_size, self.button_size)
        self.buttons = {}
        for name in self.button_names:
            self.buttons[name] = \
                     {UP: self.sprites.image_at(pygame.Rect(up_pos, size)),
                      DOWN: self.sprites.image_at(pygame.Rect(down_pos, size))}
            up_pos[X] += self.button_size
            down_pos[X] += self.button_size

        self.button_state = {
            RUN: UP,
            SAVE: UP,
            STOP: UP,
            LOAD: UP,
            CHANGE_COLOR: UP
        }
Exemplo n.º 19
0
 def __init__(self, rect, order):
     self.surface = None
     self.rect = rect
     self.order = int(order)
     self.sound_pickup = self.sound_pickup = pygame.mixer.Sound(
         self.__SOUND_PICKUP)
     self.__frames = SpriteSheet(self.__IMAGE_PATH, (25, 25)).frames
     self.reset()
     self.index = Lamp._current_index
     Lamp._current_index += 1
     print "Index %s is order %s " % (self.index, self.order)
Exemplo n.º 20
0
    def __init__(self, screen, type_fruit):
        super(Fruit, self).__init__()
        self.is_dead = False
        self.type_fruit = type_fruit
        self.points = 0
        self.position = [(35, 50, 14, 14), (52, 50, 14, 14), (67, 50, 14, 14),
                         (83, 50, 14, 14), (100, 50, 14, 14),
                         (115, 50, 14, 14), (132, 50, 14, 14),
                         (147, 50, 14, 14)]
        self.location_x = 600
        self.location_y = 585
        self.screen = screen
        self.sprite_sheet = SpriteSheet('sprites/pacman.png')

        self.image = self.sprite_sheet.image_at(self.position[self.type_fruit],
                                                None)
        self.image = pygame.transform.scale(self.image, (30, 30))
        self.rect = self.image.get_rect()
        self.rect.x = self.location_x
        self.rect.y = self.location_y
Exemplo n.º 21
0
    def __init__(self, bullet_image_list):
        #load image for bigbertha
        image_list = []  # override gun's image list
        sprite_sheet_1 = SpriteSheet("resources/images/Sprite Sheet1.png")
        image_list.append(
            sprite_sheet_1.imageAt(pygame.Rect(726, 131, 146, 34)))
        image_list.append(
            sprite_sheet_1.imageAt(pygame.Rect(726, 187, 146, 34)))
        bullet_velocity = 1100
        delay = .8
        damage = 420
        ammo = 10
        max_ammo = 10
        reload_time = 1.5
        accuracy = 0.2

        Gun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo,
                     reload_time, accuracy, image_list)

        ServerGrenadeLauncher.__init__(self)

        self.bullet_image_list = bullet_image_list
Exemplo n.º 22
0
    def __init__(self, bullet_image_list):
        bullet_velocity = 800
        sprite_sheet_1 = SpriteSheet("resources/images/Sprite Sheet1.png")
        image_list = [sprite_sheet_1.imageAt(pygame.Rect(966, 332, 35, 21)),
                      sprite_sheet_1.imageAt(pygame.Rect(471, 93, 102, 40))]
        gun_x_position = 7.0
        gun_y_position = 0.0
        delay = 1
        damage = 5
        ammo = 30
        max_ammo = 30
        reload_time = 2.0
        accuracy = .07
        width = 35
        height = 21
        look_left_offset = -16

        Gun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, image_list,
                     gun_x_position, gun_y_position, width, height, look_left_offset)

        ServerShotgun.__init__(self)

        self.bullet_image_list = bullet_image_list
Exemplo n.º 23
0
    def __init__(self, bullet_image_list):

        sprite_sheet_1 = SpriteSheet("resources/images/Sprite Sheet1.png")
        image_list = [sprite_sheet_1.imageAt(pygame.Rect(732, 316, 58, 30)),
                      sprite_sheet_1.imageAt(pygame.Rect(811, 315, 84, 40))]

        reload_time = 2
        accuracy = .1
        damage = 10
        ammo = 30
        max_ammo = 30
        delay = .8
        bullet_velocity = 1000
        width = 58
        height = 30
        look_left_offset = 16
        gun_x_position = -9.0
        gun_y_position = -13.0

        Gun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, image_list,
                     gun_x_position, gun_y_position, width, height, look_left_offset)

        ServerPistol.__init__(self)
        self.bullet_image_list = bullet_image_list
class GraphicsComponent(object):
    def __init__(self, filename, patch_size, final_size, patch_pos):
        self._sheet = SpriteSheet(filename, patch_size, final_size)
        self._patch_pos = patch_pos

    def get_image(self):
        """Retrieves the sprite's image.

        Returns:
            The sprite's requested patch image.
        """
        return self._sheet.get_patch(self._patch_pos)

    def update(self, sprite):
        sprite.image = self.get_image()
Exemplo n.º 25
0
    def __init__(self, screen, on_next):
        super(OnLoseScene, self).__init__(screen, on_next,
                                          './assets/muerte.ogg')

        mantillin_sprites = SpriteSheet("mantillin").load_strip(
            (540, 0, 108, 121.5), 1)
        self.mantillin = sprite.Group([
            Particle(mantillin_sprites,
                     (SCREEN_WIDTH / 2 - mantillin_sprites[0].get_width() / 8,
                      SCREEN_HEIGHT / 2), 0, 0, 0)
        ])
        self.text_title = HeadingFont(60).render("GAME OVER", True,
                                                 (233, 30, 99))
        self.text_continue = PixelFont(26).render("press enter to continue",
                                                  True, (255, 255, 255))
        self.star = image.load("assets/star.png").convert_alpha()
Exemplo n.º 26
0
    def __init__(self, screen):
        super(StartScene, self).__init__(screen)

        mantillin_sprites = SpriteSheet("mantillin").load_strip(
            (0, 0, 108, 121.5), 4)

        self.text_title = HeadingFont(45).render("UNAL", True, (3, 169, 244))
        self.text_subtitle = HeadingFont(60).render("INVADERS", True,
                                                    (233, 30, 99))
        self.text_start = PixelFont(26).render("press enter to start", True,
                                               (255, 255, 255))
        self.star = pygame.image.load("assets/star.png").convert_alpha()

        self.mantillin = sprite.Group([
            Particle(mantillin_sprites,
                     (SCREEN_WIDTH / 2 - mantillin_sprites[0].get_width() / 8,
                      SCREEN_HEIGHT / 3 + 2 * self.text_subtitle.get_height()),
                     0, 0, 0)
        ])
Exemplo n.º 27
0
class Bullet(Entity):
    """Base bullet class which handles movement and removal of bullets.

    Arguments:
        groups (pygame.sprite.Group): All the groups this entity will be in.

    Attributes:
        dirty (int): Wether or not the sprite should be drawn.
    """
    explosion = Animation(SpriteSheet.animation(BULLET_COLLISION, 1), 0.3)

    def __init__(self, *groups):
        super().__init__(*groups)
        self.dirty = 2
        self._collision = copy(self.explosion)

    def update(self, seconds_elapsed):
        """Update the bullets position on the display."""
        super().update(seconds_elapsed)
        self.rect.y += int(self._seconds_elapsed * self._velocity.y)

    def take_damage(self, bullets, *groups):
        """Check to see if there are any bullets in contact with each other.
        If any are destroy them both and create a collision explosion.

        Arguments:
            bullets (pygame.sprite.Group): The group of bullets.
            groups (pygame.sprite.Group): The groups the explosion will be in.
        """
        for bullet in bullets:
            if bullet is not self and pygame.sprite.collide_mask(self, bullet):
                bullet.kill()
                self.kill()
                Explosion(self._collision,
                          (self.rect.x - BULLET_COLLISION.width / 2,
                           self.rect.y - BULLET_COLLISION.height / 2), *groups)
Exemplo n.º 28
0
class Fruit(Sprite):
    def __init__(self, screen, type_fruit):
        super(Fruit, self).__init__()
        self.is_dead = False
        self.type_fruit = type_fruit
        self.points = 0
        self.position = [(35, 50, 14, 14), (52, 50, 14, 14), (67, 50, 14, 14),
                         (83, 50, 14, 14), (100, 50, 14, 14),
                         (115, 50, 14, 14), (132, 50, 14, 14),
                         (147, 50, 14, 14)]
        self.location_x = 600
        self.location_y = 585
        self.screen = screen
        self.sprite_sheet = SpriteSheet('sprites/pacman.png')

        self.image = self.sprite_sheet.image_at(self.position[self.type_fruit],
                                                None)
        self.image = pygame.transform.scale(self.image, (30, 30))
        self.rect = self.image.get_rect()
        self.rect.x = self.location_x
        self.rect.y = self.location_y

    def draw(self):
        self.screen.screen.blit(self.image, self.rect)

    def set_points(self):
        if self.type_fruit == 0:
            self.points = 100
        elif self.type_fruit >= 4:
            self.points = (self.type_fruit - 3) * 1000
        elif self.type_fruit == 1:
            self.points = 300
        elif self.type_fruit == 2:
            self.points = 500
        else:
            self.points = 700
    def __init__(self, parent, start_position=Vector2(0.0, 0.0)):
        self.width = globals.screen.get_width()
        self.height = globals.screen.get_height()
        self.font = pygame.font.SysFont('arial', 12)

        UIFrame.__init__(self, start_position, self.width, self.height, parent)
        #WorldObject.__init__(self, start_position, self.screen_size_x, self.screen_size_y, velocity, image_list)

        #self.pause_menu = PauseMenu(font, self.screen_size_x, self.screen_size_y, screen)

        # # Make a chat box.
        # self.chat_box = ChatBox(player_heads_up_display=self)

        # Load sprite sheets.
        self.health = 0
        self.max_health = 0
        crosshair_sheet = SpriteSheet("resources/images/Crosshair Sheet.png")
        sprite_sheet = SpriteSheet("resources/images/Sprite Sheet1.png")

        # Load crosshair.
        self.crosshair = BlitData(crosshair_sheet.imageAt(pygame.Rect(176, 158, 46, 48)))

        # load health bar info
        self.hp_overlay = BlitData(sprite_sheet.imageAt(pygame.Rect(652, 373, 290, 90)), (0, 0))
        self.hp_bar = BlitData(sprite_sheet.imageAt(pygame.Rect(722, 485, 213, 40)), (64, 22))
        self.mana_bar = BlitData(sprite_sheet.imageAt(pygame.Rect(722, 529, 146, 20)), (68, 65), (0, 0, 159, 20))

        # set colorkey so black pixels will be transparent
        # self.image.set_colorkey(BLACK)  # set black to transparent
        # self.image.fill(BLACK)

        # ammo and weapon data
        self.ammo_string = "send me text"
        self.weapon_string = "send me text"
        self.ammo_string_surface = self.font.render(self.ammo_string, True, [255, 255, 255])
        self.weapon_string_surface = self.font.render(self.weapon_string, True, [255, 255, 255])
        self.ammo_blit = BlitData(self.ammo_string_surface,
                                  (globals.screen.get_width() / 1.16, globals.screen.get_height() / 1.11))
        self.weapon_blit = BlitData(self.weapon_string_surface,
                                    (globals.screen.get_width() / 1.16, globals.screen.get_height() / 1.066))
        # order this list in which one you want blit first.  top picture = last in the list.
        #self.blit_list = [self.hp_overlay, self.hp_bar, self.ammo_blit, self.weapon_blit, self.crosshair]
        self.blit_list = [self.hp_overlay, self.hp_bar, self.mana_bar, self.ammo_blit, self.weapon_blit, self.crosshair]
Exemplo n.º 30
0
def run_game():
    # Initialize pygame, settings, and screen object.
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.mixer.init()
    pygame.init()
    clock = pygame.time.Clock()
    clock.tick(60)
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invader")

    # Import 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+")

    # Make sound manager
    sounds = Sounds()

    # Create an instance to store game statistics and create a scoreboard.
    stats = GameStats(ai_settings=ai_settings)
    sb = Scoreboard(ai_settings=ai_settings,
                    screen=screen,
                    stats=stats,
                    sprite_sheet=sprite_sheet,
                    high_score_file=high_score_file)

    # Make the game objects.
    ship = Ship(ai_settings=ai_settings,
                screen=screen,
                sprite_sheet=sprite_sheet,
                stats=stats,
                sb=sb,
                sounds=sounds)
    explosions = Group()
    barriers = []
    fleet = Fleet(ai_settings=ai_settings,
                  screen=screen,
                  sprite_sheet=sprite_sheet,
                  sounds=sounds)
    bullets = Bullets(ai_settings=ai_settings,
                      screen=screen,
                      sprite_sheet=sprite_sheet,
                      stats=stats,
                      sb=sb,
                      ship=ship,
                      fleet=fleet,
                      barriers=barriers,
                      explosions=explosions,
                      sounds=sounds)

    # Make the event handler
    event_handler = EventHandler(ai_settings=ai_settings,
                                 play_button=play_button,
                                 score_button=score_button,
                                 stats=stats,
                                 sb=sb,
                                 ship=ship,
                                 bullets=bullets,
                                 fleet=fleet,
                                 sounds=sounds)

    # Make the display manager
    display = Display(ai_settings=ai_settings,
                      screen=screen,
                      sprite_sheet=sprite_sheet,
                      play_button=play_button,
                      score_button=score_button,
                      stats=stats,
                      sb=sb,
                      ship=ship,
                      bullets=bullets,
                      fleet=fleet,
                      barriers=barriers,
                      explosions=explosions,
                      event_handler=event_handler)

    # Start the main loop for the game.
    while True:
        event_handler.check_events(display=display)

        if stats.game_active:
            ship.update()
            bullets.update_bullets(display=display)
            fleet.update_aliens(ship=ship, display=display, bullets=bullets)
            fleet.update_ufos()

        display.update_screen()
Exemplo n.º 31
0
class Tank(Entity):
    """The tank which the user controls to destroy the oncoming alien horde.

    Arguments:
        groups (pygame.sprite.Group): All the groups this entity will be in.

    Attributes:
        tank (pygame.Surface): The default sprite for the tank.
        bullet (pygame.Surface): The tanks bullet sprite.
        explosion (pygame.Surface): The tanks explosion animation.
        image (pygame.Surface): The current image which represents the sprite.
        rect (pygame.Rect): The rect used for placing the sprite.
        mask (pygame.mask.Mask): The mast for the image.
        _velocity (pygame.math.Vector2): The x, y velocities for the sprite.
        _last_shot (float): The last time that the tank fired a shot.
        _reload_speed (float): The amount of time it takes to reload.
        _current_time (float): Time in seconds. (Used for time based actions)
    """
    tank = SpriteSheet.sprite(TANK)
    bullet = SpriteSheet.sprite(TANK_BULLET)
    explosion = Animation(SpriteSheet.animation(TANK_EXPLOSION, 1), 0.3)
    bullet_explosion = Animation(
        SpriteSheet.animation(TANK_BULLET_EXPLOSION, 1), 0.3)

    def __init__(self, position, *groups):
        super().__init__(*groups)
        self.image = copy(self.tank).convert_alpha()
        self.rect = self.image.get_rect()
        self.mask = pygame.mask.from_surface(self.image)
        self._velocity = pygame.math.Vector2(250, 0)
        self._last_shot = 0
        self._reload_speed = 0.5
        self._current_time = self._reload_speed

        self.rect.topleft = position

    def move(self, direction):
        """Move the tank according the users input.

        Arguments:
            The direction to move the tank. left < 0 > right.
        """
        velocity = int(self._seconds_elapsed * self._velocity.x)

        if direction != 0:
            self.dirty = 1
        if direction < 0 and self.rect.left > velocity:
            self.rect.x -= velocity
        elif direction > 0 and self.rect.right < DISPLAY.height - velocity:
            self.rect.x += velocity

    def shoot(self, *groups):
        """If the tank isn't reloading then fire a shot.

        Arguments:
            groups (pygame.sprite.Group): The groups the bullet will be in.
        """
        if abs(self._last_shot - self._current_time) >= self._reload_speed:
            TankBullet(self, *groups)
            self._last_shot = self._current_time

    def take_damage(self, bullets, *groups):
        """Tank damage from any of the bullets on the display.

        Arguments:
            bullets (pygame.sprite.Group): The bullet group.
            groups (pygame.sprite.Group): The groups the explosion will be in.
        """
        for bullet in bullets:
            if pygame.sprite.collide_mask(self, bullet):
                Explosion(copy(self.explosion), (self.rect.x - 4, self.rect.y),
                          *groups)

                bullet.kill()
                self.kill()
Exemplo n.º 32
0
    def __init__(self, **argd):
        self.__dict__.update(**argd)
        super(MainScreen, self).__init__(**argd)

        # create a display image. standard pygame stuff
        self.display = pygame.display.set_mode(self.size, 0)
        self.background = pygame.Surface(SCREEN_RECT.size)

        # Initialize camera
        if ARGS.camera:
            self.init_cams(0)

        # Load graphics
        deafy_sheet = SpriteSheet("data/Undertale_Annoying_Dog.png")
        cat_sheet = SpriteSheet("data/cat.png")

        Deafy.images = [
            deafy_sheet.image_at((2, 101, 22 - 2, 119 - 101),
                                 colorkey=-1,
                                 width_height=(20 * 2, 18 * 2),
                                 flip_x=True),
            deafy_sheet.image_at((2, 204, 26 - 2, 216 - 204),
                                 colorkey=-1,
                                 width_height=(24 * 2, 12 * 2),
                                 flip_x=True),
            deafy_sheet.image_at((2, 182, 23 - 2, 200 - 182),
                                 colorkey=-1,
                                 width_height=(21 * 2, 18 * 2),
                                 flip_x=True),
            deafy_sheet.image_at((25, 182, 44 - 25, 200 - 182),
                                 colorkey=-1,
                                 width_height=(19 * 2, 18 * 2),
                                 flip_x=True),
            deafy_sheet.image_at((2, 101, 22 - 2, 119 - 101),
                                 colorkey=-1,
                                 width_height=(20 * 2, 18 * 2),
                                 flip_x=True,
                                 flip_y=True),
        ]
        Sky.images = [load_image('sky.png', (32, 32))]
        Ground.images = [load_image('grass.png', (32, 32))]
        GroundObstacle.images = [
            load_image('grass.png', (32, 32)),
            load_image('sky.png', (32, 32))
        ]
        CatObstacle.images = [
            cat_sheet.image_at((0, 0, 54, 42), colorkey=-1),
            cat_sheet.image_at((1, 158, 54, 42), colorkey=-1),
            cat_sheet.image_at((1 + 54, 158, 54, 42), colorkey=-1),
            cat_sheet.image_at((1 + 54 * 2, 158, 54, 42), colorkey=-1),
            cat_sheet.image_at((1 + 54 * 3, 158, 54, 42), colorkey=-1),
        ]
        # Load sounds
        Deafy.sounds = [
            load_sound("normal.ogg"),
            load_sound("jump.ogg"),
            load_sound("victory.ogg")
        ]

        # Initialize Game Groups
        self.all = pygame.sprite.RenderUpdates()
        self.background_group = pygame.sprite.RenderUpdates()
        self.obstacle_group = pygame.sprite.RenderUpdates()
        # Sprites in this group are rendered after background so that they appear on the top.
        self.front_group = pygame.sprite.RenderUpdates()

        # assign default groups to each sprite class
        Deafy.containers = self.all, self.front_group
        Ground.containers = self.all, self.background_group
        Sky.containers = self.all, self.background_group
        GroundObstacle.containers = self.all, self.obstacle_group
        CatObstacle.containers = self.all, self.front_group
        Dialog.containers = self.all

        # initialize stage
        self.stage = Stage(num=1)
        self.current_items = []

        # TODO: Maybe the height and width are the other way around
        self.ground_sprites = [
            Ground(pos=(w * BACKGROUND_OBJECT_WIDTH,
                        h * BACKGROUND_OBJECT_HEIGHT))
            for w in range(SCREEN_WIDTH / BACKGROUND_OBJECT_WIDTH + 1)
            for h in range(GROUND_Y_LIMITS[0] / BACKGROUND_OBJECT_HEIGHT +
                           1, GROUND_Y_LIMITS[1] / BACKGROUND_OBJECT_HEIGHT +
                           1)
        ]
        self.sky_sprites = [
            Sky(pos=(w * BACKGROUND_OBJECT_WIDTH,
                     h * BACKGROUND_OBJECT_HEIGHT))
            for w in range(SCREEN_WIDTH / BACKGROUND_OBJECT_WIDTH + 1)
            for h in range(SKY_Y_LIMITS[0] / BACKGROUND_OBJECT_HEIGHT +
                           1, SKY_Y_LIMITS[1] / BACKGROUND_OBJECT_HEIGHT + 1)
        ]
        self.deafy = Deafy(pos=DEAFY_SCREEN_POS)
        self.ground_obstacle_sprites = []
        self.cat_obstacles = []

        # Now initialize the FacialLandmarkDetector
        self.fld = FacialLandmarkDetector(SCREEN_WIDTH, SCREEN_HEIGHT,
                                          FACIAL_LANDMARK_PREDICTOR_WIDTH)
        self.dx = INITIAL_DX
        self.visible_xrange = [0, SCREEN_WIDTH]

        # to track of which dialog frame shold be rendered
        self.dialog_frame = 0
        # To trach whether dialog is displayed now. If so, disable user control.
        self.is_dialog_active = True
Exemplo n.º 33
0
class Mystery(Entity):
    """The mystery ship which flys accross the screen.

    Arguments:
        direction (int): The direction the ship will move across the screen.
        groups (pygame.sprite.Group): All the groups this entity will be in.

    Attributes:
        ship (Ship): The default image for the ship.
        explosion (Animation): The explosion animation.
        dirty (int): Wether or not to draw the entity.
        image (pygame.Surface): The sprites image.
        rect (pygame.Rect): The rect used to place the sprite.
        _explosion (Animation): The explosion animation.
    """
    ship = SpriteSheet.sprite(MYSTERY)
    explosion = Animation(SpriteSheet.animation(MYSTERY_EXPLOSION, 1), 0.3)

    def __init__(self, direction, *groups):
        super().__init__(*groups)
        self.dirty = 2
        self.image = copy(self.ship).convert_alpha()
        self.rect = self.image.get_rect()
        self.mask = pygame.mask.from_surface(self.image)
        self._explosion = copy(self.explosion)

        self.rect.y = 0 + self.rect.height

        if direction:
            self._velocity = pygame.math.Vector2(250, 0)
            self.rect.x = 0
        else:
            self._velocity = pygame.math.Vector2(-250, 0)
            self.rect.x = DISPLAY.width

    def update(self, seconds_elapsed):
        """Update the entities time based variables and update the sprites
        position.

        Arguments:
            seconds_elapsed (float): The time since the last frame was drawn.
        """
        super().update(seconds_elapsed)
        self.rect.x += int(self._seconds_elapsed * self._velocity.x)

        if not self.rect.colliderect(DISPLAY):
            self.kill()

    def take_damage(self, bullets, *groups):
        """Take any damage from the bullets on the screen. Create an explosion
        animation when the entities died.

        bullets (pygame.sprite.Group): The group containing the bullet sprites.
        groups (pygame.sprite.Group): The groups the explosion will be in.
        """
        for bullet in bullets:
            if pygame.sprite.collide_mask(self, bullet):
                Explosion(self._explosion,
                          (self.rect.x + 6, self.rect.y),
                          *groups)
                bullet.kill()
                self.kill()
Exemplo n.º 34
0
class ButtonTray:
    """ a strip of icon buttons anchored to the corner of the editor window """
    def __init__(self, icon_filename, surface):
        self.button_names = (RUN, STOP, SAVE, LOAD, CHANGE_COLOR)
        self.surface = surface
        self.button_count = 5
        self.button_size = 16
        self.button_margin = 2
        width = ((self.button_size * self.button_count) +
                 (self.button_margin * (self.button_count + 1)))
        height = self.button_size + self.button_margin * 2
        self.tray_size = (width, height)
        self.top_left = [(surface.get_size()[X] - width - 3),
                         (surface.get_size()[Y] - height) - 3]
        self.tray = pygame.Rect(self.top_left, self.tray_size)

        self.sprites = SpriteSheet(icon_filename)
        # the icons don't use alpha transparency - bg color is fixed
        #self.up_buttons = self.sprites.load_strip(
        #    pygame.Rect(0, 0, self.button_size, self.button_size),
        #    self.button_count)
        #self.down_buttons = self.sprites.load_strip(
        #    pygame.Rect(self.button_size * self.button_count, 0,
        #                self.button_size, self.button_size),
        #    self.button_count)
        self.buttons = {}
        up_pos = [0, 0]
        down_pos = [self.button_size * self.button_count, 0]
        size = (self.button_size, self.button_size)
        self.buttons = {}
        for name in self.button_names:
            self.buttons[name] = \
                     {UP: self.sprites.image_at(pygame.Rect(up_pos, size)),
                      DOWN: self.sprites.image_at(pygame.Rect(down_pos, size))}
            up_pos[X] += self.button_size
            down_pos[X] += self.button_size

        self.button_state = {
            RUN: UP,
            SAVE: UP,
            STOP: UP,
            LOAD: UP,
            CHANGE_COLOR: UP
        }

    def click(self, pos):
        # returns the button constant corresponding to the pos (x,y) coords
        # or None if pos lies outside the tray
        if self.tray.collidepoint(pos):
            # convert x coord to the button number
            button = int((pos[X] - self.top_left[X]) /
                         (self.button_size + self.button_margin)) + 1
            if button in self.button_names:
                self.button_state[button] = DOWN
                return button
        return None

    def release(self):
        # revert all the buttons to their up state
        for button in self.button_names:
            self.button_state[button] = UP

    def draw(self, fg_color, bg_color):
        pygame.draw.rect(self.surface, fg_color, self.tray)

        pos = [
            self.top_left[X] + self.button_margin,
            self.top_left[Y] + self.button_margin
        ]
        for b in self.button_names:
            button_image = self.buttons[b][self.button_state[b]]
            self.surface.blit(button_image, pos)
            pos[X] += self.button_size + self.button_margin
    def load_sprite_images(self):
        """
        gets images from sprite sheets
        """

        # sprite sheets
        effectSheet = SpriteSheet("resources/images/Effects Spritesheet.png")
        explosionSheet = SpriteSheet("resources/images/explosion.png")
        lunar_pioneer_sheet = SpriteSheet("resources/images/lunar pioneer.png")
        background_objects_sheet = SpriteSheet(
            "resources/images/grandfather clock.png")
        dust_sheet = SpriteSheet("resources/images/Dust Spritesheet.png")

        #lightning
        self.lightning_animation = [
            effectSheet.imageAt(pygame.Rect(654, 886, 34, 14)),
            effectSheet.imageAt(pygame.Rect(705, 885, 32, 14)),
            effectSheet.imageAt(pygame.Rect(750, 872, 62, 40)),
            effectSheet.imageAt(pygame.Rect(826, 871, 68, 37)),
            effectSheet.imageAt(pygame.Rect(911, 881, 72, 29))
        ]
        #putting explosion into big bertha
        berthaImage.append(explosionSheet.imageAt(pygame.Rect(22, 115, 72,
                                                              63)))
        berthaImage.append(
            explosionSheet.imageAt(pygame.Rect(110, 108, 99, 81)))
        berthaImage.append(
            explosionSheet.imageAt(pygame.Rect(384, 116, 103, 88)))
        berthaImage.append(
            explosionSheet.imageAt(pygame.Rect(509, 27, 110, 80)))
        berthaImage.append(explosionSheet.imageAt(pygame.Rect(650, 29, 84,
                                                              72)))

        #lunar pioneer images
        self.lunar_pioneer_images = [
            lunar_pioneer_sheet.imageAt(pygame.Rect(35, 25, 20, 20)),
            lunar_pioneer_sheet.imageAt(pygame.Rect(101, 26, 20, 20))
        ]
        #grandfather clock images
        self.grandfather_clock = [
            background_objects_sheet.imageAt(pygame.Rect(7, 12, 18, 71)),
            background_objects_sheet.imageAt(pygame.Rect(39, 12, 18, 71)),
            background_objects_sheet.imageAt(pygame.Rect(71, 12, 18, 71)),
            background_objects_sheet.imageAt(pygame.Rect(39, 12, 18, 71))
        ]
        #spawn images
        self.spawn_animation = [
            effectSheet.imageAt(pygame.Rect(291, 695, 2, 217)),
            effectSheet.imageAt(pygame.Rect(281, 695, 2, 217)),
            effectSheet.imageAt(pygame.Rect(270, 695, 2, 217)),
            effectSheet.imageAt(pygame.Rect(270, 695, 2, 217)),
            effectSheet.imageAt(pygame.Rect(260, 695, 4, 217)),
            effectSheet.imageAt(pygame.Rect(242, 695, 12, 216)),
            effectSheet.imageAt(pygame.Rect(215, 695, 22, 217)),
            effectSheet.imageAt(pygame.Rect(180, 695, 30, 217)),
            effectSheet.imageAt(pygame.Rect(148, 695, 22, 217)),
            effectSheet.imageAt(pygame.Rect(108, 695, 30, 217)),
            effectSheet.imageAt(pygame.Rect(53, 695, 48, 217)),
            effectSheet.imageAt(pygame.Rect(4, 695, 46, 217))
        ]

        self.spawn_animation = normalize_rects(self.spawn_animation)
        #dust cloud
        #dust_sheet.imageAt(pygame.Rect(544, 250, 82, 17))  # this image is just broken for no reason.
        self.dust_cloud = [
            dust_sheet.imageAt(pygame.Rect(156, 28, 150, 41)),
            dust_sheet.imageAt(pygame.Rect(351, 20, 189, 58)),
            dust_sheet.imageAt(pygame.Rect(2, 130, 196, 61)),
            dust_sheet.imageAt(pygame.Rect(257, 141, 194, 57)),
            dust_sheet.imageAt(pygame.Rect(3, 230, 198, 57)),
            dust_sheet.imageAt(pygame.Rect(257, 253, 197, 57))
        ]
Exemplo n.º 36
0
def init():
    global camera
    global current_screen
    global online_game
    global screen

    #menu images
    global button_img_list
    global join_game_img_list
    global forward_button_img_list
    global back_button_img_list
    global text_field_img_list
    global ready_button_img_list
    global small_forward_button_img_list
    global small_back_button_img_list
    global close_button_img_list

    #cycle button contents
    global map_names

    #sounds
    global button_1_sound

    current_screen = "main menu"
    screen_size = pygame.display.list_modes()[0]
    screen = pygame.display.set_mode(screen_size, DOUBLEBUF)

    #import button images
    button_sheet = SpriteSheet("resources/images/ButtonSpriteSheet.png")
    button_img_list = [button_sheet.imageAt(pygame.Rect(475, 306, 80, 19), None)]
    join_game_img_list = [button_sheet.imageAt(pygame.Rect(497, 281, 33, 10))]
    forward_button_img_list = [button_sheet.imageAt(pygame.Rect(0, 76, 50, 278), None)]
    back_button_img_list = [button_sheet.imageAt(pygame.Rect(54, 76, 50, 278), None)]
    small_forward_button_img_list = [button_sheet.imageAt(pygame.Rect(494, 226, 18, 15)),
                                     button_sheet.imageAt(pygame.Rect(494, 243, 18, 15))]
    small_back_button_img_list = [button_sheet.imageAt(pygame.Rect(516, 242, 18, 15)),
                                  button_sheet.imageAt(pygame.Rect(516, 225, 18, 15))]
    text_field_img_list = [button_sheet.imageAt(pygame.Rect(479, 278, 75, 12), None),
                           button_sheet.imageAt(pygame.Rect(479, 293, 75, 12), None)]
    ready_button_img_list = [button_sheet.imageAt(pygame.Rect(0, 0, 157, 38), None),
                             button_sheet.imageAt(pygame.Rect(0, 38, 157, 38), None)]
    close_button_img_list = [button_sheet.imageAt(pygame.Rect(108, 77, 44, 44), None)]

    #populate cycle_button elements
    map_names = [Label(euclid.Vector2(0, 0), "Matt World"),
                 Label(euclid.Vector2(0, 0), "Fun Zone"),
                 Label(euclid.Vector2(0, 0), "Snake Juice")]

    #sounds
    button_1_sound = pygame.mixer.Sound("resources/sounds/menu_button.wav")
    def load_sprite_images(self):
        """
        gets images from sprite sheets
        """

        # sprite sheets
        effectSheet = SpriteSheet("resources/images/Effects Spritesheet.png")
        explosionSheet = SpriteSheet("resources/images/explosion.png")
        lunar_pioneer_sheet = SpriteSheet("resources/images/lunar pioneer.png")
        background_objects_sheet = SpriteSheet("resources/images/grandfather clock.png")
        dust_sheet = SpriteSheet("resources/images/Dust Spritesheet.png")

        #lightning
        self.lightning_animation = [effectSheet.imageAt(pygame.Rect(654, 886, 34, 14)),
                                    effectSheet.imageAt(pygame.Rect(705, 885, 32, 14)),
                                    effectSheet.imageAt(pygame.Rect(750, 872, 62, 40)),
                                    effectSheet.imageAt(pygame.Rect(826, 871, 68, 37)),
                                    effectSheet.imageAt(pygame.Rect(911, 881, 72, 29))]
        #putting explosion into big bertha
        berthaImage.append(explosionSheet.imageAt(pygame.Rect(22, 115, 72, 63)))
        berthaImage.append(explosionSheet.imageAt(pygame.Rect(110, 108, 99, 81)))
        berthaImage.append(explosionSheet.imageAt(pygame.Rect(384, 116, 103, 88)))
        berthaImage.append(explosionSheet.imageAt(pygame.Rect(509, 27, 110, 80)))
        berthaImage.append(explosionSheet.imageAt(pygame.Rect(650, 29, 84, 72)))

        #lunar pioneer images
        self.lunar_pioneer_images = [lunar_pioneer_sheet.imageAt(pygame.Rect(35, 25, 20, 20)),
                                     lunar_pioneer_sheet.imageAt(pygame.Rect(101, 26, 20, 20))]
        #grandfather clock images
        self.grandfather_clock = [background_objects_sheet.imageAt(pygame.Rect(7, 12, 18, 71)),
                                  background_objects_sheet.imageAt(pygame.Rect(39, 12, 18, 71)),
                                  background_objects_sheet.imageAt(pygame.Rect(71, 12, 18, 71)),
                                  background_objects_sheet.imageAt(pygame.Rect(39, 12, 18, 71))]
        #spawn images
        self.spawn_animation = [effectSheet.imageAt(pygame.Rect(291, 695, 2, 217)),
                                effectSheet.imageAt(pygame.Rect(281, 695, 2, 217)),
                                effectSheet.imageAt(pygame.Rect(270, 695, 2, 217)),
                                effectSheet.imageAt(pygame.Rect(270, 695, 2, 217)),
                                effectSheet.imageAt(pygame.Rect(260, 695, 4, 217)),
                                effectSheet.imageAt(pygame.Rect(242, 695, 12, 216)),
                                effectSheet.imageAt(pygame.Rect(215, 695, 22, 217)),
                                effectSheet.imageAt(pygame.Rect(180, 695, 30, 217)),
                                effectSheet.imageAt(pygame.Rect(148, 695, 22, 217)),
                                effectSheet.imageAt(pygame.Rect(108, 695, 30, 217)),
                                effectSheet.imageAt(pygame.Rect(53, 695, 48, 217)),
                                effectSheet.imageAt(pygame.Rect(4, 695, 46, 217))]

        self.spawn_animation = normalize_rects(self.spawn_animation)
        #dust cloud
        #dust_sheet.imageAt(pygame.Rect(544, 250, 82, 17))  # this image is just broken for no reason.
        self.dust_cloud = [dust_sheet.imageAt(pygame.Rect(156, 28, 150, 41)),
                           dust_sheet.imageAt(pygame.Rect(351, 20, 189, 58)),
                           dust_sheet.imageAt(pygame.Rect(2, 130, 196, 61)),
                           dust_sheet.imageAt(pygame.Rect(257, 141, 194, 57)),
                           dust_sheet.imageAt(pygame.Rect(3, 230, 198, 57)),
                           dust_sheet.imageAt(pygame.Rect(257, 253, 197, 57))]
 def __init__(self, filename, patch_size, final_size, patch_pos):
     self._sheet = SpriteSheet(filename, patch_size, final_size)
     self._patch_pos = patch_pos
Exemplo n.º 39
0
    def __init__(self,
                 always_visible=False,
                 x_offset=0,
                 y_offset=0,
                 box_width=None,
                 box_height=None,
                 max_chars=65,
                 player_heads_up_display=None,
                 screen=None):
        self.screen = screen
        self.always_visible = always_visible
        self.max_chars = max_chars
        self.view_offset = 0  # The part of the text log you're viewing.  0 is the most recent on the bottom.

        # These values move the ChatBox from it's default position at the bottom left hand corner of the screen.
        self.x_offset = x_offset
        self.y_offset = y_offset

        self.hidden = not self.always_visible  # while this is true the ChatBox shouldn't be displayed.
        self.alpha = 255
        self.delaying_to_fade = False
        self.is_fading = False  # while this is true, the ChatBox text is fading to transparency.
        self.fade_delay = 3  # seconds after the ChatBox is deselected until the text starts to fade.
        self.fade_time = 2  # seconds that it fades for after the fadeDelay
        self.last_deselect_time = 0  # time that the fade process started.
        self.last_fade_start_time = 0
        self.selected = False
        self.fade_proportion = 0  # This will hold the proportion to convert the time to terms of opacity (0-255)
        self.font = pygame.font.SysFont('arial', 12)

        self.cursor_blink_time = 1.5  # the cursor will change every half of this number
        self.last_cursor_blink = 0
        self.cursor_is_blinking = False
        self.cursor_surface = self.font.render("|", True, [255, 255, 255])

        self.text_content = []  # list of strings. lower index = older
        self.input = None  # a string of input to send to the textBox.
        self.surface_content = [
        ]  # a list of surface slices. lower index = older
        self.border_offset = 14  # offset text by ten pixels to account for the border of the chatBox
        self.blit_dict = {}
        self.alpha_blit_dict = {}

        temp_sprite_sheet = SpriteSheet("resources/images/Sprite Sheet1.png")
        self.box_image = temp_sprite_sheet.imageAt(pygame.Rect(
            5, 15, 370, 135))
        # this image is cursed to never change color.
        self.unfocused_image = temp_sprite_sheet.imageAt(
            pygame.Rect(6, 158, 368, 130))
        if box_width is not None and box_height is not None:
            self.box_image = pygame.transform.scale(self.box_image,
                                                    (box_width, box_height))
            self.unfocused_image = pygame.transform.scale(
                self.box_image, (box_width, box_height))
        self.image = self.box_image  # everything will be blit onto here.

        self.shift_is_pressed = False

        if hasattr(globals, 'online_game'):
            self.last_message_received = 0
            self.get_new_messages_thread = RepeatTask(1, self.get_new_messages)
            self.get_new_messages_thread.start()

        self.player_heads_up_display = player_heads_up_display
        self.last_paused = datetime.now()
Exemplo n.º 40
0
from settings import (SCREEN_WIDTH, SCREEN_HEIGHT, SPRITE_SCALE)
from sprite_sheet import SpriteSheet
from player import Player
from enemy import Enemy
from beam import Beam

#사운드 초기화
pygame.mixer.init()

pygame.init()

screen = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])

#스프라이트 로드
#스프라이트는 opengameart.org
sheet = SpriteSheet("sprites\\sheet.png", "sprites\\sheet.xml")

#배경 서피스 설정
bg = pygame.image.load("sprites\\bg_darkPurple.png")
bg_width = bg.get_width()
bg_height = bg.get_height()
bg_surface = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT))
for y in range(0, SCREEN_HEIGHT, bg_height):
    for x in range(0, SCREEN_WIDTH, bg_width):
        bg_surface.blit(bg, (x, y))

#게임 속도 설정을 위한 시계
clock = pygame.time.Clock()

#event는 int로 정의되는데,
#USEREVENT가 가장 마지막에 위치하므로 +1로 새로운 이벤트 정의