Game Development Reference
In-Depth Information
Mouse-controlled platform game character is in a folder called Lh]pbkniIkqoa?kjpnkh.
Although platform game characters are traditionally controlled with a keyboard or keypad,
why not implement a mouse-based control scheme? I modified the cat character's control
scheme from Bug Catcher so that it's entirely mouse-based (see Figure 10-22). Move the mouse
left and right to move the cat left and right. (Cats usually follow mice, so this makes perfect
sense!) Press the left mouse button to make the cat jump when the mouse is above it. Feel free
to modify this as much as you like so that it works the way you want it to for your games.
Figure 10-22. A mouse-controlled platform game character
Dispatching events
Dispatching events is one of most useful things you can learn how to do as a game programmer. Just
because this topic happens to be the last section of the last chapter of the topic, I want to dispel any
notion that you might have that this is an “advanced” technique. It's not; for a game designer, it's as
basic as fresh air and sunshine. Dispatching events is so useful that you'll want to use it with every
game you design from now on.
You've seen events used in almost every chapter in this topic. Button clicks, frames, timers—almost
every important thing in an AS3.0 program seems to happen because of an event.
So far, all the events that you've used have been built into AS3.0. Did you know that you can create
your own events and then trigger them whenever anything important happens in your game?
For example, imagine that you're making an adventure game in which the hero or heroine needs to
steal a magical gingerbread cookie from a sleeping witch. As soon as the cookie has been stolen, it
might be very useful for other objects in the game to know that this has happened. You could inform
a game manager to update a score, you could inform the player to update its inventory, and you could
even inform the sleeping witch who may well wake up if the player isn't tip-toeing quietly enough.
Instead of informing each of these objects individually, however, the gingerbread cookie needs to
broadcast only one event to the entire game: “I've been picked up!” This known as dispatching an
event . Other objects can then choose whether they want to listen to this event or take any action if it
concerns them.
The elegance of this system is that the event isn't dispatched to a specific object, and the objects that
are listening for the event don't need to know anything about the object that sent the event.
 
Search Nedrilad ::




Custom Search