Advanced Enemy movements : Looking for references

Hi,

2 Questions:
One specific to 2 types of movement paths i wanna give enemies in mygame & one more general question of where i can find references anything related to creating movement paths.

I’m working on a vertical scolling 2d “adventure”-shooter, a clone of the msx game knightmare & I am looking to implement more advanced movement patterns to the enemies.
Right now they just have a simple downward vertical movement pattern.
But I would like to give them movements like in the original game:

VjzHcunnNaE

For example:
-At 1:00 there is a group of 4 bats that enter the screen and move off screen again along a half eliptical shaped path
-Or at 3:55 a group bats enter the top of the screen moving down on a s-curved path from top to bottom of the screen

How would you create such movement patterns?

I’m thinking now about creating a movement table for each enemy-type, but maybe there are other options I don’t know about.

Question 2.
Does anyone have any references on where i could find anything related to movement:

  • like maybe algorithms for enemy movements
  • info on how to construct & use movement tables
  • etc.

I’m a noob btw.

This is what my game looks at this moment.
Any feedback that would help improve the game would be much appreciated:

sWrWxdr0SIs

Those bats seem to just be flying along a parabola or a sine/cosine curve, nothing special about that.

Like BurntPizza said, the bats seem to be moving along the curves of mathematical functions.
Although they are moving vertical instead of horizontal, which means Inverse functions of sine or cosine.

My advice to you is look up some mathematical functions, graph em on a calculator and look at the patterns or curves. Then you have the bats/enemies follow that curve, use the y coordinate as the dependent variable, and the x coordinate as the value of the function at position y.

In code:

for(int y = 0; y < screenheight; y++){
x = widthOfSpread*Math.sin(y)+symmetryLine;
drawBatAt(x, y);
}

widthOfSpread = how much difference there is between rightmost tip and leftmost tip
symmetryLine = imagine a line going through the bats path in the video, that is a symmetry line and is the original position of the bat.

Don’t use the inverses, they are domain-restricted. Simply have x as a function of time similar to your code snippet.

Well, yes. Arcsin and arccos are restricted so don’t use those.

What I meant with an inverse was simply a function x dependant on y instead of the other way around :slight_smile:

Hey I’m a noob to game programming and it’s been a while since I’ve done any math so its all special to me ^__^.

“Domain restricted”…? <-- im still a noob. No idea what what domain restricted means.

Thanks for the feedback already!
Ill experiment with the sin function.

So how would you do the 2nd movement pattern. At 3:55 where the bats move in a zigzag s-shape like path?


A domain restriction (loosely) means a function is only defined for a certain range of numbers.

Both patterns are likely a sine or cosine function, the 2nd is for sure.

Here you can learn about functions and inverses


and here about domains

So now for getting this idea to actual code:

  • My x and y coordinates for everything i want to plot on -screen are INT’s; math.sin doesnt return an int, but a double (if i am not mistaken)
    How do I solve this? Is there a way [what code should i use] to round doubles up or down to their nearest INT value? Or should i change my x and y variable i use for drawing everything on screen to a double (is that even possible?); but then how do i do that cause my g.drawImage function requires an INT input.

java.lang.Math has everything you need.

http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#round(double)
http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#ceil(double)
http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#floor(double)

You can also cast the double to an int: [icode]int i = (int) 3.8; // truncates to 3[/icode]

Edit: BBcode is breaking the links, but you should still be able to easily find the methods.

ty ty!