Beispiel #1
0
    def update(self):
        # updating shot lasers
        tmplist = list()
        for index in range(len(self.laserlist)):
            (x, y) = self.laserlist[index]
            self.laserlist[index] = (x, y + 10)
            screen.blit(self.single_sprites[
                        'sprite_laser_blue_light.png'], (x - 29 - 32, y - 10 - 22 - 32))
            screen.blit(self.single_sprites[
                        'sprite_laser_blue.png'], (x, y - 10))
            # is the ship getting hit by one of our lasers ?

            if collisions.iscollision(x, y,
                                      self.single_sprites[
                                          'sprite_laser_blue.png'].get_width(),
                                      self.single_sprites[
                                          'sprite_laser_blue.png'].get_height(),
                                      self.ship.position_ship_x, self.ship.position_ship_y,  self.ship.width,
                                      self.ship.height):
                self.ship.damage(10, x - 40)
                tmplist.append(self.laserlist[index])

        # and we delete the old lasers
        for index in range(len(tmplist)):
            self.laserlist.remove(tmplist[index])
Beispiel #2
0
    def update(self):
        # updating shot lasers
        tmplist = list()
        for index in range(len(self.laserlist)):
            (x, y) = self.laserlist[index]
            self.laserlist[index] = (x, y + 10)
            screen.blit(self.single_sprites['sprite_laser_blue_light.png'],
                        (x - 29 - 32, y - 10 - 22 - 32))
            screen.blit(self.single_sprites['sprite_laser_blue.png'],
                        (x, y - 10))
            # is the ship getting hit by one of our lasers ?

            if collisions.iscollision(
                    x, y,
                    self.single_sprites['sprite_laser_blue.png'].get_width(),
                    self.single_sprites['sprite_laser_blue.png'].get_height(),
                    self.ship.position_ship_x, self.ship.position_ship_y,
                    self.ship.width, self.ship.height):
                self.ship.damage(10, x - 40)
                tmplist.append(self.laserlist[index])

        # and we delete the old lasers
        for index in range(len(tmplist)):
            self.laserlist.remove(tmplist[index])
Beispiel #3
0
	def processHit(self,laserlist, ship):
		oldlasers=list()
		
		
		#is the ship getting the bonus ?	
		if self.bonus:
			if collisions.iscollision(ship.position_ship_x, ship.position_ship_y,
			ship.width, ship.height, self.x, self.y, self.sprite_bonus.get_width(),
			self.sprite_bonus.get_height()):	
				if self.bonusType==0:
					ship.getBonusLife()
				elif self.bonusType==1:
					ship.getBonusArmor()
				else:
					ship.setWeapon(2)
				self.bonus=False
				self.dying=False
				self.alive=False
		
		#is the ship colliding with the enemy ?
		elif (self.dying == False):
			#check if we collide with the ship. if we collide both looses life
			if collisions.iscollision(ship.position_ship_x, ship.position_ship_y,
			 ship.width, ship.height, self.x, self.y, self.sprite_enemy.get_width(),
			self.sprite_enemy.get_height()):
				if (ship.damage(10, ship.position_ship_x)):
					self.life = self.life-150
					if self.life<=0:
						self.dying=True
						if self.typeofship==0:
							if common_pygame.explosions ==1:
								particles.addExplosion(self.x, self.y, 2)
							self.menu.play_sound(self.sounds['explosion.wav'])
						else:
							if common_pygame.explosions ==1:
								particles.addExplosion(self.x, self.y, 1)
							self.menu.play_sound(self.sounds['explosion2.wav'])
							Enemy.nbAsteroids=Enemy.nbAsteroids-1
							print("dying")
								
						#ship.hurt=True
				ship.position_ship_y=ship.position_ship_y-ship.currentspeed_y
				ship.position_ship_x= ship.position_ship_x-ship.currentspeed_x
				ship.currentspeed_x=-ship.currentspeed_x/1.5
				ship.currentspeed_y=-ship.currentspeed_x/1.5


					
				
			
			#check if we are being shot by a laser
			for index in range(len(laserlist)):
				(currentx, currenty, lasertype) = laserlist[index]
				#if currenty > self.y - self.sprite_enemy.get_height() and \
				#currenty < self.y and \
				#currentx > self.x and currentx < self.x + self.sprite_enemy.get_width():
				if lasertype==1:
					(laserX, laserY) = (5, 19)
				else:
					(laserX, laserY) = (12, 12)
					
				if collisions.iscollision(currentx, currenty, laserX, laserY, self.x, \
				 self.y, self.sprite_enemy.get_width(), self.sprite_enemy.get_height()):
					#enemy ship
					if self.typeofship==0:
						self.life=self.life-50
						if self.life<=0:
							self.dying=True
							ship.score=ship.score+10
							if common_pygame.explosions==1:
								particles.addExplosion(self.x, self.y, 2)
							self.menu.play_sound(self.sounds['explosion.wav'])
						else:
							self.shot=30
							self.menu.play_sound(self.sounds["shield1.wav"])
					#asteroid
					elif self.typeofship==1:
						self.dying = True
						ship.score=ship.score+10
						if common_pygame.explosions==1:
							particles.addExplosion(self.x, self.y, 1)
						self.menu.play_sound(self.sounds['explosion2.wav'])
						#print("dying")
						Enemy.nbAsteroids=Enemy.nbAsteroids-1
					#first boss
					else:
						self.life=self.life-10
						if self.life<=0:
							self.dying=True
							ship.score=ship.score+10
							if common_pygame.explosions==1:
								particles.addExplosion(self.x, self.y, 3)
							self.menu.play_sound(self.sounds['explosion.wav'])
						else:
							self.shot=30
							self.menu.play_sound(self.sounds["shield1.wav"])
						
					oldlasers.append((currentx, currenty, lasertype))
					
		return oldlasers
Beispiel #4
0
    def update(self, ship):
        #if dying, blit the explosion frame
        if self.dying:
            if self.dying_index / 2 < len(self.sprite_explosion_list):
                #/2 for one frame every two ticks
                #print("blitting", self.dying_index/2)
                self.screen.blit(
                    self.sprite_explosion_list[(self.dying_index / 2)],
                    (self.x - 112, self.y - 86))
                self.dying_index = self.dying_index + 1
            else:
                #asteroid
                #if (self.typeofship==1):
                self.bonus = True
                self.alive = True
                #Enemy.nbAsteroids=Enemy.nbAsteroids-1
                #enemy ship
                #else:
                #	self.dying = False
                #	self.alive = False

        elif self.alive:
            #if we are being shot, there is alternate blitting for one second
            if self.shot > 0:
                #explosion
                if 30 - self.shot < len(
                        self.sprite_sequences['ship_hurt.png']):
                    self.screen.blit(
                        self.sprite_sequences['ship_hurt.png'][30 - self.shot],
                        (self.x, self.y + 32))

                self.shot = self.shot - 1
                if self.shot % 2:
                    if self.typeofship == 0:
                        self.screen.blit(
                            self.single_sprites['sprite_enemy_fire.png'],
                            (self.x, self.y - 15))
                    self.screen.blit(self.sprite_enemy, (self.x, self.y))
                ##if we are the first boss, we draw the sprite anyway
                #if self.typeofship==2:
                #self.screen.blit(self.sprite_enemy, (self.x, self.y))
            else:
                if self.typeofship == 0:
                    self.screen.blit(
                        self.single_sprites['sprite_enemy_fire.png'],
                        (self.x, self.y - 15))
                self.screen.blit(self.sprite_enemy, (self.x, self.y))

        if self.bonus:
            self.y = self.y + 5
            self.screen.blit(self.sprite_bonus, (self.x, self.y))

        if self.alive:
            #update the position
            if self.y > self.screen.get_width():
                self.dying = False
                self.alive = False
                if (self.typeofship == 1):
                    Enemy.nbAsteroids = Enemy.nbAsteroids - 1
            else:

                #move of a living enemy
                if self.dying == False and self.typeofship == 0:
                    #update the direction in accordance to the ship's position
                    if self.x < ship.position_ship_x and ship.position_ship_x - self.x > self.offsetturn:
                        self.direction = 1
                    elif self.x - ship.position_ship_x > self.offsetturn:
                        self.direction = -1
                    #move the enemy
                    #if self.y > ship.position_ship_y -250:
                    #self.y = self.y-20
                    elif self.y < ship.position_ship_y - self.distance:
                        self.y = self.y + 5

                    self.x = self.x + 10 * self.direction

                #move of an asteroid
                elif self.typeofship == 1:

                    if (self.compteurx % 120 < 60):
                        self.x = self.x + 5 * self.direction
                    else:
                        self.x = self.x - 5 * self.direction
                        self.y = self.y + self.speed

                #move of the first boss
                if self.typeofship == 2:
                    #the first move of the boss before getting into position
                    if not self.inPlace:
                        if self.y >= 100:
                            self.inPlace = True
                        else:
                            self.y = self.y + 10
                    else:
                        #we continue to go down till we reach a value
                        if self.y >= 150 or self.y <= 20:
                            self.bossmoveVertical = -self.bossmoveVertical

                        self.y = self.y + self.bossmoveVertical

                    #we have to move across all the screen, the speed changes on each turn
                    if self.x <= 0:
                        self.bossmove = 1
                        self.bossHorizontalSpeed = random.randint(4, 10)
                    elif self.x >= 800 - self.w:
                        self.bossmove = -1
                        self.bossHorizontalSpeed = random.randint(4, 10)

                    self.x = self.x + self.bossmove * self.bossHorizontalSpeed

                    #if (self.compteurx%200<60):
                    #self.x = self.x+5*self.direction
                    #else:
                    #self.x = self.x-5*self.direction

                self.compteurx = self.compteurx + 1

                #only if we are an enemy ship ( not if asteroid), and not dying, and not dead
                if not self.bonus and not self.dying and (
                        self.typeofship == 0 or self.typeofship == 2):
                    #shooting out a laser
                    if self.lasercompteur == 0:
                        self.laserlist.append(
                            (self.x + self.w / 2, self.y + self.h))

                        #if we are the boss, shoot out the lasers faster
                        if self.typeofship == 2:
                            self.lasercompteur = 5
                        else:
                            self.lasercompteur = 60
                        self.menu.play_sound(self.sounds["laser4.wav"])

                    #print(self.lasercompteur)
                    self.lasercompteur = self.lasercompteur - 1

                    #updating shot lasers
                    tmplist = list()
                    for index in range(len(self.laserlist)):
                        (x, y) = self.laserlist[index]
                        self.laserlist[index] = (x, y + 10)
                        self.screen.blit(
                            self.single_sprites['sprite_laser_blue_light.png'],
                            (x - 29 - 32, y - 10 - 22 - 32))
                        self.screen.blit(
                            self.single_sprites['sprite_laser_blue.png'],
                            (x, y - 10))
                        #is the ship getting hit by one of our lasers ?

                        if collisions.iscollision(
                                x, y,
                                self.single_sprites['sprite_laser_blue.png'].
                                get_width(),
                                self.single_sprites['sprite_laser_blue.png'].
                                get_height(), ship.position_ship_x,
                                ship.position_ship_y, ship.width, ship.height):
                            ship.damage(10, x - 40)
                            tmplist.append(self.laserlist[index])

                    #and we delete the old lasers
                    for index in range(len(tmplist)):
                        self.laserlist.remove(tmplist[index])

                #if we are the boss : shooting out lasers
                #if self.typeofship==2:
        #if we are the first boss, we print the progress bar
        if self.typeofship == 2:
            hud.updateProgbar(self.life / 30, 10, 10, 400, (255, 0, 0), 1)
Beispiel #5
0
    def processHit(self, laserlist, ship):
        oldlasers = list()

        #is the ship getting the bonus ?
        if self.bonus:
            if collisions.iscollision(ship.position_ship_x,
                                      ship.position_ship_y, ship.width,
                                      ship.height, self.x, self.y,
                                      self.sprite_bonus.get_width(),
                                      self.sprite_bonus.get_height()):
                if self.bonusType == 0:
                    ship.getBonusLife()
                elif self.bonusType == 1:
                    ship.getBonusArmor()
                else:
                    ship.setWeapon(2)
                self.bonus = False
                self.dying = False
                self.alive = False

        #is the ship colliding with the enemy ?
        elif (self.dying == False):
            #check if we collide with the ship. if we collide both looses life
            if collisions.iscollision(ship.position_ship_x,
                                      ship.position_ship_y, ship.width,
                                      ship.height, self.x, self.y,
                                      self.sprite_enemy.get_width(),
                                      self.sprite_enemy.get_height()):
                if (ship.damage(10, ship.position_ship_x)):
                    self.life = self.life - 150
                    if self.life <= 0:
                        self.dying = True
                        if self.typeofship == 0:
                            self.menu.play_sound(self.sounds['explosion.wav'])
                        else:
                            self.menu.play_sound(self.sounds['explosion2.wav'])
                            Enemy.nbAsteroids = Enemy.nbAsteroids - 1
                            print("dying")

                        #ship.hurt=True
                ship.position_ship_y = ship.position_ship_y - ship.currentspeed_y
                ship.position_ship_x = ship.position_ship_x - ship.currentspeed_x
                ship.currentspeed_x = -ship.currentspeed_x / 1.5
                ship.currentspeed_y = -ship.currentspeed_x / 1.5

            #check if we are being shot by a laser
            for index in range(len(laserlist)):
                (currentx, currenty, lasertype) = laserlist[index]
                #if currenty > self.y - self.sprite_enemy.get_height() and \
                #currenty < self.y and \
                #currentx > self.x and currentx < self.x + self.sprite_enemy.get_width():
                if lasertype == 1:
                    (laserX, laserY) = (5, 19)
                else:
                    (laserX, laserY) = (12, 12)

                if collisions.iscollision(currentx, currenty, laserX, laserY, self.x, \
                 self.y, self.sprite_enemy.get_width(), self.sprite_enemy.get_height()):
                    #enemy ship
                    if self.typeofship == 0:
                        self.life = self.life - 50
                        if self.life <= 0:
                            self.dying = True
                            ship.score = ship.score + 10
                            self.menu.play_sound(self.sounds['explosion.wav'])
                        else:
                            self.shot = 30
                            self.menu.play_sound(self.sounds["shield1.wav"])
                    #asteroid
                    elif self.typeofship == 1:
                        self.dying = True
                        ship.score = ship.score + 10
                        self.menu.play_sound(self.sounds['explosion2.wav'])
                        #print("dying")
                        Enemy.nbAsteroids = Enemy.nbAsteroids - 1
                    #first boss
                    else:
                        self.life = self.life - 10
                        if self.life <= 0:
                            self.dying = True
                            ship.score = ship.score + 10
                            self.menu.play_sound(self.sounds['explosion.wav'])
                        else:
                            self.shot = 30
                            self.menu.play_sound(self.sounds["shield1.wav"])

                    oldlasers.append((currentx, currenty, lasertype))

        return oldlasers
Beispiel #6
0
	def update(self, ship):
		#if dying, blit the explosion frame
		if self.dying:
			if self.dying_index/2<len(self.sprite_explosion_list):
				#/2 for one frame every two ticks
				#print("blitting", self.dying_index/2)
				self.screen.blit(self.sprite_explosion_list[(self.dying_index/2)],
				 (self.x-112,
				  self.y-86))
				self.dying_index = self.dying_index +1
			else:
				#asteroid
				#if (self.typeofship==1):
				self.bonus=True
				self.alive = True
					#Enemy.nbAsteroids=Enemy.nbAsteroids-1
				#enemy ship
				#else:
				#	self.dying = False
				#	self.alive = False

		elif self.alive:
			#if we are being shot, there is alternate blitting for one second
			if self.shot>0:		
				#explosion
				if 30-self.shot<len(self.sprite_sequences['ship_hurt.png']):
					self.screen.blit(self.sprite_sequences['ship_hurt.png'][30-self.shot], (self.x, self.y+32))
					
				self.shot=self.shot-1
				if self.shot%2:
					if self.typeofship==0:
						self.screen.blit(self.single_sprites['sprite_enemy_fire.png'], (self.x, self.y-15))
					self.screen.blit(self.sprite_enemy, (self.x, self.y))
				##if we are the first boss, we draw the sprite anyway
				#if self.typeofship==2:
					#self.screen.blit(self.sprite_enemy, (self.x, self.y))
			else:
				if self.typeofship==0:
					self.screen.blit(self.single_sprites['sprite_enemy_fire.png'], (self.x, self.y-15))
				self.screen.blit(self.sprite_enemy, (self.x, self.y))
	
		if self.bonus:
			self.y=self.y+5
			self.screen.blit(self.sprite_bonus, (self.x, self.y))
			
			
			
		if self.alive:
			#update the position
			if self.y > self.screen.get_width():
				self.dying=False
				self.alive=False
				if (self.typeofship==1):
					Enemy.nbAsteroids=Enemy.nbAsteroids-1
			else:
				
				#move of a living enemy
				if self.dying==False and self.typeofship==0:
					#update the direction in accordance to the ship's position
					if self.x < ship.position_ship_x and ship.position_ship_x - self.x >self.offsetturn:
						self.direction=1
					elif self.x - ship.position_ship_x >self.offsetturn:
						self.direction=-1
					#move the enemy
					#if self.y > ship.position_ship_y -250:
						#self.y = self.y-20
					elif self.y < ship.position_ship_y -self.distance :
						self.y = self.y+5
						
					self.x = self.x+10*self.direction
					
				#move of an asteroid
				elif self.typeofship==1:
					
					if (self.compteurx%120<60):
						self.x = self.x+5*self.direction
					else:
						self.x = self.x-5*self.direction
						self.y=self.y+self.speed
				
				#move of the first boss	
				if self.typeofship==2 :
					#the first move of the boss before getting into position
					if not self.inPlace:
						if self.y>=100:
							self.inPlace=True
						else:
							self.y=self.y+10
					else:	
						#we continue to go down till we reach a value
						if self.y>=150 or self.y <=20:
							self.bossmoveVertical=- self.bossmoveVertical
						
						self.y=self.y+self.bossmoveVertical
					
						
					#we have to move across all the screen, the speed changes on each turn
					if self.x<=0:
						self.bossmove=1
						self.bossHorizontalSpeed=random.randint(4,10)
					elif self.x>=800-self.w:
						self.bossmove=-1
						self.bossHorizontalSpeed=random.randint(4,10)
					
					self.x=self.x+self.bossmove*self.bossHorizontalSpeed
					
					#if (self.compteurx%200<60):
						#self.x = self.x+5*self.direction
					#else:
						#self.x = self.x-5*self.direction
					
					
				self.compteurx=self.compteurx+1
				
				
				#only if we are an enemy ship ( not if asteroid), and not dying, and not dead 
				if not self.bonus and not self.dying and ( self.typeofship==0 or self.typeofship==2):
					#shooting out a laser 
					if self.lasercompteur==0:
						self.laserlist.append((self.x+self.w/2, self.y+self.h))
						
						#if we are the boss, shoot out the lasers faster
						if self.typeofship==2:
							self.lasercompteur=5
						else:
							self.lasercompteur=60
						self.menu.play_sound(self.sounds["laser4.wav"])
						
					#print(self.lasercompteur)
					self.lasercompteur=self.lasercompteur-1
					
					#updating shot lasers
					tmplist = list()
					for index in range(len(self.laserlist)):
						(x, y) = self.laserlist[index]
						self.laserlist[index]=(x, y+10)
						self.screen.blit(self.single_sprites['sprite_laser_blue_light.png'],(x-29-32,y-10-22-32))
						self.screen.blit(self.single_sprites['sprite_laser_blue.png'],(x,y-10))
						#is the ship getting hit by one of our lasers ?
						
						if collisions.iscollision(x, y, 
						self.single_sprites['sprite_laser_blue.png'].get_width(),
						self.single_sprites['sprite_laser_blue.png'].get_height(), 
						ship.position_ship_x, ship.position_ship_y,  ship.width, 
						ship.height ):
							ship.damage(10, x-40)
							tmplist.append(self.laserlist[index])
					
					#and we delete the old lasers
					for index in range(len(tmplist)):
						self.laserlist.remove(tmplist[index])	
				
				#if we are the boss : shooting out lasers
				#if self.typeofship==2:
		#if we are the first boss, we print the progress bar
		if self.typeofship==2:
			hud.updateProgbar(self.life/30,10, 10,400, (255,0,0), 1)