class Monster(Sprite): def __init__(self, img, map=None, pos=None, stats=None, x=0, y=0, blend_src=pyglet.gl.GL_SRC_ALPHA, blend_dest=pyglet.gl.GL_ONE_MINUS_SRC_ALPHA, batch=None, group=None, usage='dynamic'): if stats is None: self.stats = Stats(self) else: self.stats = stats self.map = map self.pos = pos self.blocked = True self.oldPos = pos self.playerOldPos = None self.dead = False self.currentPath = [] Sprite.__init__(self, img, x, y, blend_src, blend_dest, batch, group, usage) def updateState(self, map): mapPos = map.getCellAtPos(self.pos) if self.dead == True: return if mapPos.visible: self.currentPath = [] pFinder = findPath(map,self.pos,map.player.pos) pIter = pFinder.iter pIter.next() for p in pIter: self.currentPath.append(p) self.playerOldPos = map.player.pos try: next = self.currentPath.pop(0) except IndexError: return self.moveOrAttack(map, mapPos, next) def moveOrAttack(self, map, curPos, nextPos): if nextPos == map.player.pos: self.stats.attackOther(map.player) else: curPos.objects.remove(self) map.getCellAtPos(nextPos).objects.append(self) lastMapPos = map.getCellAtPos(self.oldPos) self.oldPos = self.pos self.pos = nextPos
class Player(Sprite): def __init__(self, x=0, y=0, map=None, blend_src=pyglet.gl.GL_SRC_ALPHA, blend_dest=pyglet.gl.GL_ONE_MINUS_SRC_ALPHA, pos=None, batch=None, group=None, usage='dynamic', ): self.dead = False self.charName = 'Player' self.charClass = 'Fighter' self.map = map self.mbox = msgBox() img = sheet['class'][79] self.stats = Stats(self, Con=18, hpRoll=20) self.statuswindow = statusWindow(self, batch, group) if pos is None: self.pos = Position() else: self.pos = pos Sprite.__init__(self, img, x, y, blend_src, blend_dest, batch, group, usage) def moveOrAttack(self, map, incPos): xPx, yPx = self.x, self.y newPos = Position(self.pos.x + incPos.x, self.pos.y + incPos.y) newCell = map.getCellAtPos(newPos) if newCell.blockedByTerrain: if newCell.type == DUNGEON_DOOR: newCell.type = OPEN_DOOR newCell.blockedByTerrain = False self.map.objectUpdateRequired = 1 elif newCell.blockedByObject: if len(newCell.objects) == 1: self.stats.attackOther(newCell.objects[0]) else: raise ValueError('cell should not have two objects!') else: map.getCellAtPos(self.pos).blockedByObject = False self.set_position(xPx + incPos.x * SPRITE_SIZE, yPx + incPos.y * SPRITE_SIZE) self.pos = newPos map.objectUpdateRequired = 1 self.statuswindow.updateStats()
def __init__(self, img, map=None, pos=None, stats=None, x=0, y=0, blend_src=pyglet.gl.GL_SRC_ALPHA, blend_dest=pyglet.gl.GL_ONE_MINUS_SRC_ALPHA, batch=None, group=None, usage='dynamic'): if stats is None: self.stats = Stats(self) else: self.stats = stats self.map = map self.pos = pos self.blocked = True self.oldPos = pos self.playerOldPos = None self.dead = False self.currentPath = [] Sprite.__init__(self, img, x, y, blend_src, blend_dest, batch, group, usage)
def __init__(self, x=0, y=0, map=None, blend_src=pyglet.gl.GL_SRC_ALPHA, blend_dest=pyglet.gl.GL_ONE_MINUS_SRC_ALPHA, pos=None, batch=None, group=None, usage='dynamic', ): self.dead = False self.charName = 'Player' self.charClass = 'Fighter' self.map = map self.mbox = msgBox() img = sheet['class'][79] self.stats = Stats(self, Con=18, hpRoll=20) self.statuswindow = statusWindow(self, batch, group) if pos is None: self.pos = Position() else: self.pos = pos Sprite.__init__(self, img, x, y, blend_src, blend_dest, batch, group, usage)