This week in advancers, we simulated a true story! Once Mark was driving past Athlone and encountered a car driving the wrong way down the motorway. In this case it was a poor old gentleman who had somehow ended up turning down the sliproad, but we wrote a game which simulated the incident from a crazier drivers point of view!
The idea of the game was to drive as far as possible the wrong way down a 4-lane motorway before you crash.
Step 1: Draw the car
Out first step was to draw a car – we did this by switching to “Vector” mode and dragging a few boxes together – this is mark’s car below:
Step 2: Draw the road
The next step was to draw the road – the road was drawn the same way, using vectors. One key point here was to space out the lanes more or less evenly, and to use the “Shift” button to ensure that the lines on the road were at 90 degree angles. We drew the gaps in the white line using grey lines the same colour as the road. A few bushes and buildings completed the scene!
Step 2: Make the road scroll!
In this game, we wanted the road to scroll from top to bottom. This meant that the ySpeed of the road was negative. We also wanted the road to move back to the top whenever it got to the bottom. We had done side-scrolling with multiple sprites year ago in Explorers, and this was the same idea – however we managed to do it with just one sprite by using clones in the code below:
Step 4: Make the Car Move!
In this step we started off with basic movement – we were going to get to more realistic physics, but ran out of time! I’ll see if I can show the code for this at the bottom and you can add it in yourself!
To make it move, we just checked for left and right arrows and added speed accordingly:
Step 5: Enemies!
The game was already starting to feel fun, but it’s a lot better with some unsuspecting traffic on the road! We cloned the “player” sprite, and created a bunch of costumes to represent different styles of vehicle:
Next we wrote some code VERY similar to the scrolling background code for the enemy – this also reappears at the top when it reaches the edge – the difference being that it appears in a random lane and with a new costume. This turned out great!
Final Step: Game Over
The final step was a “Game Over” text sprite – this shows whenever the player crashes!
This was a really fun game – I enjoyed making it a lot!
Exercise: Realistic Turning Physics
I said I’d have a go at realistic turning physics for the car – this code works and looks great – try adding it to your game to see what you think – basically it turns the front of the car realistically and the back skids around like a real front-wheel-drive car. It was a bit tricky so I’m glad I didn’t push it as people would have gotten really tired as I tried and failed a few times! Just pop this code into your “player” script anywhere near the end!
The game looks quite cool when finished!