[web] Design pattern for web actionscript game?

Started by
2 comments, last by ToohrVyk 15 years, 5 months ago
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!
Advertisement
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.
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
}
}

?
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.

This topic is closed to new replies.

Advertisement