示例#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)
示例#2
0
def notify(world, font, message, from_scene, to_scene):
    entity = world.create_entity()
    world.add_component(entity, components.Position(640, 500))
    world.add_component(entity, components.Image("speech.png"))
    util.drawText(world.component_for_entity(entity, components.Image).image, message, (255, 255, 255), pygame.Rect(30, 20, 246, 134), font)
    world.add_component(entity, components.Size(307, 173))
    world.add_component(entity, components.Delay(2, fade_up, world, entity, from_scene, to_scene))
    return entity
示例#3
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)
示例#4
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
示例#5
0
文件: game.py 项目: thepaperpilot/NaN
    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)
示例#6
0
文件: game.py 项目: thepaperpilot/NaN
def create_entity(world, image, rect):
    entity = world.create_entity()
    world.add_component(entity, components.Image(image))
    world.add_component(entity, components.Position(rect.x, rect.y))
    world.add_component(entity, components.Size(rect.width, rect.height))
    return entity
示例#7
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
示例#8
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)
示例#9
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)
示例#10
0
    def init(self):
        scenebase.SceneBase.init(self)

        text = self.world.create_entity()
        image = pygame.Surface([1280, 720], pygame.SRCALPHA,
                               32).convert_alpha()
        util.drawText(image, self.text, (255, 255, 255),
                      pygame.Rect(100, 100, 1080, 520), self.font)
        self.world.add_component(text, components.Position(640, 240))
        self.world.add_component(text, components.Image(image=image, alpha=0))
        self.world.add_component(
            text, components.Size(image.get_width(), image.get_height()))
        self.world.add_component(text, components.ChangePosition((640, 340),
                                                                 .5))
        self.world.add_component(text, components.ChangeAlpha(1, 1))

        #self.world.add_component(text, components.Reactive())

        def fade_out(entity):
            self.world.add_component(
                entity,
                components.ChangeAlpha(.5, 1, interpolation.Circle(), fade_in,
                                       entity))

        def fade_in(entity):
            self.world.add_component(
                entity,
                components.ChangeAlpha(1, 1, interpolation.Circle(), fade_out,
                                       entity))

        continue_text = self.world.create_entity()
        image = self.font.render("press any button to continue", False,
                                 (32, 128, 255))
        self.world.add_component(continue_text, components.Position(640, 640))
        self.world.add_component(continue_text, components.Image(image=image))
        self.world.add_component(
            continue_text,
            components.Size(image.get_width(), image.get_height()))
        #self.world.add_component(continue_text, components.Reactive())
        fade_in(continue_text)

        def fade_scene():
            for ent in [text, continue_text]:
                if self.world.has_component(ent, components.ChangeAlpha):
                    self.world.remove_component(ent, components.ChangeAlpha)
                self.world.add_component(ent, components.ChangeAlpha(0, .5))
                self.world.add_component(
                    ent,
                    components.ChangePosition(
                        (640,
                         self.world.component_for_entity(
                             ent, components.Position).y + 50), .5))

            self.world.add_component(text, components.Delay(1, next_scene))
            pygame.mixer.Sound(
                os.path.join(components.get_base_path(), 'audio',
                             'click')).play()

        def next_scene():
            self.switch_to_scene(self.scene)

        self.world.add_processor(processors.RenderProcessor())
        self.world.add_processor(processors.AnimationProcessor(), priority=5)
        self.world.add_processor(processors.TextProcessor(fade_scene),
                                 priority=10)
        self.world.add_processor(processors.InputProcessor())
示例#11
0
    def init(self):
        scenebase.SceneBase.init(self)

        def start_game():
            for ent, (p,
                      i) in self.world.get_components(components.Position,
                                                      components.Image):
                self.world.add_component(
                    ent, components.ChangePosition((p.x, p.y + 100), .25))
                self.world.add_component(ent, components.ChangeAlpha(0, .25))

            def change_scene():
                self.switch_to_scene(
                    text.TextScene(
                        "This is the story of an adventurer named NaN, known across the land for his unwavering enthusiasm for helping anyone with anything. His abilities were known far and wide, and indeed our story even begins with him defeating a dragon with ease...",
                        game.SceneOne()))

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

        def scene_select():
            self.switch_to_scene(SceneSelect())

        def quit_game():
            self.terminate()

        def highlight(entity):
            t = self.world.component_for_entity(entity, components.Text)
            image = t.font.render("> " + t.text + " <", False, (0, 128, 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()

        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()

        start = self.world.create_entity()
        image = self.large_font.render("start", False, (0, 128, 0))
        self.world.add_component(start, components.Position(640, 440))
        self.world.add_component(start,
                                 components.Text("start", self.large_font))
        self.world.add_component(start, components.Image(image=image))
        self.world.add_component(
            start, components.Size(image.get_width(), image.get_height(), .75))
        self.world.add_component(start, components.Click(start_game))
        self.world.add_component(start, components.Over(highlight, lowlight))
        self.world.add_component(start, components.Audio("click"))

        scene = self.world.create_entity()
        image = self.large_font.render("scene select", False, (0, 128, 0))
        self.world.add_component(scene, components.Position(640, 540))
        self.world.add_component(
            scene, components.Text("scene select", self.large_font))
        self.world.add_component(scene, components.Image(image=image))
        self.world.add_component(
            scene, components.Size(image.get_width(), image.get_height(), .75))
        self.world.add_component(scene, components.Click(scene_select))
        self.world.add_component(scene, components.Over(highlight, lowlight))
        self.world.add_component(scene, components.Audio("click"))

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

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

        self.world.add_processor(processors.RenderProcessor())
        self.world.add_processor(processors.InputProcessor(), priority=10)
        self.world.add_processor(processors.PhysicsProcessor(), priority=5)
        self.world.add_processor(processors.AnimationProcessor(), priority=5)
示例#12
0
    def init(self):
        scenebase.SceneBase.init(self)

        def go_back():
            self.switch_to_scene(TitleScene())

        def open_scene(scene):
            self.switch_to_scene(scene)

        def highlight(entity):
            t = self.world.component_for_entity(entity, components.Text)
            image = t.font.render("> " + t.text + " <", False, (0, 128, 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()

        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()

        back = self.world.create_entity()
        image = self.large_font.render("back", False, (0, 128, 0))
        self.world.add_component(back, components.Position(640, 360))
        self.world.add_component(back, components.Text("back",
                                                       self.large_font))
        self.world.add_component(back, components.Image(image=image))
        self.world.add_component(
            back, components.Size(image.get_width(), image.get_height(), .75))
        self.world.add_component(back, components.Reactive())
        self.world.add_component(back, components.Click(go_back))
        self.world.add_component(back, components.Over(highlight, lowlight))
        self.world.add_component(back, components.Audio("click"))

        scene1 = self.world.create_entity()
        label1 = self.world.create_entity()
        image = self.large_font.render("1", False, (0, 128, 0))
        self.world.add_component(label1, components.Position(300, 170))
        self.world.add_component(label1, components.Text("1", self.large_font))
        self.world.add_component(label1, components.Image(image=image))
        self.world.add_component(
            label1, components.Size(image.get_width(), image.get_height()))
        self.world.add_component(label1, components.Reactive())

        self.world.add_component(scene1, components.Position(300, 100))
        self.world.add_component(scene1, components.Platform())
        self.world.add_component(scene1, components.Image("IntroBG.png"))
        self.world.add_component(scene1, components.Size(320, 180))
        self.world.add_component(scene1, components.Reactive())
        self.world.add_component(scene1,
                                 components.Click(open_scene, game.SceneOne()))
        self.world.add_component(scene1,
                                 components.Over(highlight, lowlight, label1))

        scene2 = self.world.create_entity()
        label2 = self.world.create_entity()
        image = self.large_font.render("2", False, (0, 128, 0))
        self.world.add_component(label2, components.Position(980, 170))
        self.world.add_component(label2, components.Text("2", self.large_font))
        self.world.add_component(label2, components.Image(image=image))
        self.world.add_component(
            label2, components.Size(image.get_width(), image.get_height()))
        self.world.add_component(label2, components.Reactive())

        self.world.add_component(scene2, components.Position(980, 100))
        self.world.add_component(scene2, components.Platform())
        self.world.add_component(scene2,
                                 components.Image("OutsideSceneBG.png"))
        self.world.add_component(scene2, components.Size(320, 180))
        self.world.add_component(scene2, components.Reactive())
        self.world.add_component(scene2,
                                 components.Click(open_scene, game.SceneTwo()))
        self.world.add_component(scene2,
                                 components.Over(highlight, lowlight, label2))

        scene3 = self.world.create_entity()
        label3 = self.world.create_entity()
        image = self.large_font.render("3", False, (0, 128, 0))
        self.world.add_component(label3, components.Position(300, 420))
        self.world.add_component(label3, components.Text("3", self.large_font))
        self.world.add_component(label3, components.Image(image=image))
        self.world.add_component(
            label3, components.Size(image.get_width(), image.get_height()))
        self.world.add_component(label3, components.Reactive())

        self.world.add_component(scene3, components.Position(300, 350))
        self.world.add_component(scene3, components.Platform())
        self.world.add_component(scene3, components.Image("HouseScene2BG.png"))
        self.world.add_component(scene3, components.Size(320, 180))
        self.world.add_component(scene3, components.Reactive())
        self.world.add_component(
            scene3, components.Click(open_scene, game.SceneThree()))
        self.world.add_component(scene3,
                                 components.Over(highlight, lowlight, label3))

        scene4 = self.world.create_entity()
        label4 = self.world.create_entity()
        image = self.large_font.render("4", False, (0, 128, 0))
        self.world.add_component(label4, components.Position(980, 420))
        self.world.add_component(label4, components.Text("4", self.large_font))
        self.world.add_component(label4, components.Image(image=image))
        self.world.add_component(
            label4, components.Size(image.get_width(), image.get_height()))
        self.world.add_component(label4, components.Reactive())

        self.world.add_component(scene4, components.Position(980, 350))
        self.world.add_component(scene4, components.Platform())
        self.world.add_component(scene4, components.Image("HouseScene3BG.png"))
        self.world.add_component(scene4, components.Size(320, 180))
        self.world.add_component(scene4, components.Reactive())
        self.world.add_component(
            scene4, components.Click(open_scene, game.SceneFour()))
        self.world.add_component(scene4,
                                 components.Over(highlight, lowlight, label4))

        scene5 = self.world.create_entity()
        label5 = self.world.create_entity()
        image = self.large_font.render("5", False, (0, 128, 0))
        self.world.add_component(label5, components.Position(300, 670))
        self.world.add_component(label5, components.Text("5", self.large_font))
        self.world.add_component(label5, components.Image(image=image))
        self.world.add_component(
            label5, components.Size(image.get_width(), image.get_height()))
        self.world.add_component(label5, components.Reactive())

        self.world.add_component(scene5, components.Position(300, 600))
        self.world.add_component(scene5, components.Platform())
        self.world.add_component(
            scene5, components.Image("HouseSceneBlacksmithBG.png"))
        self.world.add_component(scene5, components.Size(320, 180))
        self.world.add_component(scene5, components.Reactive())
        self.world.add_component(
            scene5, components.Click(open_scene, game.SceneFive()))
        self.world.add_component(scene5,
                                 components.Over(highlight, lowlight, label5))

        scene6 = self.world.create_entity()
        label6 = self.world.create_entity()
        image = self.large_font.render("6", False, (0, 128, 0))
        self.world.add_component(label6, components.Position(980, 670))
        self.world.add_component(label6, components.Text("6", self.large_font))
        self.world.add_component(label6, components.Image(image=image))
        self.world.add_component(
            label6, components.Size(image.get_width(), image.get_height()))
        self.world.add_component(label6, components.Reactive())

        self.world.add_component(scene6, components.Position(980, 600))
        self.world.add_component(scene6, components.Platform())
        self.world.add_component(scene6, components.Image("HouseScene1BG.png"))
        self.world.add_component(scene6, components.Size(320, 180))
        self.world.add_component(scene6, components.Reactive())
        self.world.add_component(scene6,
                                 components.Click(open_scene, game.SceneSix()))
        self.world.add_component(scene6,
                                 components.Over(highlight, lowlight, label6))

        for ent, (i, p, s, r) in self.world.get_components(
                components.Image, components.Position, components.Size,
                components.Reactive):
            if r.x == 0:
                r.x = p.x
                r.y = p.y
            mousex, mousey = pygame.mouse.get_pos()
            mousex *= 1280 / pygame.display.get_surface().get_width()
            mousey *= 720 / pygame.display.get_surface().get_height()
            p.x = r.x + (r.x - mousex) / 10
            p.y = r.y + (r.y - mousey) / 10
            s.scale = 100 / min(
                400, max(100, math.sqrt((r.x - mousex)**2 +
                                        (r.y - mousey)**2)))

        self.world.add_processor(processors.RenderProcessor())
        self.world.add_processor(processors.InputProcessor(), priority=10)
        self.world.add_processor(processors.PhysicsProcessor(), priority=5)
        self.world.add_processor(processors.AnimationProcessor(), priority=5)