Game Development Reference
In-Depth Information
into how you structure your game. This is a good thing; not having
clearly defined blueprints leads to second guessing and duplication
of work later on. If a carpenter went to build a house with no plans
from the architect other than a single drawing, he would either quit
or have to improvise continually along the way. The result would
be a very inconsistent, possibly uninhabitable house. I
ll cover class
structure extensively later on, as most or all of our development
will be centered on their use. In the mean time, here is an example
of a simple class defining a player in a game.
package {
import flash.display.MovieClip;
public class Player extends MovieClip {
public const jumpHeight:Number=10;//pixels
public const speed:Number=15;//pixels per second
public var health:Number=100;//percent
public var ammo:int=20;//units
public function Player() {
Not all the codes may make sense at this point, but hopefully
you can see that we
ve just defined a player character with a prede-
fined jumping height and movement speed, and variables for how
much health and ammo he has. Granted, this little bit of code
alone won
t do anything, but it does create a foundation upon
which to build more functionality and features.
Public, Protected, Private, and Internal
The four prefixes you can give to the properties and functions
inside your classes, also known as attributes, define what items are
available from one class to the next. All of them are documented in
s Help files, but here
s a quick summary:
Public methods and variables are accessible from anywhere and
are the foundation for how classes interact with each other;
when one class extends another, all public methods and
variables are inherited.
Protected methods and variables are accessible only from inside
their class and are inherited.
Search Nedrilad ::

Custom Search