2022-07-21 16:07:13 -05:00
|
|
|
from boundedturtle import BoundedTurtle
|
|
|
|
import math
|
|
|
|
from drone import Drone
|
2022-07-28 16:00:29 -05:00
|
|
|
from audio import Audio
|
2022-07-21 16:07:13 -05:00
|
|
|
|
2022-07-26 14:12:41 -05:00
|
|
|
|
2022-07-21 16:07:13 -05:00
|
|
|
class Bomb(BoundedTurtle):
|
2022-07-26 14:12:41 -05:00
|
|
|
def __init__(self, init_heading, speed, x_min, x_max, y_min, y_max, scoreboard):
|
2022-07-28 14:55:15 -05:00
|
|
|
"""
|
|
|
|
Initialize the bomb.
|
|
|
|
:param init_heading: Heading bomb should travel towards.
|
|
|
|
:param speed: Speed of bomb.
|
|
|
|
:param x_min: Minimum x coordinate of the screen.
|
|
|
|
:param x_max: Maximum x coordinate of the screen.
|
|
|
|
:param y_min: Minimum y coordinate of the screen.
|
|
|
|
:param y_max: Maximum y coordinate of the screen.
|
|
|
|
:param scoreboard: Scoreboard object.
|
|
|
|
"""
|
2022-07-28 16:00:29 -05:00
|
|
|
super().__init__(speed, x_min, x_max, y_min, y_max)
|
|
|
|
|
|
|
|
self.resizemode('user')
|
|
|
|
self.color('red', 'red')
|
|
|
|
self.shape('circle')
|
|
|
|
self.turtlesize(0.25)
|
|
|
|
self.setheading(init_heading)
|
|
|
|
self.getscreen().tracer(False)
|
|
|
|
self.getscreen().ontimer(self.move, 100)
|
|
|
|
self.scoreboard = scoreboard
|
2022-07-21 16:07:13 -05:00
|
|
|
|
|
|
|
def move(self):
|
2022-07-28 16:18:07 -05:00
|
|
|
self.forward(0.1)
|
|
|
|
if self.out_of_bounds():
|
|
|
|
self.remove()
|
2022-07-28 16:00:29 -05:00
|
|
|
for drone in Drone.get_drones():
|
|
|
|
if self.distance(drone) < self.get_speed() and self.isvisible():
|
|
|
|
drone.remove()
|
|
|
|
self.remove()
|
|
|
|
Audio.play_explosion_sound()
|
|
|
|
self.scoreboard.increment(4)
|
2022-07-28 16:18:07 -05:00
|
|
|
self.getscreen().ontimer(self.move, 100)
|
2022-07-21 16:07:13 -05:00
|
|
|
|
|
|
|
def distance(self, other):
|
|
|
|
p1 = self.position()
|
|
|
|
p2 = other.position()
|
|
|
|
return math.dist(p1, p2)
|
|
|
|
|
|
|
|
def remove(self):
|
2022-07-28 16:00:29 -05:00
|
|
|
self.hideturtle()
|
2022-07-28 16:18:07 -05:00
|
|
|
self.penup()
|
|
|
|
self.clear()
|