def __init__(self, playerImage): super(Player, self).__init__() self.direction = None self.step = 5 # create bitmap data bmpd = BitmapData(playerImage) # create frames in animation frames = Animation.divideUniformSizeFrames(bmpd.width, bmpd.height, 4, 4) # create animation self.animation = Animation(bmpd, frames) self.animation.speed = 5 self.animation.play() self.addChild(self.animation)
class Player(Sprite): def __init__(self, playerImage): super(Player, self).__init__() #移动方向[right向右,left向左,None不移动] self.direction = None #移动速度 self.step = 5 # create bitmap data bmpd = BitmapData(playerImage) #创建图片数据 # create frames in animation frames = Animation.divideUniformSizeFrames(bmpd.width, bmpd.height, 4, 4) #创建动画帧列表,通过类对象Animation调用divideUniformSizeFrames函数 # create animation self.animation = Animation(bmpd, frames) #创建动画 self.animation.speed = 5 #设置动画播放速度 self.animation.play() #播放动画 self.addChild(self.animation) #将动画加入界面 #创建动画 def loop(self): # move towards right if self.direction == "right": self.x += self.step self.animation.currentRow = 2 # move towards left elif self.direction == "left": self.x -= self.step self.animation.currentRow = 1 # no movement else: self.animation.currentRow = 0 if self.x < 0: self.x = 0 elif self.x > stage.width - self.width: self.x = stage.width - self.width
def __init__(self, playerImage): super(Player, self).__init__() #移动方向[right向右,left向左,None不移动] self.direction = None #移动速度 self.step = 5 # create bitmap data bmpd = BitmapData(playerImage) #创建图片数据 # create frames in animation frames = Animation.divideUniformSizeFrames(bmpd.width, bmpd.height, 4, 4) #创建动画帧列表,通过类对象Animation调用divideUniformSizeFrames函数 # create animation self.animation = Animation(bmpd, frames) #创建动画 self.animation.speed = 5 #设置动画播放速度 self.animation.play() #播放动画 self.addChild(self.animation) #将动画加入界面
class Player(Sprite): def __init__(self, playerImage): super(Player, self).__init__() self.direction = None self.step = 5 # create bitmap data bmpd = BitmapData(playerImage) # create frames in animation frames = Animation.divideUniformSizeFrames(bmpd.width, bmpd.height, 4, 4) # create animation self.animation = Animation(bmpd, frames) self.animation.speed = 5 self.animation.play() self.addChild(self.animation) def loop(self): # move towards right if self.direction == "right": self.x += self.step self.animation.currentRow = 2 # move towards left elif self.direction == "left": self.x -= self.step self.animation.currentRow = 1 # no movement else: self.animation.currentRow = 0 if self.x < 0: self.x = 0 elif self.x > stage.width - self.width: self.x = stage.width - self.width
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)
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()
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