Bounding Ball Collision Detection – Game Coding Tutorial
5th January 2020Learn to Code Asteroids – Lesson 5 – Scaling Vector Graphics
14th January 2020ZX Spectrum Jetpac – Retro Game Deconstruction
Jetpac was one of the best games created for the ZX Spectrum, BBC Micro and VIC20 home computers back in 1983. It was the first Ultimate Play the Game release to feature Jetman, who then went on the star in a number of other best selling games.
The game revolves around you, Jetman, building and fuelling your spaceship whilst fighting off hoards of hostile aliens. You’re armed with a laser cannon and equipped with a jet pack so you can fly up to collect various items that fall from the sky.
This is a great game to use as a programming project for beginner games coders. If you’ve followed through on my Space Invaders course you’ll have all the skills needed to rebuild Jetpac for yourself. The video above walks you through each of the game’s programming challenges giving hints and tips on how to solve them. I’ve detailed this out for you below as well.
Happy coding!
Tips for programming Jetpac
Player Movement
Jetman can walk on the ground and platforms or fly using the jet pack. You’ll need to get your collision detection so it’s able to detect landing on a walking surface or bouncing of an obstacle (see later). The thrust button accelerates Jetman upwards and he then falls back to ground under gravity. Both the upwards and falling motions have a maximum speed so once these are reached the vertical acceleration stops.
Player Firing
The laser cannon works differently to normal firing. If you watch the video you’ll see it in action.
Each firing action creates a stream of bullet objects that form a line extending horizontally from the player. Each bullet is a stationary line. At he start each line segment touches it’s neighbour to form the full laser beam, but it them shortens from the right hand end to form the receding broken line. This gives a great laser effect, but you’ll need to model each segment as a standalone object and perform collision detection on them all.
Game Objects
The player ship parts start on the ground and platforms. Fuel pods fall from the top of the screen and then land on the platforms or ground. Each of these objects can be picked up by walking into them. Their position then tracks the player position. Carrying an item doesn’t affect the player movement speed – or you may want to alter this in your version! Bonus items also fall from the sky at land on the platforms and ground. These disappear when you walk into them.
Platforms
There are three platforms in the game. Objects can land on them and the player can walk on them. When aliens hit them some will be destroyed and some will bounce off them. Your code needs to perform an enhanced version of the bounding box collision detection where it is able to detect which edge the collision has taken place on.
For example if the player object falls down onto a platform we need to detect when the collision occurs but also that it was the player object hitting the top surface of the platform. To do this you need to store both the current position of each object and its previous position. When you get a collision you can compare which edges of the bounding boxes were overlapping before the collision and which edges were overlapping after the collision. This information will tell you which surfaces collided. For diagonal collisions you might find that to edges are involved in the collision. If this happens you might consider the direction of the moving object to help decide which edge it hit.
Aliens
There are a number of alien types in the game but they all conform to 1 of five movement patterns.
The first aliens you encounter are the meteors. These simply start at one edge of the screen and fly in a straight line, either horizontally or at a slight downward angle until they hit something. If they hit the ground or a platform they simply explode, if they hit the player the explode, killing the player.
The second alien type moves in diagonal lines bouncing off the ground and platforms. They don’t react to the player position, just bouncing around the screen until they are shot by the laser.
The third alien type again moves in diagonal lines or horizontal lines bouncing off the ground and platforms. They are also able to change direction without hitting an object. These don’t react the player position either just moving down the screen until they too are shot.
The fourth movement pattern is a variation on the first were each alien initially starts at the edge of the screen, oscillating up and down for a short time before heading off towards the player position flying in a straight line. These aliens do track the player position and will adjust the angle of the flight to try and hit the player but they always travel from one edge of the screen towards the other. If they hit the ground a platform they simply explode.
The final movement pattern is where the aliens actively track the player position and simply fly towards it, bouncing off the ground and platforms as they go.
Build Jetpac Yourself
These tips should give you a good head start in remaking Jetpac for yourself. If you’ve never coded before have a go at my beginner’s programming course for Space Invaders where you’ll learn all the programming techniques you will need to build this game. My Asteroids course is a level II beginner’s course where you will further develop your programming skills.
Whatever game development system you are using these retro games make great coding projects. If you want to play Jetpac check out my video on how to turn your PC into a ZX Spectrum. This will give you access to the complete range of software for this iconic home computer.
But above all make sure that you have fun gaming and coding your own projects. The more projects you code the better programmer you’ll become.