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))
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)
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)
def update(self, game, dt): actor = self.owner if self.finished: new_act = actions.Chain([actions.Pause(random.randrange(15, 20)), Move(0.1*random.randrange(10, 30)) ]) actor.add_action(new_act) else: body = actor['box2d'].body v = body.GetLinearVelocityFromLocalPoint((0, 0)) v.Normalize() body.ApplyForce(self.fv-10*v, body.position)
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)
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)