Creating an Aim-Game / Tower Defense Game in Scratch

Welcome back to Scratch 101! In this lesson, we will be creating an "aim-game", i.e. a precursor script to a more fully developed tower defense game.

Objective: Understand how the flow of control allows for the interaction between different sprites. Furthermore, this will strengthen student's understanding of both direction and cloning. 

Tower Defense Games
Screenshots from various tower defense games. 
To quote an article from the Loop, "Tower Defense, is a game system which, like all great game systems, is simple to learn but hard to master. Almost without exception, it involves a horde of lumbering creatures who enter from one location and are trying to make a trip to the opposite side of your screen. If enough of them are successful, you lose the game. To thwart their plans, you build “towers” to block their paths as best you can. The towers don’t just get in their way, however; they shoot, pummel or otherwise attack the passing creeps. If you’re quick on your feet and a bit of a strategist, you can prevent the oncoming hordes from successfully making it from point A to point B. And that’s what it’s all about."

This tutorial modifies this structure by creating a target that neither moves nor interacts with the user. Rather, this game simply tests "aim" towards a static structure. You can see more of the logistics within the video sample of the completed project below.

Final Product:




Graphic Template: Please find the necessary costumes/backgrounds in this project. Hit the "remix" button to move this to your personal account (the projects are named "precision shot").

Scripts: 

Place these sequences within the "Turrent" sprite

Turrent Sprite Code
Script to connect the "turrent" the mouse and provide "turrent" functionality to the user. 


Place these sequences within the "shot" sprite


Scratch Code Cloning Shot Sprite
Sprite script to execute "turrent" functionality utilizing cloning (primarily).

Place these sequences within the "target" sprite

Scratch Code Target Sprite
Sprite to execute "target" random movement and functionality.


Consider: At the end of my video, the "target" sprite become to small to hit. How would I change the movement of the sprite towards my target (i.e. the "shot") in order to avoid this from happening in the future? During the second half of my video, I just started moving the cursor onto the target (kind of removing the necessity of having any skill). What code would you add in order to make sure that the person could only change the direction of the turrent within a limited (circular) radius around the turrent?

Wrap Up: This lesson focused on the interaction between sprites and clones to create a simpler version of more famous tower defense games. If you wish to continue with this concept, see what other game elements you can build into the project. 

Completed Project: Attached is the final version of the project.

7 comments: