Пример #1
0
def shake():
    """Predefined action that performs a slight rotation and then goes back to the original rotation
    position.
    """
    angle = 5
    duration = 0.05

    rot = ac.Accelerate(ac.RotateBy(angle, duration), 2)
    rot2 = ac.Accelerate(ac.RotateBy(-angle * 2, duration), 2)
    return rot + (rot2 + ac.Reverse(rot2)) * 2 + ac.Reverse(rot)
Пример #2
0
 def rotate_by(self, radians):
     '''
     positive angle - counter-clockwise rotation
     negative angle - clockwise rotation
     angle 0 means turned right
     '''
     angle = math.degrees(radians)
     self.do(ac.RotateBy(angle, self._rotation_speed))
     return self._rotation_speed
Пример #3
0
 def show_under_attack(self, cri_dice):
     '''show the action and the sprites when the player is attacked
     '''
     _action = actions.RotateBy(15, 0.1) + actions.RotateBy(-15, 0.1)
     self.sprite.do(_action)
     _sprite = materials.sprites['strike']
     _sprite.visible = True
     _sprite.position = 200, 340
     if cri_dice == 1:
         _sprite.image = const.image_from_file(
             const.CRITICAL_STRIKE_IMG_FILE, const.GUI_ZIP_FILE)
         _sprite.do(actions.FadeOut(1.5))
     elif cri_dice == 0:
         _sprite.image = const.image_from_file(const.STRIKE_IMG_FILE,
                                               const.GUI_ZIP_FILE)
         _sprite.do(actions.FadeOut(1))
     elif cri_dice == 2:
         _sprite.image = const.image_from_file(const.SUPER_STRIKE_IMG_FILE,
                                               const.GUI_ZIP_FILE)
         _sprite.do(actions.FadeOut(2.5))
Пример #4
0
 def show_under_attack(self, cri_dice=False):
     '''Show the action of enemy when attacked (shake)
     and the corresponding strike-sprite
     '''
     _action = actions.RotateBy(-15, 0.1) + actions.RotateBy(15, 0.1)
     self.sprite.do(_action)
     _sprite = materials.sprites['strike'] 
     _sprite.visible = True
     _sprite.position = 650,340
     if cri_dice==1:
         _sprite.image = const.image_from_file(
                 const.CRITICAL_STRIKE_IMG_FILE, const.GUI_ZIP_FILE)
         _sprite.do(actions.FadeOut(1.5))
     elif cri_dice==0:
         _sprite.image = const.image_from_file(
                 const.STRIKE_IMG_FILE, const.GUI_ZIP_FILE)
         _sprite.do(actions.FadeOut(1))
     elif cri_dice==2:
         _sprite.image = const.image_from_file(
                 const.SUPER_STRIKE_IMG_FILE, const.GUI_ZIP_FILE)
         _sprite.do(actions.FadeOut(2.5))
Пример #5
0
    def __init__(self, line: Line):
        class Qwq(cac.IntervalAction):
            def init(self, width, duration):
                self._width = width
                self.duration = duration

            def start(self):
                self._cur = self.target.scale_y

            def update(self, t):
                self.target.scale_y = (self._cur - self._width) * (1 - t) + self._width

        def p(state: Line.LineState):
            res = copy.copy(state)
            res.x *= settings.size
            res.x += (settings.width - settings.size) / 2
            res.y *= settings.size
            res.y += (settings.height - settings.size) / 2
            return res

        states = list(map(p, sorted(line.states, key=lambda e: e.sec)))
        super().__init__('line_empty.png', (states[0].x, states[0].y), states[0].angle)
        for note in line.notes:
            self.add(NoteSprite(note))
        line_sprite = cocos.sprite.Sprite('line.png')

        self.add(line_sprite)
        action = None
        pre = states[0]
        for i in states[1:]:
            act = cac.MoveTo((i.x, i.y), i.sec - pre.sec) | cac.RotateBy(i.angle - pre.angle, i.sec - pre.sec)
            if i.rev != pre.rev:
                act |= cac.Delay(i.sec - pre.sec) + cac.FlipY(duration=0.01)
            if not action:
                action = act
            else:
                action += act
            pre = i
        if action:
            self.do(action)
        action = None
        sec = 0
        for i in states:
            act = Qwq(i.width, i.sec - sec)
            if not action:
                action = act
            else:
                action += act
            sec = i.sec
        if action:
            line_sprite.do(action)
Пример #6
0
def main():
    # Director is a singleton object of cocos.
    director.director.init(
        caption='Hello World',
        resizable=True,
    )

    hello_layer = HelloActions()

    # [LEARN] layers (in fact, all CocosNode objects) can take actions.
    hello_layer.do(actions.RotateBy(360, duration=10))
    main_scene = scene.Scene(hello_layer)

    director.director.run(main_scene)
Пример #7
0
 def create_material(self):
     # ein neues Material kreieren und ins Lager legen
     start_pos = self.level_info.start
     segments = self.level_info.segments
     delay = self.level_info.beltDelay
     x = (start_pos[0] + 0.5) * self.cell_size
     y = (start_pos[1] + 0.5) * self.cell_size + random.randint(-5, 5)  # so ist mehr zufall dabei
     steps = [ac.MoveBy((segment[0] * self.cell_size, segment[1] * self.cell_size),
                        duration=(9*abs(segment[0] + segment[1]) * delay)) for segment in segments]
     actions = ac.RotateBy(0, 0)
     for step in steps:
         actions += step
     material = Material(x, y, actions, delay)
     self.add(material)  # gamelayer sollte es dazu addieren
Пример #8
0
def main():
  global keyboard # Declare this as global so it can be accessed within class methods.
  # Initialize the window
  director.init(width=size[0], height=size[1], autoscale=True, resizable=True)

  # Create a layer and add a sprite to it.
  player_layer = layer.Layer()
  molecule = sprite.Sprite('sprites/molecule.png')
  molecule.scale = 2
  player_layer.add(molecule, z=1)
  scale = actions.ScaleBy(3, duration=2)

  # Add a Label, because we can.
  label = cocos.text.Label('Hello, world@' + str(deltaTime), font_name='Times New Roman', font_size=32, anchor_x='left', anchor_y='center')
  label.position = 0, size[1]/2
  label.velocity = 0, 0
  player_layer.add(label)

  # Set initial position and velocity.
  molecule.position = (size[0]/2, size[1]/2)
  molecule.velocity = (0, 0)

  # Set the sprite's movement class and run some actions.
  molecule.do(actions.Repeat(scale + actions.Reverse(scale)))

  label.do(Me())

  # Rotate the entire player_layer (includes ALL nodes, will rotate ONCE)
  player_layer.do(actions.RotateBy(360, duration=10))

  # Create a scene and set its initial layer.
  main_scene = scene.Scene(player_layer)

  # Set the sprite's movement class.
  keyboard = key.KeyStateHandler()
  director.window.push_handlers(keyboard)

  # Play the scene in the window.
  director.run(main_scene)
Пример #9
0
 def actions(self, actions):
     self._actions = ac.RotateBy(90, 0.5)
     for step in actions:
         self._actions += step
Пример #10
0
import cocos
import cocos.actions as ac

RIGHT = ac.RotateBy(90, 1)
LEFT = ac.RotateBy(-90, 1)


def move(x, y):
    dur = abs(x + y) / 100.0
    return ac.MoveBy((x, y), duration=dur)


def get_scenario():
    turret_slots = [(192, 352), (320, 352), (448, 352), (192, 192), (320, 192),
                    (448, 192), (96, 32), (224, 32), (352, 32), (480, 32)]
    bunker_position = (528, 430)
    enemy_start = (-80, 110)
    sc = Scenario('map0', turret_slots, bunker_position, enemy_start)
    sc.actions = [
        move(610, 0), LEFT,
        move(0, 160), LEFT,
        move(-415, 0), RIGHT,
        move(0, 160), RIGHT,
        move(420, 0)
    ]
    return sc


class Scenario(object):
    def __init__(self, tmx_map, turrets, bunker, enemy_start):
        self.tmx_map = tmx_map
 def actions(self, actions):
     self._actions = ac.RotateBy(90, 0.5)
     self._actions = reduce((lambda x, y: x + y), actions)
 def stop(self):
     self.chasee.do(ac.RotateBy(360, 1.0))
     self.on_bullet_hit(self.target)