Sign in to follow this  
assaf

[web] Design pattern for web actionscript game?

Recommended Posts

Hi everybody, Me and a friend of mine are trying to write an Actionscript based web game these days. We've got some experience with other languages (C, Matlab, Python) but we're not big on either Actionscript or game programming and would appreciate some insight from more experienced users. What we're looking for is a general "design pattern" for the game. The game consists of several board pieces which can interact with each other - think, say, "Desktop Tower Defense". How should the game be structured and events be handled? I know this is a broad question, so let me try and narrow it down. Take collisions for example, and suppose we have 10 pieces on the board. Should we have a game-loop in which, at every frame, collisions are checked for between all pairs (total of 45 pairs)? Should we try doing it with events, by creating and attaching an event to each object? How would the game loop look like in such cases? I hope my question is answerable :). I'd really appreciate any insight you can offer. Thanks!

Share this post


Link to post
Share on other sites
For a small, simple game, don't bother with complex design patterns all over the place. Half the power of complex design patterns is that they're well-known and make documentation of a large-scale project. But since your project is neither large-scale nor needs to be documented for third party users, that's useless.

Some patterns are useful, however. One of these would be to separate audio/video from logic (either by splitting them into classes, or by keeping them within the same class in an easily refactored state). Another would be to segregate objects into different arrays by type instead of inheriting everything from a base class (though with the type system of arrays in AS, this is somewhat diminished).

However, the most important element is that you should keep things simple. You need 45 pairs to interact? Loop through all pairs and run the interaction code. Don't complicate yourself with anything more complex than that until the game itself becomes more complex.

Share this post


Link to post
Share on other sites
Hi ToohrVyk,

Thanks for the response!
So, basically, you'd have a game-loop of the form:

for each sprite {
Check for collision with boundaries
}

for each pair of sprites {
if sprite1.hitTestObject(sprite2) {
Do collision logic
}
}

?

Share this post


Link to post
Share on other sites
Yes. I would keep a cleanly delimited area in my game loop where I would be doing that. At first, a mere "/* Collision detection begin */" and "/* Collision detection end */" pair of comments around the area would be enough to identify it. If you find yourself with a loop that is too large, you can cut along the comments to refactor the area into a function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this