예제 #1
0
파일: mapObject.py 프로젝트: arikel/PPARPG
class EquippedObject(MapObject):
	def __init__(self, npc, modelPath, texturePath=None):
		self.npc = npc
		self.modelPath = modelPath
		self.texturePath = texturePath
		
		self.model = Actor(self.modelPath, self.npc.animDic)
		#self.model.setTransparency(True)
		
		self.model.reparentTo(self.npc.model)
		if texturePath is not None:
			self.tex = loader.loadTexture(texturePath)
			self.model.clearTexture(TextureStage.getDefault())
			self.model.clearTexture()
			self.model.setTexture(TextureStage.getDefault(), self.tex)
			#print "Adding object with texture : %s" % texturePath
			
	def loop(self, animName):
		self.model.loop(animName)
		
	def destroy(self):
		self.model.cleanup()
		self.model.remove()	
예제 #2
0
class EquippedObject(MapObject):
    def __init__(self, npc, modelPath, texturePath=None):
        self.npc = npc
        self.modelPath = modelPath
        self.texturePath = texturePath

        self.model = Actor(self.modelPath, self.npc.animDic)
        #self.model.setTransparency(True)

        self.model.reparentTo(self.npc.model)
        if texturePath is not None:
            self.tex = loader.loadTexture(texturePath)
            self.model.clearTexture(TextureStage.getDefault())
            self.model.clearTexture()
            self.model.setTexture(TextureStage.getDefault(), self.tex)
            #print "Adding object with texture : %s" % texturePath

    def loop(self, animName):
        self.model.loop(animName)

    def destroy(self):
        self.model.cleanup()
        self.model.remove()
예제 #3
0
파일: mapObject.py 프로젝트: arikel/PPARPG
class MapObject(MapObjectBase):
	"""MapObject can't move or change map in game"""
	def __init__(self, map, genre, name):
		MapObjectBase.__init__(self, name)
		self.map = map # reference to the Map the object belongs to
		self.genre = genre # NPC, building, decor, item, warp...
		self.name = name
		self.model = None
		self.modelPath = None
		self.texturePath = None
		
		self.state = None
		self.data = {}
		self.dialog = None
		self.task = None
		self.posTask = None
		
		if self.genre in mapObjectDB:
			self.loadModel(mapObjectDB[self.genre][0], mapObjectDB[self.genre][1])
			self.addCollision(mapObjectDB[self.genre][2])
			#self.oldPos= Point3()
		
		'''	
		if self.genre is not "NPC":
			print("\n\n- mapObject init : %s, pos = %s" % (self.name, self.getPos()))
			self.posTask = taskMgr.add(self.checkPosTask, "posTask")
		else:
			self.posTask = None
		'''
		
	def checkPosTask(self, task):
		if self.getPos() != self.oldPos:
			print "WARNING : map object pos changed from %s to %s, correcting" % (self.oldPos, self.getPos())
			#self.oldPos = self.getPos()
			self.setPos(self.oldPos)
		#else:
		#	print "%s pos is still %s" % (self.name, self.oldPos)
		return task.cont
		
	def addCollision(self, pos):
		self.colSphere = CollisionSphere(pos[0],pos[1],pos[2],pos[3])
		#self.colSphere = CollisionTube(0,0,0,0,0,1.8,0.4)
		self.colNodepath = CollisionNode(self.name)
		self.colNode = self.model.attachNewNode(self.colNodepath)
		self.colNode.node().addSolid(self.colSphere)
		
	def loadModel(self, modelPath, texturePath=None):
		if self.model:
			self.model.remove()
		self.modelPath = modelPath
		self.model = loader.loadModel(modelPath)
		self.model.setTransparency(TransparencyAttrib.MAlpha)
		
		if texturePath:
			tex = loader.loadTexture(texturePath)
			self.texturePath = texturePath
			self.model.setTexture(tex)
		self.model.reparentTo(self)
		
	def loadActor(self, modelPath, animDic={}, texturePath=None):
		if self.model is not None:
			self.model.remove()
		
		self.model = Actor(modelPath, animDic)
		#self.model.setTransparency(True)
		
		if texturePath is not None:
			self.tex = loader.loadTexture(texturePath)
			#self.model.clearTexture(TextureStage.getDefault())
			self.model.clearTexture()
			self.model.setTexture(TextureStage.getDefault(), self.tex)
		self.currentAnim = None
		self.model.reparentTo(self)
		
	#def reparentTo(self, np):
	#	self.model.reparentTo(np)
		#if self.genre is not "NPC":
		#	print "Reparenting %s to %s, pos is now %s" % (self.name, str(np), self.getPos())
		
	def getSaveData(self):
		data = []
		data.append(self.name)
		data.append(self.genre)
		data.append(self.model.getPos())
		data.append(self.model.getHpr())
		data.append(self.model.getScale())
		return data
		
		
	#-------------------------------------------------------------------
	# Pos
	def setPos(self, pos):
		#self.model.setPos(pos[0], pos[1], pos[2])
		'''
		if self.genre is not "NPC":
			print "- mapObject (%s): set pos, oldpos = %s, newpos = %s" % (self.name, self.getPos(), pos)
		'''
		self.model.setPos(pos)
		'''
		if self.genre is not "NPC":
			print "--- after setPos, mapObject pos = %s" % (self.getPos())
		self.oldPos = pos
		'''
		
	def getPos(self):
		if self.model: return self.model.getPos()
		else: return None	
	
	def setZ(self, z):
		self.model.setZ(z)
		
	def getZ(self):
		return self.model.getZ()
	
	def setTilePos(self, x, y):
		self.setPos((x+0.5, y+0.5, self.model.getZ()))
		
	def getTilePos(self):
		return int(self.model.getX()), int(self.model.getY())
	
	def moveZ(self, dt=0.01):
		self.model.setZ(self.model.getZ()+dt)
		
	#-------------------------------------------------------------------
	# Hpr
	def setHpr(self, hpr):
		self.model.setHpr(hpr)
		
	def getRot(self):
		return self.model.getH()
		
	def setRot(self, n):
		self.model.setH(n)
	
	def rotate(self, dt=0.01):
		self.model.setH(self.model.getH()+dt*50)
	
	#-------------------------------------------------------------------
	# Scale
	def setScale(self, scale):
		self.model.setScale(scale)
		
	def getScale(self):
		return self.model.getScale()
	
	def getScaleX(self):
		return self.model.getSx()
		
	def scale(self, dt=0.01):
		self.model.setScale(self.model.getSx() + dt)
		
	
		
	def destroy(self):
		if self.task:
			taskMgr.remove(self.task)
		if self.posTask:
			taskMgr.remove(self.posTask)
			
		if self.model:
			self.model.detachNode()
			self.model.remove()
예제 #4
0
class MapObject(MapObjectBase):
    """MapObject can't move or change map in game"""
    def __init__(self, map, genre, name):
        MapObjectBase.__init__(self, name)
        self.map = map  # reference to the Map the object belongs to
        self.genre = genre  # NPC, building, decor, item, warp...
        self.name = name
        self.model = None
        self.modelPath = None
        self.texturePath = None

        self.state = None
        self.data = {}
        self.dialog = None
        self.task = None
        self.posTask = None

        if self.genre in mapObjectDB:
            self.loadModel(mapObjectDB[self.genre][0],
                           mapObjectDB[self.genre][1])
            self.addCollision(mapObjectDB[self.genre][2])
            #self.oldPos= Point3()
        '''	
		if self.genre is not "NPC":
			print("\n\n- mapObject init : %s, pos = %s" % (self.name, self.getPos()))
			self.posTask = taskMgr.add(self.checkPosTask, "posTask")
		else:
			self.posTask = None
		'''

    def checkPosTask(self, task):
        if self.getPos() != self.oldPos:
            print "WARNING : map object pos changed from %s to %s, correcting" % (
                self.oldPos, self.getPos())
            #self.oldPos = self.getPos()
            self.setPos(self.oldPos)
        #else:
        #	print "%s pos is still %s" % (self.name, self.oldPos)
        return task.cont

    def addCollision(self, pos):
        self.colSphere = CollisionSphere(pos[0], pos[1], pos[2], pos[3])
        #self.colSphere = CollisionTube(0,0,0,0,0,1.8,0.4)
        self.colNodepath = CollisionNode(self.name)
        self.colNode = self.model.attachNewNode(self.colNodepath)
        self.colNode.node().addSolid(self.colSphere)

    def loadModel(self, modelPath, texturePath=None):
        if self.model:
            self.model.remove()
        self.modelPath = modelPath
        self.model = loader.loadModel(modelPath)
        self.model.setTransparency(TransparencyAttrib.MAlpha)

        if texturePath:
            tex = loader.loadTexture(texturePath)
            self.texturePath = texturePath
            self.model.setTexture(tex)
        self.model.reparentTo(self)

    def loadActor(self, modelPath, animDic={}, texturePath=None):
        if self.model is not None:
            self.model.remove()

        self.model = Actor(modelPath, animDic)
        #self.model.setTransparency(True)

        if texturePath is not None:
            self.tex = loader.loadTexture(texturePath)
            #self.model.clearTexture(TextureStage.getDefault())
            self.model.clearTexture()
            self.model.setTexture(TextureStage.getDefault(), self.tex)
        self.currentAnim = None
        self.model.reparentTo(self)

    #def reparentTo(self, np):
    #	self.model.reparentTo(np)
    #if self.genre is not "NPC":
    #	print "Reparenting %s to %s, pos is now %s" % (self.name, str(np), self.getPos())

    def getSaveData(self):
        data = []
        data.append(self.name)
        data.append(self.genre)
        data.append(self.model.getPos())
        data.append(self.model.getHpr())
        data.append(self.model.getScale())
        return data

    #-------------------------------------------------------------------
    # Pos
    def setPos(self, pos):
        #self.model.setPos(pos[0], pos[1], pos[2])
        '''
		if self.genre is not "NPC":
			print "- mapObject (%s): set pos, oldpos = %s, newpos = %s" % (self.name, self.getPos(), pos)
		'''
        self.model.setPos(pos)
        '''
		if self.genre is not "NPC":
			print "--- after setPos, mapObject pos = %s" % (self.getPos())
		self.oldPos = pos
		'''

    def getPos(self):
        if self.model: return self.model.getPos()
        else: return None

    def setZ(self, z):
        self.model.setZ(z)

    def getZ(self):
        return self.model.getZ()

    def setTilePos(self, x, y):
        self.setPos((x + 0.5, y + 0.5, self.model.getZ()))

    def getTilePos(self):
        return int(self.model.getX()), int(self.model.getY())

    def moveZ(self, dt=0.01):
        self.model.setZ(self.model.getZ() + dt)

    #-------------------------------------------------------------------
    # Hpr
    def setHpr(self, hpr):
        self.model.setHpr(hpr)

    def getRot(self):
        return self.model.getH()

    def setRot(self, n):
        self.model.setH(n)

    def rotate(self, dt=0.01):
        self.model.setH(self.model.getH() + dt * 50)

    #-------------------------------------------------------------------
    # Scale
    def setScale(self, scale):
        self.model.setScale(scale)

    def getScale(self):
        return self.model.getScale()

    def getScaleX(self):
        return self.model.getSx()

    def scale(self, dt=0.01):
        self.model.setScale(self.model.getSx() + dt)

    def destroy(self):
        if self.task:
            taskMgr.remove(self.task)
        if self.posTask:
            taskMgr.remove(self.posTask)

        if self.model:
            self.model.detachNode()
            self.model.remove()