Search for question
Question

Purpose: Pew pew! Degree of Difficulty: Moderate. This is pretty simple when done right, but it will be easy to go quite far of the right path. Think about this

carefully, and plan your work. The current space invaders game only allows one laser to be fired at a time; the user must wait until the laser has collided with something before another laser can be fired. This is too boring. You should modify the game so that a multiple laser beams can be fired by the player. Laser guns take some time to be recharged, so the player should only be allowed to shoot a laser once every 0.5 seconds. • Currently, only one Laser object is stored in the class Game. You'll need to change that with a container for multiple Laser objects. And there are places in the package model where the Laser object(s) are managed. You'll have to modify these locations to handle multiple Laser objects. Hint: the model already handles multiple Missile objects. Currently, the code in class Player prevents the player from firing if another laser object already exists.The simplest way to limit the player to 1 Laser per 0.5 seconds is by implementing a cool-down. To do this, a new boolean attribute in Player can be used to indicate whether the cool-down is over or not. The attribute should be initialized to true. Every time a Laser object is fired, the boolean attribute should be set to false. - The attribute should be set to true using a Timer object (java.swing.Timer). This Timer should be set for 500ms, and should have an Action Listener whose only job is to set the previously mentioned boolean attribute to true. In the method Player.fire(), if a laser is fired, the timer should be started (again).

Fig: 1

Fig: 2

Fig: 3

Fig: 4

Fig: 5

Fig: 6

Fig: 7

Fig: 8

Fig: 9