Question: Given LaserCanon.py(python code) below: # screen - manage the laser cannon # bounded turtle - superclass for all turtles (drawable objects) on the screen #

 Given LaserCanon.py(python code) below: # screen - manage the laser cannon

Given LaserCanon.py(python code) below:

# screen - manage the laser cannon # bounded turtle - superclass for all turtles (drawable objects) on the screen # Bomb, Alien - inherit from bounded turtle # Game engine from turtle import Turtle, mainloop import random import math class LaserCannon(Turtle): def __init__(self, xmin, xmax, ymin, ymax): super().__init__() self.screen = self.getscreen() self.screen.bgcolor("light green") self.screen.setworldcoordinates(xmin, ymin, xmax, ymax) self.screen.onclick(self.aim) #we need to create a method for aim self.screen.onkey(self.shoot, "s") #we need to create a method for shoot self.screen.onkey(self.quit, "q") #we need to create a method for quit def aim(self, x, y): heading = self.towards(x, y) self.setheading(heading) def shoot(self): Bomb(self.heading(), 5) #we do not know at this point what this does, but we know we are creating a Bomb object #first argument is the direction, the second argument is the speed def quit(self): self.screen.bye() class BoundedTurtle(Turtle): #any object bounded by the screen def __init__(self, speed, xmin=-200, xmax=200, ymin=0, ymax=400): #the bounded turtle object has default values super().__init__() self.xmin = xmin self.xmax = xmax self.ymin = ymin self.ymax = ymax self.speed = speed def outOfBounds(self): xpos, ypos = self.position() #tuple indicating the current position of the BoundedTurtle out = False # assume the BoundedTurtle is inside of the bounds if xpos  self.xmax: out = True if ypos  self.ymax: out = True return out def move(self): self.forward(self.speed) if self.outOfBounds(): self.remove() #we need a method to remove the object from the screen else: self.getscreen().ontimer(self.move, 200) #this method .ontimer creates a callback to .move in the current instance # every 200 seconds def remove(self): self.hideturtle() class Bomb(BoundedTurtle): def __init__(self, initHeading, speed): super().__init__(speed) self.initHeading = initHeading self.shape("circle") self.color('red', 'red') self.resizemode('user') self.setheading(initHeading) self.up() self.turtlesize(.25) self.getscreen().ontimer(self.move, 100) def distance(self, other): #calculate distance between two BoundedTurtles for collision detection p1 = self.position() p2 = other.position() a = p1[0] - p2[0] b = p1[1] - p2[1] dist = math.sqrt(a**2 + b**2) return dist #overriding superclass move def move(self): exploded = False self.forward(self.speed) #collision detection for i in Alien.getAliens(): # this assumes that Alien in a class that can be iterated and that contains a method # .getAliens if self.distance(i)  

Question : I appreciate if you solve the problem by following information, but if you want to do by your codes, would take screenshot for me?
Problem 6 (50 XP): Modify the spaceinvades game so that the LaserCanon0 object automatically fires a Bomb onclik, rather than with the use of the "s" key. The LaserCanon0 still changes direction towards the direction of the (x.y) coordinate you click. This modification makes the game easier to play since it does not require the player to press "s" after changing direction to fire a Bomb

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!