Exemple #1
0
    def update(self):
        if self.x_status == Ship.LEFT and self.x_momentum < self.max_x_momentum:
            self.x_momentum -= self.momentum_delta
        if self.x_status == Ship.RIGHT and self.x_momentum > -self.max_x_momentum:
            self.x_momentum += self.momentum_delta
        if (self.x_momentum < 0 and self.rect.left > 0) or (
            self.x_momentum > 0 and self.rect.left < 640 - self.rect.width
        ):
            self.rect = self.rect.move((self.x_momentum / (4 - self.powerup["speedup"]), 0))
        self.x_momentum *= self.decceleration
        if abs(self.x_momentum) < 1:
            self.x_momentum = 0

        if self.status == Ship.UP and self.y_momentum > -self.max_y_momentum:
            self.y_momentum -= self.momentum_delta
        if self.status == Ship.DOWN and self.y_momentum < self.max_y_momentum:
            self.y_momentum += self.momentum_delta
        if (self.y_momentum < 0 and self.rect.top > 0) or (
            self.y_momentum > 0 and self.rect.top < 480 - self.rect.height
        ):
            self.rect = self.rect.move((0, self.y_momentum / (4 - self.powerup["speedup"])))
        self.y_momentum *= self.decceleration
        if abs(self.y_momentum) < 1:
            self.y_momentum = 0

        # change image depending on vertical momentum
        if self.y_momentum > 4:
            self.image, foo = utils.load_image_sprite("spaceship.gif", rect=pygame.Rect(0, 128, 64, 64))
        elif self.y_momentum < -4:
            self.image, foo = utils.load_image_sprite("spaceship.gif", rect=pygame.Rect(0, 64, 64, 64))
        else:
            self.image, foo = utils.load_image_sprite("spaceship.gif", rect=pygame.Rect(0, 0, 64, 64))
Exemple #2
0
    def update(self):
        self.age += 0.6
        if self.x_status==Ship.LEFT and self.x_momentum < self.max_x_momentum:
            self.x_momentum-=self.momentum_delta
        if self.x_status==Ship.RIGHT and self.x_momentum > -self.max_x_momentum:
            self.x_momentum+=self.momentum_delta
        if (self.x_momentum < 0 and self.rect.left > 0) or (self.x_momentum > 0 and self.rect.left < 640-self.rect.width):
            self.rect = self.rect.move((self.x_momentum/(6-self.powerup['speedup']), 0))
        self.x_momentum *= self.decceleration - (self.powerup['speedup'] * 0.04)
        if abs(self.x_momentum) < 1:
            self.x_momentum = 0

        if self.status==Ship.UP and self.y_momentum > -self.max_y_momentum:
            self.y_momentum-=self.momentum_delta
        if self.status==Ship.DOWN and self.y_momentum < self.max_y_momentum:
            self.y_momentum+=self.momentum_delta
        if (self.y_momentum < 0 and self.rect.top > 0) or (self.y_momentum > 0 and self.rect.top < 480-self.rect.height):
            self.rect = self.rect.move((0, self.y_momentum/(6-self.powerup['speedup'])))
        self.y_momentum *= self.decceleration - (self.powerup['speedup'] * 0.04)
        if abs(self.y_momentum) < 1:
            self.y_momentum = 0

        #change image depending on vertical momentum
        if self.y_momentum > 4:
            self.image, foo = utils.load_image_sprite('spaceship.png', rect=pygame.Rect(0,86,54,43))
        elif self.y_momentum < -4:
            self.image, foo = utils.load_image_sprite('spaceship.png', rect=pygame.Rect(0,43,54,43))
        else:
            self.image, foo = utils.load_image_sprite('spaceship.png', rect=pygame.Rect(0,0,54,43))
Exemple #3
0
 def __init__(self):
     pygame.sprite.Sprite.__init__(self)  # call Sprite intializer
     self.image, self.rect = utils.load_image_sprite("spaceship.gif", rect=pygame.Rect(0, 0, 64, 64))
     screen = pygame.display.get_surface()
     self.area = screen.get_rect()
     # Initial position
     self.powerup = {"penetrate": False, "speedup": 0}
Exemple #4
0
 def update(self):
     self.age += 1
     if self.age %3 == 0:
         if self.status == 5:
             self.status = 6
         elif self.status == 6:
             self.status = 5
     pos = pygame.Rect((self.status)*40, 0, 40,60)
     self.image, foo = utils.load_image_sprite(self.image_file, rect=pos)
Exemple #5
0
 def __init__(self):
     pygame.sprite.Sprite.__init__(self) #call Sprite intializer
     self.image, self.rect = utils.load_image_sprite('spaceship.png', rect=pygame.Rect(0,0,54,43))
     screen = pygame.display.get_surface()
     self.age = 0
     self.area = screen.get_rect()
     self.rect.top = self.area.height / 2 - self.rect.height / 2
     #Initial position
     self.powerup = { 'penetrate' : False, 'speedup' : 0 }
Exemple #6
0
    def update(self):
        self.age += 1
        if self.age %3 == 0:
            if self.status == 5:
                self.status = 6
            elif self.status == 6:
                self.status = 5
	try:	
            pos = pygame.Rect((self.status)*40, 0, 40,60)
	    self.image, foo = utils.load_image_sprite(self.image_file, rect=pos)
	except ValueError:
	    print "Error loading image"
Exemple #7
0
 def update(self):
     self.age += 1
     if self.value == 3:
         self.image, rect = utils.load_image_sprite("alien4.gif", rect=pygame.Rect(self.age%12*58,0,58,34))
     self.cycle+=self.frequency
     self.cycle_2+=self.frequency_2
     self.rect = self.rect.move((self.move, self.amplitude_2*math.sin(self.cycle_2)+self.amplitude*math.sin(self.cycle)))
     if self.rect.left < 0:
         self.kill()
     #move vertically towards the target
     if self.target != None:
         self.rect = self.rect.move((0, -(self.rect.top-self.target.rect.top)*(self.agressivity/10)))
Exemple #8
0
 def update(self):
     if self.life > 0:
         pos = pygame.Rect(0,(self.life-1)*20,140,20)
     else:
         pos = pygame.Rect(0,0,140,20)
     self.image, foo = utils.load_image_sprite('life.gif', rect=pos)
     #reduce status until 0 to shake
     if self.status>0:
         if self.status % 2 == 0:
             self.rect = self.rect.move((0,2))
         else:
             self.rect = self.rect.move((0,-2))
         self.status-=1
Exemple #9
0
    def update(self):
        self.age = self.age+1
        self.rect = self.rect.move((-(self.age/2-10), 0))

        if self.rect.left < 0:
            self.kill()
            return
        pos = pygame.Rect((self.status)*28, self.type*28, 26,26)
        self.image, foo = utils.load_image_sprite('powerups.png', rect=pos)
        if self.age % 4 != 0:
            return
        self.status = self.status + 1
        if self.status == self.max_status:
            self.status = 0
Exemple #10
0
    def __init__(self, rect):
        pygame.sprite.Sprite.__init__(self) #call Sprite intializer

        self.life = 10
        self.rect = pygame.Rect(0,0,64,64)
        self.rect.top = rect.top
        self.rect.left = rect.left
        self.status = 0
        self.max_status = 40
        #Cache in the class static
        if Explosion.images_1 == False:
            self.images = []
            for i in range(self.max_status):
                pos = pygame.Rect((i%8)*64,int(i/8)*64,64,64)
                image, foo = utils.load_image_sprite('explosion_1.png', rect=pos)
                self.images.append(image)
            Explosion.images_1 = self.images
            self.images = []
            for i in range(self.max_status):
                pos = pygame.Rect((i%8)*64,int(i/8)*64,64,64)
                image, foo = utils.load_image_sprite('explosion_2.png', rect=pos)
                self.images.append(image)
            Explosion.images_2 = self.images
            self.images = []
            for i in range(self.max_status):
                pos = pygame.Rect((i%8)*64,int(i/8)*64,64,64)
                image, foo = utils.load_image_sprite('explosion_3.png', rect=pos)
                self.images.append(image)
            Explosion.images_3 = self.images
            self.images = []
            for i in range(self.max_status):
                pos = pygame.Rect((i%8)*64,int(i/8)*64,64,64)
                image, foo = utils.load_image_sprite('explosion_4.png', rect=pos)
                self.images.append(image)
            Explosion.images_4 = self.images
        else:
            self.images = eval("Explosion.images_{0}".format(random.randint(1,4)))
Exemple #11
0
 def __init__(self, ship):
     pygame.sprite.Sprite.__init__(self)
     self.ship = ship
     self.image, self.rect = utils.load_image_sprite('buddy.png', rect=pygame.Rect(0,0,14,14))
     self.image.set_colorkey((0,0,0))
     self.phase = self.ship.buddies * 2.09 #(2/3)*pi
Exemple #12
0
 def update(self):
     pos = pygame.Rect(0,(self.status)*52,64,52)
     self.image, foo = utils.load_image_sprite('explosion.gif', rect=pos)
     self.status+=1
     if self.status == self.max_status:
         self.kill()