ID:1173969
 
(See the best response by Keeth.)
Code:


Problem description:
I made a path for a tower defense game but I used the step instruction and I ended up writing 500 lines for each level. And the bad thing is that the 1st enemy in the wave stops while the others move. Any better solutions?
...
Before posting in this section you woul want to take in mind the following:
Without a code snippet, we cannot help you at all. Or atleast, some good explanation as to such your problem happens.
I can't post 500 lines of code. What I mean is are there any other ways to make a wave of x enemies move along a certain path besides having to manually code each step of each wave member?
In response to Victorqr
Best response
Victorqr wrote:
I can't post 500 lines of code. What I mean is are there any other ways to make a wave of x enemies move along a certain path besides having to manually code each step of each wave member?

I can think of a few ways to go about this without calling step 500 times manually. I'd suggest path finding, but path finding may not be feasible if you want certain enemies to follow a certain path. That is an option you should consider, though, depending on what you want. We have some path finding libraries here, go look them up. They essentially (or can) provide a list of steps you need to take to reach your destination.

A more visual approach I came to involves using "invisible" objects on the map editor that specify which direction mobs on it should be moving.



All you need to do is specify the stepper:
// make this invisible at runtime if necessary. (invisibility=1?)
// I suggest giving them an icon for the sake of map editing.
stepDirection
parent_type = /obj
north
dir = NORTH // we use this value to determine step direction

south
dir = SOUTH

east
dir = EAST

west
dir = WEST

and then have the mob access it when it needs to.
mob
proc
getStepDirection()
var/stepDirection/direction = locate(/stepDirection) in loc // stepDirection on our tile
if(direction)
return direction.dir // return its direction

wanderer
proc
doStaticStepLoop()
var/stepDirection = getStepDirection()
while(stepDirection && step(src,stepDirection))
stepDirection = getStepDirection()
sleep(5)

That method may not be feasible when you have a "BLOCK" of enemies that has to move in a certain formation, though. That's when we start getting into more complicated movement instructions that may require very specific movement instructions for each mob. Or just a more streamlined function for your specific needs. Maybe even something like a "formation" datum which handles that kinda stuff.

(Plus it's pretty much the same as using pathfinding. So maybe just use pathfinding.)
In response to Fushimi
Fushimi wrote:
Without a code snippet, we cannot help you at all. Or atleast, some good explanation as to such your problem happens.

For future reference, you do not need a code snippet to get help here. A code snippet is necessary if you're asking for help with a piece of code. His problem is theoretical.
I thank you on behalf of all question-askers Keeth.

Just because you don't have a code snippet does NOT mean you have to ignore a question.

That's all I wanted to say.

Hashtagirrelevantbutstillrelevant

Balt
Thanks I never thought of this Idea