Exemplo n.º 1
0
    def __init__(self):
        super(Level1, self).__init__()
        layer = core.Layer()
        view_up, view_down = utils.split_view(game.default_camera,
                                              utils.VERTICAL)
        view_up_l, view_up_r = utils.split_view(view_up, utils.HORIZONTAL)
        layer.add_camera(view_up_l)
        layer.add_camera(view_down)
        self.add_layer(layer)
        self.speed_x = 100.0
        self.speed_y = 50.0

        self.im0 = sf.Texture.load_from_file(b'princess.png')
        for y in range(0, 500, 100):
            for x in range(0, 800, 100):
                sprite = sf.Sprite(self.im0)
                sprite.position = (x, y)
                layer.add_actor(core.Actor(sprite))

        layer2 = core.Layer()
        view_up_rt, view_up_rb = utils.split_view(view_up_r,
                                                  utils.VERTICAL,
                                                  ratio=0.8)
        layer2.add_camera(view_up_rt)
        layer2.add_camera(view_up_rb)
        text = sf.Text('PySFML', sf.Font.DEFAULT_FONT, 32)
        text.color = sf.Color.BLACK
        layer2.add_actor(core.Actor(text))
        self.add_layer(layer2)
Exemplo n.º 2
0
    def __init__(self):
        super(Level1, self).__init__()
        layer = core.Layer()
        view_up, view_down = utils.split_view(game.default_camera,
                                              utils.VERTICAL)
        action_h = actions.Repeat(
            actions.Chain(
                [actions.Move(5.0, 500, 0),
                 actions.Move(5.0, -500, 0)]))
        action_v = actions.Repeat(
            actions.Chain(
                [actions.Move(8.0, 0, 450),
                 actions.Move(8.0, 0, -450)]))
        view_up.add_action(action_h)
        view_up.add_action(action_v)
        layer.add_camera(view_up)
        layer.add_camera(view_down)
        self.add_layer(layer)

        self.im0 = sf.Texture.load_from_file(b'princess.png')
        for y in range(0, 500, 100):
            for x in range(0, 800, 100):
                sprite = sf.Sprite(self.im0)
                sprite.position = (x, y)
                layer.add_actor(core.Actor(sprite))
Exemplo n.º 3
0
    def __init__(self, space):
        super(Level1, self).__init__(space)
        layer = core.Layer()
        self.add_layer(layer)
        
        self.ground = ground = pm.Body(None, None)
        ground.position = (400, 25)
        ground_shape = pm.Poly(ground, [(0, 0), (800,0), (800, 50), (0, 50)])
        space.add_static(ground_shape)
        
        self.im0 = sf.Texture.load_from_file(b'princess.png')
#        inert = pm.moment_for_circle(10.0, 50.0, 50.0)
        for x in range(100, 800, 200):
            sprite = sf.Sprite(self.im0)
            sprite.origin = (self.im0.width//2, self.im0.height//2)
            body = pm.Body(50.0, pm.inf)
            shape = pm.Circle(body, 50.0)
            body.position = self.convert_coords((x, 300))
            b = pymunk_phy.PymunkBehavior(body, shape)
            actor = core.Actor(sprite, behavior=b)
            layer.add_actor(actor)
        
        actors = self.layers[0].actors
        act = actions.Chain([actions.Move(10.0, 400, -50),
                             actions.Rotate(3.0, 360),
                             actions.MoveTo(2.0, 100, 300),
                             actions.MoveTo(10.0, 700, 300)])
        actors[0].add_action(act)
        actors[1].add_action(actions.Move(5.0, -400, -50))
        actors[2].add_action(actions.MoveTo(15.0, 80, 180))
        act2 = actions.Chain([actions.Pause(5.0), actions.Kill()])
        actors[3].add_action(act2)
Exemplo n.º 4
0
    def __init__(self, world):
        super(Level1, self).__init__(world)
        layer = core.Layer()
        self.add_layer(layer)

        self.ground = world.CreateStaticBody(position=(0, -2),
                                             shapes=b2.polygonShape(box=(50,
                                                                         5)))

        self.im0 = sf.Texture.load_from_file(b'princess.png')
        for x in range(100, 800, 200):
            sprite = sf.Sprite(self.im0)
            sprite.origin = (self.im0.width // 2, self.im0.height // 2)
            #            sprite.position = (x, 300)
            body = world.CreateDynamicBody()
            body.linearDamping = 10.0
            body.CreateCircleFixture(radius=2.5, density=10.0, friction=0.3)
            body.position = self.convert_coords_to_b2((x, 300))
            body.fixedRotation = True
            actor = core.Actor(sprite, behavior=box2d.Box2DBehavior(body))
            layer.add_actor(actor)
        actors = self.layers[0].actors
        act = actions.Chain([
            actions.Move(10.0, 400, -50),
            actions.Rotate(3.0, 360),
            actions.MoveTo(2.0, 100, 300),
            actions.MoveTo(10.0, 700, 300)
        ])
        actors[0].add_action(act)
        actors[1].add_action(actions.Move(5.0, -400, -50))
        actors[2].add_action(actions.MoveTo(15.0, 10, 180))
        act2 = actions.Chain([actions.Pause(5.0), actions.Kill()])
        actors[3].add_action(act2)
Exemplo n.º 5
0
 def __init__(self):
     super(Level2, self).__init__()
     layer = core.Layer()
     self.add_layer(layer)
     text = sf.Text('PySFML', sf.Font.DEFAULT_FONT, 32)
     text.color = sf.Color.BLACK
     layer.add_actor(core.Actor(text))
     game.add_event_handler(sf.Event.KEY_RELEASED, self.handle_key_up)
Exemplo n.º 6
0
 def __init__(self):
     super(Level1, self).__init__()
     layer = core.Layer()
     self.add_layer(layer)
     
     self.im0 = sf.Texture.load_from_file(b'princess.png')
     for y in range(0, 501, 100):
         for x in range(0, 701, 100):
             s0 = sf.Sprite(self.im0)
             s0.position = (x, y)
             layer.add_actor(core.Actor(s0))
     
     sprite = sf.Sprite(self.im0)
     sprite.position = 400, 300
     sprite.origin = self.im0.width//2, self.im0.height//2
     actor = core.Actor(sprite)
     actor.add_action(Mover(sf.Vector2f(0, -200)))
     layer.add_actor(actor)
     camera = game.default_camera
     camera.add_action(actions.CameraFollow(actor, True))
     layer.add_camera(camera)
Exemplo n.º 7
0
 def __init__(self):
     super(Level1, self).__init__()
     layer = core.Layer()
     self.add_layer(layer)
     self.im0 = sf.Texture.load_from_file(b'princess.png')
     for x in range(50, 600, 50):
         for y in range(50, 400, 80):
             sprite = sf.Sprite(self.im0)
             sprite.position = (x, y)
             sprite.origin = (sprite.width//2, sprite.height//2)
             act = core.Actor(sprite)
             act.add_action(Rotate(30))
             layer.add_actor(act)
Exemplo n.º 8
0
 def __init__(self):
     super(Level1, self).__init__()
     layer = core.Layer()
     self.add_layer(layer)
     self.im0 = sf.Texture.load_from_file(b'princess.png')
     for x in range(50, 600, 50):
         for y in range(50, 400, 80):
             sprite = sf.Sprite(self.im0)
             sprite.position = (x, y)
             sprite.origin = (sprite.width // 2, sprite.height // 2)
             act = core.Actor(sprite)
             action = actions.Repeat(actions.Chain(
                 [Move(3.0, 50, 10), Rotate(4.0, 90)]),
                                     num=3)
             act.add_action(action)
             layer.add_actor(act)
Exemplo n.º 9
0
    def __init__(self, world):
        super(Level1, self).__init__(world)
        layer = core.Layer()
        self.add_layer(layer)

        self.ground = world.CreateStaticBody(position=(0, -2),
                                             shapes=b2.polygonShape(box=(50,
                                                                         5)))

        self.im0 = sf.Texture.load_from_file(b'princess.png')
        for y in range(0, 500, 120):
            for x in range(200, 700, 120):
                sprite = sf.Sprite(self.im0)
                sprite.origin = (self.im0.width // 2, self.im0.height // 2)
                sprite.position = (x, y)
                actor = core.Actor(sprite)
                body = world.CreateDynamicBody()
                body.CreateCircleFixture(radius=2.5, density=1.0, friction=0.3)
                actor.add_action(Updater(body), name='box2d')
                layer.add_actor(actor)
Exemplo n.º 10
0
 def __init__(self):
     super(Level1, self).__init__()
     layer = core.Layer()
     self.add_layer(layer)
     self.im0 = sf.Texture.load_from_file(b'rpg_sprite_walk.png')
     num = 0
     for x in range(50, 600, 50):
         for y in range(50, 400, 80):
             sprite = sf.Sprite(self.im0)
             sprite.position = (x, y)
             act = core.Actor(sprite)
             anim = actions.Animate(1.0, 4, 8,
                                    start=(num % 4, 0),
                                    stop=(num % 4, 7),
                                    repeats=0)
             act['walk'] = anim
             act.add_action(SwitchAnimation())
             layer.add_actor(act)
             print(act.action_ids)
             num += 1
Exemplo n.º 11
0
 def __init__(self):
     super(Level1, self).__init__()
     layer = core.Layer()
     self.add_layer(layer)
     self.im0 = sf.Texture.load_from_file(b'princess.png')
     for x in range(50, 600, 50):
         for y in range(50, 400, 80):
             sprite = sf.Sprite(self.im0)
             sprite.position = (x, y)
             sprite.origin = (sprite.width//2, sprite.height//2)
             act = core.Actor(sprite)
             act_list = [actions.Move(3.0, 150, 25),
                         actions.Pause(2.5),
                         actions.Rotate(4.0, 360),
                         actions.Pause(1.5)]
             act_list2 = [actions.Repeat(actions.Chain(act_list),
                                     num=3),
                          actions.MoveTo(10.0, sprite.x, sprite.y)]
             action = actions.Repeat(actions.Chain(act_list2))
             act.add_action(action)
             layer.add_actor(act)
Exemplo n.º 12
0
    def __init__(self, world):
        super(Level1, self).__init__(world)
        layer = core.Layer()
        self.add_layer(layer)

        self.ground = world.CreateStaticBody(position=(0, -2),
                                             shapes=b2.polygonShape(box=(50,
                                                                         5)))

        self.im0 = sf.Texture.load_from_file(b'princess.png')
        for x in range(100, 800, 300):
            sprite = sf.Sprite(self.im0)
            sprite.origin = (self.im0.width // 2, self.im0.height // 2)
            sprite.position = (x, 300)
            actor = core.Actor(sprite)
            body = world.CreateDynamicBody()
            body.CreateCircleFixture(radius=2.5, density=1.0, friction=0.3)
            actor.add_action(Updater(body), name='box2d')
            layer.add_actor(actor)
        actors = self.layers[0].actors
        actors[1].obstacle = True
        actors[0].add_action(actions.DefferedCall(1.0, self.test_los))