I have a int called Frame which I increment each frame and then an array of events (function pointers). Something like this:
EVENT[100] = BADGUY1
Each frame I check if their is an event for that frame and if so execute it.
I think this is a decent enough way of doing it, and guess that most shmups use something similar... But please correct me if I'm wrong!
What I am having trouble with is scripting enemy behaviour. I have a bunch of functions for different behaviours:
function enemy1()
{
enemy. x++;
enemy.y++;
}
....might be one.
When an enemy is spawned I assign one of these behaviour functions to it as a function pointer. So in my main loop I have something like this:
i=0;
while(i<enemies)
{
enemy.behaviour();
}
This works fine however it seems a bit clunky to me. For a full game I might have hundreds of these functions so was wondering if anyone could suggest something a bit more elegant.
For bullets I have a structure which defines the start angle, the angle increment, the amount of bullets and an array which defines bullet speed. So I can have something like:
start=0
step=1
amount=360
speed = {1,2,3,4,3,2}
..to do a sort of star shape.
The first bullet has a speed of 1, the second 2.. and when it reaches the end of the speed array it loops around.
Again this works fine and is alot more elegant than my enemy stuff but is fairly limited. Bullets can't change speed or direction. Is there a better way of doing this? I was thinking of just using enemies to simulate bullets if I want them to change speed / direction but that seems a bit hackish to me. Especially as right now it would mean adding more functions... Going to end up with a huge executable, bah!
Anyway any advice would be greatly appreciated!
btw, I'm prototyping in javascript (don't really want to be messing around learning this stuff and having to worry about coding properly lol) so if anyone wants to see a shmup with hundreds of things moving on screen in HTML let me know
![Wink ;)](./images/smilies/icon_wink.gif)