Beispiel #1
0
    def __init__(self, player: Player):
        self.player = player  # Hook a player into the HUD

        pg.sprite.Sprite.__init__(self)  # call Sprite intializer
        self.rect = load_image("player/heart_0.png", -1)[1]
        self.hearts = [
            load_image(f"player/heart_{n}.png", -1)[0] for n in range(0, 9)
        ]
        self.image = self.hearts[0]
        screen = pg.display.get_surface()
        self.area = screen.get_rect()
        self.rect.topleft = 700, 500
    def __init__(self, player: Player):
        self.player = player  # Hook a player into the HUD

        pg.sprite.Sprite.__init__(self)  # call Sprite intializer
        self.rect = load_image("powerup/potion2_ready_0.png", -1)[1]
        self.potions = [
            load_image(f"powerup/potion2_ready_{n}.png", -1)[0]
            for n in range(0, 5)
        ]
        self.image = self.potions[0]
        screen = pg.display.get_surface()
        self.area = screen.get_rect()
        self.rect.topleft = 705, 430
Beispiel #3
0
 def __init__(self, x, y, world, image):
     pygame.sprite.Sprite.__init__(self)
     self.x = x*TILE_SIZE
     self.y = y*TILE_SIZE
     self.image = load_image(image+'.bmp')
     self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
     self.rect = self.image.get_rect()
     self.rect.topleft = self.x, self.y
     self.world = world
     world.tiles.add(self)
Beispiel #4
0
    def __init__(self, screen_width, screen_height):
        pg.sprite.Sprite.__init__(self)  # call Sprite intializer
        self.image, self.rect = load_image("powerup/potion1.png", -1)

        # hitbox debug
        self.hitbox_debug = False

        screen = pg.display.get_surface()
        self.area = screen.get_rect()
        self.rect.topleft = randint(10, screen_width - 34), randint(
            10, screen_height - 200)

        # auto move down
        self.auto_move = True
        self.move_x = 0
        self.move_y = 1
Beispiel #5
0
    def __init__(self, screen_width, screen_height):
        pg.sprite.Sprite.__init__(self)
        self.image, self.rect = load_image("enemy/enemy2.png", -1)

        # hitbox debug
        self.hitbox_debug = False

        self.radius = 20
        self.rect.x = randint(100, screen_width-100)
        self.rect.y = 0
        self.true_x = self.rect.x
        self.true_y = self.rect.y

        # # spawn only from top of screen
        # self.rect.topleft = randint(80, screen_width - 80), 0

        # spawn randomly in top half of screen
        # self.rect.topleft = randint(0, screen_width - 80), randint(0, screen_height//2 - 80 )
        # while distance.euclidean(self.rect.topleft, player_coordinates) < 200:
        #     self.rect.topleft = randint(0, screen_width - 80), randint(0, screen_height//2 - 80)

        self.hurtbox = pg.Rect(self.rect.x + 10, self.rect.y + 10, 0, 0)    # instantiate hitbox; not actually used

        # automatic movement (to reflect map movement)
        self.auto_move = True
        self.move_x = 0
        self.move_y = 0.05

        # bullet generation
        self.shoot_delay = 150      # pause between bursts
        self.burst_delay = 0        # pause between shots in a burst; 0 for no burst
        self.burst_count = 1        # number of shots per burst
        self.bullet_counter = 0
        # generate frames at which enemy shoots
        if self.burst_delay != 0:
            self.bullet_counter_reset = self.shoot_delay + self.burst_delay * self.burst_count
            self.bullet_frames = range(self.shoot_delay, self.bullet_counter_reset, self.burst_delay)
        else:
            self.bullet_counter_reset = self.shoot_delay
            self.bullet_frames = [self.shoot_delay-1]

        self.pew_sound = pg.mixer.Sound("sound/pew_12.wav")
Beispiel #6
0
    def __init__(self, screen_width, screen_height):
        pg.sprite.Sprite.__init__(self)  # call Sprite intializer
        self.image, self.rect = load_image("powerup/potion2_00.png", -1)

        self.frame = 0
        self.images = []
        for i in range(0, 10):
            filename = "art/powerup/potion2_0" + str(i) + ".png"
            self.images.append(pg.image.load(filename))

        # hitbox debug
        self.hitbox_debug = False

        screen = pg.display.get_surface()
        self.area = screen.get_rect()
        self.rect.topleft = randint(10, screen_width - 34), randint(
            10, screen_height // 5)

        # auto move down
        self.auto_move = True
        self.move_x = 0
        self.move_y = 1
Beispiel #7
0
    def __init__(self, start_x, start_y, player_x, player_y, angle_offset=0):
        pg.sprite.Sprite.__init__(self)
        self.image, self.rect = load_image("bullet/knife1.png", -1)

        # hitbox debug
        self.hitbox_debug = False

        self.rect.x = start_x
        self.rect.y = start_y
        # 'true' coordinates to hold decimal coordinates
        self.true_x = start_x * 1.0
        self.true_y = start_y * 1.0

        # hitbox
        self.size_x = 8
        self.size_y = 8
        self.offset_x = 20 - self.size_x / 2  # offset_x of 20 leads to centre x
        self.offset_y = 20 - self.size_y / 2  # offset_y of 20 leads to centre y
        self.hurtbox = pg.Rect(self.rect.x, self.rect.y, 0, 0)

        self.speed = 2

        # set movement + rotation towards player
        self.dx, self.dy, self.angle = self.face_to_player(
            start_x, start_y, player_x, player_y)
        self.angle += angle_offset
        self.image = self.rot_center_sq(self.image, self.angle)

        # memes
        self.auto_rotate = False
        self.auto_rotate_angle = 10

        # rotate hitbox - doesn't work
        # self.hurtbox = self.hurtbox(center=rect.center)

        # move knife a little bit away from Enemy sprite before appearing
        self.true_x += self.dx * 5
        self.true_y += self.dy * 5
Beispiel #8
0
    def __init__(self, start_x, start_y, player_x):
        pg.sprite.Sprite.__init__(self)
        self.image, self.rect = load_image("bullet/knife2.png", -1)

        # hitbox debug
        self.hitbox_debug = False

        self.rect.x = start_x
        self.rect.y = start_y
        # 'true' coordinates to hold decimal coordinates
        self.true_x = start_x * 1.0
        self.true_y = start_y * 1.0

        # hitbox
        self.size_x = 32
        self.size_y = 32
        self.offset_x = 64 - self.size_x / 2  # offset_x of 64 leads to centre x
        self.offset_y = 96 - self.size_y / 2  # offset_y of 64 leads to centre y; offset_y of 96 for lower portion
        self.hurtbox = pg.Rect(self.rect.x, self.rect.y, 0,
                               0)  # initialises hitbox; not actual size

        self.player_x = player_x
        self.xspeed = 0.03  # proportion of distance covered in a frame
        self.yspeed = 8
Beispiel #9
0
    def __init__(self, screen_width, screen_height, potion_list):
        pg.sprite.Sprite.__init__(self)  # call Sprite intializer
        self.image, self.rect = load_image("player/player_default.png", -1)

        # for showing hitboxes
        self.hitbox_debug = False

        self.sprite_img_radius = 50
        self.sprite_char_radius = 15
        self.hitbox_radius = 10
        self.rect.x = 350
        self.rect.y = 450
        screen = pg.display.get_surface()
        self.area = screen.get_rect()
        self.dist = 2
        self.screen_width = screen_width
        self.screen_height = screen_height
        self.walls = None
        self.health = 8  # there are 9 stages of health; starting from heart_0 to heart_8 (death)
        self.score = 0

        self.scroll_background = False  # toggles automatic movement due to scrolling background; not working
        self.bg_move = 1  # rate of movement; not a 1:1 ratio with background movement, for some reason

        # attack data
        self.attack_cooldown = 0
        self.attack_box = (self.rect.x - 20, self.rect.y + 20, 70, 90)
        # attack animation
        self.attack = False
        self.attack_frame = 0
        self.attack_images = []
        for i in range(0, 5):
            filename = "art/player/attack_" + str(i) + ".png"
            self.attack_images.append(pg.image.load(filename))

        # attack_ready animation
        self.attack_ready = False
        self.attack_ready_frame = 0
        self.attack_ready_images = []
        for i in range(0, 3):
            filename = "art/player/ready_" + str(i) + ".png"
            self.attack_ready_images.append(pg.image.load(filename))

        # attack_ready progress bar
        self.attack_ready_bar = pg.Surface((10, 50))
        for x in range(self.attack_ready_bar.get_width()):
            for y in range(self.attack_ready_bar.get_height()):
                self.attack_ready_bar.set_at((x, y), pg.Color(100, 100, 100))

        # bomb ready (from potion)
        self.bomb_count = 0
        self.bomb_ready = False  # set to True when bomb_count == 4

        self.potions = potion_list

        # healing animation
        self.heal = False
        self.heal_frame = 0
        self.heal_images = []
        for i in range(0, 3):
            filename = "art/player/heal_" + str(i) + ".png"
            self.heal_images.append(pg.image.load(filename))

        # damage animation
        self.damage = False
        self.damage_frame = 0
        self.damage_images = []
        for i in range(0, 3):
            filename = "art/player/hurt_" + str(i) + ".png"
            self.damage_images.append(pg.image.load(filename))

        # hurtbox data
        self.hurtbox = pg.Rect(self.rect.x + 30, self.rect.y + 30, 30, 30)
        self.damage_cooldown = 0
Beispiel #10
0
 def kill_enemy(self, player):
     player.score += 1
     topleft = self.rect.topleft
     self.image, self.rect = load_image("enemy/enemy1x_big.png", -1)
     self.rect.topleft = topleft