Lesson 6: Programming the Shooter Game in Squeak/Smalltalk

Lesson 6 – Object Interaction and Behavior

In the last lesson, you were asked to identify the objects present in Figure 1 of Lesson 5. From the example, we will be using the object names ShooterGame, Ship, Shot, Enemy, and Score. These names have been chosen because they are clear, descriptive, and directly relate to the roles these objects will play within the game. Each name corresponds to a specific function within the game, and using such intuitive names helps to keep the code organized and easy to understand.

The reason these names were selected is tied to their roles and responsibilities within the game. As you will see in the following explanations, each object has a clear purpose. At the core of everything is ShooterGame, which provides the game screen – the boundary within which all gameplay takes place. It serves as the origin point for the entire game, coordinating the creation and management of other game elements and the overall flow of activity. The Ship represents the player’s character, allowing for movement and interaction with enemies. Shot represents the projectiles fired by the player, which interact with enemies to destroy them. Enemy objects are the targets that move across the screen and can be destroyed by shots. Finally, the Score object tracks the points the player earns by destroying enemies. The following sections of this article will further explain the roles and responsibilities of each object in detail, providing a better understanding of how they work together in the game.

Key Object Behaviors

  • ShooterGame: The ShooterGame object provides the screen boundary and serves as the foundation from which the entire game emerges. It defines the playable area that other objects use to determine their positions and limits. In addition to supplying this essential structure, ShooterGame also acts as the central controller of the game. It initializes the Ship and Score at the start and recreates Enemy objects when all have been eliminated. It also coordinates the overall flow of the game, including when it begins and ends, and keeps track of the main objects involved in gameplay.
  • Ship: The Ship is controlled by the player, and its movements will be essential to the game. You can program the Ship to move in all four directions: up, down, left, and right. Unlike many games, the ship will not be destroyed if it comes into contact with an enemy, meaning the player can continue to control the ship without worrying about direct collisions with enemies. The ship’s movement and interactions with other objects will be crucial to progressing through the game.
  • Shot: The Shot object represents the projectiles that the player shoots at the enemies. Shots will move in an upward direction as the player fires them. The behavior of the Shot is simple: when a shot hits an enemy, the enemy is destroyed. This interaction between the shot and the enemy is one of the core mechanics of your space shooter game.
  • Enemy: The Enemy objects will move left and right across the screen, adding a dynamic element to the game. There will be three Enemy objects in the game, each with its own movement pattern. As the player’s shots hit the Enemy objects, the Enemy objects will be destroyed, and the player will earn points.
  • Score: The Score object is responsible for keeping track of the player’s points. Each time an enemy is destroyed, the player earns 100 points, and the score increases accordingly. The score is updated when a Shot hits an Enemy. Because the Score object displays its information on the ShooterGame screen, it maintains a relationship with it.

Object Interactions

Now that each object’s role and behavior has been identified, it is important to understand how these objects interact during gameplay. Their interactions define how the game functions and how players experience the game world.

  • Ship and ShooterGame: The Ship appears within the game screen provided by ShooterGame. It moves in response to player input and uses the boundaries of the game screen to determine how far it can travel. The screen boundaries provided by ShooterGame limit how far the Ship can move. ShooterGame provides the space in which the Ship operates, but it does not control the Ship’s movement.
  • Ship and Shot: When the player activates a firing action, the Ship releases a Shot that travels upward. This interaction allows the player to engage with enemies and is central to gameplay. The firing of a Shot gives the player a way to respond to the movement of Enemy objects on the screen.
  • Shot and ShooterGame: The game screen provided by ShooterGame establishes the upper boundary for shots. When a Shot moves upward and reaches the top of the screen, it is removed from play. ShooterGame does not manage or direct shots, but its boundaries help determine when a Shot leaves the gameplay area.
  • Shot and Enemy: If a Shot comes into contact with an Enemy during its path, both the Shot and the Enemy are removed from play. This interaction is a key part of gameplay: successful hits on Enemy objects are the player’s goal. When this happens, the Score is also updated to reflect the player’s progress.
  • Enemy and ShooterGame: Enemy objects move left and right across the game screen using the screen’s width to guide their motion. The screen boundaries provided by ShooterGame limit how far Enemy objects can move. When an Enemy is hit by a Shot, it is removed from the game screen.
  • Score and ShooterGame: The Score is displayed on the game screen and increases when an Enemy is destroyed. ShooterGame provides the location where the Score is shown during gameplay. As the game progresses, the Score gives players feedback on their performance and accomplishments.

Understanding how these objects behave and interact lays the groundwork for building a playable game. By thinking carefully about each object’s role and how it connects with others, you will be better prepared to implement the necessary features in code. These foundational concepts will continue to guide your work as you move forward with designing and programming the game’s functionality.

The tutorials are now also available for use inside the Squeak development environment through the Squeak Help System. Once installed, this resource allows you to read and follow the lessons directly within Squeak, making it easy to experiment with code and concepts without leaving the environment. The Help System documentation is included as part of the downloadable resources for the game and can be added to your Squeak image just like the other game assets.

Lesson Resources

To access Lesson 6 and the full series of tutorials for building the Shooter Game, visit https://scottgibson.site/ShooterGame/. There you will find everything you need to follow along, including PDFs, Squeak Help lesson content, source code, images, sound files, and other game assets. This resource also allows you to try out the game directly in your browser using SqueakJS. Whether you are new to programming, just getting started with Squeak/Smalltalk, or building on prior experience, these materials will support you as you continue developing your own version of the game.

Have a great time with Smalltalk and keep on Squeaking!

Comments

Leave a comment


Discover more from The Weekly Squeak

Subscribe to get the latest posts sent to your email.