Gaming Your Way

May contain nuts.

We have the baddies

Time for a quick catch up on DN8. It's been a bit of a slow week hence the lack of updates, but it's finally starting to take shape.

dn8_grab3.png


Since last time we've got a player sprite in there, which just follows the mouse on the horizontal, nice simple stuff. I added in some player bullets which really didn't take much time ( Although I feel there's going to be some re-factoring when it comes to the power-ups ), and fresh off the press are the baddies. At last.

Normally for baddie waves I take an ultra simple approach. Open a fla, draw a nice curve, turn it into a guide, tween a sprite along that guide and spit out the coords as an array, drop that into the game and its job done.
I started doing it this way again for DN8, but for the life of me I couldn't get it to follow the guide properly. After about 5 minutes of swearing at Flash ( Not my fault obviously ) I decided that we're going to have mathematically created waves. Yes, my lack of patience has created a ton more work.

At present the game only handles Bézier curves, but they sure do look pretty. To create a pattern I just do the following:

new Array("beizer",[startX,startY],[controlX,controlY],[endX,endY]);

That's for the actual wave ( Curve ), and then we just

push([triggerTime,waveReference,baddieType,NumberOfBaddies,GapBetweenEachBaddie]);

triggerTime being when we want the wave to run, waveReference being the first array with the curve parameters in, baddieType just because, NumberOfBaddies is so we only have to calculate one curve and have as many baddies as we want following it, and GapBetweenEachBaddie being a delay in frames before triggering the next baddie ( So say we have 10 baddies, to stop them all appearing at once we can set GapBetweenEachBaddie to frameRate*2 to leave a two second pause between each coming in ).

There is a bit more in there which is possible due to using curves like this, but I don't want to splurge it all into your face in one go, we need a bit of mystery in our relationship don't we.

Squize.

Comments (2) -

  • wtfaremypants

    2/25/2011 5:07:31 PM |

    First: I'm a n00b. Got that out of the way :)

    Now: I'm curious about your methodology of using some math, arrays, and so on to do this instead of utilizing something like TweenMax/TweenLite?

    Looks cool so far!

  • Squize

    2/25/2011 9:01:06 PM |

    Hi mate,

    TweenLite is perfect for transitions and sliding things in and out, but I'm not sure what it actually does internally ( If some 3rd party code works then I have no interest in seeing how ).
    I'm guessing it uses an enterFrame to run, which is costly. Ideally a game should just have the one enterFrame event which runs the mainloop.

    So for something really time critical, such as a shoot'em up, its better to roll your own code.

    All we do in this is work out the x/y points for the curve and store that in an array, then the baddies just move through that array setting sprite.x / sprite.y, it couldn't be any quicker or any more simple.

    Here's a really good blog post about curves if you want to read up more about it:
    blog.onebyonedesign.com/.../

Comments are closed