Thank you for visiting Blazing Games

Spawning BSoDs

While it would be possible to simply create BSoDs as they are needed, I opted for a slightly different approach. There is a maximum number of possible BSoDs so I just pre-create all of them and hide them until they are needed. This has the advantage of not having to instantiate the classes while the game is playing which in theory will speed up the game though Flash is fast enough now that it is unlikely anybody would notice.

            // bsod layer
            _bsods = new Array();
            for (cntr = 0; cntr < MAXBSODS; ++cntr) {
                _bsods[cntr] = new BSoD();
                addChild(_bsods[cntr]);
            }

BSoDs have generations. The generation determines the size of the BSoD and if the BSoD will re-spawn when killed. When a BSoD is spawned, it is randomly assigned a speed and direction.

        public function spawn(nx:int, ny:int, gen:int)
        {
            var rad:Number = Math.random() * Math.PI * 2;
            var speed:Number = Math.random() * (MAX_SPEED-MIN_SPEED)+MIN_SPEED;

            _xspeed = Math.min(speed * Math.sin(rad));
            _yspeed = Math.min(speed * -Math.cos(rad));
            x = nx;
            y = ny;
            visible = true;
            _generation = gen & 3;
            scaleX = GENSIZES[_generation];
            scaleY = scaleX;
        }

Previous page
Chapter 35 Page 5

About - Privacy Policy - Contact - Links - FAQ
Copyright © 2009 Blazing Games Inc. All Rights Reserved