def _draw_laser(cls, canvas: tk.Canvas, laser: Laser): """Draws a laser with random colours""" try: canvas.laser_counts[laser] += 1 except KeyError: canvas.laser_counts[laser] = 1 if canvas.laser_counts[laser] < 3: canvas.total_laser_count += 1 x, y = laser.position length, width = laser.size dx, dy = rotate_point((length / 2, width / 2), laser.rotation) #head = x + dx, y + dy #tail = x - dx, y - dy head = x + dx, y + dy tail = x, y colour = random.choice(('red', 'lightblue', 'yellow', 'white')) return canvas.create_line(head, tail, tag='laser', fill=colour, width=random.random() * 3) #was #00ffff (aqua)
def _draw_missile(cls, canvas: tk.Canvas, missile: Missile): """Draws a missile""" x, y = missile.position length, width = missile.size dx, dy = rotate_point((length / 2, width / 2), missile.rotation) head = x + dx, y + dy tail = x - dx, y - dy return canvas.create_line(head, tail, tag='obstacle')
def _draw_turret(cls, canvas: tk.Canvas, turret: Turret): """Draws a missile""" x, y = turret.position length, width = turret.size dx, dy = rotate_point((length / 1, width / 1), turret.rotation) head = x + dx, y + dy tail = x - dx, y - dy return canvas.create_line(head, tail, fill = turret.colour, tag='obstacle')
def _draw_fire(cls, canvas: tk.Canvas, fire: Fire): """Draws a fire""" x, y = fire.position length, width = fire.size dx, dy = rotate_point((length / 2, width / 2), fire.rotation) head = x + dx, y + dy tail = x - dx, y - dy return canvas.create_line(head, tail, tag='obstacle')
def _draw_bullet(cls, canvas: tk.Canvas, missile: Missile): """Draws a missile""" x, y = missile.position length, width = missile.size dx, dy = rotate_point((length / 2, width / 2), missile.rotation) head = x + dx, y + dy tail = x - dx, y - dy return canvas.create_line(head, tail, tag='obstacle', fill='orange', width=1) # had no fill before (black)
def draw_obstacles(self, obstacles): """ Draw a list of obstacles to the view, simultaneously removing previous obstacles Parameters: obstacles (list<Unit>): A list of obstacles to draw to the view """ self.delete('obstacle') # assuming missile for missile in obstacles: x, y = missile.position length, width = missile.size dx, dy = rotate_point((length / 2, width / 2), missile.rotation) head = x + dx, y + dy tail = x - dx, y - dy self.create_line(head, tail, tag='obstacle')