2022-07-21 16:07:13 -05:00
|
|
|
from turtle import Turtle
|
|
|
|
from bomb import Bomb
|
2022-07-28 14:54:31 -05:00
|
|
|
from audio import Audio
|
2022-07-21 16:07:13 -05:00
|
|
|
|
2022-07-26 14:12:41 -05:00
|
|
|
|
2022-07-26 14:39:29 -05:00
|
|
|
class Rocket(Turtle):
|
2022-07-21 16:36:45 -05:00
|
|
|
def __init__(self, x_min, x_max, y_min, y_max, screen, scoreboard):
|
2022-07-28 14:54:31 -05:00
|
|
|
"""
|
|
|
|
Initialize the rocket.
|
|
|
|
: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 screen: Screen object.
|
|
|
|
:param scoreboard: Scoreboard object.
|
|
|
|
"""
|
|
|
|
super().__init__()
|
|
|
|
self.x_min = x_min
|
|
|
|
self.x_max = x_max
|
|
|
|
self.y_min = y_min
|
|
|
|
self.y_max = y_max
|
|
|
|
self.screen = screen
|
|
|
|
self.scoreboard = scoreboard
|
|
|
|
|
|
|
|
# Set heading to 90 (pointing up)
|
|
|
|
for i in range(0, 360, 10):
|
|
|
|
shape = f'rocket{i}.gif'
|
|
|
|
if shape not in self.screen.getshapes():
|
|
|
|
self.screen.addshape(f'images/rocket/{shape}')
|
|
|
|
self.shape(f'images/rocket/rocket90.gif')
|
|
|
|
self.setheading(90)
|
2022-07-26 14:12:41 -05:00
|
|
|
|
2022-07-21 16:07:13 -05:00
|
|
|
def aim(self, x, y):
|
2022-07-28 14:54:31 -05:00
|
|
|
"""
|
|
|
|
Set the rocket's heading to point towards the given coordinates.
|
|
|
|
:param x: X coordinate.
|
|
|
|
:param y: Y coordinate.
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
heading = self.towards(x, y)
|
|
|
|
heading = int(heading / 10) * 10
|
|
|
|
self.setheading(heading)
|
|
|
|
self.shape(f'images/rocket/rocket{heading}.gif')
|
2022-07-21 16:07:13 -05:00
|
|
|
|
|
|
|
def shoot(self):
|
2022-07-28 14:54:31 -05:00
|
|
|
"""
|
|
|
|
Shoot a bomb.
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
Bomb(self.heading(), 0.1, self.x_min, self.x_max, self.y_min, self.y_max, self.scoreboard)
|
2022-07-28 16:00:29 -05:00
|
|
|
self.scoreboard.increment(-1, droneLost=False)
|
2022-07-28 14:54:31 -05:00
|
|
|
Audio.play_laser_sound()
|