Created June 15th, 2014. Built on the Raspberry Pi.
This game is by far the most challenging we’ve built yet. We actually had to use some trigonometry! I felt like an idiot drawing triangles on paper to figure out if it was the sin, cosine, or tangent I needed… or the inverse of them. (Remember SohCahToa?)
Turns out we needed the arctangent to figure out which angle to send the missiles once we selected a random end point. Here’s the code:
I used a lot of broadcast signals in this game, primarily because I didn’t realize you could dig into variables of other sprites so I thought you had to broadcast information between them.
Before I get too far ahead of myself, here’s the code for the stage:
We set up the game so you start with only one missile coming down. Once you get to ten points, a second missile and a second defense system appears so you can fire off two defense shots at the same time. Adding in some random values here and there (like waiting between 1 and 3 seconds per shot) makes things fun. If you notice, for the missile code above, we also used a random speed for each missile shot.
Also, I started using different costumes on the stage for doing things like a game over screen.
The house code is pretty straight forward. I apologize for the color of the houses. That’s what Devon wanted and I couldn’t talk him out of it.
The defense guns are simple but I wanted to end the game if they got hit since you’d have no way to keep shooting. Later when we added a second defense gun, I realized that’s not exactly the case, but yeah… details.
I had fun with the defense shots also as they grow in size like an explosion when they reach their destination point.
Keep in mind, I’m only showing the code for one version of the sprites above, but you have to write click and duplicate them as needed, along with modifying the code and creating individual variables and broadcast messages.
When fixing a bug or adding a feature which other sprites also need, I find it really helpful to take the whole code block and just drag it over to the other sprite. It automatically creates a duplicate block for you.
This was a challenging game to build but it’s a whole lot of fun to play. It’s amazing to remember these games from my childhood and then rebuild them starting with just a blank slate. Super fun. 🙂
If you want to try it out, here’s the Scratch file for the Missile Attack Game.
Do you remember playing this game as a kid?