Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / I need some help x.x please

Author
Message
Seraf
20
Years of Service
User Offline
Joined: 22nd Feb 2004
Location:
Posted: 31st May 2004 09:49
I am working on a 2-D space type game and I have it going along alright, but I just can't get the enemies to move in their own patterns for an Attack type mode (ramming into the player). Well I tried this

if enemyx>playerx then enemyx=enemyx-1
if enemyx<playerx then enemyx=enemyx+1

For each of the enemy ships (they all followed the players movement) but this was all chaos as all the ships began overlapping and colliding with one another and was a mess. I am stuck and don't know what to do, sombody please help me.
Mizipzor
20
Years of Service
User Offline
Joined: 24th May 2004
Location: Sweden
Posted: 31st May 2004 10:07
"Chaos" and "overlapping" is just two words could you give me an .exe or the source so i can run it myself and have a look? Have the project got that far?

Im not a good programmer but i can most certainly come with advice how it could be solved in theory.

Dreaming of creating a highly advanced AI mind
Seraf
20
Years of Service
User Offline
Joined: 22nd Feb 2004
Location:
Posted: 31st May 2004 10:11
^_^ lol, well the version where all the ships overlapped I trashed and I went back a few steps, so only 1 enemy ship does this >.> but you can picture what this will look like if all of them were doing the exact same movement X.X;


Here is a link to a .exe version of its current state ^^http://68.47.249.196/modules/Hosting/web_pages/ironmetroid/space.zip
Mizipzor
20
Years of Service
User Offline
Joined: 24th May 2004
Location: Sweden
Posted: 31st May 2004 10:27 Edited at: 31st May 2004 10:32
Well to me it looks like you just run the AI part for one ship, i.e. looking up the players position and steers towards it. You should have this in a subroutine with a loop doing it for all the enemy ships.



Heres a loop i wrote on the run, i havent tried it but ill think itll do the work. Thats how i think it should be done imho.

But you want collision detection as well? Hmm... sorry... cant do that in 2d

Dreaming of creating a highly advanced AI mind
Seraf
20
Years of Service
User Offline
Joined: 22nd Feb 2004
Location:
Posted: 31st May 2004 10:34
I'm having a bit of trouble still x.x I'm still rather new to DB myself and that kind of lost me x.x;
DeepBlue
21
Years of Service
User Offline
Joined: 17th May 2003
Location: A little box in the UK
Posted: 31st May 2004 10:51
OK think I've worked out what you want (well maybe).

1) If you are trying to create enemy ship formations:

To allow the ships to stay in 'formation' the simplest way to start with is to create a variable prior to the movement loop that calculates the width of the enemy ship formation divided by 2 to find the centre of the formation ie:

enemyformationX=((emeny width*no of ships across)+(enemy spacing*(no of ships across-1)))/2

you can do the same for the height of a formation as well if the height of the enemy formation is greater than 1.

You can then offset each enemy ships position from the above variable each loop. You then just change the formation variable relative to the player position & all the enemy ships will move as one.

You would probably want the formation to recentre on the player if one of the end ships is lost. So you would have to recalculate the centre position, but this would probably create a jump in movement so you may wish to use something like a Curvevalue to readjust the centre position

2) If you dont want formations but want individual ships tracking in different ways:

You are going to have to use the sprite collision command where the target sprite number (each enemy ship) loops through all of the other enemy ships to test for collisions. Then dont shift its x value if a hit occurs.

Of course you can store the ship positions in an array and manually calculate each ships position for a collision as you already know its size & position & then just update the array each loop (possibly quicker but a lot more work.


Hope they may help a little.

Twynklet

Login to post a reply

Server time is: 2024-11-26 18:42:59
Your offset time is: 2024-11-26 18:42:59