Exemplo n.º 1
0
    def __init__(self, mov, xInMap, yInMap):
        super(Enemy, self).__init__()

        self.xInMap = xInMap
        self.yInMap = yInMap
        self.x = xInMap * 48
        self.y = yInMap * 48
        # direction that enemy move towards
        self.dir = "up"
        # notice that value of stepLength property must be a divisible number of 48
        self.stepLength = 8
        self.stepIndex = 0
        self.stepNum = 48 / self.stepLength
        self.fullHp = 150
        self.hp = self.fullHp

        self.animaSet = AnimationSet()
        self.addChild(self.animaSet)

        frameList = Animation.divideUniformSizeFrames(48, 96, 1, 2)

        # move down
        bmpd = BitmapData(mov, 0, 0, 48, 96)
        anima = Animation(bmpd, frameList)
        self.animaSet.addAnimation("mov_down", anima)

        # move up
        bmpd = BitmapData(mov, 0, 96, 48, 96)
        anima = Animation(bmpd, frameList)
        self.animaSet.addAnimation("mov_up", anima)

        # move left
        bmpd = BitmapData(mov, 0, 192, 48, 96)
        anima = Animation(bmpd, frameList)
        self.animaSet.addAnimation("mov_left", anima)

        # move right
        bmpd = BitmapData(mov, 0, 192, 48, 96)
        anima = Animation(bmpd, frameList)
        anima.mirroring = True
        self.animaSet.addAnimation("mov_right", anima)

        # uniform treatment of these animations
        for n in self.animaSet.animationList:
            o = self.animaSet.animationList[n]

            o.playMode = AnimationPlayMode.VERTICAL
            o.speed = 3

            o.addEventListener(AnimationEvent.CHANGE_FRAME, self.step)

        self.animaSet.changeAnimation("mov_" + self.dir)

        # create hp layer
        self.hpLayer = Sprite()
        self.hpLayer.x = 8
        self.hpLayer.y = -5
        self.addChild(self.hpLayer)

        self.hpLayer.graphics.beginFill("red")
        self.hpLayer.graphics.drawRect(0, 0, 32, 5)
        self.hpLayer.graphics.endFill()
Exemplo n.º 2
0
    def __init__(self, name, mov, atk, xInMap, yInMap, atkValue):
        super(AttackCharacter, self).__init__()

        self.xInMap = xInMap
        self.yInMap = yInMap
        self.x = xInMap * 48
        self.y = yInMap * 48
        self.isAtk = False

        self.atkValue = atkValue

        self.dir = "down"

        self.animaSet = AnimationSet()
        self.addChild(self.animaSet)

        frameList = Animation.divideUniformSizeFrames(48, 96, 1, 2)

        # move down
        bmpd = BitmapData(mov, 0, 0, 48, 96)
        anima = Animation(bmpd, frameList)
        self.animaSet.addAnimation("mov_down", anima)

        # move up
        bmpd = BitmapData(mov, 0, 96, 48, 96)
        anima = Animation(bmpd, frameList)
        self.animaSet.addAnimation("mov_up", anima)

        # move left
        bmpd = BitmapData(mov, 0, 192, 48, 96)
        anima = Animation(bmpd, frameList)
        self.animaSet.addAnimation("mov_left", anima)

        # move right
        bmpd = BitmapData(mov, 0, 192, 48, 96)
        anima = Animation(bmpd, frameList)
        anima.mirroring = True
        self.animaSet.addAnimation("mov_right", anima)

        frameList = Animation.divideUniformSizeFrames(64, 256, 1, 4)

        # atk down
        bmpd = BitmapData(atk, 0, 0, 64, 256)
        anima = Animation(bmpd, frameList)
        self.animaSet.addAnimation("atk_down", anima)

        # atk up
        bmpd = BitmapData(atk, 0, 256, 64, 256)
        anima = Animation(bmpd, frameList)
        self.animaSet.addAnimation("atk_up", anima)

        # atk left
        bmpd = BitmapData(atk, 0, 512, 64, 256)
        anima = Animation(bmpd, frameList)
        self.animaSet.addAnimation("atk_left", anima)

        # atk right
        bmpd = BitmapData(atk, 0, 512, 64, 256)
        anima = Animation(bmpd, frameList)
        anima.mirroring = True
        self.animaSet.addAnimation("atk_right", anima)

        # uniform treatment of these animations
        for n in self.animaSet.animationList:
            o = self.animaSet.animationList[n]

            o.playMode = AnimationPlayMode.VERTICAL
            o.speed = 5

            o.addEventListener(AnimationEvent.CHANGE_FRAME, self.step)

            # if atk animation...
            if n.find("atk") >= 0:
                o.loopTimes = 1
                o.x -= 8
                o.y -= 8

                o.addEventListener(AnimationEvent.STOP, self.atkOver)

        self.animaSet.changeAnimation("mov_" + self.dir)
Exemplo n.º 3
0
def demoInit(result):
    global loadingBar, animaSet

    loadingBar.remove()

    # move image
    mov = result["mov"]
    # atk image
    atk = result["atk"]

    ###
    # create animation set to contain a sort of animations
    ###
    animaSet = AnimationSet()
    animaSet.x = animaSet.y = 100
    addChild(animaSet)

    ###
    # move animation
    ###
    # get move animation frame list
    frameList = Animation.divideUniformSizeFrames(48, 96, 1, 2)

    # move down
    bmpd = BitmapData(mov, 0, 0, 48, 96)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("move_down", anima)
    # move up
    bmpd = BitmapData(mov, 0, 96, 48, 96)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("move_up", anima)
    # move left
    bmpd = BitmapData(mov, 0, 192, 48, 96)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("move_left", anima)
    # move right
    bmpd = BitmapData(mov, 0, 192, 48, 96)
    anima = Animation(bmpd, frameList)
    anima.mirroring = True
    animaSet.addAnimation("move_right", anima)

    ###
    # attack animation
    ###
    # get atk animation frame list
    frameList = Animation.divideUniformSizeFrames(64, 256, 1, 4)

    # atk down
    bmpd = BitmapData(atk, 0, 0, 64, 256)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("atk_down", anima)
    # atk up
    bmpd = BitmapData(atk, 0, 256, 64, 256)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("atk_up", anima)
    # atk left
    bmpd = BitmapData(atk, 0, 512, 64, 256)
    anima = Animation(bmpd, frameList)
    animaSet.addAnimation("atk_left", anima)
    # atk right
    bmpd = BitmapData(atk, 0, 512, 64, 256)
    anima = Animation(bmpd, frameList)
    anima.mirroring = True
    animaSet.addAnimation("atk_right", anima)

    for n in animaSet.animationList:
        o = animaSet.animationList[n]

        o.playMode = AnimationPlayMode.VERTICAL
        o.speed = 5

        # if atk animation... (because atk animation is bigger than move animation)
        if n.find("atk") >= 0:
            o.x -= 8
            o.y -= 8

    animaSet.changeAnimation("move_down")

    ###
    # create buttons
    ###
    btnList = [
        "move down", "move up", "move right", "move left", "atk down",
        "atk up", "atk right", "atk left"
    ]

    btnLayer = Sprite()
    btnLayer.x = 200
    btnLayer.y = 50
    addChild(btnLayer)

    for i, n in enumerate(btnList):
        btn = ButtonSample(text=n)
        btn.label = n
        btnLayer.addChild(btn)
        btn.addEventListener(MouseEvent.MOUSE_DOWN, onBtnClick)

        btn.x = (0 if (4 - i) > 0 else 1) * 150
        btn.y = (i % 4) * 50