
It took me a while, but I finally got my next game done. This is the culmination of everything we have done so far in this game development project. We have built upon all the techniques and skills from all the chapters before us to make a fun retro style arcade game.
The main point of Meteor Defense is to protect cities from falling meteors by shooting missiles to intercept them. As the game progresses, more meteors will fall at faster rates. Once all four cities are destroyed, the game ends.
As for new concepts to be found in this game, the main one to point out is how we used call back functions. These are functions that are called after certain other functions are completed. We had two instances that we haven’t used before.
The first callback we used was the onComplete callback function we called when the missile movement tween completed.
FlxTween.linearPath(missile, [FlxPoint.get(FlxG.width/4*3-8, FlxG.height-60), FlxPoint.get(FlxG.mouse.x, FlxG.mouse.y)], 100, false,
{type: FlxTweenType.ONESHOT, onComplete: (_) -> destroyMissile(missile)});
When the linearPath tween completes, meaning the missile reaches its final location, we call the destroyMissile function to kill the missile.
The other one we used was at the end of a timer in the explosion function:
var timer:FlxTimer = new FlxTimer();
timer.start(0.5, (_) -> removeExplosion(explosion), 0);
When the timer finishes it calls the removeExplosion function.
Finally, I want to highlight two different functions we use in this game. kill and destroy.
missile.kill();
explosion.destroy();
When we call the kill function of a FlxSprite, the game sets its exists flag to false, and no longer displays the object on the screen. But the object remains in the game and can be called by the recycle function. We use this on missiles and asteroids because we want to reuse them.
Destroy, on the other hand, actually removes the object from the game, freeing up memory. There is no way to recover this object after it is destroyed. We use this on the explosions because we don’t need them after they finish playing their animation.
You can see the the full Meteor Defense game at itch.io. You can see the source code for the game on Codeberg.