def __init__(self, avatar): self.done = False self.avatar = avatar self.currentAnim = Anim('subWalkSquash', 5) #img = data.pngs['avatar.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) events.AddListener(self) self.blinkingCounter = 0.0 self.yoyo = yoyo.YoYo() self.shadow = ShadowSprite() self.shadow.scale = float(self.width)/self.shadow.width self.shadow.opacity = 128 self.on_key_press = window.window.event(self.on_key_press) self.on_key_release = window.window.event(self.on_key_release) self.mouseButton = None self.on_mouse_press = window.window.event(self.on_mouse_press) self.on_mouse_release = window.window.event(self.on_mouse_release) self.attackImgs = {Facing.left: data.pngs[self.avatar.attackImg +'_left'], Facing.right: data.pngs[self.avatar.attackImg]} self.deadImgs = {Facing.left: data.pngs[self.avatar.deadImg +'_left'], Facing.right: data.pngs[self.avatar.deadImg]}
class TeddySprite(EnemySprite): imgPrefix = 'ted' def __init__(self, enemy): self.enemy = enemy events.AddListener(self) self.currentAnim = Anim(self.imgPrefix + 'Walk', 5) #img = data.pngs['enemy.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) self.blinkingCounter = 0.0 self.shadow = ShadowSprite() self.shadow.scale = float(self.width) / self.shadow.width self.shadow.opacity = 100 self.hugImgs = { Facing.left: data.pngs[self.imgPrefix + 'Hug_left'], Facing.right: data.pngs[self.imgPrefix + 'Hug'] } self.stunImgs = { Facing.left: data.pngs[self.imgPrefix + 'Stun_left'], Facing.right: data.pngs[self.imgPrefix + 'Stun'] } self.idleImg = data.pngs[self.imgPrefix + 'Stand'] self.walkImg = self.currentAnim.animation def draw(self): self.shadow.draw() if hasattr(self.enemy, 'mad') and self.enemy.mad: self.color = (200, 10, 10) EnemySprite.draw(self) def update(self, timeChange=None): EnemySprite.update(self, timeChange) if self.enemy.state in State.walkingStates: if self.enemy.facing != self.currentAnim.facing: self.currentAnim.flip() self.image = self.currentAnim.animation elif self.image != self.currentAnim.animation: self.image = self.currentAnim.animation elif self.enemy.state in State.attackingStates: self.image = self.hugImgs[self.enemy.facing] elif self.enemy.state == State.stunned: self.image = self.stunImgs[self.enemy.facing] elif self.enemy.state == State.idle: self.image = self.idleImg self.shadow.x = self.x self.shadow.y = self.y - (self.shadow.height / 2 ) #shadow center = feetpos
def __init__(self, avatar): self.done = False self.avatar = avatar self.currentAnim = Anim("subWalkSquash", 5) # img = data.pngs['avatar.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) events.AddListener(self) self.blinkingCounter = 0.0 self.yoyo = yoyo.YoYo() self.shadow = ShadowSprite() self.shadow.scale = float(self.width) / self.shadow.width self.shadow.opacity = 128 self.on_key_press = window.window.event(self.on_key_press) self.on_key_release = window.window.event(self.on_key_release) self.mouseButton = None self.on_mouse_press = window.window.event(self.on_mouse_press) self.on_mouse_release = window.window.event(self.on_mouse_release) self.attackImgs = { Facing.left: data.pngs[self.avatar.attackImg + "_left"], Facing.right: data.pngs[self.avatar.attackImg], } self.deadImgs = { Facing.left: data.pngs[self.avatar.deadImg + "_left"], Facing.right: data.pngs[self.avatar.deadImg], }
class ThrownBottleSprite(pyglet.sprite.Sprite): def __init__(self): self.currentAnim = animation.BeerThrowAnim() pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) self.shadow = ShadowSprite() self.shadow.scale = float(self.width)/self.shadow.width self.shadow.opacity = 128 def draw(self): self.shadow.x = self.x self.shadow.y = self.y - (self.shadow.height/2) #shadow center = feetpos self.shadow.draw() pyglet.sprite.Sprite.draw(self) def update(self, timeChange=None): pass
class ThrownBottleSprite(pyglet.sprite.Sprite): def __init__(self): self.currentAnim = animation.BeerThrowAnim() pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) self.shadow = ShadowSprite() self.shadow.scale = float(self.width) / self.shadow.width self.shadow.opacity = 128 def draw(self): self.shadow.x = self.x self.shadow.y = self.y - (self.shadow.height / 2 ) #shadow center = feetpos self.shadow.draw() pyglet.sprite.Sprite.draw(self) def update(self, timeChange=None): pass
class TeddySprite(EnemySprite): imgPrefix = 'ted' def __init__(self, enemy): self.enemy = enemy events.AddListener(self) self.currentAnim = Anim(self.imgPrefix+'Walk', 5) #img = data.pngs['enemy.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) self.blinkingCounter = 0.0 self.shadow = ShadowSprite() self.shadow.scale = float(self.width)/self.shadow.width self.shadow.opacity = 100 self.hugImgs = {Facing.left: data.pngs[self.imgPrefix+'Hug_left'], Facing.right: data.pngs[self.imgPrefix+'Hug']} self.stunImgs = {Facing.left: data.pngs[self.imgPrefix+'Stun_left'], Facing.right: data.pngs[self.imgPrefix+'Stun']} self.idleImg = data.pngs[self.imgPrefix+'Stand'] self.walkImg = self.currentAnim.animation def draw(self): self.shadow.draw() if hasattr(self.enemy, 'mad') and self.enemy.mad: self.color = (200, 10, 10) EnemySprite.draw(self) def update(self, timeChange=None): EnemySprite.update(self, timeChange) if self.enemy.state in State.walkingStates: if self.enemy.facing != self.currentAnim.facing: self.currentAnim.flip() self.image = self.currentAnim.animation elif self.image != self.currentAnim.animation: self.image = self.currentAnim.animation elif self.enemy.state in State.attackingStates: self.image = self.hugImgs[self.enemy.facing] elif self.enemy.state == State.stunned: self.image = self.stunImgs[self.enemy.facing] elif self.enemy.state == State.idle: self.image = self.idleImg self.shadow.x = self.x self.shadow.y = self.y - (self.shadow.height/2) #shadow center = feetpos
def __init__(self, enemy): self.enemy = enemy events.AddListener(self) self.currentAnim = Anim(self.imgPrefix + 'Walk', 5) #img = data.pngs['enemy.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) self.blinkingCounter = 0.0 self.shadow = ShadowSprite() self.shadow.scale = float(self.width) / self.shadow.width self.shadow.opacity = 100 self.hugImgs = { Facing.left: data.pngs[self.imgPrefix + 'Hug_left'], Facing.right: data.pngs[self.imgPrefix + 'Hug'] } self.stunImgs = { Facing.left: data.pngs[self.imgPrefix + 'Stun_left'], Facing.right: data.pngs[self.imgPrefix + 'Stun'] } self.idleImg = data.pngs[self.imgPrefix + 'Stand'] self.walkImg = self.currentAnim.animation
def __init__(self, enemy): self.enemy = enemy events.AddListener(self) self.currentAnim = Anim(self.imgPrefix+'Walk', 5) #img = data.pngs['enemy.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) self.blinkingCounter = 0.0 self.shadow = ShadowSprite() self.shadow.scale = float(self.width)/self.shadow.width self.shadow.opacity = 100 self.hugImgs = {Facing.left: data.pngs[self.imgPrefix+'Hug_left'], Facing.right: data.pngs[self.imgPrefix+'Hug']} self.stunImgs = {Facing.left: data.pngs[self.imgPrefix+'Stun_left'], Facing.right: data.pngs[self.imgPrefix+'Stun']} self.idleImg = data.pngs[self.imgPrefix+'Stand'] self.walkImg = self.currentAnim.animation
class AvatarSprite(pyglet.sprite.Sprite): def __init__(self, avatar): self.done = False self.avatar = avatar self.currentAnim = Anim("subWalkSquash", 5) # img = data.pngs['avatar.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) events.AddListener(self) self.blinkingCounter = 0.0 self.yoyo = yoyo.YoYo() self.shadow = ShadowSprite() self.shadow.scale = float(self.width) / self.shadow.width self.shadow.opacity = 128 self.on_key_press = window.window.event(self.on_key_press) self.on_key_release = window.window.event(self.on_key_release) self.mouseButton = None self.on_mouse_press = window.window.event(self.on_mouse_press) self.on_mouse_release = window.window.event(self.on_mouse_release) self.attackImgs = { Facing.left: data.pngs[self.avatar.attackImg + "_left"], Facing.right: data.pngs[self.avatar.attackImg], } self.deadImgs = { Facing.left: data.pngs[self.avatar.deadImg + "_left"], Facing.right: data.pngs[self.avatar.deadImg], } def draw(self): self.shadow.draw() pyglet.sprite.Sprite.draw(self) if self.avatar.yoyo and not self.avatar.health == 0: if self.avatar.selectedAttack: self.avatar.selectedAttack.draw(self.avatar, self.yoyo) else: self.yoyo.draw() def update(self, timeChange=None): self.avatar.update(timeChange) if self.done: return self.cleanup() if self.avatar.state == State.attacking: self.image = self.attackImgs[self.avatar.facing] elif self.avatar.health == 0: self.image = self.deadImgs[self.avatar.facing] else: if self.avatar.facing != self.currentAnim.facing: self.currentAnim.flip() self.image = self.currentAnim.animation elif self.image != self.currentAnim.animation: self.image = self.currentAnim.animation if self.blinkingCounter > 0: self.opacity = (10 + self.opacity) % 255 self.blinkingCounter -= timeChange elif not self.opacity == 255: self.opacity = 255 self.x = self.avatar.x self.y = self.avatar.y self.x += window.bgOffset[0] self.y += window.bgOffset[1] if self.avatar.yoyo: self.avatar.yoyo.gfxYoyo = self.yoyo self.yoyo.moveToFeetPos(self.avatar.feetPos, self.avatar.facing) self.yoyo.stringMaxLength = self.avatar.getStringLength() * 30 if not self.avatar.selectedAttack: self.yoyo.update(timeChange) self.shadow.x = self.x self.shadow.y = self.y - (self.shadow.height / 2) # shadow center = feetpos if self.avatar.health == 0: self.shadow.y += 10 def On_AttackHit(self, attack, attacker, victim): if victim == self.avatar: self.blinkingCounter = 1.0 def On_LevelCompletedEvent(self, *args): # clean up self.done = True def cleanup(): events.RemoveListener(self) del self.avatar del self.currentAnim del self.yoyo del self.shadow del self.mouseButton del self.attackImgs del self.deadImgs del self.on_key_press del self.on_key_release del self.on_mouse_press del self.on_mouse_release def press(self): from pyglet.window import key if keysPressed.get(key.DOWN): self.yoyo.throw("walkthedog") self.avatar.setAttack("walkthedog") elif keysPressed.get(key.UP): self.yoyo.throw("shootthemoon") self.avatar.setAttack("shootthemoon") else: self.yoyo.throw("looping") self.avatar.setAttack("looping") self.avatar.doAttack() def on_key_press(self, symbol, modifiers): if self.avatar.health == 0: return from pyglet.window import key keysPressed[symbol] = True if keysPressed.get(key.LCTRL) or keysPressed.get(key.SPACE): self.press() else: moveDict = { key.UP: self.avatar.On_UpKeyPress, key.W: self.avatar.On_UpKeyPress, key.RIGHT: self.avatar.On_RightKeyPress, key.D: self.avatar.On_RightKeyPress, key.DOWN: self.avatar.On_DownKeyPress, key.S: self.avatar.On_DownKeyPress, key.LEFT: self.avatar.On_LeftKeyPress, key.A: self.avatar.On_DownKeyPress, } fn = moveDict.get(symbol) if fn: # oldFacing = self.avatar.facing fn() # print 'old', oldFacing, 'new', self.avatar.facing # if self.avatar.facing != oldFacing: # self.currentAnim.flip() def release(self): self.yoyo.yoyoReturn = True self.avatar.fireSpecial() def on_key_release(self, symbol, modifiers): from pyglet.window import key keysPressed[symbol] = False if symbol in [key.LCTRL, key.SPACE] and self.yoyo.moveType: self.release() moveDict = { key.UP: self.avatar.On_UpKeyRelease, key.W: self.avatar.On_UpKeyRelease, key.RIGHT: self.avatar.On_RightKeyRelease, key.D: self.avatar.On_RightKeyRelease, key.DOWN: self.avatar.On_DownKeyRelease, key.S: self.avatar.On_DownKeyRelease, key.LEFT: self.avatar.On_LeftKeyRelease, key.A: self.avatar.On_LeftKeyRelease, } fn = moveDict.get(symbol) if fn: fn() def on_mouse_press(self, x, y, button, modifiers): self.mouseButton = button self.press() def on_mouse_release(self, x, y, button, modifiers): if self.mouseButton == button: self.release()
def __init__(self): self.currentAnim = animation.BeerThrowAnim() pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) self.shadow = ShadowSprite() self.shadow.scale = float(self.width) / self.shadow.width self.shadow.opacity = 128
def __init__(self): self.currentAnim = animation.BeerThrowAnim() pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) self.shadow = ShadowSprite() self.shadow.scale = float(self.width)/self.shadow.width self.shadow.opacity = 128
class AvatarSprite(pyglet.sprite.Sprite): def __init__(self, avatar): self.done = False self.avatar = avatar self.currentAnim = Anim('subWalkSquash', 5) #img = data.pngs['avatar.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) events.AddListener(self) self.blinkingCounter = 0.0 self.yoyo = yoyo.YoYo() self.shadow = ShadowSprite() self.shadow.scale = float(self.width)/self.shadow.width self.shadow.opacity = 128 self.on_key_press = window.window.event(self.on_key_press) self.on_key_release = window.window.event(self.on_key_release) self.mouseButton = None self.on_mouse_press = window.window.event(self.on_mouse_press) self.on_mouse_release = window.window.event(self.on_mouse_release) self.attackImgs = {Facing.left: data.pngs[self.avatar.attackImg +'_left'], Facing.right: data.pngs[self.avatar.attackImg]} self.deadImgs = {Facing.left: data.pngs[self.avatar.deadImg +'_left'], Facing.right: data.pngs[self.avatar.deadImg]} def draw(self): self.shadow.draw() pyglet.sprite.Sprite.draw(self) if self.avatar.yoyo and not self.avatar.health == 0: if self.avatar.selectedAttack: self.avatar.selectedAttack.draw(self.avatar, self.yoyo) else: self.yoyo.draw() def update(self, timeChange=None): self.avatar.update(timeChange) if self.done: return self.cleanup() if self.avatar.state == State.attacking: self.image = self.attackImgs[self.avatar.facing] elif self.avatar.health == 0: self.image = self.deadImgs[self.avatar.facing] else: if self.avatar.facing != self.currentAnim.facing: self.currentAnim.flip() self.image = self.currentAnim.animation elif self.image != self.currentAnim.animation: self.image = self.currentAnim.animation if self.blinkingCounter > 0: self.opacity = (10 + self.opacity) % 255 self.blinkingCounter -= timeChange elif not self.opacity == 255: self.opacity = 255 self.x = self.avatar.x self.y = self.avatar.y self.x += window.bgOffset[0] self.y += window.bgOffset[1] if self.avatar.yoyo: self.avatar.yoyo.gfxYoyo = self.yoyo self.yoyo.moveToFeetPos(self.avatar.feetPos, self.avatar.facing) self.yoyo.stringMaxLength = self.avatar.getStringLength()*30 if not self.avatar.selectedAttack: self.yoyo.update(timeChange) self.shadow.x = self.x self.shadow.y = self.y - (self.shadow.height/2) #shadow center = feetpos if self.avatar.health == 0: self.shadow.y += 10 def On_AttackHit(self, attack, attacker, victim): if victim == self.avatar: self.blinkingCounter = 1.0 def On_LevelCompletedEvent(self, *args): # clean up self.done = True def cleanup(): events.RemoveListener(self) del self.avatar del self.currentAnim del self.yoyo del self.shadow del self.mouseButton del self.attackImgs del self.deadImgs del self.on_key_press del self.on_key_release del self.on_mouse_press del self.on_mouse_release def press(self): from pyglet.window import key if keysPressed.get(key.DOWN): self.yoyo.throw('walkthedog') self.avatar.setAttack('walkthedog') elif keysPressed.get(key.UP): self.yoyo.throw('shootthemoon') self.avatar.setAttack('shootthemoon') else: self.yoyo.throw('looping') self.avatar.setAttack('looping') self.avatar.doAttack() def on_key_press(self, symbol, modifiers): if self.avatar.health == 0: return from pyglet.window import key keysPressed[symbol] = True if (keysPressed.get(key.LCTRL) or keysPressed.get(key.SPACE)): self.press() else: moveDict = { key.UP: self.avatar.On_UpKeyPress, key.W: self.avatar.On_UpKeyPress, key.RIGHT: self.avatar.On_RightKeyPress, key.D: self.avatar.On_RightKeyPress, key.DOWN: self.avatar.On_DownKeyPress, key.S: self.avatar.On_DownKeyPress, key.LEFT: self.avatar.On_LeftKeyPress, key.A: self.avatar.On_DownKeyPress, } fn = moveDict.get(symbol) if fn: #oldFacing = self.avatar.facing fn() #print 'old', oldFacing, 'new', self.avatar.facing #if self.avatar.facing != oldFacing: #self.currentAnim.flip() def release(self): self.yoyo.yoyoReturn = True self.avatar.fireSpecial() def on_key_release(self, symbol, modifiers): from pyglet.window import key keysPressed[symbol] = False if symbol in [key.LCTRL,key.SPACE] and self.yoyo.moveType: self.release() moveDict = { key.UP: self.avatar.On_UpKeyRelease, key.W: self.avatar.On_UpKeyRelease, key.RIGHT: self.avatar.On_RightKeyRelease, key.D: self.avatar.On_RightKeyRelease, key.DOWN: self.avatar.On_DownKeyRelease, key.S: self.avatar.On_DownKeyRelease, key.LEFT: self.avatar.On_LeftKeyRelease, key.A: self.avatar.On_LeftKeyRelease, } fn = moveDict.get(symbol) if fn: fn() def on_mouse_press(self, x, y, button, modifiers): self.mouseButton = button self.press() def on_mouse_release(self, x, y, button, modifiers): if self.mouseButton == button: self.release()