'Position_Enemies()' function...?
Blitz3D Forums/Blitz3D Beginners Area/'Position_Enemies()' function...?
| ||
Ok, I'm starting the enemy/AI coding part if my game and I need some help. Basically, I need some enemies that will form different formations like 'V' or 'Line' etc. I'm probably going to do this with functions [duh], but how do I write it so that I can change the ammount of enemies etc. ie.function form_V(ammount#,xpos#,zpos#) ???????????????? ;the part i need help with lol end function ok, now I call the function... form_V(5,0,50) ...And te enemies should appear on the screen like this: V-------V --V---V-- ----V---- Or if i called 'form_line(5,0,50)' the enemies would appear on screen like this: V V V V V Does anyone have any ideas? Please help me with this...Ps, im using types to do this... |
| ||
you could do a linecheck on the enemy to see wether it has someone standing at its left or right and then if not make someone go stand there. With one enemy chosen as the main enemy who takes the first position. |
| ||
This is in Blitz3D, right? |
| ||
yep, position the first enemy where you want it, then do a check on him using linepick to his left,right etc and if the position is clear position the next enemy there and loop till the last one. |
| ||
Not enough information...like where is the X,Z position in relateion to the eneimes...how far they are to be spaced appart, etc...but here is a simple way of doing what you want:function form_V(ammount%,xpos#,zpos#) ;note: changed ammount to an integer Svee%=1 ;counters for the loop Evee%=ammount ;Start and End of the vee Mpoint% = Evee / 2 ;trying to find the mid point If (Evee AND 1) Then Mpoint = Mpoint + 1 ;If the integer Evee is odd then add 1 to it to account for integer divide truncation (5/2=2 in integer math) Xoff# = 10 Zoff# = -10 ;the offsets or how far appart to place the enemies ;the values of xpos and zpos represnet the top-left corner of the vee For i = Svee to Evee enemy = NEW enemytype PosistionEntity enemy, xpos, 0 ,zpos If i = Mpoint then Zoff = -(Zoff) xpos = xpos + Xoff zpos = zpos + Zoff Next End function the form_line function is even simpler: Function form_line(ammount%,xpos#,zpos#) ;again ammount is an integer ;and xpos,zpos is in refrence to the left most side of the line Xoff# = 10 ;how far appart they should be For i = 1 to ammount enemy = NEW enemytype PosistionEntity enemy, xpos,0,zpos xpos =xpos + Xoff Next End function There is more to it, especialy involveing the use of entities/types...but I have a feeling that you just were trying to figure out how to get them into posistion more then anything |