Advertisement

Create a Microphone-Controlled Flash Game: Code

by

This Cyber Monday Tuts+ courses will be reduced to just $3 (usually $15). Don't miss out.

In this mini-series, we're creating a spaceship game where the main control is via the microphone: shout louder to make the ship fly higher. So far, we've created all the required graphical elements for the game. Now, it's time to work on our code. We've got a lot to do, so let's get started!


Final Result Preview

For the purposes of keeping the tutorial simple, we have done no error checking for the existence of a microphone. This means that, if you do not have a microphone plugged in, turned on, and set up for use with Flash, the game won't work: you'll get an Error #1009. Check the comments in Player.as in the source files for information on how to deal with this.


A Small Note:

For some reason Flash Builder isn't working perfectly. In particular, it's ignoring code hinting - but, nevertheless, one should be able to follow the tutorial.


Project Setup

Don't like ads? Subscribe to Activetuts+ screencasts via iTunes!


Creating the Player

Don't like ads? Subscribe to Activetuts+ screencasts via iTunes!


Creating Space Objects

Don't like ads? Subscribe to Activetuts+ screencasts via iTunes!


Player Animation and Collision Response

Don't like ads? Subscribe to Activetuts+ screencasts via iTunes!


Setting Up Scores and Lives

Don't like ads? Subscribe to Activetuts+ screencasts via iTunes!


Creating Our Background

Don't like ads? Subscribe to Activetuts+ screencasts via iTunes!


Cleaning Up Our Game

Don't like ads? Subscribe to Activetuts+ screencasts via iTunes!


Creating the Game Over Screen

Don't like ads? Subscribe to Activetuts+ screencasts via iTunes!


Conclusion

Thank you for watching. It's been a huge tutorial, and afterwards I would have liked to do some things differently:

  • First off the classes have just been added one by one, but it would have made more sense for the classes to be organised in packages.
  • Even though our project works fine, we do get some run time errors, which isn't very neat.
  • Also, it's pretty easy to get very far by saying nothing, and just sticking to the bottom of the screen.

Nevertheless, I hope you enjoyed this tutorial, and most importantly learned something from it.

Advertisement