Пример #1
0
class CDonu (CEnemy):
    def __init__(self, x, y, z):
        CEnemy.__init__(self, x, y, z)
        
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        #---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        self.life = 1
        self.scale = (2.5,1.0,3.0)
        self.bitmap = Image();
        self.model = self.bitmap.loadModel("./models/Square.egg", "./tex/eDona.png", self.posX, self.posY, self.posZ, self.scale)
        
        # Sound
        self.soundDeath = base.loadSfx('./sound/die3.wav')
        self.soundDeath.setVolume(.5)
        
    #end __init__
    
    #-----------------------------------------------------------------------------------------------------------------------------------------------
    #----------------------------------------------------------------FUNCTIONS----------------------------------------------------------------------
    #-----------------------------------------------------------------------------------------------------------------------------------------------
    # It shoots an attack to the point where is the main character at that moment
    def attack(self,mainCharX,mainCharY,mainCharZ):
        char = [mainCharX,mainCharY,mainCharZ]
        enemy = [self.posX,self.posY,self.posZ]
        
        self.att = Attack("ENEMY", "DONA", self, char)
        self.attacking = True;
    #end attack
    
#end class CDona
Пример #2
0
class IBanana (Item):
    def __init__(self, x, y, z, scale):
        Item.__init__(self, x, y, z)
        
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        #---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        self.scale = scale;
        self.energy = 25;
        self.powerAbility = 35;
        self.type = "FRUIT"
        self.specialItem = True
        self.bitmap = Image()
        self.model = self.bitmap.loadModel("./models/Square.egg", "./tex/banana_s.png", self.posX, self.posY, self.posZ, self.scale)        
    #end __init__
    
#end class IBanana
Пример #3
0
class ILetuce (Item):
    def __init__(self, x, y, z, scale):
        Item.__init__(self, x, y, z)
        
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        #---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        self.scale = scale;
        self.energy = 15;
        self.powerAbility = 35;
        self.type = "VEGETABLE"
        self.specialItem = False
        self.bitmap = Image()
        self.model = self.bitmap.loadModel("./models/Square.egg", "./tex/letuce.png", self.posX, self.posY, self.posZ, self.scale)        
    #end __init__
    
#end class ILetuce
Пример #4
0
class Attack (DirectObject):	
	def __init__(self, type, enemy_type, enemies, char):
		#-----------------------------------------------------------------------------------------------------------------------------------------------
		#---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
		#-----------------------------------------------------------------------------------------------------------------------------------------------
		self.posX = 0
		self.posY = 0
		self.posZ = 0
		self.bitmap = None
		self.flag = True
		self.lastTime = 0.0
		self.tex1 = "None"
		self.tex2 = "None"
		self.texFinal = "None"
		self.isexploding = False
		
		# Character Attack
		self.nearEnemy = None
		self.mainChar = None
		
		# Enemy attack
		self.enemy = None
		self.finalX = 0
		self.finalY = 0
		self.finalZ = 0		
		
		if( type == "ENEMY"):
			#-----------------------------------------------------------------------------------------------------------------------------------------------
			#----------------------------------------------------------------ENEMY ATTACK INIT--------------------------------------------------------------
			#-----------------------------------------------------------------------------------------------------------------------------------------------
			# Initial position
			self.posX = enemies.posX
			self.posY = enemies.posY
			self.posZ = enemies.posZ
			
			self.enemy = enemies
			
			# Destination position
			self.finalX = char[0]
			self.finalY = char[1]
			self.finalZ = char[2]
			
			# Generate attack
			self.bitmap = Image()
			if enemy_type == "HAMBURGUER": 	
				self.bitmap = self.bitmap.loadModel("./models/Square.egg", "./tex/ham_attack1.png", self.posX, self.posY, self.posZ, scale = (1.6,1.0,0.75))
				self.tex1 = "./tex/ham_attack1.png"
				self.tex2 = "./tex/ham_attack2.png"
				self.texFinal = "./tex/ham_exp.png"
				self.sound = base.loadSfx('./sound/enemyHit.wav')
			if enemy_type == "CAN": 	
				self.bitmap = self.bitmap.loadModel("./models/Square.egg", "./tex/can_attack1.png", self.posX, self.posY, self.posZ, (1.0,1.0,0.75))
				self.tex1 = "./tex/can_attack1.png"
				self.tex2 = "./tex/can_attack2.png"
				self.texFinal = "./tex/can_exp.png"
				self.sound = base.loadSfx('./sound/enemyHit2.wav')
			if enemy_type == "DONA":	
				self.bitmap = self.bitmap.loadModel("./models/Square.egg", "./tex/dona_attack1.png", self.posX, self.posY, self.posZ, (1.6,1.0,0.75))
				self.tex1 = "./tex/dona_attack1.png"
				self.tex2 = "./tex/dona_attack2.png"
				self.texFinal = "./tex/dona_exp.png"
				self.sound = base.loadSfx('./sound/enemyHit3.wav')
			if enemy_type == "POTATOES":	
				self.bitmap = self.bitmap.loadModel("./models/Square.egg", "./tex/potatoes_attack1.png", self.posX, self.posY, self.posZ, (1.5,1.0,0.75) )
				self.tex1 = "./tex/potatoes_attack1.png"
				self.tex2 = "./tex/potatoes_attack2.png"
				self.texFinal = "./tex/potatoes_exp.png"
				self.sound = base.loadSfx('./sound/enemyHit.wav')
		
			# Shoot attack
			if self.finalX<self.posX:
				self.bitmap.setTexScale(TextureStage.getDefault(),1,1)    	
				self.interval = self.bitmap.posInterval(1.75, Point3(self.posX-15,self.finalZ,self.finalY))
				self.interval.start()
			else:
				self.bitmap.setTexScale(TextureStage.getDefault(),-1,1)
				self.interval = self.bitmap.posInterval(1.75, Point3(self.posX+15,self.finalZ,self.finalY))
				self.interval.start()
			
			# Tasks
			taskMgr.add(self.taskEnemyAttack, 'taskEnemyAttack' )
			taskMgr.add(self.taskAttackAnimation, 'taskAttackAnimation' )
		
			# Sound
			self.sound.setVolume(.3)
			self.sound.play()
		else:
			#-----------------------------------------------------------------------------------------------------------------------------------------------
			#----------------------------------------------------------------CHARACTER ATTACK INIT----------------------------------------------------------
			#-----------------------------------------------------------------------------------------------------------------------------------------------
			# Initial position
			self.posX = char.posX
			self.posY = char.posY
			self.posZ = char.posZ
			
			self.mainChar = char
	    
			# Searching nearest enemy to attack
			distMin = 99999999.9;
			if enemies == []:
			    # There are no enemies
			    self.nearEnemy = None
			else:
			    for x in enemies:
				distX = char.posX - x.posX
				distY = char.posY - x.posY
				distZ = char.posZ - x.posZ
				distX = distX*distX
				distY = distY*distY
				distZ = distZ*distZ
				distToEnemy = sqrt(distX+distY+distZ)
				
				# Nearest enemy
				if distToEnemy<distMin:
				    distMin = distToEnemy
				    self.nearEnemy = x
			
			# Generate attack    
			self.bitmap = Image()
			if(type == "GRAIN"):            self.bitmap = self.bitmap.loadModel("./models/Square.egg", "./tex/attacks/grain.png", self.posX, self.posY, self.posZ, (2.0,1.0,1.5))
			if(type == "FRUIT"):            self.bitmap = self.bitmap.loadModel("./models/Square.egg", "./tex/attacks/fruit.png", self.posX, self.posY, self.posZ, (2.0,1.0,1.5))
			if(type == "MILK"):             self.bitmap = self.bitmap.loadModel("./models/Square.egg", "./tex/attacks/milk.png", self.posX, self.posY, self.posZ, (2.0,1.0,1.5))
			if(type == "VEGETABLE"):        self.bitmap = self.bitmap.loadModel("./models/Square.egg", "./tex/attacks/vegetable.png", self.posX, self.posY, self.posZ, (2.0,1.0,1.5))
			if(type == "FISH"):             self.bitmap = self.bitmap.loadModel("./models/Square.egg", "./tex/attacks/fish.png", self.posX, self.posY, self.posZ, (2.0,1.0,1.5))
		    
			self.attacking = True;
			
			# Shoot attack
			if( self.nearEnemy == None ):
				self.interval = self.bitmap.posInterval(1.75, Point3(40,self.posZ,self.posY))
				self.interval.start()
			else:
				if self.nearEnemy.posX<self.posX:
					self.bitmap.setTexScale(TextureStage.getDefault(),1,1)    	
					self.interval = self.bitmap.posInterval(1.75, Point3(self.posX-20,self.posZ,self.posY))
					self.interval.start()
				else:
					self.bitmap.setTexScale(TextureStage.getDefault(),-1,1)
					self.interval = self.bitmap.posInterval(1.75, Point3(self.posX+20,self.nearEnemy.posZ,self.nearEnemy.posY))
					self.interval.start()
			
			# Tasks	
			taskMgr.add(self.taskCharAttack, 'taskCharAttack' )
			
			# Sound
			self.sound = base.loadSfx('./sound/charAttack.wav')
			self.sound.setVolume(.3)
			self.sound.play()
	    #end __init__

	#-----------------------------------------------------------------------------------------------------------------------------------------------
	#----------------------------------------------------------------FUNCTIONS----------------------------------------------------------------------
	#-----------------------------------------------------------------------------------------------------------------------------------------------
	# It studies distance between this enemy and character's attack.
	# It returns true if the distance is into collision's area.
	def en_charAttCollide(self, enemy):
		# Distance between the enemy and character's attack
		distX = self.posX - enemy.posX
		distY = self.posY - enemy.posY
		distZ = self.posZ - enemy.posZ
		distX = distX*distX
		distY = distY*distY
		distZ = distZ*distZ
		self.distAttack = sqrt(distX+distY+distZ)
		
		if self.distAttack <= 2.0:      return True
		else:                           return False
	#end en_charACollide
	
	# It studies the distance between Character and Enemy's Attack.
	# It returns true if the distance is into area collision.
	def char_enAttCollide(self, mainChar):
		# Distance between the character and the this enemy attack
		distX = self.posX - mainChar.posX
		distY = self.posY - mainChar.posY
		distZ = self.posZ - mainChar.posZ
		distX = distX*distX
		distY = distY*distY
		distZ = distZ*distZ
		self.distAttack = sqrt(distX+distY+distZ)
		
		if self.distAttack<=1.5:return True
		else: return False
       #end char_enACollide
       
	# Attack explosion
	def explode(self):
		taskMgr.remove('taskAttackAnimation')
		self.isexploding = True
		self.bitmap.clearTexture()
		tex = loader.loadTexture(self.texFinal) 
		self.bitmap.setTexture(tex, 1)
		self.bitmap.setScale((1.5,1.0,1.5))
	#end explode
       
	# Destroy this attack
	def destroyAttack(self):
		self.posX = -100
		self.bitmap.hide()
		self.bitmap.setX(self.posX)
		self.sound.stop()
		if self.mainChar != None:
			self.mainChar.attacking = False
		else:
			self.enemy.attacking = False
			
	#end destroyAttack
	
	
	#-----------------------------------------------------------------------------------------------------------------------------------------------
	#----------------------------------------------------------------TASKS,THREADS------------------------------------------------------------------
	#-----------------------------------------------------------------------------------------------------------------------------------------------
	# It makes move the attack of the character through the screen, 2 seconds of duration.
	def taskCharAttack(self, task):  
		if( task.time > 2 ):
		    self.destroyAttack()
		    return task.done
		else:		    
			self.posX = self.bitmap.getX()
			self.posZ = self.bitmap.getY()
			return task.cont
	#end taskCharAttack
	
	# It makes move the attack of the enemy through the screen, 2 seconds of duration.
	def taskEnemyAttack(self, task):
		if( task.time > 2 ):
		    self.destroyAttack()
		    return task.done
		else:
		    if self.isexploding == False:
				if ((self.finalX+0.075 > self.posX) and (self.finalX-0.075 < self.posX)):
					pass
				else:
					self.posX = self.bitmap.getX()
					self.posZ = self.bitmap.getY()
		    
		    return task.cont
	#end taskAttack
	
	#Attack animation
	def taskAttackAnimation(self,task):
		if task.time > 1.75:
			self.bitmap.clearTexture()
			tex = loader.loadTexture(self.texFinal) 
			self.bitmap.setTexture(tex, 1)
			self.bitmap.setScale((1.5,1.0,1.5))
			return task.done
		else:
			if (task.time - self.lastTime) > 0.15:
				self.lastTime = task.time
				if self.flag==True:
					self.bitmap.clearTexture()
					tex = loader.loadTexture(self.tex1) 
					self.bitmap.setTexture(tex, 1)
					self.flag = False
				else:
					self.bitmap.clearTexture()
					tex = loader.loadTexture(self.tex2) 
					self.bitmap.setTexture(tex, 1)
					self.flag = True
			return task.cont
	#end taskAttackAnimation
		
#end class Attack
Пример #5
0
class CMain (Character):
    def __init__(self, x, y, z):
        Character.__init__(self, x, y, z)
        
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        #---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        self.energy = 100
        self.power = array.array("I",[0,0,0,0,0])
        self.life = 3
        self.scale = 3.0
        self.bitmap = Image();
        self.walking = False
        self.model = self.bitmap.loadModel("./models/Square.egg", "./tex/boy.png", self.posX, self.posY, self.posZ, self.scale)
        self.isInvincible = False
        self.isVisible = True
        self.att = None
        self.attacking = False
        self.nearEnemy = None
        self.lastTime = 0.0
        self.soundDamage = base.loadSfx('./sound/damage.wav')
        self.soundDamage.setVolume(.8)
        
        self.lastPosX = 0
        self.lastPosY = 0
    #end __init__
    
    #-----------------------------------------------------------------------------------------------------------------------------------------------
    #----------------------------------------------------------------FUNCTIONS----------------------------------------------------------------------
    #-----------------------------------------------------------------------------------------------------------------------------------------------
    # It moves the character depending on sun pointer position on the screen
    def movement(self, x, y):
        self.walking = False
        
        if (y>=-1) and (y<=1):
            # Moving the character
            if (y<-0.75): realZ = 28
            if (y>-0.35) and (y<=1): realZ = 59
            if (y<=-0.35) and (y>=-0.75):
                #Z coordinate
                realZ = ( ( (y-(-0.35))/(-0.75-(-0.35)) )*(28-59) ) + 59
            
            # X coordinate    
            realX = ( ( (realZ-(28))/(59-28) )*(21-10) ) + 10
            
            # Velocity of the character depends on the distance to the sun pointer
            velX = math.fabs((x*realX) - self.posX)
            velY = math.fabs(realZ - self.posZ)
            modVel = (velX*velX) + 1.0
            modVel = (velX*velX) + (velY*velY)
            modVel = math.sqrt(modVel)
            modVelX = velX/modVel
            modVelY = velY/modVel

            # Moving the character to the correct side
            pointX = x*realX
            pointZ = realZ
            if self.posX > x*realX: pointX = self.posX - 0.625*modVelX
            if self.posX < x*realX: pointX = self.posX + 0.625*modVelX
            if self.posZ < realZ:   pointZ = self.posZ + 0.625*modVelY
            if self.posZ > realZ:   pointZ = self.posZ - 0.625*modVelY
            if( (self.posX < x*realX+0.3) and (self.posX > x*realX-0.3)  ):
                pass
            else:
                self.interval = self.model.posInterval(0.0625, Point3(pointX,pointZ,self.posY))
                self.interval.start()
            
            # Update position
            self.lastPosX = self.posX
            self.lastPosY = self.posY
            self.posX = self.model.getX()
            self.posZ = self.model.getY()
            
            # Checking if the character is walking or not
            if ( (math.fabs(self.posX-self.lastPosX) != 0) | (math.fabs(self.posY-self.lastPosY) != 0 ) ):
                self.walking = True
    #end movement
    
    # It gets an item and indentify the type to extract energy and power to the character
    def itemCollect(self, item):
        item.collectIt = True
        self.energy = self.energy + item.energy
        
        if self.energy>200: self.energy=200
        
        # Power ability
        if item.type == "GRAIN":        self.power[0] = self.power[0] + 1
        if item.type == "FRUIT":        self.power[1] = self.power[1] + 1
        if item.type == "MILK":         self.power[2] = self.power[2] + 1
        if item.type == "VEGETABLE":    self.power[3] = self.power[3] + 1
        if item.type == "FISH":         self.power[4] = self.power[4] + 1
        
        # Energy
        self.energy = self.energy + item.energy
    #end itemCollect
    
    # It sets the character invincible and start the corresponding task
    def setInvincible(self, invincible):
        self.isInvincible = True
        taskMgr.add(self.taskInvincible, 'taskInvincible' )
    #end setInvincible
    
    # It makes disappear the character
    def hide(self):
        self.model.hide()
    #end hide
    
    #-----------------------------------------------------------------------------------------------------------------------------------------------
    #----------------------------------------------------------------TASKS,THREADS------------------------------------------------------------------
    #-----------------------------------------------------------------------------------------------------------------------------------------------
    # It makes that sprite's character have an alpha effect for 2 seconds
    def taskInvincible(self, task):
        if task.time > 2:
            # Finishes the invicible property
            self.isInvincible = False
            self.model.show()
            self.isVisible = True
            self.lastTime = 0.0
            return task.done
        else:
            if (task.time - self.lastTime) > 0.15:
                self.lastTime = task.time
                if self.isVisible == True:  
                    self.model.hide()
                    self.isVisible = False
                else:
                    self.model.show()
                    self.isVisible = True
                
            return task.cont
    #end taskInvincible
    
#end class CMain