Esempio n. 1
0
def fade_up(world, entity, from_scene, to_scene):
    world.add_component(
        entity,
        components.ChangePosition((0, -100), 4, interpolation.Smooth(), True,
                                  fade_out, world))
    world.add_component(entity,
                        components.ChangeAlpha(0, 4, interpolation.Smooth()))
    world.add_component(entity,
                        components.Delay(5, next_scene, from_scene, to_scene))
Esempio n. 2
0
        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))
Esempio n. 3
0
        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()
Esempio n. 4
0
        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))
Esempio n. 5
0
 def move_down(entity):
     self.world.add_component(
         entity,
         components.ChangePosition((0, 40), 1, interpolation.Smooth(),
                                   True, move_up, entity))
Esempio n. 6
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
Esempio n. 7
0
 def move_to_bottom(circle, idx):
     self.world.add_component(
         circle, components.ChangePosition((16 + 250 * idx, 16), .5))
Esempio n. 8
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())