Turning a Fun Project into Lessons: Programming a Space Shooter in Squeak/Smalltalk

Screenshot of the Shooter Game

These lessons are based on a simplified version of a space shooter game that I developed using Squeak. The original version was very fun to develop and was my first Squeak program. I continue to work on it to improve it and to further my understanding of object-oriented programming. I am not an expert and still have much to learn.

The original game lent itself well to teaching an entire program to my son using Smalltalk and its environment. He already had a couple of years learning Python. I figured that in the second half of his school year I would teach him Smalltalk. The game had elements he would enjoy programming, and it was in a domain he was already familiar with.

My son picked up Smalltalk quickly. While he understood Python well, he grasped Smalltalk even more easily. As a language, Smalltalk removed the language barrier and made it easy for him to focus instead on the tasks at hand and be creative (at his level, he is 12). The language just seemed natural to him. Smalltalk is a great language, even for kids. Squeak, in particular, offers a lot in this regard. It provides an excellent environment for teaching and learning Smalltalk, object-oriented programming, and programming in general.

He enjoyed using Squeak, and here is a bit of what he wrote in a report about his experience:

Smalltalk is an object-oriented programming language that is really easy to use. If you create a game, you can change it while it is still running! Unlike other programming languages this takes less time to code. In other languages you have to type SO many lines of code.

In Smalltalk there is a thing called the debugger that puts you straight to the flaw so you can fix it, you don't even need to get out of the debugger to fix the flaw. Other languages you have to look at almost all of your code to find one tiny mistake.

You can also “explore” morphs to find out what it took to code the morph. Smalltalk is like a digital playground, you can add so many things in your code, like sound effects.

Programming concepts are introduced throughout the lessons to keep things moving and to ensure that each topic receives proper attention. These lessons are designed for live coding, meaning the game does not need to be closed and restarted when changes are made. You can follow through the lessons just as easily without live coding; however, you may not learn as many topics, as some only arise from using live coding. Each lesson also includes a corresponding downloadable PDF document for additional reference.

Although the lessons were created for my middle school-aged child, they could also be fun for adults (I have had some ask for them, which is why I have made them available). I wrote the lessons daily and tried to be consistent throughout, but I am sure such may not always be the case. I also discussed topics before each lesson, providing much more detail. There may be things not written that would be helpful – if so, please let me know. I am happy to add more helpful information. Feedback is certainly welcome. Chapter 1 of the Squeak By Example PDF/book below would be a great resource to get started.

Key Learning Topics and Skills Covered in These Lessons:

  1. Foundational Concepts and Object-Oriented Programming
  2. Practical Development Practices
  3. User Interface and Interaction
  4. Working with Morphs in Squeak/Smalltalk
  5. Learning Approach

Game Controls:

Game Features:

Resources

Squeak Smalltalk – squeak.org
Squeak by Example PDF (6.0 Edition) – SBE-6.0.pdf
Squeak by Example printed book (6.0 Edition) – Amazon, Lulu
An Introduction to Morphic: The Squeak User Interface Framework – morphic.final.pdf

Source code (open, MIT license):
Filein code for this game – ShooterGame.st (full code for the game)
Hit sound file – HitSound.wav
Ship image file – Ship.png
Enemy image file – Enemy.png
Shooter Game in your browser – Play Now!

Lessons

Lesson 1 – Creating and Positioning Morphs
Lesson 2 – Moving Morphs
Lesson 3 – Moving a Morph with Code
Lesson 4 – Using Cascades in Code
Lesson 5 – Designing Objects
Lesson 6 – Defining Object Behavior and Interaction
Lesson 7 – Creating a Game Screen
Lesson 8 – Creating a Ship
Lesson 9 – Adding a Ship
Lesson 10 – Positioning the Ship on the Game Screen
Lesson 11 – Handling Events
Lesson 12 – Moving the Ship
Lesson 13 – Giving the Ship Boundaries
Lesson 14 – Creating a Shot
Lesson 15 – Moving the Shot
Lesson 16 – Creating an Enemy
Lesson 17 – Moving the Enemy
Lesson 18 – Making the Enemy Move Automatically
Lesson 19 – Checking for Contact with an Enemy
Lesson 20 – Destroying an Enemy
Lesson 21 – Creating a Score
Lesson 22 – Using the Score in the Game
Lesson 23 – Updating the Score on Enemy Destruction
Lesson 24 – Adding More Enemies
Lesson 25 – Making Enemies Appear Again
Lesson 26 – Adding a Starry Background (Student Requested Feature)
Lesson 27 – Adding Sound (Student Requested Feature)
Lesson 28 – Aimbot! (Student Requested Feature)
Lesson 29 – Making Stars Twinkle (Student Requested Feature)
Lesson 30 – Using Images as Morphs
Lesson 31 – Making Enemies Appear Randomly

If you have any questions, comments, or suggestions you can reach me at scott.gibson@posteo.net.