Hi, as many of my regulars have noticed it has been some time since my last article. I have been doing some soul searching over the last year or so and decided to switch paths to some degree. More than likely I won’t be focusing on programming any longer. Instead I will be spending my energy to build and develop my new website Colbycheeze.com which will be focused on personal growth, productivity, time management, health, and overall happiness.
I want to leave by giving huge thanks to my readers, and have no worries I will continue to leave the website / code up for all to view. In addition I plan on releasing a large part of my unfinished code / projects as open source for anyone to learn / expand upon.
I am also willing to support any guest posts as well, if anyone has a topic they wish to share with my audience. Farewell, and I wish you all a great 2010!
Woot! I am so excited to be able to finally release this to the public. Panayoti from GamePoetry.com and I have been working hard on this for the past 9 months or so ( on and off ) This was originally sparked off by my reading of his request for help: Improving Performance With Animated Bitmaps. I said to myself, “Hey I’ve basically already done all of this!” So after talking over the vision of the animation system for a while I set out to create a robust and extensible API. It only took a day or so to get the bulk of it coded, however over the last few months we have been using it in projects so that we can test / refine it further. Finally it is to the point that we can both happily release it to you guys!
So without further delay, I now introduce you to Ginger :
Features :
Extremely fast and optimized animations
Set the rotation precision, and each frame is pre cached for speed
Attach an event dispatch to any frame of animation
Adjustable frame rate
Set your own offset for each frame of animation
Queue up multiple animations
Import Tile sheets and convert to an animation
*NEW – 9/10/09* Import MovieClips, Sprites, and Bitmaps and convert to an animation
So after a long hiatus I have decided to jump back into the Flash scene. I am going to kick off my return with a continuation of the Building a Game Stucture series. Today we look into FSM ( Finite State Machines ). FSMs are used as the basic AI for most games, especially RPG / Platformer / RTS type games.
What is an FSM / What is it used for?
An FSM can be used to determine the behavior of an entity based on specific conditions. Essentially they imbue an entity with the illusion of intelligence. Coding a state machine is a simple matter. There are in fact numerous ways to implement an FSM and there isn’t necessarily one “right” way to do it.
Big update for you guys! Hey I know I’ve been a bit AWOL on posts lately, but recently I just finished a project which I was on a time crunch to get done. Also I had been having issues with ironing out the last of some bugs with my new big library for you guys. It is an AS3 Artificial Intelligence Steering Behaviors library which works with the game structure code I’ve been writing.
Also I’ve made several adds / changes / fixes to the game structure which I’ll list out below. I wanted to write a big article ( or several ) explaining this big AI library and how each thing works, but I didn’t want to keep everyone waiting any longer so I am going to go ahead and release it now and I’ll write up articles about it as time permits. ( which I have more of now )
For those of you who want to dig in and learn it all on your own go ahead, but for everyone else I promise I’ll get some articles up soon explaining the changes and some tutorials on how steering behaviors work and how I’ve designed mine.
Here is a demo app that I created which shows off everything. You can download the source from the google project page. I highly suggest setting up a repository folder on your PC and keep it updated with the current game library folder, as that is the one which I will be submitting updates to. I won’t be updating the various zips any longer. I recommend tortoise SVN.
So anyhow, here is a list of changes to the game structure that I have made so far. Be sure to check back soon for more AI / Game Structure fun!
ENGINE CHANGES:
Added more functionality to the Sound Manager class.
GameFactory is no longer a singleton.
Added creation of gameworld to GameFactory for easy game setup.
Fixed dispose function on Entity.
MovingEntity now restricts its movements to the max speed variable.
MovingEntity has a MaxAcceleration var, which is mainly just for external use.
Added a damping variable to MovingEntity.
Fixed an incorrect math function on Matrix2D.rotateVector()
CreateCallback function added to Root
Updated all classes extending EntityParams with the ability to pass variables in the constructor IE:
new EntityParams( { radius:10, type:”Blob” } );
NOTE: be sure to call super( a_params:Object ) AFTER you set any of your defaults, or anything passed in will be overwritten ( by the defaults )
Added a createCallback function to Root. Quite useful in some cases, check it out.
Cleaned up Root by taking out the FPS calculation. Use a custom FPS class for this now, such as the Urbansquall one which I am using in the Main() class.
- Added astage width/height const to Root for ease of use. Obviously you will have to change it depending on your games size.
Fixed the lineIntersecton function of the Geometry Class. ( Thanks to Ryan from Mochimedia for pointing this out )
Added a “getRandomPolygon” utility function to the Geometry class which returns an array of points based on some parameters
Hey guys, just wanted to say I am still alive. Haven’t been able to finish my latest post yet due to lack of time and some bugs I’m having trouble figuring out. I decided to go ahead and create an SVN for all of the code here, so that everyone who prefers to stay up to date and use that sort of thing can. It is also MUCH easier than updating .zip files, so that is what I will keep most up to date now.
This is the third post in the series “Programming Tidbits.” These articles consist of useful bits of information or code that I would like to share, but are not necesarily full length articles.
Sometimes you may wish to constrain the amount of rotation an entity can rotate per second or tick or whatever, such as the turret on a tank or the turning of the tank itself. This can be done with a bit of math. It could seem a bit complicated without using the math libraries I have already created.
Here it is using my code:
We are going to assume the maxTurnRate will be in degrees per second.
So let’s take a look at what is happening there. First, we are checking to see if maxTurnRate is > 0…because we will assume if it is set as 0 then the entity should be able to turn freely. If it is greater, then we will get the angle from our current velocity and check to see if it is greater than the max turn rate multiplied by the step size. The step size is generally just: tickSize / 1000.
The math to get the angle from one vector to another is:
Next, if the rotation is greater than the max amount aloud…we will use a matrix to rotate the velocity vector to it’s correct position and transform it and the heading ( the direction the entity is going ). Note: The “sign” function just returns -1 if vector is counterclockwise, else 1 if clockwise. We need this to know which direction to rotate obviously.
The Matrix Code
Here is some of the matrix code, though I definitely don’t plan on explaining matrices in this post. Which is why it’s best to just use the library if you don’t actually understand the math part itself.
/**
* Use to rotate.
* ( Considers that the Vector object represents a point, not an actual vector )
* @param rot
*
*/publicfunction rotate(rot:Number):void{varsin:Number = Math.sin(rot);
varcos:Number = Math.cos(rot);
multiply(new Matrix2D(cos, sin, 0, -sin, cos, 0, 0, 0, 1));
}/**
* Use to multiply two Matrixes...mainly used internally.
* @param matrix The Matrix to multiply by.
*
*/publicfunction multiply(matrix:Matrix2D):void{var m:Matrix2D = new Matrix2D();
//first row
m.a1 = (a1 * matrix.a1) + (a2 * matrix.b1) + (a3 * matrix.c1);
m.a2 = (a1 * matrix.a2) + (a2 * matrix.b2) + (a3 * matrix.c2);
m.a3 = (a1 * matrix.a3) + (a2 * matrix.b3) + (a3 * matrix.c3);
//second row
m.b1 = (b1 * matrix.a1) + (b2 * matrix.b1) + (b3 * matrix.c1);
m.b2 = (b1 * matrix.a2) + (b2 * matrix.b2) + (b3 * matrix.c2);
m.b3 = (b1 * matrix.a3) + (b2 * matrix.b3) + (b3 * matrix.c3);
//third row
m.c1 = (c1 * matrix.a1) + (c2 * matrix.b1) + (c3 * matrix.c1);
m.c2 = (c1 * matrix.a2) + (c2 * matrix.b2) + (c3 * matrix.c2);
m.c3 = (c1 * matrix.a3) + (c2 * matrix.b3) + (c3 * matrix.c3);
Set(m.a1,m.a2,m.a3,m.b1,m.b2,m.b3,m.c1,m.c2,m.c3);
}/**
* This is used to do the final transformation upon the Vector
* @param point The Vector to apply this Matrix transformation to.
*
*/publicfunction transformVector(point:Vector2D):void{var tempX:Number = (a1*point.x) + (b1*point.y) + (c1);
var tempY:Number = (a2*point.x) + (b2*point.y) + (c2);
point.x = tempX;
point.y = tempY;
}
And that’s all!
So anyways…I’ve shown the internal workings of the math code there for you, though the first code block is all that should really matter to you in the end…since it shows how to actually use the math.
No example today, since I’m pretty sure you can imagine a turret rotating at a max speed…lol. However, it will be used in the next Game Structure post for the entities.
Also for those of you waiting for the next article…be patient, it is a BIG one! I’ve created many Artificial Intelligence behaviors and a great OOP structure to use them, and I’ll be discussing Boids and many of the behaviors in detail. I’ll try to get it finished as soon as possible.
I hope everyone is enjoying their Christmas break!
Dealing with sounds in Actionscript can be kind of wacky. Sound Objects, Channels, Transforms…blah. I don’t like messing with all of that, so I’ve built a sweet, easy to use Sound Manager. I don’t suppose it has any magical powers or anything but that’s only because I couldn’t think of anything magical a Sound Manager should do…other than play sounds and control volume.
The Sound Manager Class
It is a Singleton, and can be used from anywhere in your game / project. Simply register all of your sounds to the manager, and play them using IDs rather than having references to the sounds themselves.
Also, I have made it so that you can play a “sound”, or play “music” which is controlled at a different volume. Also, it is set up so that only one music sound will play at a time.
This is the 4th article in the series: Building a Game Structure. Be sure to read the introduction which also has links to the rest of the articles in the series.
In previous articles we have put together a framework to handle various issues with our game. As of now, it would be quite sufficient for creating many simple games. One problem however, is that the creation of multiple types of entities in various places in our code can get cumbersome and is prone to errors and/or problems if we begin to make changes to the way we want our entities to be created
The Factory Method
The proper way to handle the creation of multiple objects with similar functionality is to Read the rest of this entry »
This is the 3rd article in the series Building a Game Structure. Be sure to read the introduction which also has links to the rest of the articles in the series.
There comes a time when working on a game that you realize the need for an effective way to manage all of your entities and game objects. Also, not all games consist of just one simple non-scrolling screen so you must devise a robust way to deal with the problems of displaying your entities in the correct position based on where in the world you want the view to be centered, not to mention handling the mouse’ world position. Not only that, but it would certainly be nice to have some basic, simple, and reusable classes for rendering your entities so that you don’t ever have to deal with it again.
These are the issues I will be covering in today’s article, and of course I will wrap up by showing the code that I use and handing you the source to play with. I’ve made a few slight changes to some of the classes which I will talk about below. Read the rest of this entry »