def return_to_player(self): if self.is_active and self.returning: try: px, py = game_object.position distance = (get_distance((self.x, self.y), (px, py))) self.velocity = ((-px + self.x) / distance * -5, (-py + self.y) / distance * -5) except ZeroDivisionError: pass
def physics(self): if self.is_active: dog = game_object.collide_with(self.box_collider, Dog) if dog is not None: # self.deactivate() # dog.deactivate() distance1 = get_distance((self.x, self.y), (dog.x, dog.y)) dog.velocity = ((dog.x - self.x) / distance1 * 10, (dog.y - self.y) / distance1 * 10) dog.stun_timer.reset() dog.returning = False enemy = game_object.collide_with(self.box_collider, Enemy) if enemy is not None: distance2 = get_distance((self.x, self.y), (enemy.x, enemy.y)) enemy.velocity = ((enemy.x - self.x) / distance2 * 20, (enemy.y - self.y) / distance2 * 20) enemy.stun_timer.reset() enemy.returning = False
def shoot_left(self): if self.input_manager.left_mouse_clicked and self.has_shoot1: self.has_shoot1 = False # print('left hitu') # game_object.recycle(Shot1) try: distance = (get_distance( (self.x, self.y), (self.input_manager.mouse_x, self.input_manager.mouse_y))) shot1 = game_object.recycle(Shot1, self.x, self.y) shot1.velocity = ((self.input_manager.mouse_x - self.x) / distance * 5, (self.input_manager.mouse_y - self.y) / distance * 5) shot1.counter.reset() except ZeroDivisionError: # game_object.add(shot1) pass
def move(self): if self.stun_timer.expired: try: px, py = game_object.position distance = (get_distance((self.x, self.y), (px, py))) self.velocity = ((-px + self.x) / distance * -1, (-py + self.y) / distance * -1) except ZeroDivisionError: pass else: self.stun_timer.run() print(self.stun_timer.count) self.return_to_player() vx, vy = self.velocity # print(self.velocity) self.x += vx self.y += vy
def shoot_right(self): if self.input_manager.right_mouse_clicked and self.has_shoot2: self.has_shoot2 = False try: distance = (get_distance( (self.x, self.y), (self.input_manager.mouse_x, self.input_manager.mouse_y))) shot2 = game_object.recycle(Shot2, self.x, self.y - 10) shot2.velocity = ((self.input_manager.mouse_x - self.x) / distance * 10, (self.input_manager.mouse_y - self.y) / distance * 10) shot2.time_before_disappear.reset() except ZeroDivisionError: # game_object.add(shot1) pass if self.has_shoot2 == False: self.counter2.run() if self.counter2.expired: self.has_shoot2 = True self.counter2.reset()