Beispiel #1
0
def get_player(world):
    player = world.create_entity()
    image = components.Image("playerIdle.png")
    animation = components.Animation("playerSimple.png", splitx=80, framelength=.1)
    carry_image = components.Image("playerCarryIdle.png")
    carry_animation = components.Animation("playerCarrySimple.png", splitx=80, framelength=.1)
    jump = components.Audio("jump.ogg")
    throw = components.Audio("throw")
    world.add_component(player, components.Position(100, 560))
    world.add_component(player, components.Velocity())
    world.add_component(player, image)
    world.add_component(player, components.Size(80, 80))
    world.add_component(player, components.Player(image, animation, carry_image, carry_animation, jump, throw))

    return player
Beispiel #2
0
    def init(self):
        scenebase.SceneBase.init(self)

        bg = create_entity(self.world, "IntroBG.png", pygame.Rect(640, 360, 1280, 720))
        self.world.add_component(bg, components.Background())

        player = get_player(self.world)

        saddle = create_entity(self.world, "saddle.png", pygame.Rect(300, 560, 80, 80))
        self.world.add_component(saddle, components.Velocity())
        self.world.add_component(saddle, components.Audio("light"))
        def dragon_hit():
            self.world.component_for_entity(dragon, components.Animation).frame = 1
            damage = notify(self.world, self.font, "Dragon Tamed", self, text.TextScene("Sadly, the dragon refused to be tamed. Instead, though, it granted NaN the power of fireballs! Let's see how this turns out...",SceneEight()))
            image = self.font.render("Dragon Tamed", False, (255, 128, 0))
            self.world.component_for_entity(damage, components.Image).image = image
            self.world.component_for_entity(damage, components.Position).x = 960
            self.world.component_for_entity(damage, components.Position).y = 320
            self.world.component_for_entity(damage, components.Size).width = image.get_width()
            self.world.component_for_entity(damage, components.Size).height = image.get_height()
            pygame.mixer.Sound(os.path.join(components.get_base_path(), 'audio', 'dragon.ogg')).play()
        dragon = self.world.create_entity()
        self.world.add_component(dragon, components.Position(1000, 500))
        self.world.add_component(dragon, components.Velocity(0, 0))
        self.world.add_component(dragon, components.Animation("dragon.png", splitx=640, frame=0))
        self.world.add_component(dragon, components.Size(640, 640))
        self.world.add_component(dragon, components.Touch(saddle, rect=pygame.Rect(0, -400, -320, 0), touch=dragon_hit))

        
        def move_up(entity):
            self.world.add_component(entity, components.ChangePosition((0, -40), 1, interpolation.Smooth(), True, move_down, entity))
        def move_down(entity):
            self.world.add_component(entity, components.ChangePosition((0, 40), 1, interpolation.Smooth(), True, move_up, entity))





        tutorial = self.world.create_entity()
        image = self.font.render("'put' the saddle on the dragon", False, (32, 255, 128))
        self.world.add_component(tutorial, components.Position(640, 680))
        self.world.add_component(tutorial, components.Image(image=image))
        self.world.add_component(tutorial, components.Size(image.get_width(), image.get_height()))
        move_up(tutorial)


        clouds = []
        for i in [1,2,3,4,5,6]:
            cloud = create_entity(self.world, "cloud.png", pygame.Rect(random.randrange(100, 1180), random.randrange(75, 200), 160, 80))
            self.world.add_component(cloud, components.Background())
            self.world.add_component(cloud, components.Hang())
            clouds.append(cloud)

        self.world.add_processor(processors.RenderProcessor())
        self.world.add_processor(processors.InputProcessor(), priority=10)
        self.world.add_processor(processors.PhysicsProcessor(600), priority=5)
        self.world.add_processor(processors.AnimationProcessor(), priority=5)
        self.world.add_processor(processors.PlayerProcessor(player, 100), priority=25)
        self.world.add_processor(processors.DragonSceneProcessor(player, tutorial, self.font), priority=20)
def creature(**args):
    """Creature components."""
    if "image" not in args:
        args["image"] = None

    components = [
        c.Render(args["image"]),
        c.TilePosition(args["x"], args["y"]),
        c.Movement(diagonal=args["diagonal"]),
        c.Blocker(),
        c.Health(args["health"]),
        c.Attack(args["attack"]),
    ]
    if "anim_idle" in args:
        components.append(
            c.Animation(idle=args["anim_idle"], ready=args["anim_ready"]))
    if "speed" in args:
        components.append(c.Initiative(args["speed"]))

    return components
Beispiel #4
0
    def init(self):
        scenebase.SceneBase.init(self)

        bg = create_entity(self.world, "IntroBG.png",
                           pygame.Rect(640, 360, 1280, 720))
        self.world.add_component(bg, components.Background())

        player = get_player(self.world)

        sword = create_entity(self.world, "sword.png",
                              pygame.Rect(300, 560, 80, 80))
        self.world.add_component(sword, components.Velocity())
        self.world.add_component(sword, components.Audio("light"))

        def dragon_hit():
            self.world.component_for_entity(dragon,
                                            components.Animation).frame = 1
            damage = notify(
                self.world, self.font, "999,999,999,999,999,999", self,
                text.TextScene(
                    "And thusly the skilled adventurer NaN took out yet another dragon. Dragon killing was no longer a dangerous quest but rather routine cleaning. With the dragon population dwindling NaN had time to help more people with their non life threatening problems.",
                    SceneTwo()))
            image = self.font.render("999,999,999,999,999,999", False,
                                     (255, 128, 0))
            self.world.component_for_entity(damage,
                                            components.Image).image = image
            self.world.component_for_entity(damage,
                                            components.Position).x = 960
            self.world.component_for_entity(damage,
                                            components.Position).y = 320
            self.world.component_for_entity(
                damage, components.Size).width = image.get_width()
            self.world.component_for_entity(
                damage, components.Size).height = image.get_height()
            pygame.mixer.Sound(
                os.path.join(components.get_base_path(), 'audio',
                             'dragon.ogg')).play()

        dragon = self.world.create_entity()
        self.world.add_component(dragon, components.Position(1000, 500))
        self.world.add_component(dragon, components.Velocity(0, 0))
        self.world.add_component(
            dragon, components.Animation("dragon.png", splitx=640, frame=0))
        self.world.add_component(dragon, components.Size(640, 640))
        self.world.add_component(
            dragon,
            components.Touch(sword,
                             rect=pygame.Rect(0, -400, -320, 0),
                             touch=dragon_hit))

        def move_up(entity):
            self.world.add_component(
                entity,
                components.ChangePosition((0, -40), 1, interpolation.Smooth(),
                                          True, move_down, entity))

        def move_down(entity):
            self.world.add_component(
                entity,
                components.ChangePosition((0, 40), 1, interpolation.Smooth(),
                                          True, move_up, entity))

        tutorial = self.world.create_entity()
        image = self.font.render("use arrow keys or WASD to move", False,
                                 (32, 255, 128))
        self.world.add_component(tutorial, components.Position(640, 680))
        self.world.add_component(tutorial, components.Image(image=image))
        self.world.add_component(
            tutorial, components.Size(image.get_width(), image.get_height()))
        move_up(tutorial)

        clouds = []
        for i in [1, 2, 3, 4, 5, 6]:
            cloud = create_entity(
                self.world, "cloud.png",
                pygame.Rect(random.randrange(100, 1180),
                            random.randrange(75, 200), 160, 80))
            self.world.add_component(cloud, components.Background())
            self.world.add_component(cloud, components.Hang())
            clouds.append(cloud)

        self.world.add_processor(processors.RenderProcessor())
        self.world.add_processor(processors.InputProcessor(), priority=10)
        self.world.add_processor(processors.PhysicsProcessor(600), priority=5)
        self.world.add_processor(processors.AnimationProcessor(), priority=5)
        self.world.add_processor(processors.PlayerProcessor(player, 100),
                                 priority=25)
        self.world.add_processor(processors.Scene1Processor(
            player, tutorial, self.font),
                                 priority=20)