How pure is pure oop, how usefull are design patterns and how to abuse asBroadcast?
Well, for the current game I'm bound to f8/AS2 because the client's audience is still mostly on f8 and the attempts to make them update the player greatly failed and resulted in a lot of "what is an update of the flash player", "what is a flash player" and "I don't know how" emails ...
The game currently uses my usual structure, that is a single class for the game and some classes for UI, sprites, tiles ... I usually made the game class "LMGame" (LM for the game's name) a singleton, but I wondered if that would be a good practice after all.
(You might guess it, this is a more or less philosophic question.)
I wanted to reduce refrences and singletons to a minimum. (Squize wrote about the problems earlier)
So far I came up with few different methods for accessing the LMGame class from various other classes during the game ...
If needed I pas a reference to the LMGame / needed class but you must admit that this feels rather clumsy.
For the Sprites however I didn't want pass a reference to the LMGame class just to say "Hello" or "I'm dead" ... so I tried a rather unusual way for sprite -> game communication:
While the game has a list of sprites and could call functions directly, I decided to rely heavily on asBroadcast.
I installed a stack (FIFO), to pass values if needed and tried if things were working like I expected ... and they did ... :)
A sprite is moved with
this._asBroadcast.broadcastMessage("onTickEvent"); (from the LMGame class' onEnterFrame) and if a sprite dies it places it's id into the stack and calls
this._asBroadcast.broadcastMessage("onSpriteDie"); (which is triggered by the LMGame class).
This might seem overly complicated but it really "looks" wonderfull in code and it saves a great deal of thinking, too.
As this is just a "try", I'm not sure if it's going to become very usefull, but I just like trying new "ideas" ...