Enemy movement patterns, scripting, etc..

A place for people with an interest in developing new shmups.
Post Reply
CabaretVoltaire
Posts: 1
Joined: Fri Aug 12, 2005 10:19 pm

Enemy movement patterns, scripting, etc..

Post by CabaretVoltaire »

I have started prototyping a shmup (my first) and was wondering how everyone else does the actual scripting behind their games. I've got a basic engine working but am pretty sure that I'm not using the best methods.

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 ;)
User avatar
mirkvid
Posts: 572
Joined: Wed Jan 26, 2005 11:41 pm
Location: las vegas NV

Post by mirkvid »

bump!

im having the same problem!
i've got my graphics engine pretty much done, but have no idea how to set up the enemy patterns. i thought about setting up a class that has an array of sprites for members to group them together. then setting up 10 or so different objects of that class with different patterns......seems like there should be a better way tho.
User avatar
nullpointer
Posts: 66
Joined: Tue Jan 25, 2005 11:12 pm

Post by nullpointer »

HI Guys,

I will let u know how I do it, it may not be the best solution but it works for me

basically each enemy has 2 values that keep track of its movement

m_movestageand m_movesubstep

they also have a value that dicates the sort of pattern the follow

m_Pattern

I have 50+ movement patterns

each pattern has a number of stages and a number of steps within each stage

so.
stage 1,
x+=1;
y+=2;
number of steps=5
stage 2,
x+=1;
y+=1;
number of steps=10

etc
etc

the enemy position is modified based on the x & y values for each stage
and each time this is done the step marker is increase d by one. If the step marker goes over the number of steps for that stage the enemy starts moving according to the next stage. (actually I use the values to update velocity of movement rather than explicit x & y positions, but thats another story) Usually if an enemy goes beyond the final stage for a pattern it goes back to the first stage

this way i can have a structure that i can easiliy fill for each stage of a pattern

i can then spawn an enemy at any locatin and start it on any stage of any pattern

ie. startalien(alientype,startx,starty,pattern,startstage,startstep)

this means i can re-use patterns for the same movements from different parts of the screen etc.


.. i use the x,+y values to increment velocity on each ship, so that the movement is smoother than just changing x & y locations

you will have to call an update function for each enemy each frame, but with this method the update/move function is the same for each enemy, it is only the pattern reference that is different.

as for bullets i use a similar approach to you. i generally use a function to spawn the bullets and then each frame, every bullet just continues along its initial path (eith maybe some simple changes dependingon its specific type etc.. like homing missiles etc)

anyways i hope this helps

there is no way around the fact that shmup level design is all about patterns and placing patterns, this in itself is like 80% of the game development if u want to make a well written game!
User avatar
mirkvid
Posts: 572
Joined: Wed Jan 26, 2005 11:41 pm
Location: las vegas NV

Post by mirkvid »

thanks for the help. i also have the idea of using fstream to read in enemy data from a file. it would be a lot easier to set up, but do you think it would slow the game down too much?
i want to set it up like this:
read until "*"

in data file:
# for enemy type
# for x starting position
# for y start
# for velocity
*
i'm going to flesh it out this weekend. i'll let you guys know how it goes!
User avatar
shiftace
Posts: 435
Joined: Tue Jan 25, 2005 10:18 pm
Location: yes

Post by shiftace »

Nomltest uses a plaintext scripting language to specify enemy behavior, the data sits in default\script\. It's not at all documented though. You can tweak it, but the game runs some kind of integrity check sensitive to any change outside of comments, and it refuses to record high scores if the check fails.

Reading data out of a file should be real fast, although you might want to do all your loading when the game starts up or at the beginning of each stage. The nice thing about using a special purpose language or file format is that you can make tweaks without recompiling, so long as the language is powerful enough to describe those changes. The other advantage is it makes the source code cleaner, but that should only matter if you're going to publish the source, use it as a resume project, collaborate on development, etc.

(I have never programmed a shmup, this just seemed like a straightforward programming question wher a generic answer is suitable).
"Can they really get inside my head?"
"As long as you keep an open mind."
User avatar
mirkvid
Posts: 572
Joined: Wed Jan 26, 2005 11:41 pm
Location: las vegas NV

Post by mirkvid »

cool, i was hoping it would be fast. im programming it in c++ from scratch. i dont really feel like taking the time to learn another language on top of all the classes im taking!
User avatar
louisg
Posts: 2897
Joined: Wed Jul 20, 2005 7:27 pm
Location: outer richmond
Contact:

Enemy movement scripting

Post by louisg »

What I found useful about programming the enemy behaviors in the language I was coding in is that it was not only as flexible as the main language (C in this case), but could potentially call any game function, whether it is an exploding boss triggering an end-of-level sequence or whatever. Of course the downside is I had to recompile it when it changed. I used function pointers to assign an AI function to the sprite objects.
Humans, think about what you have done
Post Reply