Exemplo n.º 1
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)
Exemplo n.º 2
0
    def init(self):
        scenebase.SceneBase.init(self)

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

        player = get_player(self.world)

        floor = self.world.create_entity()
        self.world.add_component(floor, components.Position(640, 560))
        self.world.add_component(floor, components.Size(1280, 100))
        #self.world.add_component(floor, components.Image("box1.png"))

        def spider_tally():
            self.count += 1
            if self.count == 3:
                puzzle_complete()

        for i in [(200, 320), (280, 240), (420, 230), (440, 400), (590, 300), (680, 170), (760, 390), (830, 230)]:
            spider = create_entity(self.world, "Cobweb.png", pygame.Rect(i[0], i[1], 80, 80))
            self.world.add_component(spider, components.Hang())
            self.world.add_component(spider, components.Flammable())
            self.world.add_component(spider, components.Audio("light"))
            self.world.add_component(spider, components.Touch(floor, touch=spider_tally))

        box = create_entity(self.world, "box1.png", pygame.Rect(520, 560, 80, 80))
        self.world.add_component(box, components.Velocity())
        self.world.add_component(box, components.Flammable(True))
        self.world.add_component(box, components.Audio("light"))

        guy = create_entity(self.world, "NPC3.png", pygame.Rect(210, 560, 80, 80))
        self.world.add_component(guy, components.Velocity())
        self.world.add_component(guy, components.Flammable())
        self.world.add_component(guy, components.Audio("grunt"))

        def puzzle_complete():
            notify(self.world, self.small_font, "Now get out of my barn!", self, text.TextScene("Lack of real adventuring work not only wore on NaN, but it dulled him. His body atrophied as his mind numbed, and he realized he could no longer perform the same feats he'd grown accustomed to.", SceneFive()))

        cat = create_entity(self.world, "Cat.png", pygame.Rect(1190, 560, 80, 80))
        self.world.add_component(cat, components.Velocity(0,0))
        self.world.add_component(cat, components.Flammable())
        self.world.add_component(cat, components.Audio("light"))

        bubble = create_entity(self.world, "speech.png", pygame.Rect(1000, 100, 307, 173))
        self.world.add_component(bubble, components.Hang())
        image = self.world.component_for_entity(bubble, components.Image).image
        util.drawText(image, "My barn is dusty and full of cobwebs. NaN! Come here and do this for me.", (255, 255, 255), pygame.Rect(30, 20, 246, 134), self.small_font)

        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, 75), priority=25)
Exemplo n.º 3
0
    def init(self):
        scenebase.SceneBase.init(self)

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

        player = get_player(self.world)

        flower = create_entity(self.world, "Flower.png", pygame.Rect(240, 560, 80, 80))
        self.world.add_component(flower, components.Velocity())
        self.world.add_component(flower, components.Flammable())
        self.world.add_component(flower, components.Audio("light"))

        vase = create_entity(self.world, "Vase.png", pygame.Rect(510, 560, 80, 80))
        self.world.add_component(vase, components.Velocity())
        self.world.add_component(vase, components.Flammable())
        self.world.add_component(vase, components.Audio("light"))

        guy = create_entity(self.world, "NPC2.png", pygame.Rect(340, 560, 80, 80))
        self.world.add_component(guy, components.Velocity())
        self.world.add_component(guy, components.Flammable())
        self.world.add_component(guy, components.Audio("grunt"))

        guy2 = create_entity(self.world, "NPC1.png", pygame.Rect(950, 560, 80, 80))
        self.world.add_component(guy2, components.Velocity())
        self.world.add_component(guy2, components.Flammable())
        self.world.add_component(guy2, components.Audio("grunt"))
        self.world.component_for_entity(guy2, components.Image).image = pygame.transform.flip(self.world.component_for_entity(guy2, components.Image).image, False, False)

        def puzzle_complete():
            notify(self.world, self.small_font, "MY CAT!!! GET THE HECK OUT OF HERE!!!!", self, text.TextScene("NaN was so overjoyed with his power he decided to slay a dragon. Not just any dragon. The hardest dragon known to man.", SceneTen()))
            
        cat = create_entity(self.world, "Cat.png", pygame.Rect(1100, 170, 80, 80))
        self.world.add_component(cat, components.Hang())
        self.world.add_component(cat, components.Flammable())
        self.world.add_component(cat, components.Touch(guy, touch=puzzle_complete))
        self.world.add_component(cat, components.Audio("light"))

        bubble = create_entity(self.world, "speech.png", pygame.Rect(200, 100, 307, 173))
        self.world.add_component(bubble, components.Hang())
        image = self.world.component_for_entity(bubble, components.Image).image
        util.drawText(image, "Hey NaN, yeah you! Get my cat out of that tree! Note: giv her cat to continue, all other scenes are like this now!", (255, 255, 255), pygame.Rect(30, 20, 246, 134), self.small_font)

        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.FireballPlayerProcessor(player, 95), priority=25)
Exemplo n.º 4
0
    def init(self):
        scenebase.SceneBase.init(self)

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

        player = get_player(self.world)

        flower = create_entity(self.world, "Flower.png", pygame.Rect(240, 560, 80, 80))
        self.world.add_component(flower, components.Velocity())
        self.world.add_component(flower, components.Flammable())
        self.world.add_component(flower, components.Audio("light"))

        vase = create_entity(self.world, "Vase.png", pygame.Rect(510, 560, 80, 80))
        self.world.add_component(vase, components.Velocity())
        self.world.add_component(vase, components.Flammable())
        self.world.add_component(vase, components.Audio("light"))

        guy = create_entity(self.world, "NPC2.png", pygame.Rect(340, 560, 80, 80))
        self.world.add_component(guy, components.Velocity())
        self.world.add_component(guy, components.Flammable())
        self.world.add_component(guy, components.Audio("grunt"))

        guy2 = create_entity(self.world, "NPC1.png", pygame.Rect(950, 560, 80, 80))
        self.world.add_component(guy2, components.Velocity())
        self.world.add_component(guy2, components.Flammable())
        self.world.add_component(guy2, components.Audio("grunt"))
        self.world.component_for_entity(guy2, components.Image).image = pygame.transform.flip(self.world.component_for_entity(guy2, components.Image).image, False, False)

        def puzzle_complete():
            notify(self.world, self.small_font, "You better not have dropped her or anything.", self, text.TextScene("With adventuring work in low demand and the cost of living constantly increasing, NaN was forced to stoop to more and more menial work.", SceneThree()))
            
        cat = create_entity(self.world, "Cat.png", pygame.Rect(1100, 170, 80, 80))
        self.world.add_component(cat, components.Hang())
        self.world.add_component(cat, components.Flammable())
        self.world.add_component(cat, components.Touch(guy, touch=puzzle_complete))
        self.world.add_component(cat, components.Audio("light"))

        bubble = create_entity(self.world, "speech.png", pygame.Rect(200, 100, 307, 173))
        self.world.add_component(bubble, components.Hang())
        image = self.world.component_for_entity(bubble, components.Image).image
        util.drawText(image, "Oh no! My wonderful cat has found herself stuck in a tree! Won't someone please help me?", (255, 255, 255), pygame.Rect(30, 20, 246, 134), self.small_font)

        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, 95), priority=25)
Exemplo n.º 5
0
 def open_container(container, item_string):
     if container is not None:
         p = self.world.component_for_entity(container,
                                             components.Position)
         self.world.delete_entity(container)
         item = create_entity(self.world, item_string,
                              pygame.Rect(p.x, p.y, 80, 80))
         self.world.add_component(item, components.Audio("light"))
         self.world.add_component(item, components.Flammable())
         if container is chest:
             self.world.add_component(
                 item,
                 components.Touch(guy,
                                  rect=pygame.Rect(0, 0, 0, 0),
                                  touch=puzzle_complete))
         if self.world.component_for_entity(
                 player, components.Player).holding == container:
             self.world.component_for_entity(
                 player, components.Player).holding = item
             i = self.world.component_for_entity(item, components.Image)
             s = self.world.component_for_entity(item, components.Size)
             i.image = pygame.transform.rotate(i.image, 90)
             tmp = s.width
             s.width = s.height
             s.height = tmp
         else:
             v = self.world.component_for_entity(
                 container, components.Velocity)
             self.world.add_component(item,
                                      components.Velocity(v.x, v.y))
         self.world.component_for_entity(item,
                                         components.Audio).sound.play()
Exemplo n.º 6
0
 def create_player(self, position, max_hp, max_x_vel, max_y_vel, attack_list):
     
     """Create player.
     
     :param position: position where player is created
     :type position: 2d list
     """
     #Create players hp gui
     temp = pygame.image.load(os.path.join('data', 'hp.png')).convert_alpha()
     hp = components.Health(max_hp, 8, temp)
     c_hp = (hp, hp.current_image)
     hp_ID = self.create_entity(c_hp)
     #Players hitbox, it is 50 pixel width and 96 pixel height
     coll = components.Collider(position[0], position[1], 50, 96)
     vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
     #Create players animations
     temp = pygame.image.load(os.path.join('data', 'char.png')).convert_alpha()
     anim_list = [4, 10, 8, 8, 2, 2]
     anim_time_list = [240, 50, 44, 60, 30, 44]
     anim = components.Appearance(temp, 128, 128, anim_list, anim_time_list)
     anim.rect.center = coll.center
     direction = components.Direction([1, 0])
     player = components.Player(0, hp_ID, )
     c = (direction, coll, vel, anim, player)
     self.player = self.create_entity(c)
     #Now create the players orb
     #It is created afterward, so orb will be
     #displayed over players sprite
     temp = pygame.image.load(os.path.join('data', 'orb.png'))
     orb_sprite = components.Appearance(temp.convert_alpha())
     c_orb = (orb_sprite,)
     orb_ID = self.create_entity(c_orb)
     #Set orb ID
     self.players[self.player].orb_ID = orb_ID
     self.add_component_to_entity(self.player, attack_list)
Exemplo n.º 7
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
Exemplo n.º 8
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)
Exemplo n.º 9
0
    def init(self):
        scenebase.SceneBase.init(self)

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

        player = get_player(self.world)

        for i in [("WoodPlatform3.png", 520, 390, 720, 40),
                  ("WoodPlatformHalf.png", 1000, 500, 120, 40),
                  ("WoodPlatformThird.png", 920, 440, 80, 40),
                  ("WoodPlatformThird.png", 1080, 560, 80, 40)]:
            platform = create_entity(self.world, i[0],
                                     pygame.Rect(i[1], i[2], i[3], i[4]))
            self.world.add_component(platform, components.Platform())
            self.world.add_component(platform, components.Background())

        for i in [(520, 330), (760, 330), (280, 560), (520, 560)]:
            bed = create_entity(self.world, "Bed.png",
                                pygame.Rect(i[0], i[1], 160, 80))
            self.world.add_component(bed, components.Velocity())
            self.world.add_component(bed, components.Flammable())
            self.world.add_component(bed, components.Audio("heavy"))

        guy = create_entity(self.world, "NPC2.png",
                            pygame.Rect(1000, 460, 80, 80))
        self.world.add_component(guy, components.Velocity())
        self.world.add_component(guy, components.Flammable())
        self.world.add_component(guy, components.Audio("grunt"))

        table = create_entity(self.world, "TableBig.png",
                              pygame.Rect(280, 330, 160, 80))
        self.world.add_component(table, components.Velocity())
        self.world.add_component(table, components.Flammable())
        self.world.add_component(table, components.Audio("heavy"))

        def puzzle_complete():
            if self.world.component_for_entity(mug, components.Flammable).lit:
                p = self.world.component_for_entity(player, components.Player)
                if p.holding is mug:
                    p.holding = None
                self.world.delete_entity(mug)
                #self.switch_to_scene(text.TextScene("NaN was unsure how much longer he could go on like this. He still wanted to help people, but was filled with thoughts of inadequacy and self doubt.", SceneSeven()))
                notify(
                    self.world, self.small_font, "Way to take your time.",
                    self,
                    text.TextScene(
                        "Eventually he'd had enough. There was no way he could go back to adventuring, but he similarly could not stop here. He began a new journey, leaving his town without a single goodbye. Thanks for playing.",
                        title.TitleScene()))
            else:
                complaint = create_entity(self.world, "speech.png",
                                          pygame.Rect(640, 500, 307, 173))
                self.world.add_component(
                    complaint,
                    components.ChangeAlpha(0, 4, interpolation.Smooth()))
                util.drawText(
                    self.world.component_for_entity(complaint,
                                                    components.Image).image,
                    "It's cold! Heat it up for me.", (255, 255, 255),
                    pygame.Rect(30, 20, 246, 134), self.small_font)

        mug = create_entity(self.world, "Mug.png",
                            pygame.Rect(250, 160, 80, 80))
        self.world.add_component(mug, components.Hang())
        self.world.add_component(mug, components.Flammable())
        self.world.add_component(
            mug, components.Touch(guy, True, touch=puzzle_complete))
        self.world.add_component(mug, components.Audio("light"))

        lamp = create_entity(self.world, "Chandelier.png",
                             pygame.Rect(520, 160, 80, 80))
        self.world.add_component(lamp, components.Flammable(True))
        self.world.add_component(lamp, components.Hang())

        lamp2 = create_entity(self.world, "Chandelier.png",
                              pygame.Rect(760, 160, 80, 80))
        self.world.add_component(lamp2, components.Flammable(True))
        self.world.add_component(lamp2, components.Hang())

        fireplace = create_entity(self.world, "Fireplace.png",
                                  pygame.Rect(760, 520, 160, 160))
        self.world.add_component(fireplace, components.Flammable(True))
        self.world.add_component(fireplace, components.Velocity())
        self.world.add_component(fireplace, components.Background())

        # shelf
        create_entity(self.world, "shelf.png", pygame.Rect(250, 210, 80, 20))

        bubble = create_entity(self.world, "speech.png",
                               pygame.Rect(1000, 100, 307, 173))
        self.world.add_component(bubble, components.Hang())
        image = self.world.component_for_entity(bubble, components.Image).image
        util.drawText(
            image,
            "About time you got here, NaN. I need my coffee stat! It's probably been sitting there for hours!",
            (255, 255, 255), pygame.Rect(30, 20, 246, 134), self.small_font)

        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, 40),
                                 priority=25)
Exemplo n.º 10
0
    def init(self):
        scenebase.SceneBase.init(self)

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

        player = get_player(self.world)

        for i in [("WoodPlatform3.png", 760, 390, 720, 40),
                  ("WoodPlatformHalf.png", 280, 500, 120, 40),
                  ("WoodPlatformThird.png", 360, 440, 80, 40),
                  ("WoodPlatformThird.png", 200, 560, 80, 40)]:
            platform = create_entity(self.world, i[0],
                                     pygame.Rect(i[1], i[2], i[3], i[4]))
            self.world.add_component(platform, components.Platform())
            self.world.add_component(platform, components.Background())

        anvil = create_entity(self.world, "Anvil.png",
                              pygame.Rect(710, 560, 80, 80))
        self.world.add_component(anvil, components.Velocity())
        self.world.add_component(anvil, components.Audio("heavy"))

        bed = create_entity(self.world, "Bed.png",
                            pygame.Rect(500, 330, 160, 80))
        self.world.add_component(bed, components.Velocity())
        self.world.add_component(bed, components.Flammable())
        self.world.add_component(bed, components.Audio("heavy"))

        bookshelf = create_entity(self.world, "Bookshelf.png",
                                  pygame.Rect(640, 290, 80, 160))
        self.world.add_component(bookshelf, components.Velocity())
        self.world.add_component(bookshelf, components.Flammable())
        self.world.add_component(bookshelf, components.Audio("heavy"))

        guy = create_entity(self.world, "NPC3.png",
                            pygame.Rect(280, 560, 80, 80))
        self.world.add_component(guy, components.Velocity())
        self.world.add_component(guy, components.Flammable())
        self.world.add_component(guy, components.Audio("grunt"))

        left_chair = create_entity(self.world, "Chair.png",
                                   pygame.Rect(480, 560, 80, 80))
        self.world.add_component(left_chair, components.Velocity())
        self.world.add_component(left_chair, components.Flammable())
        self.world.add_component(left_chair, components.Audio("light"))

        top_chair = create_entity(self.world, "Chair.png",
                                  pygame.Rect(770, 330, 80, 80))
        self.world.add_component(top_chair, components.Velocity())
        self.world.add_component(top_chair, components.Flammable())
        self.world.add_component(top_chair, components.Audio("light"))

        table = create_entity(self.world, "Table.png",
                              pygame.Rect(570, 560, 80, 80))
        self.world.add_component(table, components.Velocity())
        self.world.add_component(table, components.Flammable())
        self.world.add_component(table, components.Audio("heavy"))

        def puzzle_complete():
            notify(
                self.world, self.small_font,
                "You got a crack in it. Thanks for nothing.", self,
                text.TextScene(
                    "NaN was depressed. For the majority of his life he was the strongest, fastest, all around best adventurer in the whole realm. But it was his own effectiveness led to his now pitiful existence.",
                    SceneSix()))

        def open_container(container, item_string):
            if container is not None:
                p = self.world.component_for_entity(container,
                                                    components.Position)
                self.world.delete_entity(container)
                item = create_entity(self.world, item_string,
                                     pygame.Rect(p.x, p.y, 80, 80))
                self.world.add_component(item, components.Audio("light"))
                self.world.add_component(item, components.Flammable())
                if container is chest:
                    self.world.add_component(
                        item,
                        components.Touch(guy,
                                         rect=pygame.Rect(0, 0, 0, 0),
                                         touch=puzzle_complete))
                if self.world.component_for_entity(
                        player, components.Player).holding == container:
                    self.world.component_for_entity(
                        player, components.Player).holding = item
                    i = self.world.component_for_entity(item, components.Image)
                    s = self.world.component_for_entity(item, components.Size)
                    i.image = pygame.transform.rotate(i.image, 90)
                    tmp = s.width
                    s.width = s.height
                    s.height = tmp
                else:
                    v = self.world.component_for_entity(
                        container, components.Velocity)
                    self.world.add_component(item,
                                             components.Velocity(v.x, v.y))
                self.world.component_for_entity(item,
                                                components.Audio).sound.play()

        chest = create_entity(self.world, "chest.png",
                              pygame.Rect(1070, 330, 80, 80))
        self.world.add_component(chest, components.Velocity())
        self.world.add_component(chest, components.Flammable())
        self.world.add_component(
            chest,
            components.Touch(anvil, False, pygame.Rect(0, 0, 0, 0),
                             open_container, chest, "Vase.png"))
        self.world.add_component(chest, components.Audio("chest"))

        box = create_entity(self.world, "box1.png",
                            pygame.Rect(860, 330, 80, 80))
        self.world.add_component(box, components.Velocity())
        self.world.add_component(box, components.Flammable())
        self.world.add_component(
            box,
            components.Touch(anvil, False, pygame.Rect(0, 0, 0, 0),
                             open_container, box, "Chair.png"))
        self.world.add_component(box, components.Audio("heavy"))

        box2 = create_entity(self.world, "box2.png",
                             pygame.Rect(950, 330, 80, 80))
        self.world.add_component(box2, components.Velocity())
        self.world.add_component(box2, components.Flammable())
        self.world.add_component(
            box2,
            components.Touch(anvil, False, pygame.Rect(0, 0, 0, 0),
                             open_container, box2, "PileOfBooks.png"))
        self.world.add_component(box2, components.Audio("heavy"))

        lamp = create_entity(self.world, "Chandelier.png",
                             pygame.Rect(520, 170, 80, 80))
        self.world.add_component(lamp, components.Flammable(True))
        self.world.add_component(lamp, components.Hang())

        lamp2 = create_entity(self.world, "Chandelier.png",
                              pygame.Rect(1000, 170, 80, 80))
        self.world.add_component(lamp2, components.Flammable(True))
        self.world.add_component(lamp2, components.Hang())

        forge = create_entity(self.world, "Forge.png",
                              pygame.Rect(1040, 520, 80, 160))
        self.world.add_component(anvil, components.Velocity())
        self.world.add_component(forge, components.Flammable(True))
        self.world.add_component(anvil, components.Audio("heavy"))

        workbench = create_entity(self.world, "Workbench.png",
                                  pygame.Rect(870, 560, 160, 80))
        self.world.add_component(workbench, components.Velocity())
        self.world.add_component(workbench, components.Flammable())
        self.world.add_component(workbench, components.Audio("heavy"))

        bubble = create_entity(self.world, "speech.png",
                               pygame.Rect(200, 100, 307, 173))
        self.world.add_component(bubble, components.Hang())
        util.drawText(
            self.world.component_for_entity(bubble, components.Image).image,
            "Shoot, now where did that vase go? NaN, you touched it last. You need to find it for me!",
            (255, 255, 255), pygame.Rect(30, 20, 246, 134), self.small_font)

        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, 60),
                                 priority=25)
Exemplo n.º 11
0
    def init(self):
        scenebase.SceneBase.init(self)

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

        player = get_player(self.world)

        floor2 = create_entity(self.world, "WoodPlatform2.png",
                               pygame.Rect(400, 390, 480, 40))
        self.world.add_component(floor2, components.Platform())
        self.world.add_component(floor2, components.Background())

        stair = create_entity(self.world, "WoodPlatform1.png",
                              pygame.Rect(760, 500, 240, 40))
        self.world.add_component(stair, components.Platform())
        self.world.add_component(stair, components.Background())

        bed = create_entity(self.world, "Bed.png",
                            pygame.Rect(260, 330, 160, 80))
        self.world.add_component(bed, components.Velocity())
        self.world.add_component(bed, components.Flammable())
        self.world.add_component(bed, components.Audio("heavy"))

        bookshelf = create_entity(self.world, "Bookshelf.png",
                                  pygame.Rect(420, 290, 80, 160))
        self.world.add_component(bookshelf, components.Velocity())
        self.world.add_component(bookshelf, components.Flammable())
        self.world.add_component(bookshelf, components.Audio("heavy"))

        chest = create_entity(self.world, "chest.png",
                              pygame.Rect(540, 330, 80, 80))
        self.world.add_component(chest, components.Velocity())
        self.world.add_component(chest, components.Flammable())
        self.world.add_component(chest, components.Audio("chest"))

        guy = create_entity(self.world, "NPC1.png",
                            pygame.Rect(280, 560, 80, 80))
        self.world.add_component(guy, components.Velocity())
        self.world.add_component(guy, components.Flammable())
        self.world.add_component(guy, components.Audio("grunt"))

        left_chair = create_entity(self.world, "Chair.png",
                                   pygame.Rect(430, 560, 80, 80))
        self.world.add_component(left_chair, components.Velocity())
        self.world.add_component(left_chair, components.Flammable())
        self.world.add_component(left_chair, components.Audio("light"))

        right_chair = create_entity(self.world, "Chair.png",
                                    pygame.Rect(610, 560, 80, 80))
        self.world.add_component(right_chair, components.Velocity())
        self.world.add_component(right_chair, components.Flammable())
        self.world.add_component(right_chair, components.Audio("light"))
        self.world.component_for_entity(
            right_chair, components.Image).image = pygame.transform.flip(
                self.world.component_for_entity(right_chair,
                                                components.Image).image, False,
                False)

        table = create_entity(self.world, "Table.png",
                              pygame.Rect(520, 560, 80, 80))
        self.world.add_component(table, components.Velocity())
        self.world.add_component(table, components.Flammable())
        self.world.add_component(table, components.Audio("heavy"))

        def puzzle_complete():
            p = self.world.component_for_entity(player, components.Player)
            if p.holding is books:
                p.holding = None
            self.world.delete_entity(books)
            notify(
                self.world, self.small_font,
                "Wow, you got the books dirty. I can't use these anymore.",
                self,
                text.TextScene(
                    "These thankless jobs took their toll on NaN. He put on a friendly face, but inside he was growing weary...",
                    SceneFour()))

        books = create_entity(self.world, "PileOfBooks.png",
                              pygame.Rect(1000, 560, 80, 80))
        self.world.add_component(books, components.Velocity())
        self.world.add_component(books, components.Flammable())
        self.world.add_component(
            books,
            components.Touch(bookshelf,
                             rect=pygame.Rect(5, 0, -10, 0),
                             touch=puzzle_complete))
        self.world.add_component(books, components.Audio("light"))

        lamp = create_entity(self.world, "Chandelier.png",
                             pygame.Rect(760, 170, 80, 80))
        self.world.add_component(lamp, components.Flammable(True))
        self.world.add_component(lamp, components.Hang())
        self.world.add_component(lamp, components.Audio("glass.ogg"))

        bubble = create_entity(self.world, "speech.png",
                               pygame.Rect(1000, 100, 307, 173))
        self.world.add_component(bubble, components.Hang())
        image = self.world.component_for_entity(bubble, components.Image).image
        util.drawText(
            image,
            "Ah! NaN, just in time! I need your help putting my books away. They are very important!",
            (255, 255, 255), pygame.Rect(30, 20, 246, 134), self.small_font)

        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, 85),
                                 priority=25)
Exemplo n.º 12
0
    def process(self, filtered_events, pressed_keys, dt, screen):
        v = self.world.component_for_entity(self.player, components.Velocity)
        p = self.world.component_for_entity(self.player, components.Player)
        s = self.world.component_for_entity(self.player, components.Size)
        pos = self.world.component_for_entity(self.player, components.Position)
        v.x = 0
        if pressed_keys[pygame.K_LEFT] or pressed_keys[pygame.K_a]:
            v.x -= 3 * self.vitality
            self.player_is_facing_right = False
            self.player_is_facing_left = True
        if pressed_keys[pygame.K_RIGHT] or pressed_keys[pygame.K_d]:
            v.x += 3 * self.vitality
            self.player_is_facing_right = True

        p.holdingfireball = False

        if (p.facing_right and v.x < 0) or (not p.facing_right and v.x > 0):
            p.facing_right = not p.facing_right
            self.player_is_facing_right = False
            p.image.image = pygame.transform.flip(p.image.image, True, False)
            p.animation.image = pygame.transform.flip(p.animation.image, True,
                                                      False)
            p.carry_image.image = pygame.transform.flip(
                p.carry_image.image, True, False)
            p.carry_animation.image = pygame.transform.flip(
                p.carry_animation.image, True, False)
        if v.x == 0 and self.world.has_component(self.player,
                                                 components.Animation):
            self.world.remove_component(self.player, components.Animation)
            if p.holding:
                self.world.add_component(self.player, p.carry_image)
            else:
                self.world.add_component(self.player, p.image)
        elif v.x != 0 and self.world.has_component(self.player,
                                                   components.Image):
            self.world.remove_component(self.player, components.Image)
            if p.holding:
                self.world.add_component(self.player, p.carry_animation)
            else:
                self.world.add_component(self.player, p.animation)
        for event in filtered_events:
            if event.type == pygame.KEYDOWN:
                if (event.key == pygame.K_UP or event.key == pygame.K_w
                        or event.key == pygame.K_SPACE) and v.y == 0:
                    v.y -= 6 * self.vitality
                    p.jump.sound.play()
                elif event.key == pygame.K_f:
                    if self.MessageShown == False:
                        game.FireballMessage(self.world)
                        self.MessageShown = True

                    global fireball
                    self.fireball = game.CreateFireball(
                        self.world, pos.x, pos.y)
                    self.world.add_component(self.fireball,
                                             components.Position(pos.x, pos.y))
                    self.world.add_component(self.fireball,
                                             components.Velocity())
                    self.world.add_component(self.fireball,
                                             components.Flammable(True))
                    v = self.world.component_for_entity(
                        self.fireball, components.Velocity)
                    if self.player_is_facing_right == True:
                        while not v.x > 1300:
                            v.x += 3

                    elif self.player_is_facing_right == False:
                        while not v.x == 0:
                            v.x -= 3

                elif event.key == pygame.K_e:
                    if p.holding:
                        if self.world.has_component(self.player,
                                                    components.Image):
                            self.world.remove_component(
                                self.player, components.Image)
                            self.world.add_component(self.player, p.image)
                        elif self.world.has_component(self.player,
                                                      components.Animation):
                            self.world.remove_component(
                                self.player, components.Animation)
                            self.world.add_component(self.player, p.animation)
                        i = self.world.component_for_entity(
                            p.holding, components.Image)
                        s = self.world.component_for_entity(
                            p.holding, components.Size)
                        i.image = pygame.transform.rotate(i.image, -90)
                        tmp = s.width
                        s.width = s.height
                        s.height = tmp
                        self.world.add_component(p.holding,
                                                 components.Velocity(0, 0))
                        p.holding = None

                    else:
                        rect = pygame.Rect(
                            pos.x, pos.y - s.height * s.scale / 2,
                            s.width * s.scale * (1 if p.facing_right else -1),
                            s.height * s.scale)
                        rect.normalize()
                        for ent, (p2, i, s, v) in self.world.get_components(
                                components.Position, components.Image,
                                components.Size, components.Velocity):
                            if self.world.has_component(
                                    ent, components.Player):
                                continue
                            if rect.collidepoint(p2.x, p2.y):
                                p.holding = ent
                                if self.world.has_component(
                                        self.player, components.Image):
                                    self.world.remove_component(
                                        self.player, components.Image)
                                    self.world.add_component(
                                        self.player, p.carry_image)
                                elif self.world.has_component(
                                        self.player, components.Animation):
                                    self.world.remove_component(
                                        self.player, components.Animation)
                                    self.world.add_component(
                                        self.player, p.carry_animation)
                                if self.world.has_component(
                                        ent, components.RotationalVelocity):
                                    r = self.world.component_for_entity(
                                        ent, components.RotationalVelocity)
                                    i.image = r.image
                                    s.width = r.width
                                    s.height = r.height
                                    self.world.remove_component(
                                        ent, components.RotationalVelocity)
                                i.image = pygame.transform.rotate(i.image, 90)
                                tmp = s.width
                                s.width = s.height
                                s.height = tmp
                                self.world.remove_component(
                                    ent, components.Velocity)
                                if self.world.has_component(
                                        ent, components.Audio):
                                    self.world.component_for_entity(
                                        ent, components.Audio).sound.play()
                                break
            elif event.type == pygame.MOUSEBUTTONDOWN and p.holding:
                if self.world.has_component(self.player, components.Image):
                    self.world.remove_component(self.player, components.Image)
                    self.world.add_component(self.player, p.image)
                elif self.world.has_component(self.player,
                                              components.Animation):
                    self.world.remove_component(self.player,
                                                components.Animation)
                    self.world.add_component(self.player, p.animation)
                i = self.world.component_for_entity(p.holding,
                                                    components.Image)
                s = self.world.component_for_entity(p.holding, components.Size)
                i.image = pygame.transform.rotate(i.image, -90)
                tmp = s.width
                s.width = s.height
                s.height = tmp
                x = event.pos[1] * 1280 / pygame.display.get_surface(
                ).get_width()
                y = event.pos[0] * 720 / pygame.display.get_surface(
                ).get_height()
                angle = math.atan2(x - pos.y, y - pos.x) % (2 * math.pi)
                self.world.add_component(
                    p.holding,
                    components.Velocity(
                        math.cos(angle) * 16 * self.vitality,
                        math.sin(angle) * 12 * self.vitality))
                self.world.add_component(p.holding,
                                         components.RotationalVelocity(320))
                p.holding = None
                p.throw.sound.play()
            elif event.type == pygame.MOUSEBUTTONDOWN and p.holdingfireball == True:

                v = self.world.component_for_entity(self.fireball,
                                                    component.Velocity)

                while not v.x == 800:
                    v.x = v.x + 1
                    v = self.world.component_for_entity(
                        self.fireball, component.Velocity)

        if p.holding:
            p3 = self.world.component_for_entity(p.holding,
                                                 components.Position)
            p3.x = pos.x
            p3.y = pos.y - s.height + 10

        def BossBattleFireballLoop():
            while True:
                if fireball:
                    return fireball
Exemplo n.º 13
0
    def process(self, filtered_events, pressed_keys, dt, screen):
        for ent, (p, s,
                  v) in self.world.get_components(components.Position,
                                                  components.Size,
                                                  components.Velocity):
            if v.y == 0 and self.world.has_component(
                    ent, components.RotationalVelocity):
                r = self.world.component_for_entity(
                    ent, components.RotationalVelocity)
                i = self.world.component_for_entity(ent, components.Image)
                i.image = r.image
                s.width = r.width
                s.height = r.height
                self.world.remove_component(ent, components.RotationalVelocity)

            v.y = min(v.y + 9.81 * 100 * dt, 53 * 100)  # terminal velocity
            if not self.world.has_component(ent, components.Player):
                v.x *= .98

            p.x = max(min(p.x + v.x * dt, 1280), 0)
            if self.ground != -1:
                p.y = min(p.y + v.y * dt, self.ground - s.height * s.scale / 2)

                if p.y >= self.ground - s.height * s.scale / 2 and v.y > 0:
                    v.y = 0

            else:
                p.y -= v.y * dt
        #Touch Physics
        for ent, (t, p,
                  s) in self.world.get_components(components.Touch,
                                                  components.Position,
                                                  components.Size):
            rect = pygame.Rect(p.x + t.rect.x, p.y + s.height / 2 + t.rect.y,
                               s.width + t.rect.width,
                               s.height + t.rect.height)
            tp = self.world.component_for_entity(t.target, components.Position)
            ts = self.world.component_for_entity(t.target, components.Size)
            if rect.colliderect(pygame.Rect(tp.x, tp.y, ts.width, ts.height)):
                if not t.active:
                    t.touch(*t.args)
                    if t.multi:
                        t.active = True
                    else:
                        self.world.remove_component(ent, components.Touch)
            else:
                t.active = False
        #Hanging Object Physics
        for hangEnt, (h, p,
                      s) in self.world.get_components(components.Hang,
                                                      components.Position,
                                                      components.Size):
            rect = pygame.Rect(p.x, p.y, s.width, s.height)
            for ent, (v, tp,
                      ts) in self.world.get_components(components.Velocity,
                                                       components.Position,
                                                       components.Size):
                if not self.world.has_component(ent, components.Player):
                    if rect.colliderect(
                            pygame.Rect(tp.x, tp.y, ts.width, ts.height)):
                        if self.world.has_component(hangEnt, components.Hang):
                            self.world.remove_component(
                                hangEnt, components.Hang)
                        self.world.add_component(hangEnt,
                                                 components.Velocity(0, 0))
                        break
        #Platform physics
        for platEnt, (tl, box,
                      pf) in self.world.get_components(components.Position,
                                                       components.Size,
                                                       components.Platform):
            for ent, (p, s,
                      v) in self.world.get_components(components.Position,
                                                      components.Size,
                                                      components.Velocity):
                if (tl.x - box.width / 2) < p.x < (tl.x + box.width / 2) and (
                        tl.y - box.height) < (p.y + s.height / 2) - 20 < tl.y:
                    if v.y > 0:
                        p.y = min(((tl.y - box.height) - s.height / 2) + 20,
                                  p.y)
                    v.y = min(0, v.y)
        #Flamable stuff
        for flamEnt, (f, p,
                      s) in self.world.get_components(components.Flammable,
                                                      components.Position,
                                                      components.Size):
            if f.lit:
                if not self.world.has_component(flamEnt, components.Delay):
                    flame = self.world.create_entity()
                    self.world.add_component(
                        flame,
                        components.Position(
                            p.x - s.width / 2 + random.random() * s.width,
                            p.y - s.height / 2 + random.random() * s.height))
                    self.world.add_component(flame, components.Size(60, 60))
                    size = int(random.random() * 20)
                    self.world.add_component(
                        flame,
                        components.Rect((255, random.random() * 255, 0),
                                        pygame.Rect(0, 0, size, size)))
                    self.world.add_component(
                        flame,
                        components.ChangePosition(
                            (-25 + random.random() * 50,
                             -50 - random.random() * 100), 1,
                            interpolation.PowIn(2), True, self.remove_entity,
                            flame))
                    self.world.add_component(flamEnt, components.Delay(.03))

                for ent, (f2, tp, ts) in self.world.get_components(
                        components.Flammable, components.Position,
                        components.Size):
                    if not f2.lit:
                        rect = pygame.Rect(p.x, p.y, s.width, s.height)
                        if rect.colliderect(
                                pygame.Rect(tp.x, tp.y, ts.width, ts.height)):
                            f2.lit = True
Exemplo n.º 14
0
    def init(self):
        scenebase.SceneBase.init(self)

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

        player = get_player(self.world)

        floor2 = create_entity(self.world, "WoodPlatform2.png", pygame.Rect(400, 390, 480, 40))
        self.world.add_component(floor2, components.Platform())
        self.world.add_component(floor2, components.Background())

        stair = create_entity(self.world, "WoodPlatform1.png", pygame.Rect(760, 500, 240, 40))
        self.world.add_component(stair, components.Platform())
        self.world.add_component(stair, components.Background())

        bed = create_entity(self.world, "Bed.png", pygame.Rect(260, 330, 160, 80))
        self.world.add_component(bed, components.Velocity())
        self.world.add_component(bed, components.Flammable())
        
        self.world.add_component(bed, components.Audio("heavy"))

        bookshelf = create_entity(self.world, "Bookshelf.png", pygame.Rect(420, 290, 80, 160))
        self.world.add_component(bookshelf, components.Velocity())
        self.world.add_component(bookshelf, components.Flammable())
        self.world.add_component(bookshelf, components.Audio("heavy"))

        chest = create_entity(self.world, "chest.png", pygame.Rect(540, 330, 80, 80))
        self.world.add_component(chest, components.Velocity())
        self.world.add_component(chest, components.Flammable())
        self.world.add_component(chest, components.Audio("chest"))

        guy = create_entity(self.world, "NPC1.png", pygame.Rect(280, 560, 80, 80))
        self.world.add_component(guy, components.Velocity())
        self.world.add_component(guy, components.Flammable())
        self.world.add_component(guy, components.Audio("grunt"))

        left_chair = create_entity(self.world, "Chair.png", pygame.Rect(430, 560, 80, 80))
        self.world.add_component(left_chair, components.Velocity())
        self.world.add_component(left_chair, components.Flammable())
        self.world.add_component(left_chair, components.Audio("light"))

        right_chair = create_entity(self.world, "Chair.png", pygame.Rect(610, 560, 80, 80))
        self.world.add_component(right_chair, components.Velocity())
        self.world.add_component(right_chair, components.Flammable())
        self.world.add_component(right_chair, components.Audio("light"))
        self.world.component_for_entity(right_chair, components.Image).image = pygame.transform.flip(self.world.component_for_entity(right_chair, components.Image).image, False, False)

        table = create_entity(self.world, "Table.png", pygame.Rect(520, 560, 80, 80))
        self.world.add_component(table, components.Velocity())
        self.world.add_component(table, components.Flammable())
        self.world.add_component(table, components.Audio("heavy"))
        puzzledone = False
        def puzzle_complete():
            puzzledone = True
            p = self.world.component_for_entity(player, components.Player)
            if p.holding is bed:
                p.holding = None
            self.world.delete_entity(books)
            notify(self.world, self.small_font, "OH MY GOD. MY HOUSE. GET THE HECK OUT OF HERE.", self, text.TextScene("These thankless jobs took their toll on NaN. He put on a friendly face, but inside he was growing weary...", SceneFour()))

        books = create_entity(self.world, "PileOfBooks.png", pygame.Rect(1000, 560, 80, 80))
        self.world.add_component(books, components.Velocity())
        self.world.add_component(books, components.Flammable())
        self.world.add_component(books, components.Touch(bookshelf, rect=pygame.Rect(5, 0, -10, 0)))
        self.world.add_component(books, components.Audio("light"))

        lamp = create_entity(self.world, "Chandelier.png", pygame.Rect(760, 170, 80, 80))
        self.world.add_component(lamp, components.Flammable(True))
        self.world.add_component(lamp, components.Hang())
        self.world.add_component(lamp, components.Audio("glass.ogg"))

        bubble = create_entity(self.world, "speech.png", pygame.Rect(1000, 100, 307, 173))
        self.world.add_component(bubble, components.Hang())
        image = self.world.component_for_entity(bubble, components.Image).image
        util.drawText(image, "Where the heck is NaN? My other books fell off! Note: you must scene select next scene", (255, 255, 255), pygame.Rect(30, 20, 246, 134), self.small_font)

        
        
        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("press f to launch a fireball", 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)
        
        
        
        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.FireballPlayerProcessor(player, 85), priority=25)
Exemplo n.º 15
0
 def create_enemy(self, position, max_hp, max_x_vel, max_y_vel, attack_list, ai_ID, tags):
     """Create an enemy.
     
     :param position: position where enemy is created
     :type position: 2d list
     """
     if ai_ID == "green_1":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 50, 96, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_green_1.png')).convert_alpha()
         anim_list = [2, 10, 4, 8, 2, 1]
         anim_time_list = [240, 60, 44, 120, 10, 10]
         anim = components.Appearance(temp, 128, 128, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         
         enemy_AI = ai.AI_1(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "green_2":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 100, 100, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_green_2.png')).convert_alpha()
         anim_list = [5, 6, 4, 2, 2, 2]
         anim_time_list = [74, 60, 60, 10, 10, 10]
         anim = components.Appearance(temp, 128, 128, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         enemy_AI = ai.AI_3(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "pink_1":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 50, 96, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_pink_1.png')).convert_alpha()
         anim_list = [4, 8, 6, 8, 2, 4]
         anim_time_list = [240, 60, 44, 58, 10, 44]
         anim = components.Appearance(temp, 243, 128, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         
         enemy_AI = ai.AI_2(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "pink_2":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 70, 70, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_pink_2.png')).convert_alpha()
         anim_list = [5, 6, 5, 2, 2, 2]
         anim_time_list = [60, 60, 44, 10, 10, 10]
         anim = components.Appearance(temp, 75, 75, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         
         enemy_AI = ai.AI_3(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "pink_3":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 50, 96, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_pink_3.png')).convert_alpha()
         anim_list = [5, 10, 7, 8, 2, 1]
         anim_time_list = [240, 60, 54, 120, 10, 10]
         anim = components.Appearance(temp, 128, 128, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         
         enemy_AI = ai.AI_4(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "pink_boss":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 86, 170, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_pink_boss.png')).convert_alpha()
         anim_list = [4, 8, 5, 8, 2, 4, 5, 5]
         anim_time_list = [240, 60, 44, 58, 10, 44, 44, 44]
         anim = components.Appearance(temp, 250, 200, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         enemy_AI = ai.AI_Boss_2(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     self.deactivate_entity(enemy_ID)
Exemplo n.º 16
0
    def init(self):
        self.font = pygame.font.Font("RobotoMono-Regular.ttf", 42)
        self.titlefont = pygame.font.Font("RobotoMono-Regular.ttf", 72)

        def start_game():
            for ent, c in self.world.get_component(components.CircleAnimation):
                c.loop = False
                c.chain = move_to_bottom
            for ent in [start, quitbutton, title]:
                pos = self.world.component_for_entity(ent, components.Position)
                self.world.add_component(
                    ent, components.ChangePosition((pos.x, pos.y + 100), 1))
                self.world.add_component(ent, components.ChangeAlpha(1, 0, 1))

            def change_scene():
                print("TODO: game screen")

            next_scene = self.world.create_entity()
            self.world.add_component(next_scene,
                                     components.Delay(2, change_scene))

        def quit_game():
            self.Terminate()

        def highlight(entity):
            t = self.world.component_for_entity(entity, components.Text)
            image = t.font.render("> " + t.text + " <", False, (128, 0, 128))
            self.world.component_for_entity(entity,
                                            components.Image).image = image
            size = self.world.component_for_entity(entity, components.Size)
            size.width = image.get_width()
            size.height = image.get_height()
            self.world.add_component(
                entity, components.ChangeSize(1, .25, interpolation.Smooth()))

        def lowlight(entity):
            t = self.world.component_for_entity(entity, components.Text)
            image = t.font.render(t.text, False, t.color)
            self.world.component_for_entity(entity,
                                            components.Image).image = image
            size = self.world.component_for_entity(entity, components.Size)
            size.width = image.get_width()
            size.height = image.get_height()
            self.world.add_component(
                entity, components.ChangeSize(.5, .25, interpolation.Smooth()))

        def start_circle(circle, idx):
            self.world.add_component(
                circle,
                components.CircleAnimation(400, 1,
                                           math.pi * (1.25 + .15 * idx), True,
                                           None, circle, idx))

        def move_to_bottom(circle, idx):
            self.world.add_component(
                circle, components.ChangePosition((16 + 250 * idx, 16), .5))

        start = self.world.create_entity()
        image = self.font.render("start", False, (0, 128, 0))
        self.world.add_component(start, components.Position(640, 480))
        self.world.add_component(start, components.Text("start", self.font))
        self.world.add_component(start, components.Image(image=image))
        self.world.add_component(
            start, components.Size(image.get_width(), image.get_height(), .5))
        self.world.add_component(start, components.Click(start_game))
        self.world.add_component(start, components.Over(highlight, lowlight))

        quitbutton = self.world.create_entity()
        image = self.font.render("quit", False, (0, 128, 0))
        self.world.add_component(quitbutton, components.Position(640, 540))
        self.world.add_component(quitbutton,
                                 components.Text("quit", self.font))
        self.world.add_component(quitbutton, components.Image(image=image))
        self.world.add_component(
            quitbutton,
            components.Size(image.get_width(), image.get_height(), .5))
        self.world.add_component(quitbutton, components.Click(quit_game))
        self.world.add_component(quitbutton,
                                 components.Over(highlight, lowlight))

        title = self.world.create_entity()
        image = self.titlefont.render("Puzzle Painter", False, (0, 128, 0))
        self.world.add_component(title, components.Position(640, 240))
        self.world.add_component(
            title, components.Text("Puzzle Painter", self.titlefont))
        self.world.add_component(title, components.Image(image=image))
        self.world.add_component(
            title, components.Size(image.get_width(), image.get_height()))

        for idx, val in enumerate(["blue", "green", "orange", "purple",
                                   "red"]):
            circle = self.world.create_entity()
            self.world.add_component(circle, components.Position(640, 300))
            self.world.add_component(circle,
                                     components.Image("pastel" + val + ".png"))
            self.world.add_component(circle, components.Size(16, 16))
            self.world.add_component(circle, components.Velocity())
            self.world.add_component(
                circle, components.Delay(idx / 5, start_circle, circle, idx))

        self.world.add_processor(processors.ClickProcessor(), priority=10)
        self.world.add_processor(processors.RenderProcessor())
        self.world.add_processor(processors.OverProcessor(), priority=10)
        self.world.add_processor(processors.VelocityProcessor(), priority=5)
        self.world.add_processor(processors.AnimationProcessor(), priority=5)