コード例 #1
0
 def create_torpedo(self):
     torp = Torpedo(self.__ship_dict["ship"].get_location(X),
                    self.__ship_dict["ship"].get_location(Y),
                    self.__ship_dict["ship"].get_speed(X),
                    self.__ship_dict["ship"].get_speed(Y),
                    self.__ship_dict["ship"].get_heading())
     self.__screen.register_torpedo(torp)
     self.__screen.draw_torpedo(torp, torp.get_location(X),
                                torp.get_location(Y), torp.get_heading())
     self.__torpedo_dict[self.__torpedo_counter] = torp
コード例 #2
0
    def register_torpedo(self):
        '''

        :return: Generates objects with Class type Torpedo and draws them to the screen
        '''
        if self._screen.is_space_pressed() and len(self._torpedo_list) <= MAX_TORPEDOS:
            temp_x_speed, temp_y_speed = self._ship.get_speed()
            new_x_speed = temp_x_speed + ACC_FACTOR * math.cos(math.radians(self._ship.get_heading()))
            new_y_speed = temp_y_speed + ACC_FACTOR * math.sin(math.radians(self._ship.get_heading()))
            speed = new_x_speed, new_y_speed
            temp_torpedo = Torpedo(self._ship.get_location(), speed, self._ship.get_heading(), TORPEDO_RADIUS)
            if (id(temp_torpedo) not in TORPEDO_LIST_ID):
                TORPEDO_LIST_ID.append(temp_torpedo)
                self._screen.register_torpedo(temp_torpedo)
            x, y = temp_torpedo.get_location()
            self._screen.draw_torpedo(temp_torpedo, x, y, temp_torpedo.get_heading())
            self._torpedo_list.append(temp_torpedo)