Welcome, Guest. Please Login or Register.  • Help
SMF Underground
|-+ Enemy movement patterns in Java

Pages: [1]   Go Down
0 Members and 1 Guest are viewing this topic. Topic Tools  
Read November 23, 2010, 02:40:52 AM #0

Enemy movement patterns in Java

Hello everyone,

I'm new to this forum and a relative novice in programming.  I'm trying to program a simple shmup in Java for a class and I'm stuck on how to do enemy movement patterns.  My programming knowledge is not good enough for me to use other programming languages and I also don't really know how to use BulletML.  Are there any simple ways of implementing relatively decent movement of enemy ships?  Any help would be greatly appreciated.  Thanks.
Read November 23, 2010, 06:07:29 AM #1

Re: Enemy movement patterns in Java

I guess the most simplistic approach would be to store an array of relative coordinates in an enemy class, (X,Y) pairs like
(0,0),(100,0),(100,0),(100,480), and then linearly interpolate between those.

Taking the above values and asuming you spawn your enemy at X=0 and Y=50 this would then move it
to the right (X=0+100, Y=50+0)
then stay there for a while (same value 100,0 results in pause)
then move it down (X=100, Y=50+480)

If you want to keep it ultra-simple you can use a fixed factor for interpolation. More flexible would be to add some speed-attribute to your enemy class and / or extend the X,Y-pairs by some additional time value X,Y,T, where T is basically just a factor to speed up or slow down the interpolation.

I can't think of something more basic Smiley

What coordinate system you use for your enemies is up to you, above I used pixels, but if you target different resolutions you have to scale the resulting values to match it.

"When the Amiga came out, everyone at Apple was scared as hell."
(Jean-Louis Gassée - Head of Macintosh development at Apple)
Read November 25, 2010, 11:23:22 PM #2

Re: Enemy movement patterns in Java

I think you might be looking for something like movement along a spline?  motorherp has a nice tutorial around here that is easily ported to Java.  I use it myself.  The idea is that you can easily calculate position on the spline by time slice t.  This allows you to set your enemy velocity as you know the length of the spline, etc.

Simpler still is a simple position vector class (x,y) which acts as the enemy's position.  Each tick you update it by the velocity vector (dX, dY).  This works well for movement along a straight line.

The key to pretty much every method will be storing the enemy's position, then adjusting that each tick of your game loop. 


the2bears - the indie shmup blog
Pages: [1]   Go Up
Jump to:  

Page created in 0.145 seconds with 17 queries.