Smalltalk Programming
Lesson 10

You still need to integrate your ship better with your game. Today you will do so by adding a change in your ShooterGame class.

1. In your ShooterGame class, update your initializeShip with the changes below and then save your changes.

initializeShip

    
| myBottomCenter |
    
ship := Ship new.
    
myBottomCenter := self bottomCenter.
    
ship center: myBottomCenter x @ (myBottomCenter y - (ship height * 2)).
    
self addMorph: ship

2. You will notice a variable different from what you have learned up until now. In this change, you declared a temporary variable named myBottomCenter. This variable is only seen and known by this method. It is forgotten once this method has completed.

3. There are different reasons to use temporary variables. Here, you are using one so that you only have to type bottomCenter instead of continually typing self bottomCenter. This will also make your code easier to read. In this case it also helps Squeak to not have to calculate self bottomCenter multiple times. The more your program needs to calculate, the harder it needs to work.

4. Temporary variables are declared when placed between pipe (|) characters. Temporary variables can also be declared within blocks ([]’s).

5. What do you notice about the ship and your shooter game? What else needs to be done?

6. Save and Quit your Smalltalk image.

Download the PDF version.