Smalltalk Programming
Lesson 7

Today you will begin programming your shooter game. After completing this lesson, you will already be able to see results from your code.

1. Start by creating the class ShooterGame. To do this, open a System Browser. You can do this from the menu at the top by selecting Tools→Browser. Or, you can left click on the background and select Browser.

2. In the System Browser you can view and type code. This is not the only place where you can type and view code, but it will be what you use the most.

3. In your browser, left click within the top left pane. This will display some code that you can use to create your ShooterGame class.

System Browser – Before Creating a ShooterGame Class
Figure 1: System Browser – Before Creating a ShooterGame Class

4. In the bottom pane, make the changes below that are in yellow. When you are done, save your changes by pressing Ctrl-s. You can also right click your mouse in the code pane and select “accept (s)”. You will be asked to type your initials. This is so that Smalltalk can help keep track of your changes.

Morph subclass: #ShooterGame
    
instanceVariableNames: ''
    
classVariableNames: ''
    
poolDictionaries: ''
    
category: 'ShooterGame'

5. When you saved your code, you created a new class called ShooterGame. ShooterGame is a subclass of Morph. This means that ShooterGame inherits the things that Morph can do. The category is ShooterGame.

6. The category does not really do anything other than provide a way to group your code together as well as some other helpful things. You can name your category anything, but for now the name of your game (without spaces) which is ShooterGame.

7. Now add an initialization method. This is a method that is used when a new instance from your class is created. To do this, left click on “-- all --”.

System Browser - initialize method
Figure 2: System Browser - initialize method

8. In the bottom pane, type the following code like Figure 2 above.

initialize

    
super initialize.
    
self position: 100 @ 100.
    
self extent: 640 @ 480.
    
self color: Color black.
    
self setNameTo: 'Shooter Game'

9. After you are done, save your changes (Ctrl-s) and enter your initials (if necessary).

10. Look at each line of code. Can you figure out what each line of code is doing?

11. You can already see the beginnings of your game! Though it might not have everything just yet, soon you will have much more and a game that can be played that you made!

12. Save and Quit your Smalltalk image.

Download the PDF version.