Beispiel #1
0
 def update(self):
     self.collision_object.set_position(self.fire_position)
     self.break_points = [self.fire_position]
     l = 1
     d = 10
     while l < self.length:
         self.collision_object.set_position(
             calculate_directional_position(
                 self.direction, self.collision_object.get_position(), d))
         collide_obj = collision_tools.is_colliding(
             self.collision_object, self.collision_object.get_position(),
             self.collision_object)
         if collide_obj is not None and isinstance(
                 collide_obj, collision_tools.CollisionFixRectangle):
             pos = position_class.Position(
                 self.collision_object.move_to_edge(collide_obj,
                                                    self.direction))
             self.break_points.append(pos)
             self.direction = reflect(
                 self.direction,
                 collide_obj.get_colliding_surface_angle(
                     self.collision_object))
         l += d
     self.break_points.append(
         position_class.Position(self.collision_object.get_position()))
Beispiel #2
0
 def __init__(self,
              pos,
              direction=0,
              speed=0,
              image=None,
              size=None,
              collision_object=None,
              t=10,
              room=None,
              player=None):
     self.size = size
     self.image_original = image
     # todo it is a good idea to create a class able to handle animation and use it instead
     self.image = pygame.transform.scale(self.image_original, self.size)
     self.image = pygame.transform.rotozoom(self.image, -direction, 1)
     self.position = position_class.Position(pos)  # current position of obj
     self.speed = speed
     self.direction = direction
     self.collision_obj = collision_object
     # todo Do I really need to give the room to object ??
     self.room = room  # room which this object is in
     self.timer = timer_obj.Timer(t)  # t sec to self destruction
     self.timer.set_timer()  # start of timer is creation time
     self.player = player
     FireLoadObjectsList.append(self)  # add self to object list
Beispiel #3
0
 def __init__(self,
              pos,
              image,
              size,
              clock,
              player=None,
              room=None,
              direction=0):
     # position
     self.position = position_class.Position(pos)  # center of panzer
     self.speed = 0
     self.acceleration = 0
     self.direction = 0
     # image
     self.original_image = image
     self.image = pygame.transform.scale(image, size)
     self.size = size
     self.clock = clock
     # collision
     self.collision_obj = collision_tools.CollisionCircle(self.position,
                                                          20,
                                                          self,
                                                          solid=True)
     # fire
     self.flag_ready_fire = True
     self.timer = timer_obj.Timer(1)  # reload timer
     self.room = room
     self.bullet_type = fire_load.BouncyFireLoad
     self.Gun = None
     self.player = player
     self.set_direction(direction)
     self.Ragbar_timer = timer_obj.Timer(2)
 def __init__(self, img, pos):
     self.position = position_class.Position(pos)
     self.size = img.get_rect().size
     self.image = img
     self.collision_object =\
         collision_tools.CollisionFixRectangle(self.get_left_corner(), self.size[0], self.size[1], self)
     object_list.append(self)
Beispiel #5
0
 def mouse_on_index(self, mp):
     if not isinstance(mp, position_class.Position):
         mp = position_class.Position(mp)
     if tools.is_in_rectangle(mp, self.get_rect()):
         for index in range(len(self.label_list)):
             if self.label_list[index].is_mouse_on():
                 return index
     return None
Beispiel #6
0
 def undo(self, window):
     if len(self.last_move) == 3:
         self.board[self.last_move[1]] = self.board[self.last_move[2]]
         self.board[self.last_move[1]].has_moved = self.last_move[0]
         self.board[self.last_move[2]] = None
         self.board[self.last_move[1]].position = position_class.Position(
             self.last_move[1], self)
         self.turn = self.turn_switch[self.turn]
     elif len(self.last_move) == 6:
         self.board[self.last_move[1]] = self.board[self.last_move[2]]
         self.board[self.last_move[1]].has_moved = self.last_move[0]
         self.board[self.last_move[2]] = refer[self.last_move[3]](
             position=self.last_move[2], team=self.last_move[4], game=self)
         self.board[self.last_move[2]].has_moved = self.last_move[5]
         self.board[self.last_move[1]].position = position_class.Position(
             self.last_move[1], self)
         self.turn = self.turn_switch[self.turn]
     window.update()
 def __init__(self, pos, r, link_object=None, solid=False):
     self.position = position_class.Position(pos)  # center position
     self.radius = r
     self.parent = link_object
     self.solid = solid
     # add object to collidabel_objects dictionary
     global count
     self.id = count
     collidable_objects[self.id] = self
     count += 1
Beispiel #8
0
 def __init__(self, position, team, game, initialize=True):
     self.game = game
     self.team = team
     self.status = 'Alive'
     self.has_moved = False
     self.position = position_class.Position(position, game)
     self.line = int(position[1])
     self.column = position[0]
     ## the initialize attribute is added so that when the rook class is called inside the queen class, it does't overwrite it in the board
     if initialize:
         game.board[position] = self
         game.pieces.append(self)
Beispiel #9
0
 def __init__(self, image, size, pos, direction=0):
     self.image = image
     self.image = pygame.transform.smoothscale(self.image, size)
     self.image = pygame.transform.rotozoom(self.image, direction, 1)
     self.size = size
     self.direction = direction  # wall direction
     self.pos = position_class.Position(pos)
     rotate_size = rotate_point(size, self.direction)
     rotate_size = ceil(abs(rotate_size[0])), ceil(abs(rotate_size[1]))
     self.collision_obj = \
         collision_tools.CollisionFixRectangle(self.pos, rotate_size[0], rotate_size[1], self, solid=True)
     object_list.append(self)
Beispiel #10
0
 def __init__(self, pos, direction, panzer):
     self.fire_position = position_class.Position(pos)
     self.direction = direction
     self.fire_direction = direction
     self.collision_object = collision_tools.CollisionPoint(
         self.fire_position, self)
     self.fire_state = 'Aim'
     self.length = 200
     self.break_points = [pos]
     self.update()
     self.panzer = panzer
     FireLoadObjectsList.append(self)
    def __init__(self, pos, w, h, link_object=None, solid=False):
        self.position = position_class.Position(
            pos)  # top left corner of rectangle
        self.width = w
        self.height = h
        self.parent = link_object
        self.solid = solid
        # add object to collidabel objects dictionary

        global count
        self.id = count
        collidable_objects[self.id] = self
        count += 1
Beispiel #12
0
 def __init__(self,
              text,
              pos,
              color,
              font=pygame.font.SysFont('serif', 20, True, False),
              click_able=False):
     self.label_name = text
     self.text_str = text
     self.pos = position_class.Position(pos)
     self.color = color
     self.font = font
     self.render = font.render(self.text_str, True, self.color)
     self.click_able = click_able
     self.background = None
     self.background_size = None
Beispiel #13
0
 def update_collision_points(self):
     list_temp = self.collision_points + [self.position]
     d = self.line_length()
     if d > self.length:
         len_need = d - self.length
         p0 = list_temp[0]
         p1 = list_temp[1]
         dy = p1[1] - p0[1]
         dx = p1[0] - p0[0]
         line_dir = degrees(atan2(dy, dx))
         p = position_class.Position(
             calculate_directional_position(line_dir, p0, len_need))
         if distance(p, list_temp[1]) < 10 and len(list_temp) > 2:
             del self.collision_points[0]
         else:
             self.collision_points[0] = p
Beispiel #14
0
 def update_collision_points(self):
     list_temp = self.collision_points + [self.position]
     d = 0
     for i in range(len(list_temp) - 1):
         d += distance(list_temp[i], list_temp[i + 1])
     if d > self.length:
         len_need = d - self.length
         p0 = list_temp[0]
         p1 = list_temp[1]
         dy = p1[1] - p0[1]
         dx = p1[0] - p0[0]
         line_dir = degrees(atan2(dy, dx))
         p = position_class.Position(
             calculate_directional_position(line_dir, p0, len_need))
         if len(list_temp) > 2:
             del self.collision_points[1]
         self.collision_points[0] = p
Beispiel #15
0
    def move(self, position):
        if position in self.possible_attacks():
            self.game.last_move = [
                self.has_moved, self.position.position, position,
                self.game.board[position].type, self.game.board[position].team,
                self.game.board[position].has_moved
            ]
            if self.game.board[position].type == 'king':
                self.game.winner = self.team
            self.game.board[self.position.position] = None
            position_class.Position(position,
                                    self.game)._get_piece().status = 'Dead'
            position_class.Position(position,
                                    self.game)._get_piece().line = None
            position_class.Position(position,
                                    self.game)._get_piece().column = None
            position_class.Position(position,
                                    self.game)._get_piece().position = None
            self.has_moved = True
            self.line = position[1]
            self.column = position[0]
            self.position = position_class.Position(position, self.game)
            self.game.board[position] = self
            if self.type == 'pawn' and (position[1] == '1'
                                        or position[1] == '8'):
                return True
            return False

        elif position in self.possible_moves():
            self.game.last_move = [
                self.has_moved, self.position.position, position
            ]
            self.game.board[self.position.position] = None
            self.has_moved = True
            self.line = position[1]
            self.column = position[0]
            self.position = position_class.Position(position, self.game)
            self.game.board[position] = self
            return False

        else:
            return None
 def get_left_corner(self):
     return self.position - position_class.Position(self.size)/2
Beispiel #17
0
 def set_position(self, pos):
     self.position = position_class.Position(pos)
     self.collision_obj.set_position(self.position)
Beispiel #18
0
 def get_top_left_corner(self):
     return self.position - (
         position_class.Position(self.image.get_rect().size) / 2)
Beispiel #19
0
 def __init__(self, pos):
     self.label_list = []
     self.count_labels = 0
     self.pos = position_class.Position(pos)
     self.size = (0, 0)
     self.padding = [10, 10, 50]  # top, left, between
 def set_position(self, pos):
     self.position = position_class.Position(pos)
     collidable_objects[self] = self.position