Exemple #1
0
    def potion_healing(self, x, y):
        self.log.debug("Adding healing potion at (" + str(x) + ", " + str(y) +
                       ")")

        item = self.world.create_entity(
            components.Position(x, y),
            components.Render("!", libtcod.light_red),
            components.Optics(transparent=True, lit=True), components.Item(),
            components.Text(
                noun="healing potion",
                pronoun=pronoun_from_name("healing potion"),
                description=
                "A bubbling red potion with miraculous healing powers."),
            components.HealingEffect(hit_points=5,
                                     duration=3000,
                                     interval=1000))

        drop_action = components.DropAction(item)
        self.world.add_component(item, drop_action)

        drink_action = components.DrinkAction(item)
        self.world.add_component(item, drink_action)

        throw_action = components.ThrowAction(item, distance=4)
        self.world.add_component(item, throw_action)

        return item
Exemple #2
0
 def wall(self, x, y):
     return self.world.create_entity(
         components.Position(x, y),
         components.Render("#", libtcod.dark_gray),
         components.Tangible(True),
         components.Optics(transparent=False),
         components.Terrain(),
         components.Text("wall", "a", description="A smooth stone wall."),
         components.Essence(0),
     )
Exemple #3
0
 def troll(self, x, y):
     self.log.debug("Adding troll at (" + str(x) + ", " + str(y) + ")")
     return self.world.create_entity(
         components.Actor(), components.Position(x, y),
         components.Render("T", libtcod.darker_green),
         components.Tangible(True), components.Optics(transparent=True),
         components.Creature(),
         components.Text("troll", description="A slimy green troll"),
         components.Health(20), components.Fighter(5, 1),
         components.Essence(40), components.Time(), components.Inventory())
Exemple #4
0
 def orc(self, x, y):
     self.log.debug("Adding orc at (" + str(x) + ", " + str(y) + ")")
     return self.world.create_entity(
         components.Actor(), components.Position(x, y),
         components.Render("o", libtcod.desaturated_green),
         components.Tangible(True), components.Optics(transparent=True),
         components.Creature(),
         components.Text("orc", description="A massive snarling orc"),
         components.Health(10), components.Fighter(3, 0),
         components.Essence(20), components.Time(), components.Inventory())
Exemple #5
0
    def player(self, x, y):
        player = self.world.create_entity(
            components.Actor(initial=0), components.Position(x, y),
            components.Render("@", libtcod.turquoise),
            components.Tangible(False), components.Optics(transparent=True),
            components.Player(),
            components.Text("ghost", "a", "A creepy old ghost..."),
            components.Possessor(2.0), components.Essence(100),
            components.EssenceAbsorber(1, 10),
            components.EssenceDrain(0.1, 1000), components.Time())

        return player
Exemple #6
0
    def corpse(self, x, y, creature_type):
        self.log.debug("Adding corpse at (" + str(x) + ", " + str(y) + ")")

        item = self.world.create_entity(
            components.Position(x, y),
            components.Render("%", libtcod.darker_red),
            components.Optics(transparent=True, lit=True), components.Item(),
            components.Text(noun=creature_type.lower() + " corpse",
                            pronoun=pronoun_from_name(creature_type),
                            description="A mutilated " + creature_type +
                            " corpse."))

        drop_action = components.DropAction(item)
        self.world.add_component(item, drop_action)

        return item
    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)
Exemple #8
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)
Exemple #9
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)