Space Invaders Tutorial 2

Coming Soon

Shields
To make the game fairer, we will add in a Shield that will help protect our Laser Cannon from the Alien Lasers. The Shield can be destroyed by Alien and Laser Cannon fire.

Create Shield Agent: Create a new agent named "shield". We need two additional depictions for the Shield, which we can name "left_shield" and "right_shield". Use the pictures below as examples of how to make your Shield depictions.

 

Programming the Shield While Behaviors: Use the picture below to add the three rules to the Shield While Running loop.

 

Add Shields to the game worksheet: Now add some Shield agents to the game worksheet that we are making. You can use the picture at the top of this tutorial to help. Generally you will start with a Left Shield, next adding a Middle Shield section, and finally closing the Shield off with a Right Shield section. You will also want your shields to be at least two spaces above the level of the Laser Cannon. Save your worksheet when you are finished adding the Shields.

Explanation: The first rule sets up a "Health Point (HP)" variable for each Shield agent on the worksheet. To make the game simpler, we will give each Shield a "HP" value of 2. The variable name is only a description, but what we are going to do is allow each Shield segment to be hit two times before it is destroyed. Using the "game_start" value prevents the "HP" value from being reset to 2 each time the While Loop runs.

The second and third rules check for laser fire from either the top or bottom (Alien Laser or Laser). If a laser is seen, we wait to make sure the player actually gets to see the laser and then a "update_status" message is sent to the Shield that saw the laser and the appropriate message is sent back to the laser to destroy it.

Pro Tip: Variables always start with a zero value in AgentSheets. This is why the "game_start" value passes the test for zero before we assigned it a value!

Updating Shield Status
We now need to program what happens when a Shield is hit by a Laser. To start we need to make three new agent depictions for the Shield agent.

Add new depictions to Shield agent: The three new depictions that we need will show the Shields after being hit by a single Laser. The Shields should look damaged in some way.

 

Programming the Shield "update_status" Method Behaviors: Add a new Method to react to the "update_status" message in the Shield behavior and use the picture below to program how the behaviors should act.

 

Programming the Shield "update_pic" Method Behaviors: Add another new Method to react to the "update_pic" message in the Shield behavior and use the picture below to program how the behaviors should act.

 

Explanation: We make the extra depictions to visually show the player that their shields have been hit by their Laser or an Alien Laser. In this version of the game the shields can only be hit twice before being destroyed, but it would be easy to make them stronger.

The "update_status" method checks the current Shield condition (based on HP), updates the HP as necessary, and also calls the "update_pic" method to change the way that the Shields look.