Expand / Contract like in GALAGA

BlitzMax Forums/BlitzMax Beginners Area/Expand / Contract like in GALAGA

Matt McFarland(Posted 2005) [#1]
You know how in Galaga the enemies sort of expand and contract from each other? I'm really having a hard time thinking of a logical way to do this.

My first attempt yesterday was to make additional points for them to go to. So when I assign them their coordinates, they are also assigned additional points (the expanded point, and contracted point)

That was easy, but then after I tested it I found out that they all dont move in uniform and they move too choppy. So its back to the drawing board for me.

Anyways, I've asked around and was given some information about an epicentre, and use cosine(time) * scale factor * original distance from epicenttre. and use slightly different scale factors for X and Y for more elliptical expansion. Could anyone tell me how they would code this? Perhaps its something simple to understand?


Perturbatio(Posted 2005) [#2]
Never heard of Galaga, so not entirely sure what you want, but is this of any use as a start?

Graphics 640,480,0,0

Type TAlien
	Global AlienList:TList
	Field X:Float
	Field Y:Float
	
	Field DiffX:Float
	Field DiffY:Float
	
	Field Count:Float
	Field CountMod:Float = 0.1
	
	Field HandleX:Float
	Field HandleY:Float
	
	Method  Update()
		HandleX = MouseX()
		HandleY = MouseY()
		X = (Cos(Count)*DiffX)
		Y = (Cos(Count)*DiffY)
		'Print Cos(count)
		Draw()
		count:+CountMod
		If count>100 Then countMod = -0.1
		If Count < 1 Then CountMod = 0.1
	End Method
	
	Function UpdateAll()
		For Local tempAlien:TAlien = EachIn AlienList
			tempAlien.Update()
		Next
	End Function
	

	Method  Draw()
		DrawRect(HandleX+X, HandleY+Y, 20,20)
	End Method


	Function Create:TAlien(X:Float, Y:Float)
		If Not AlienList Then AlienList = New TList
		Local tempAlien:TAlien = New TAlien
			tempAlien.DiffX = X
			tempAlien.DiffY = Y
			AlienList.AddLast(tempAlien)
		Return tempAlien
	End Function


	Function Destroy(a:TAlien Var)
		a = Null
	End Function
End Type


TAlien.Create(100,0)
TAlien.Create(200,0)
TAlien.Create(-200,0)
TAlien.Create(-100,0)
TAlien.Create(200,100)
TAlien.Create(280,50)

While Not KeyDown(KEY_ESCAPE) And Not AppTerminate()
	Cls
	
	TAlien.UpdateAll()

	Flip
Wend
End




Steve Elliott(Posted 2005) [#3]

never heard of Galaga



http://www.breumelhof.nl/emulationroms/component/option,com_wrapper/Itemid,62/

5 - insert coin
1 - start
Ctrl - fire


ImaginaryHuman(Posted 2005) [#4]
Galaga is cool. I dunno. I was thinking you'd need to have some AI which handled that kind of thing, that's how I'd do it, more than some fixed routine for it.


Matt McFarland(Posted 2005) [#5]
Well the enemies are controlled by a very simple AI that is like a "controller" that tells them what "phase" they're in.

Regardless of what "phase" they're in (like if they're diving) they're going to have to fly back into formation, and I want the formation to be a set thing. The formation moves from left to right and expands and contracts like in galaga... I'm still on the fence on how to do this just yet, but I am going to get a crack at it and probably post what's going on here within an hour or so.. hopefully.. If I get my ARSE IN GEAR!!


Dreamora(Posted 2005) [#6]
I would use splines for their path and basic flocking to force them into their formation (or a movement AI that sets their place in the formation as their movement target if they need to go there)


ImaginaryHuman(Posted 2005) [#7]
You could have two levels of control. Each ship has its own AI to fly in a set pattern, ie it's individual flight style, then there is a second level - an overriding level, which uses splines or whatever to manouver the ship into a specific slot in the formation, then animate the formation and use it to override all the ships that are part of it.


Matt McFarland(Posted 2005) [#8]
I'm using a simple method. Very simple indeed.. But I have one problem.. Here's what's going on..

enemy.AssignedModX = (64)+enemy.PlaceID * wavewidth / 12

Basically, I followed Yavin's advice here:
http://www.shmup-dev.com/index.php?topic=24.0

The PlaceID is the number assigned to the enemy that shows "how far to the right" it goes. such as 3, means 3 to the right. The 64 is so it starts on the right spot of the screen. Then the wavewidth, is how long all the enemies are in pixels when placed together. 12 is how many enemies there are alltogether. (in one line)

I have a line of 12. The enemies are placed correctly when using this method. Now if I alter the wavewidth, I can have the enemy's position "stretch" but unfortunately. They're all stretching towards the right..

Does anyone know how I can get the stretch to appear from the center as opposed to the left?


Matt McFarland(Posted 2005) [#9]
It looks like this


STEP 1:
xxxxx
STEP 2:
xxxx x
STEP 3:
xxx x  x
STEP 4:
xx x   x   x




QuietBloke(Posted 2005) [#10]
your almost there. what you need is to have the enemies either side of the wave position. so if you have 12 columns you need to have 6 to the right as positive offsets and 6 to the left as negative offsets.


Matt McFarland(Posted 2005) [#11]
A guy they call "Dev" gave me extensive help (over IRC, then ICQ) and I have officially finished this daunting task. I owe him big thanks ;)

Pretty much I'm using the sin() method and it looks great!!! I'm glad I finally got past this obstacle, so now I can work on other stuff involving the game :)

The greatest thing about all of this is that I have finally gained the comprehension of how to use the sin function!! woot! :)


Steve Elliott(Posted 2005) [#12]
Are you gonna post the code you were given? ;-)


Matt McFarland(Posted 2005) [#13]
Sure, I can do that!

It's "blitz basic" code that I had to retranslate and change around so that it would used in my game. Also, since I learned sin() (thanks dev for your high amount of patience as a tutor) I made more changes to it that allowed them to "expand downwards"

Perhaps I could write a tutorial..


Matt McFarland(Posted 2006) [#14]
Here's the mighty code that I am using to do this:
*shamelessly pointing at my website ;) ;)*
http://www.shmup-dev.com/index.php?topic=24.msg933#msg933

heh..Ok, first.. THANK YOU DEV!!.. Second.. here's you go:
Ok First, I set the following constants up:
My playfield is 600 pixels wide, this is the center.
LevelCenter = 300 

wavewidth Tells the code how far left and right the whole group moves left and right, in my case, not far at all.
wavewidth:Float = 4       

WaveY_Width Tells the code how far they Stretch out downward
WaveY_Width:Float = 2  

StretchWidth tells the code how far they stretch out from center
StretchWidth:Float = 15   

Second, I set the following variables up when an alien is created
Enemy.CenterID
0 is the middle guy, -1 is to his left, 1 is to his right and so on (2 left over is -2, 2 over right is 2, etc)
This tells the code at the bottom to stretch them out from the center.
Enemy.RowID
1 is the top row, and so on.. This tells the code at the bottom which row moves down more (stretching effect)
Third, we set up our sin timing.
basically the Time-Variable is nothing but a float variable that starts at zero and goes up by any number per cycle. I have timestep go up by .3 every cycle. The higher the number the faster they go.
Here's what I use:
timestep:float = .3
time:Float = time:Float + timestep:Float 

Ok Fouth the following script is fired on every enemy object every cylce...


Any Questions? I will gladly answer as best as possible... but you might find them at http://www.shmup-dev.com/index.php?topic=24.msg933#msg933