Esempio n. 1
0
class State_GameOver(StateBase):


	def __init__(self,gameDisplay,gameWidth,gameHeight,FPS,stateID):
		StateBase.__init__(self,gameDisplay, gameWidth, gameHeight,FPS,stateID)
		self.themeSound = MySound("res/sounds/gameOverSound.ogg")
		self.myScoreRef = MyScore()

	def renderState(self):
		self.renderSP()
		self.renderScore()

	def updateState(self):

		self.playThemeSound(self.themeSound)
		if pygame.key.get_pressed()[K_6]:
			self.BG.resetCountAndDelay()
			self.themeSound.stop()
			self.setCurrentStateID(0)

	def initSP(self,path):
		self.BG = MySprite(self.gameDisplay,path)
		
	
	def renderSP(self):
		self.BG.setFadeInImg(1)
		self.BG.renderImgConvert(0,0)

	def renderScore(self):
		pass
Esempio n. 2
0
class State_Menu(StateBase):


	def __init__(self,gameDisplay,gameWidth,gameHeight,FPS,stateID):
		StateBase.__init__(self,gameDisplay, gameWidth, gameHeight,FPS,stateID)
		self.initSP(gameDisplay)
		self.themeSound = MySound("res/sounds/menuTheme.ogg")

	def renderState(self):
		self.renderSP()

	def updateState(self):

		self.playThemeSound(self.themeSound)
		if pygame.key.get_pressed()[K_SPACE]:
			self.BG.resetCountAndDelay()
			self.themeSound.stop()
			self.setCurrentStateID(1)

	def initSP(self,gameDisplay):
		self.BG = MySprite(gameDisplay,"res/images/menuBG4.png")
		self.spaceTostartBG = MySprite(gameDisplay,"res/sprites/spaceTostartSP.png",2,580,50)
	
	def renderSP(self):
		self.BG.setFadeInImg(1)
		self.BG.renderImgConvert(0,0)
		if self.BG.alphaIn > 40:
			self.spaceTostartBG.loop(self.gameWidth/2 - 280, self.gameHeight/2 +200,10)
Esempio n. 3
0
 def getSprite(self):
     if not self.bloqueDestruido:
         sprite = MySprite(self.directorio + self.spriteBloque + ".png",self.x, self.y, 0)
     else:
         if self.tienePowerUp:
             sprite = MySprite(self.spritePowerUp,self.x, self.y, 0)
     if (not self.bloqueDestruido) or (self.tienePowerUp):
         sprite.listframes(1,1,50,50)
         sprite.setframe(1)
         #sprite = sf.Sprite(imagen)
         sprite.SetCenter(0,0)
         sprite.SetScale(self.escalaX,self.escalaY)
         return sprite
Esempio n. 4
0
	def initSP(self,path):
		self.BG = MySprite(self.gameDisplay,path)
Esempio n. 5
0
	def initMap(self,gameDisplay):
		self.fadeOutBG = MySprite(gameDisplay,"res/images/fadeOut.png")
		self.initMap1Layer1(gameDisplay)
		self.initMap1Layer2(gameDisplay)
Esempio n. 6
0
class State_GamePlay(StateBase):


	def __init__(self,gameDisplay,gameWidth,gameHeight,FPS,stateID):
		StateBase.__init__(self,gameDisplay, gameWidth, gameHeight,FPS,stateID)
		self.initMap(gameDisplay)
		self.themeSound = MySound("res/sounds/gamePlayTheme2.ogg")
		self.enemy1Num = 2
		self.enemy2Num = 1
		self.enemy3Num = 1
		self.myClockRef = MyClock(FPS)
		self.setUpState(gameDisplay,gameWidth,gameHeight,FPS)
		self.cPlayerDead = 0
		self.myScoreRef = MyScore()
		self.myTextWriterRef = MyTextWriter(gameDisplay, gameWidth, gameHeight)
		self.scoreSummonBoss = 2000

	def renderState(self):
		self.renderMap()
		self.renderEnemy()
		self.renderPlayer()

	def updateState(self):
		self.myClockRef.update()
		self.playThemeSound(self.themeSound)
		self.updatePlayer()
		if self.summonEnemy or self.myClockRef.isSec(5):
			self.summonEnemy = True
			self.updateEnemy()
			self.checkCollide()

		for player in self.playerList:
			if player.score > self.scoreSummonBoss:
				self.summonBoss()


		self.updateScore()
		self.checkGameOver(self.gameDisplay, self.gameWidth,self.gameHeight,self.FPS)
	def summonBoss(self):
		for enemy in self.enemyList:
			enemy.isBoss = False

	def checkGameOver(self,gameDisplay, gameWidth, gameHeight, FPS):
		cPlayerDead = 0
		for player in self.playerList:
			if player.HP <= 0 :
				cPlayerDead += 1
				if cPlayerDead == len(self.playerList):
					self.setUpState(gameDisplay, gameWidth, gameHeight, FPS)
					self.themeSound.stop()
					self.setCurrentStateID(self.nextStateId)

	def initSP(self,gameDisplay):
		pass

	def renderMapLayer(self,mapLayerList,mapLayerPosXList,mapLayerPosYList,speed):
		mapLayerList[0].renderImg(mapLayerPosXList[0],mapLayerPosYList[0])
		mapLayerList[1].renderImg(mapLayerPosXList[1],mapLayerPosYList[1])
		
		for i in range(len(mapLayerPosXList)):
			mapLayerPosXList[i] -= speed
			if mapLayerPosXList[i] < -2*self.gameWidth:
				mapLayerPosXList[i] = 2*self.gameWidth-speed

	def initMap(self,gameDisplay):
		self.fadeOutBG = MySprite(gameDisplay,"res/images/fadeOut.png")
		self.initMap1Layer1(gameDisplay)
		self.initMap1Layer2(gameDisplay)

	def initMap1Layer1(self,gameDisplay):
		self.map1Layer1 = MySprite(gameDisplay,"res/images/map1Layer1.png")
		self.map1Layer1List = [self.map1Layer1,self.map1Layer1,self.map1Layer1]
		self.map1Layer1PosXList = [0,2*self.gameWidth]
		self.map1Layer1PosYList = [0,0]

	def initMap1Layer2(self,gameDisplay):
		self.map1Layer2 = MySprite(gameDisplay,"res/images/map1Layer2.png")
		self.map1Layer2List = [self.map1Layer2,self.map1Layer2,self.map1Layer2]
		self.map1Layer2PosXList = [0,2*self.gameWidth]
		self.map1Layer2PosYList = [0,0]

	def renderMap(self):
		self.renderMapLayer(self.map1Layer2List,self.map1Layer2PosXList,self.map1Layer2PosYList,1)
		self.renderMapLayer(self.map1Layer1List,self.map1Layer1PosXList,self.map1Layer1PosYList,2)
		self.renderFadeIn()

	def renderFadeIn(self):
		self.fadeOutBG.setFadeOutImg(10)
		self.fadeOutBG.renderImgConvert(0, 0)

	def initEnemy(self,gameDisplay,gameWidth,gameHeight,FPS):
		self.enemyList = []
		self.enemyBeamList = []
		for i in range(self.enemy1Num):
			enemy1Ref = Enemy1(gameDisplay,gameWidth,gameHeight,FPS)
			self.enemyList.append(enemy1Ref)
			self.enemyBeamList.append(enemy1Ref.beam)

		for i in range(self.enemy2Num):
			enemy2Ref = Enemy2(gameDisplay,gameWidth,gameHeight,FPS)
			self.enemyList.append(enemy2Ref)
			self.enemyBeamList.append(enemy2Ref.beam)	

		for i in range(self.enemy3Num):
			enemy3Ref = Enemy3(gameDisplay,gameWidth,gameHeight,FPS)
			self.enemyList.append(enemy3Ref)
			self.enemyBeamList.append(enemy3Ref.beam)

		enemyBoss1Ref = EnemyBoss1(gameDisplay,gameWidth,gameHeight,FPS)
		self.enemyList.append(enemyBoss1Ref)
		self.enemyBeamList.append(enemyBoss1Ref.beam)

		enemyBoss2Ref = EnemyBoss2(gameDisplay,gameWidth,gameHeight,FPS)
		self.enemyList.append(enemyBoss2Ref)
		self.enemyBeamList.append(enemyBoss2Ref.beam)

		enemyBoss3Ref = EnemyBoss3(gameDisplay,gameWidth,gameHeight,FPS)
		self.enemyList.append(enemyBoss3Ref)
		self.enemyBeamList.append(enemyBoss3Ref.beam)

	def renderEnemy(self):
		for enemy in self.enemyList:
				enemy.render()

	def updateEnemy(self):
		for enemy in self.enemyList:
			if not enemy.isBoss:
				enemy.update()

	def checkCollidePlayerAndEnemy(self):
		for player in self.playerList:
			for sp in player.SPList:
				for enemy in self.enemyList:
					if sp.isCollide(enemy.SP):
						if player.currentMotion == 5:
							enemy.HPdamage(player.power)
							if enemy.HP < 0: 
								player.score += enemy.score
						else:
							if player.currentMotion != 6:
								player.HPdamage(enemy.power)

	def checkCollidePlayerAndEnemyBeam(self):
		for player in self.playerList:
			for sp in player.SPList:
				for beam in self.enemyBeamList:
					if sp.isCollide(beam.enemyBeamSP):
						if player.currentMotion != 6:
							player.HPdamage(beam.power)
						beam.resetPos()

	def checkCollidePlayerBeamAndEnemy(self):
		for player in self.playerList:
			for beam in player.beamList:
				for enemy in self.enemyList:
					if beam.beamSP.isCollide(enemy.SP):
						enemy.HPdamage(beam.power)
						beam.resetPos()
						if enemy.HP < 0: 
							player.score += enemy.score

	def checkCollide(self):
		self.checkCollidePlayerAndEnemy()
		self.checkCollidePlayerAndEnemyBeam()
		self.checkCollidePlayerBeamAndEnemy()		

	def renderPlayer(self):
		for player in self.playerList:
			player.render()

	def updatePlayer(self):
		for player in self.playerList:
			player.update()

	def initPlayer(self):
		pass

	def setUpState(self,gameDisplay,gameWidth,gameHeight,FPS):
		self.initPlayer(gameDisplay, gameWidth, gameHeight, FPS)
		self.initEnemy(gameDisplay,gameWidth,gameHeight,FPS)
		self.fadeOutBG.resetCountAndDelay()
		self.summonEnemy = False

	def updateScore(self):
		pass
Esempio n. 7
0
 def getSprite(self):
     sprite = MySprite(self.spritePlayer,self.iniX+52, self.iniY+52, 10)
     #sprite.listframes(12, 6, 44, 49)
     sprite.listframes(4,4,40,50)
     sprite.setframe(2)
     return sprite
Esempio n. 8
0
	def initSP(self,gameDisplay):
		self.BG = MySprite(gameDisplay,"res/images/menuBG4.png")
		self.spaceTostartBG = MySprite(gameDisplay,"res/sprites/spaceTostartSP.png",2,580,50)
Esempio n. 9
0
 def __init__(self):
     # Call the parent's constructor
     MySprite.__init__(self)
Esempio n. 10
0
 def getSprite(self):
     sprite = MySprite(self.spriteName, self.x, self.y, 10)
     sprite.t = 20.0
     sprite.listframes(1, 7, 50, 50)
     sprite.setframe(1)
     return sprite