Exemplo n.º 1
0
 def move(self, x_change, y_change):
     if not self.isInTree:
         Player.move(self, x_change, y_change)
         return
          
     # check x
     old_rect = self.rect
     delta_x = x_change * self.speed
     self.rect = self.rect.move(delta_x, 0)
     if self.rect.left < 0 or self.rect.left + self.rect.width >= self.game.current_map.width:
         self.rect = old_rect
     elif (not check_collision(self, self.game.current_map.high_level)):
         self.rect = old_rect
     
     old_rect = self.rect
     delta_y = y_change * self.speed
     self.rect = self.rect.move(0, delta_y)
     if self.rect.top < 0 or self.rect.top + self.rect.height >= self.game.current_map.height:
         self.rect = old_rect
     elif (not check_collision(self, self.game.current_map.high_level)):
         self.rect = old_rect
         
     self.x = self.rect.left - self.left_offset
     self.y = self.rect.top - self.top_offset
     
     self.fire_tiles()
 def move(self, x_change, y_change):
     
     # check x
     old_rect = self.rect
     delta_x = x_change * self.speed
     self.rect = self.rect.move(delta_x, 0)
     if (check_collision(self, self.game.current_map.unwalkable_tiles)):
         self.rect = old_rect
         
     old_rect = self.rect
     delta_y = y_change * self.speed
     self.rect = self.rect.move(0, delta_y)
     if (check_collision(self, self.game.current_map.unwalkable_tiles)):
         self.rect = old_rect
         
     self.x = self.rect.left - self.left_offset
     self.y = self.rect.top - self.top_offset
     if self.driver:
         self.driver.x = self.x
         self.driver.y = self.y
     
     collisions = pygame.sprite.spritecollide(self, self.game.current_map.game_objects, False)
     self.fix_me()
     if collisions is not None:
         for collision in collisions:
             if collision is not self:
                 collision.ranOver(self)
                 
     self.fire_tiles()
     
     if (pygame.time.get_ticks() > (self.start_time + 1600)) and self.driving and self.driver:
             self.game.soundUtil.LoadSound('idle.wav', "car")
             self.game.soundUtil.PlaySound("car")
Exemplo n.º 3
0
    def move(self, x_change, y_change):
        if not self.isInTree:
            Player.move(self, x_change, y_change)
            return

        # check x
        old_rect = self.rect
        delta_x = x_change * self.speed
        self.rect = self.rect.move(delta_x, 0)
        if self.rect.left < 0 or self.rect.left + self.rect.width >= self.game.current_map.width:
            self.rect = old_rect
        elif (not check_collision(self, self.game.current_map.high_level)):
            self.rect = old_rect

        old_rect = self.rect
        delta_y = y_change * self.speed
        self.rect = self.rect.move(0, delta_y)
        if self.rect.top < 0 or self.rect.top + self.rect.height >= self.game.current_map.height:
            self.rect = old_rect
        elif (not check_collision(self, self.game.current_map.high_level)):
            self.rect = old_rect

        self.x = self.rect.left - self.left_offset
        self.y = self.rect.top - self.top_offset

        self.fire_tiles()
Exemplo n.º 4
0
 def fix_me(self):
     if not (check_collision(self, self.game.current_map.game_objects) or 
             check_collision(self, self.game.current_map.unwalkable_tiles)):
         return
     
     old_x = self.x
     old_y = self.y
     
     radius = 1
     amt = TILE_SIZE/32
     
     while(True):
         self.x = old_x + radius * amt
         self.y = old_y
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if self.rect.left >= 0 and self.rect.left + self.rect.width < self.game.current_map.width and \
             self.rect.top >= 0 and self.rect.top + self.rect.height < self.game.current_map.height:
             if not (check_collision(self, self.game.current_map.game_objects) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                 return
         
         self.x = old_x
         self.y = old_y + radius * amt
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if self.rect.left >= 0 and self.rect.left + self.rect.width < self.game.current_map.width and \
             self.rect.top >= 0 and self.rect.top + self.rect.height < self.game.current_map.height:
             if not (check_collision(self, self.game.current_map.game_objects) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                 return
         
         self.x = old_x - radius * amt
         self.y = old_y
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if self.rect.left >= 0 and self.rect.left + self.rect.width < self.game.current_map.width and \
             self.rect.top >= 0 and self.rect.top + self.rect.height < self.game.current_map.height:
             if not (check_collision(self, self.game.current_map.game_objects) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                 return
         
         self.x = old_x
         self.y = old_y - radius * amt
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if self.rect.left >= 0 and self.rect.left + self.rect.width < self.game.current_map.width and \
             self.rect.top >= 0 and self.rect.top + self.rect.height < self.game.current_map.height:
             if not (check_collision(self, self.game.current_map.game_objects) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                 return
         
         radius += 1
Exemplo n.º 5
0
 def land(self):
     self.current_image = self.image
     
     collisions = pygame.sprite.spritecollide(self, self.game.current_map.game_objects, False)
     for collider in collisions:
         if isinstance(collider, Visitor):
             collider.die()
     
     if check_collision(self, self.game.current_map.unwalkable_tiles) \
         or check_collision(self, self.game.current_map.game_objects):
         self.fix_me()
         
     pass
Exemplo n.º 6
0
 def getOutOfTree(self):
     #find some spot to put myself
     oldx = self.x
     oldy = self.y
     self.y = oldy - TILE_SIZE
     self.rect.top = self.y + self.top_offset
     self.rect.left = self.x + self.left_offset
     if (check_collision(self, self.game.current_map.game_objects) or 
         check_collision(self, self.game.current_map.unwalkable_tiles)):
         self.y = oldy + TILE_SIZE
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if (check_collision(self, self.game.current_map.game_objects) or 
             check_collision(self, self.game.current_map.unwalkable_tiles)):
             self.x = oldx - TILE_SIZE
             self.y = oldy
             self.rect.top = self.y + self.top_offset
             self.rect.left = self.x + self.left_offset
             if (check_collision(self, self.game.current_map.game_objects) or 
                 check_collision(self, self.game.current_map.unwalkable_tiles)):
                 self.x = oldx + TILE_SIZE
                 self.rect.top = self.y + self.top_offset
                 self.rect.left = self.x + self.left_offset
                 if (check_collision(self, self.game.current_map.game_objects) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                     self.x = oldx
                     self.y = oldy
                     self.rect = self.climbing_rect
                     self.left_offset = self.climbing_left_offset
                     self.top_offset = self.climbing_top_offset
                     self.rect.top = self.y + self.top_offset
                     self.rect.left = self.x + self.left_offset
                     return
     self.isInTree = False    
Exemplo n.º 7
0
 def leave_car(self):
     if self.isInCar:
         #find some spot to put myself
         self.x = self.car.x
         self.y = self.car.y - self.rect.height - 1
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if (check_collision(self, self.game.current_map.game_objects) or 
             check_collision(self, self.game.current_map.unwalkable_tiles)):
             self.y = self.car.y + self.car.rect.height
             self.rect.top = self.y + self.top_offset
             self.rect.left = self.x + self.left_offset
             if (check_collision(self, self.game.current_map.game_objects) or 
                 check_collision(self, self.game.current_map.unwalkable_tiles)):
                 self.x = self.car.x - self.rect.width - 1
                 self.y = self.car.y
                 self.rect.top = self.y + self.top_offset
                 self.rect.left = self.x + self.left_offset
                 if (check_collision(self, self.game.current_map.game_objects) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                     self.x = self.car.x + self.car.rect.width + self.rect.width + 1
                     self.rect.top = self.y + self.top_offset
                     self.rect.left = self.x + self.left_offset
                     if (check_collision(self, self.game.current_map.game_objects) or 
                         check_collision(self, self.game.current_map.unwalkable_tiles)):
                         # Oh well, I guess we're stuck
                         return
         
         self.car.leaveCar()
         self.isInCar = False
         self.car = None
         self.game.current_map.game_objects.add(self)
Exemplo n.º 8
0
    def land(self):
        self.current_image = self.image

        collisions = pygame.sprite.spritecollide(
            self, self.game.current_map.game_objects, False)
        for collider in collisions:
            if isinstance(collider, Visitor):
                collider.die()

        if check_collision(self, self.game.current_map.unwalkable_tiles) \
            or check_collision(self, self.game.current_map.game_objects):
            self.fix_me()

        pass
Exemplo n.º 9
0
 def move(self, x_change, y_change):
     if (check_collision(self, self.game.current_map.game_objects) or 
         check_collision(self, self.game.current_map.unwalkable_tiles)):
         self.fix_me()
          
     # check x
     old_rect = self.rect
     delta_x = x_change * self.speed
     self.rect = self.rect.move(delta_x, 0)
     if self.rect.left < 0 or self.rect.left + self.rect.width >= self.game.current_map.width:
         self.rect = old_rect
     elif (check_collision(self, self.game.current_map.game_objects) or 
           check_collision(self, self.game.current_map.unwalkable_tiles)):
         self.rect = old_rect
     
     old_rect = self.rect
     delta_y = y_change * self.speed
     self.rect = self.rect.move(0, delta_y)
     if self.rect.top < 0 or self.rect.top + self.rect.height >= self.game.current_map.height:
         self.rect = old_rect
     elif (check_collision(self, self.game.current_map.game_objects) or 
           check_collision(self, self.game.current_map.unwalkable_tiles)):
         self.rect = old_rect
         
     self.x = self.rect.left - self.left_offset
     self.y = self.rect.top - self.top_offset
Exemplo n.º 10
0
 def move(self, x_change, y_change):
     new_damage = 0
     
     # check x
     old_rect = self.rect
     delta_x = x_change * self.speed
     self.rect = self.rect.move(delta_x, 0)
     if (check_collision(self, self.game.current_map.unwalkable_tiles)):
         new_damage = .1
         self.rect = old_rect
         self.side_speed = -self.side_speed
         
     old_rect = self.rect
     delta_y = y_change * self.speed
     self.rect = self.rect.move(0, delta_y)
     if (check_collision(self, self.game.current_map.unwalkable_tiles)):
         new_damage = .1
         self.rect = old_rect
         self.forward_speed = -self.forward_speed
         
     self.x = self.rect.left - self.left_offset
     self.y = self.rect.top - self.top_offset
     if self.driver:
         self.driver.x = self.x
         self.driver.y = self.y
     
     collisions = pygame.sprite.spritecollide(self, self.game.current_map.game_objects, False)
     self.fix_me()
     if collisions is not None:
         for collision in collisions:
             if collision is not self:
                 collision.ranOver(self)
     
     self.damage += new_damage
 
     if (pygame.time.get_ticks() > (self.start_time + 1600)) and self.driving and self.driver:
             self.game.soundUtil.LoadSound('idle.wav', "car")
             self.game.soundUtil.PlaySound("car")
Exemplo n.º 11
0
    def move(self, x_change, y_change):
        if not self.is_jumping:
            Player.move(self, x_change, y_change)
            return

        newx = x_change + self.x
        newy = y_change + self.y

        # x
        # make sure we're still on the map
        if newx < 0 or newx >= self.game.current_map.tiles_wide * 32:
            newx = self.x

        if newy < 0 or newy >= self.game.current_map.tiles_high * 32:
            newy = self.y

        if self.x is newx and self.y is newy:
            return

        # check x
        old_rect = self.rect
        delta_x = x_change * self.speed
        self.rect = self.rect.move(delta_x, 0)
        if check_collision(self, self.game.current_map.unjumpable_tiles) or \
            check_collision(self, self.game.current_map.unjumpable_objects) :
            self.rect = old_rect

        old_rect = self.rect
        delta_y = y_change * self.speed
        self.rect = self.rect.move(0, delta_y)
        if check_collision(self, self.game.current_map.unjumpable_tiles) or \
            check_collision(self, self.game.current_map.unjumpable_objects) :
            self.rect = old_rect

        self.x = self.rect.left - self.left_offset
        self.y = self.rect.top - self.top_offset
Exemplo n.º 12
0
 def move(self, x_change, y_change):
     if not self.is_jumping:
         Player.move(self, x_change, y_change)
         return
     
     newx = x_change + self.x
     newy = y_change + self.y
     
     # x
     # make sure we're still on the map
     if newx < 0 or newx >= self.game.current_map.tiles_wide*32:
         newx = self.x
     
     if newy < 0 or newy >= self.game.current_map.tiles_high*32:
         newy = self.y
         
     if self.x is newx and self.y is newy:
         return
     
     # check x
     old_rect = self.rect
     delta_x = x_change * self.speed
     self.rect = self.rect.move(delta_x, 0)
     if check_collision(self, self.game.current_map.unjumpable_tiles) or \
         check_collision(self, self.game.current_map.unjumpable_objects) :
         self.rect = old_rect
         
     old_rect = self.rect
     delta_y = y_change * self.speed
     self.rect = self.rect.move(0, delta_y)
     if check_collision(self, self.game.current_map.unjumpable_tiles) or \
         check_collision(self, self.game.current_map.unjumpable_objects) :
         self.rect = old_rect
         
     self.x = self.rect.left - self.left_offset
     self.y = self.rect.top - self.top_offset
Exemplo n.º 13
0
    def leave_car(self):
        if self.isInCar:
            #find some spot to put myself
            self.x = self.car.x
            self.y = self.car.y - self.rect.height - 1
            self.rect.top = self.y + self.top_offset
            self.rect.left = self.x + self.left_offset
            if (check_collision(self, self.game.current_map.game_objects)
                    or check_collision(
                        self, self.game.current_map.unwalkable_tiles)):
                self.y = self.car.y + self.car.rect.height
                self.rect.top = self.y + self.top_offset
                self.rect.left = self.x + self.left_offset
                if (check_collision(self, self.game.current_map.game_objects)
                        or check_collision(
                            self, self.game.current_map.unwalkable_tiles)):
                    self.x = self.car.x - self.rect.width - 1
                    self.y = self.car.y
                    self.rect.top = self.y + self.top_offset
                    self.rect.left = self.x + self.left_offset
                    if (check_collision(self,
                                        self.game.current_map.game_objects)
                            or check_collision(
                                self, self.game.current_map.unwalkable_tiles)):
                        self.x = self.car.x + self.car.rect.width + self.rect.width + 1
                        self.rect.top = self.y + self.top_offset
                        self.rect.left = self.x + self.left_offset
                        if (check_collision(self,
                                            self.game.current_map.game_objects)
                                or check_collision(
                                    self,
                                    self.game.current_map.unwalkable_tiles)):
                            # Oh well, I guess we're stuck
                            return

            self.car.leaveCar()
            self.isInCar = False
            self.car = None
            self.game.current_map.game_objects.add(self)
Exemplo n.º 14
0
 def getOutOfTree(self):
     #find some spot to put myself
     oldx = self.x
     oldy = self.y
     self.y = oldy - TILE_SIZE
     self.rect.top = self.y + self.top_offset
     self.rect.left = self.x + self.left_offset
     if (check_collision(self, self.game.current_map.game_objects) or
             check_collision(self, self.game.current_map.unwalkable_tiles)):
         self.y = oldy + TILE_SIZE
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if (check_collision(self, self.game.current_map.game_objects)
                 or check_collision(
                     self, self.game.current_map.unwalkable_tiles)):
             self.x = oldx - TILE_SIZE
             self.y = oldy
             self.rect.top = self.y + self.top_offset
             self.rect.left = self.x + self.left_offset
             if (check_collision(self, self.game.current_map.game_objects)
                     or check_collision(
                         self, self.game.current_map.unwalkable_tiles)):
                 self.x = oldx + TILE_SIZE
                 self.rect.top = self.y + self.top_offset
                 self.rect.left = self.x + self.left_offset
                 if (check_collision(self,
                                     self.game.current_map.game_objects)
                         or check_collision(
                             self, self.game.current_map.unwalkable_tiles)):
                     self.x = oldx
                     self.y = oldy
                     self.rect = self.climbing_rect
                     self.left_offset = self.climbing_left_offset
                     self.top_offset = self.climbing_top_offset
                     self.rect.top = self.y + self.top_offset
                     self.rect.left = self.x + self.left_offset
                     return
     self.isInTree = False
Exemplo n.º 15
0
 def move(self, x_change, y_change):
     if (check_collision(self, self.game.current_map.game_objects) or 
         check_collision(self, self.game.current_map.unswimmable_and_unwalkable_tiles)):
         self.fix_me()
          
     # check x
     old_rect = self.rect
     delta_x = x_change * self.speed
     self.rect = self.rect.move(delta_x, 0)
     if (check_collision(self, self.game.current_map.game_objects) or 
         check_collision(self, self.game.current_map.unswimmable_and_unwalkable_tiles)):
         self.rect = old_rect
         
     old_rect = self.rect
     delta_y = y_change * self.speed
     self.rect = self.rect.move(0, delta_y)
     if (check_collision(self, self.game.current_map.game_objects) or 
         check_collision(self, self.game.current_map.unswimmable_and_unwalkable_tiles)):
         self.rect = old_rect
         
     self.x = self.rect.left - self.left_offset
     self.y = self.rect.top - self.top_offset
Exemplo n.º 16
0
 def fix_me(self):
     if not (check_collision(self, self.game.current_map.not_player) or 
             check_collision(self, self.game.current_map.unwalkable_tiles)):
         return
     
     old_x = self.x
     old_y = self.y
     
     radius = 1
     amt = TILE_SIZE/32
     
     while(True):
         # Checks Right, Left, Top, Bottom
         self.x = old_x + radius * amt
         self.y = old_y
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if self.rect.left >= 0 and self.rect.left + self.rect.width < self.game.current_map.width and \
             self.rect.top >= 0 and self.rect.top + self.rect.height < self.game.current_map.height:
             if not (check_collision(self, self.game.current_map.not_player) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                 #self.side_speed = -self.side_speed
                 #self.side_acceleration = -self.side_acceleration
                 return
         
         self.x = old_x
         self.y = old_y + radius * amt
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if self.rect.left >= 0 and self.rect.left + self.rect.width < self.game.current_map.width and \
             self.rect.top >= 0 and self.rect.top + self.rect.height < self.game.current_map.height:
             if not (check_collision(self, self.game.current_map.not_player) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                 #self.side_speed = -self.side_speed
                 #self.side_acceleration = -self.side_acceleration
                 return
         
         self.x = old_x - radius * amt
         self.y = old_y
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if self.rect.left >= 0 and self.rect.left + self.rect.width < self.game.current_map.width and \
             self.rect.top >= 0 and self.rect.top + self.rect.height < self.game.current_map.height:
             if not (check_collision(self, self.game.current_map.not_player) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                 #self.foward_speed = -self.forward_speed
                 #self.forward_acceleration = -self.forward_acceleration
                 return
         
         self.x = old_x
         self.y = old_y - radius * amt
         self.rect.top = self.y + self.top_offset
         self.rect.left = self.x + self.left_offset
         if self.rect.left >= 0 and self.rect.left + self.rect.width < self.game.current_map.width and \
             self.rect.top >= 0 and self.rect.top + self.rect.height < self.game.current_map.height:
             if not (check_collision(self, self.game.current_map.not_player) or 
                     check_collision(self, self.game.current_map.unwalkable_tiles)):
                 #self.foward_speed = -self.forward_speed
                 #self.forward_acceleration = -self.forward_acceleration
                 return
         
         radius += 1