Feeds:
Posts
Comments

Archive for June, 2009

I recently finished writing ActionScript for Multiplayer Games and Virtual Worlds, my first book since Flash 8! With the help of some amazing contributors I think this is the most useful and geeky-fun book I’ve ever been a part of. According to Amazon (shameless link) it hits shelves in 8/3/2009.

So what’s it about? If the title of the book doesn’t give it away, it is a book that focuses on multiplayer concepts and applies them to games and virtual worlds via ActionScript. Some of the coolest topics are those on dead reckoning, real-time movement and time synchronization, loads of information on avatar rendering, and other useful topics like thorough coverage of isometric concepts.
While there are many examples throughout the book, there are 3 major examples. In one chapter we build a real-time multiplayer tank game (top down). In another chapter a cooperative multiplayer games is created, and its a fun one! Then over the course of several chapters we dig into various major topics on virtual worlds to build a complete world.
Here are some screenshots, and I hope some of you check it out and find it useful 🙂
Virtual world
[image missing]
Real-time tank game
Cooperative multiplayer game
Advertisements

Read Full Post »

I’m working on a new game that requires me to dig into some physics and math that I haven’t touched in a while. The Vector3D class was introduced with Flash Player 10. I used this as an opportunity to get familiar with that class and see if it could make life a little easier, and it does!

The Vector3D class keeps track of x and y (and z if you want it to) values. It uses the sign on the value to imply direction. You can then perform cross products or dot products and a few other basic vector actions via its methods.

Conceptually, here is how to make a ball (or sphere) bounce off of a line (assuming you can calculate that the collision is occurring).

  1. Use a vector for the ball velocity
  2. Use a vector to represent the line normal (perpendicular to line)
  3. Do simple vector algebra to get new velocity

Step 1
Represent the ball velocity as a vector. For instance,
var velocity:Vector3D = new Vector3D(2, 0);

Step 2
Represent the line normal as a vector (which it is). For instance,
var normal:Vector3D = new Vector3D(1, -1/line_slope);
normal.normalize();

Step 3
Do the vector math when a collision is detected. You can imagine that the velocity vector can be projected onto the normal, and it is only that bit that will be reflected off of the surface. So, we’ll project it onto the normal and set the net change to 2 * this value. 1* the value makes the velocity 0, 2 * the value sends it back an equal amount. We then take this reflected vector and subtract from the incident velocity vector.

var reflectionScalar:Number = 2 *velocity.dotProduct(normal);
var reactionProjection:Vector3D = normal.clone();
reactionProjection.scaleBy(reflectionScalar);
velocity.subtract(reactionProjection);

Download source

click to view example

Read Full Post »

Lately I’ve been able to find a few hours here and there to start experimenting with code again and exploring ideas that have been on my mind for a while. (I sure have missed that!)

What I’ve been working on specifically is a particle engine. Over the years I’ve kicked out simple one-off particle effects just for fun (like this one in AS2 a couple of years ago). But I never took the time to do it right and build something extensible and reusable. The example shown in this blog post on theflashblog.com is what inspired me to make an engine rather than one-off effects. All cool projects deserve a cool name, so I call this progeny.

Before I talk about how the system works and where I think I am in the development cycle, here is an example that shows 4 effects. Each effect uses progeny and has no throw-away code other than the lines used to configure the effect.

click to view example

You can see that some of the effects that I show here are made to look similar to the partigen example from theflashblog.org post I referred to above. I started with those since I knew they were possible and could be fairly high performance.

This version of progeny is sprite-based. Each particle is a sprite that is scaled, alpha’d, rotated, and moved over time. It is used by adding an emitter (or progenitor if you will) to the screen and then configuring it. The example above contains 4 emitters. Effects can be made up of multiple emitters. For example, if the smoke was made to be a bit more subtle and then offset above the fire, it makes for a much cooler and realistic fire example.

I hope to be able to go into more detail about what is going in here and how it really works in one or more future posts. And I hope that I can do that really soon (within days) if my schedule allows.

My current plan is to develop a simple user interface that allows you to create and configure effects. Also, I am considering toying with making this a 100% bitmap-based approach, where there is a single display object and the scene is rendered by manipulating BitmapData instances directly.

That’s it for now!

Read Full Post »