Beispiel #1
0
	def update(self, ship, lasers):
		#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 don't have max live, smoke is going out 
			if self.life!=100 and self.compteurx%5==0:
				smoke.addSmoke(self.x,self.y, 25)
			
			#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:
            #move the bonus in the y axis
			self.y=self.y+10
			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 and not self.dying:
					
					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:
						
						lasers.addLaser(self.x+self.w/2, self.y+self.h)
						#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=15
						self.menu.play_sound(self.sounds["laser4.wav"])
						
					#print(self.lasercompteur)
					self.lasercompteur=self.lasercompteur-1
					
		#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, self.single_sprites)
Beispiel #2
0
    def update(self, ship, lasers):
        # 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 don't have max live, smoke is going out
            if self.life != 100 and self.compteurx % 5 == 0:
                smoke.addSmoke(self.x, self.y, 25)

            # 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:
            # move the bonus in the y axis
            self.y = self.y + 10
            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 and not self.dying:

                    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:

                        lasers.addLaser(self.x + self.w / 2, self.y + self.h)
                        #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 = 15
                        self.menu.play_sound(self.sounds["laser4.wav"])

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

        # 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,
                              self.single_sprites)
Beispiel #3
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 #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)