Whoops! I’ve been away for a while.

So I haven't really been on the internet recently...somewhat of a leave of absence for the month of July or so. Sorry for anyone trying to access my website while it has been down, however that shouldn't happen again.

Anyways. I am back to work on Space Crusade and I should be done shortly. No more demo updates until I am done though sorry! Also I have some plans for new articles and videos after I get some work done. Hope everyone has been having a great Summer. See you around!

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Adopt Some Coding Conventions for Projects: Sloppy Code SUCKS!

I am writing this article in the hopes that you will learn from mistakes that I have made. Let me just tell you...sloppy code SUCKS! Once you start getting into bigger projects (or even not such a big project) and even worse when you start to work with others and share code things can become a mess. So I am hoping some of you with no coding standard or no idea of how to "properly" structure your code will get something out of this and decide to do the same or at the least come up with your own standard and stick with it.

Occasionally I do tweak or add to my standards but for the most part I really do keep everything the same.

Currently I've been improving some habits of mine (mainly things like spacing and brackets etc) a bit so my older code is a little sloppier than my newer stuff which is okay. I also want to first point out this article by GamePoetry which links to the "UrbanSquall" coding standards. Those are basically what I stick to except for the few additions / changes mentioned below.

So let's get started.

Class properties / Members

Public
The idea here is to always avoid using getter/setter functions whenever possible. Well, atleast for anything that would be called once or more each frame. If it's an obscure variable that is rarely called or used for something that isn't speed related you can use them...otherwise NO. Anything that is both gettable/settable will be simply written as it is:

//it probably wouldn't matter too much if you externally modified this variable
public var maxSpeed:Number;

Read-Only
In order to decipher between variables that should only be read-only I will use an underscore to define them as follows:

//obviously you wouldn't want to externally change this variable...
public var _bulletsLeft:int;

The speed difference of NOT using getters/setters can be very apparent with something like a "Vector" class where the 'x/y' variables are public. This adds probably 20-30 FPS to a demo with about 2-3000 sprites all doing world bounds wrap checks etc. Just imagine the speed difference when ALL of your code complies with this.

Obviously sometimes we may want to reduce the "_bulletsLeft" safely so in that case create your function "shootGun()" inside the class that holds "_bulletsLeft" rather than implementing some external code to reduce the "_bulletsLeft" variable. (This is more of a proper OO design practice: 'Encapsulate Change')

Private / Protected
For all properties usable only by the class that created them we will use the m_:

//this helps avoid naming conflicts...which is good!
private var m_beanCounter:int;
protected static var m_nextID:int = 0;

Naming Conventions

Booleans
Any boolean properties and functions will always be structured in question format. They are followed by the words: "is, has, can, does":

public var _isCollidable:Boolean;
public function doesRayIntersectCircle(rayOrigin:Vector, rayHeading:Vector, circleCenter:Vector, circleRadius:Number):Boolean{ //code }
private var m_hasGun:Boolean;
protected var m_canComeToTheParty:Boolean; // lol

Constants
All constants will be in caps with phrases separated by underscores:

public static const HEAVY_ARMOR:int = 0x000001;
public static const WOODEN_SHIELD:int = 0x000010;
public static const SLARGH_FIGHTER:String = "slargh_fighter";
private static const ENEMIES_PER_WAVE:int = 15;

Public Functions / Private Functions
Usually I stick to the "Urbansquall" convention on this however I do not prefix an 'a_' before the parameter names. Sometimes my functions will stray slightly from the "verbNoun" format when parameters are available and instead I will try to complete a sentence with the parameters. In other words I use "verbPreposition(noun)" format:

public function addTo(vector:Vector):void;
public function wrapAround(topLeft:Vector,bottomRight:Vector):void;
public function dotOf(vector:Vector):Number;

Event Handler Functions
I will treat event handlers slightly different when naming them. I always name them as if they are happening because of an event (hmm...) Which means basically all of them have "on" preceding them.

onScriptLoad(e:Event):void{}
onEntityCollision(e:CollisionEvent):void{}

Alright well as far as I can think of those + the urbanSquall link from above are the conventions I stick with. Hopefully you decide to do the same! Also be sure to read: Better Debug Tracing for some tracing conventions that should be followed as well.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5 out of 5)
Loading ... Loading ...

Actionscript 3 Math Classes for Game Developers

As I have been teaching myself game programming, one of the harder parts has been the math involved. It can be quite complex depending on what you are trying to do. While building various parts for my game engine I've needed several math functions. I've read through a couple of game and math books and have also created quite a few extras just based on what I had learned. I have created a pretty good library of useful functions and so after showing a friend of mine and him remarking that it was quite helpful I decided I would go ahead and release the code for everyone else to use!

I currently don't really have any demos or anything showing how to use the code, however go ahead and take a browse through the functions and there may be some stuff you will use eventually. It's pretty self explanatory anyways and it is all documented. I will definitely be referring to a lot of the code from these classes in some upcoming posts as well so if you are waiting for a more detailed explanation of when and how to use some of it don't worry it's on the way!

You can download everything as a package or just get the classes you need in the repository from my google project page here: http://code.google.com/p/cheezeworld/

As of writing this I currently have:

Vector - Perfect alternative to using the built in "Point" class and has basically ALL of the Vector operations you would need to perform plus a few more.

AABBox - A very lightweight object to simply store "rect" data for whatever purpose.

Matrix2D - Handles any Matrix math needed. Use in conjunction with the Vector class.

Transformations - Some static functions for performing transformations to Vectors easily (such as local to global etc...)

Geometry - A very powerful bunch of static functions for doing a wide range of math such as line intersection tests between rays, segments, polygons, circles, etc etc... This is great for most hit test operations and ray casting + other stuff...just check it out.

Math Utils - This is pretty much just a small number of things that I actually just usually copy directly into the code I am working on or as a private function into a class that needs it but wanted to have a reference to it since they are useful so it's all bundled up in this class.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5 out of 5)
Loading ... Loading ...

Google Code Sharing Project Created

Now that I will soon be releasing much more code and files I decided to go ahead and set up a google project page. You can set up a "read-only" repository to download all of my code as it is updated and added to or download the code as I post it in the packages with the demos / tutorials.

Check it out here: http://code.google.com/p/cheezeworld/

If you would like to contribute some code or a helpful tutorial etc I'd be happy to add it to the project!

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Using Objects for initialization

While programming my game's "Entity Framework" as I like to call it, I had the need for a better way to initialize all of my entities. Here are the properties for just the base "Entity" class:

public class Entity extends EventDispatcher{
 
	public static const DISPOSE:String = "dispose_event";
 
	public var pos:Vector;
	public var rotation:Number;
	public var scale:Number;
	public var radius:Number;
	public var isCollidable:Boolean;
	public var team:String;
 
	public var _id:String;
	public var _type:String;
	public var _pos:Vector;
	public var _oldPos:Vector;
	public var _world:GameWorld;
	public var _timePassed:int;
	//...the rest of the code
}

Also I wanted to have default values as well as the ability to load the defaults from some sort of "Settings" file for pretty much all of these values so normally you would have to do your constructor like:

public function Entity(position:Vector, rotation:Number=360, scale:Number=1, radius:Number=1, isCollidable:Boolean=true, team:String="neutral", id:String=null, type:String=null, world:GameWorld=null){
 
	if(pos != null) { pos = position; } else { pos = new Vector(); }
	if(rotation != 360) { rotation = rotation } else { rotation = Settings.EntityRotation; }
	//etc...
 
}

So as you can see that would get pretty messy ESPECIALLY when you decided to extend it since you'd have to put all of those properties in the constructure PLUS any new properties...so you can just imagine the headache there.

Anyways lets just cut to the chase. Here is the wonderful solution I came up with to handle any type of constructor nightmare like that: Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Lost in Debug Hell : Fix Your Messy Trace Commands!

I've done some collab coding work as well as plenty of my own projects and if you have done the same you would probably agree that debugging can be one of the biggest tasks that we as programmers have to face in our projects.

Usually proper debugging consists of many many trace statements until we are able to pinpoint areas that aren't doing exactly what it is that we want our code to be doing. Well, one problem that I have run along many times within my own code and more so when working with other people's code is the problem of not being able to find trace statements and / or not knowing where a particular trace statement came from!

Take for example Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...

How to use Flex for your Actionscript only projects

During this tutorial I will explain how to set and get started with using Flex, as well as explain some of the not so obvious at first things that go along with it. Watch the first minute or so for an intro and then you can skip to the different parts depending on what help you need (or just watch the whole thing).

Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...

Custom BitmapClip Class. Speed up your games!

It took me a bit longer than I thought, but it is done! I have created a custom "BitmapClip" class for you guys! This class can do it all:

  1. Import MovieClip, Sprite, and even tilesheets!
  2. Animate each clip at it's own frame rate.
  3. Control it just like you would a MovieClip.
  4. It even creates pre-rotated frames for you! Now you can have super fast animated clips AND support rotation! WOOT.
  5. You can also support scaling by simply adding the clip to a sprite without losing *much* speed.

If you want to see a demo where I am using the BitmapClip with thousands of clips on screen moving / scaling and rotating then go here: Game Framework Test

You can download the package containing all of the code and demos or simply grab the file off of the repository on my Google project page.

The following are instructions on how to use it (which are included in the download as well):
Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5 out of 5)
Loading ... Loading ...

Simple and Easy to Use Custom Input Manager Class

Sweet! It's ready to go. I have created a custom Input Manager for you to take advantage of. Check out this quick video tutorial that will walk you through how to use it in your projects or feel free to look it over yourself.

You can download the package containing the demos and the files or just grab it directly from the repository on my Google Project Page.

Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5 out of 5)
Loading ... Loading ...

Breakball

Description:
Control your Break Ball through a series of challenging levels. Can you beat the game?
This is the first game that I completed. If you create any of your own custom levels be sure to post a comment with the level code so others can try it! Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 3.8 out of 5)
Loading ... Loading ...