예제 #1
0
 def __init__(self, gs = None, initX = 0, initY = 0, hspeed = 10, vspeed = 0, angle = 0):
     pygame.sprite.Sprite.__init__(self)
     
     self.gs = gs
     self.image = pygame.image.load("res/projectile.png").convert()
     self.rect = self.image.get_rect()
     
     self.hspeed = hspeed
     self.vspeed = vspeed
     
     #Tilt the image
     self.image = Utilities.rot_center(self.image, angle)
     
     #Make it start at the local player's position
     self.rect.centerx = initX
     self.rect.centery = initY
     
     #keep original image to limit resize errors
     self.orig_image = self.image
예제 #2
0
    def ship_update(self):
        
        #Calculate rotation, only if local player
        if self.isLocal:
            self.sprite_info[ANGLE] = self.calculate_angle()

        if self.sprite_info[FIRE] == True:
            rotationRad = math.radians(self.sprite_info[ANGLE])
            
            # create projectile with the correct velocities to match the player's angle
            speedMultiplier = 5
            projectileRad = rotationRad - math.pi / 2
            xspeed = -(math.cos(projectileRad) * speedMultiplier + (math.pi / 2))
            yspeed = math.sin(projectileRad) * speedMultiplier + (math.pi / 2)
            
            newProjectile = Projectile(self.gs, self.rect.centerx + (20 * xspeed), self.rect.centery + (20 * yspeed), xspeed, yspeed, self.sprite_info[ANGLE])
            
            # add to projectile list
            self.gs.projectileList.append(newProjectile)
            
        #Update the image based on the mouse position
        self.image = Utilities.rot_center(self.orig_image, self.sprite_info[ANGLE] + 40)
        
        #Check if the player's ship is colliding with a projectile
        hasCollision = False
        
        for projectile in self.gs.projectileList:
            if self.rect.colliderect( projectile.rect):
                hasCollision = True
                break
        
        #Update the life points, and change the player into an explosion if necessary
        if hasCollision:
            #A collision occurred            
            self.sprite_info[HEALTH] = self.sprite_info[HEALTH] - 100
            
            #Check if the health has been depleted
            if self.sprite_info[HEALTH] <= 0:
                self.explosionCounter = pygame.time.get_ticks()
                self.image = self.explosionImages[0]
                pygame.mixer.music.load("res/explode.wav")
                pygame.mixer.music.play()