Exemplo n.º 1
0
    def __init__(self, scene, pos=(3, 3)):
        super().__init__(scene)
        self.priority = 3
        self.blocking = True
        self.interactive = True
        self.dialogue = None

        tag_dict = {"Player": "player", "Emilia": "captain", None: "player"}
        tag = tag_dict[self.name]

        down = SpriteSheet(scene.load_image(f"{tag}_walk_down"), (6, 1), 6)
        up = SpriteSheet(scene.load_image(f"{tag}_walk_up"), (6, 1), 6)
        down_idle = SpriteSheet(scene.load_image(f"{tag}_idle_down"), (4, 1),
                                4)
        up_idle = SpriteSheet(scene.load_image(f"{tag}_idle_up"), (4, 1), 4)
        right = SpriteSheet(scene.load_image(f"{tag}_walk_right"), (6, 1), 6)
        left = SpriteSheet(scene.load_image(f"{tag}_walk_right"), (6, 1), 6)
        left.reverse(1, 0)
        right_idle = SpriteSheet(scene.load_image(f"{tag}_idle_right"), (4, 1),
                                 4)
        left_idle = SpriteSheet(scene.load_image(f"{tag}_idle_right"), (4, 1),
                                4)
        left_idle.reverse(1, 0)
        self.sprite = Sprite(8)
        self.sprite.add_animation({
            "down": down,
            "up": up,
            "down_idle": down_idle,
            "up_idle": up_idle,
            "right": right,
            "left": left,
            "right_idle": right_idle,
            "left_idle": left_idle
        })
        self.sprite.start_animation("down_idle")
        self.idles = {
            c.DOWN: "down_idle",
            c.UP: "up_idle",
            c.RIGHT: "right_idle",
            c.LEFT: "left_idle"
        }
        self.idle_playing = True

        self.x = pos[0]
        self.y = pos[1]
        self.scene.map.add_to_cell(self, self.x, self.y)
        self.draw_x = self.x
        self.draw_y = self.y
        self.prev_x = self.x
        self.prev_y = self.y
        self.shadow = CharacterShadow(scene, self)
        self.scene.map.add_to_cell(self.shadow, self.x, self.y)

        self.since_move = 0
        self.move_speed = 3

        self.in_motion = False
        self.next_direction = c.NO_DIRECTION
        self.face_direction = c.DOWN
        self.last_face_direction = c.DOWN
        self.since_arrive = 999

        self.shadow_surf = pygame.Surface(c.TILE_SIZE)
        self.shadow_surf.fill(c.WHITE)
        width = int(c.TILE_WIDTH * 0.7)
        height = int(c.TILE_HEIGHT * 0.5)
        pygame.draw.ellipse(
            self.shadow_surf, c.BLACK,
            (c.TILE_WIDTH // 2 - width // 2,
             3.2 * c.TILE_HEIGHT // 5 - height // 2, width, height))
        self.shadow_surf.set_alpha(30)
        self.shadow_surf.set_colorkey(c.WHITE)
Exemplo n.º 2
0
import pygame
import constants as c
import random
import math
from sprite_tools import SpriteSheet, Sprite
from pickup import Cash
from particle import DasherSmoke, DasherSmokeRed


crawler_running = SpriteSheet("images/crawler.png", (4, 1), 4, scale=2)
crawler_running_ceiling = SpriteSheet("images/crawler.png", (4, 1), 4, scale=2)
crawler_running_ceiling.reverse(0, 1)
crawler_jump = SpriteSheet("images/crawler_jump.png", (1, 1), 1, scale=2)
crawler_hurt = SpriteSheet("images/crawler_hurt.png", (1, 1), 1, scale=2)
crawler_hurt_ceiling = SpriteSheet("images/crawler_hurt.png", (1, 1), 1, scale=2)
crawler_hurt_ceiling.reverse(0, 1)
crawler_dead = SpriteSheet("images/crawler_dead.png", (1, 1), 1, scale=2)

dasher_hovering = SpriteSheet("images/dasher.png", (1, 1), 1, scale=2)
dasher_dashing = SpriteSheet("images/dasher_dashing.png", (1, 1), 1, scale=2)
dasher_damage = SpriteSheet("images/dasher_damage.png", (1, 1), 1, scale=2)
dasher_dashing_damage = SpriteSheet("images/dasher_dashing_damage.png", (1, 1), 1, scale=2)

blocker = SpriteSheet("images/blocker.png", (4, 1), 4, scale=2)
blocker_hurt = SpriteSheet("images/blocker_hurt.png", (1, 1), 1, scale=2)
blocker_dead = SpriteSheet("images/blocker_dead.png", (1, 1), 1, scale=2)


class Enemy:
    def __init__(self, game, x, y, radius=60):
        self.game = game