enemy wave.. almost there HELP!
BlitzMax Forums/BlitzMax Programming/enemy wave.. almost there HELP!
| ||
Ok I got an enemy wave, using Cos to move on the y and atan2 to set their angle but... as they are now they are all in a line when they are created, when they are created i need them to all ready be in a nice wavey line, but i cant figure it out, ive tried changing lots of things but what every i try they move off the line they need to follow. Can ya help??? I know i need to set some vars when im creating the types but ive tried lots with no success. !!NO MEDIA NEEDED!!, copy'n'paste and run. Graphics 640,480,0,60 Global Ltemp:TList=New TList Type Ttemp Field x#,y# Field waveinc# Field vx#,vy#,angle End Type make(8) ' make 8 ships '=================================== Repeat ; Cls Update() DrawLine 0,240,640,240,1 ' centre point line DrawLine 0,240+64,640,240+64,1 ' top boundry DrawLine 0,240-64,640,240-64,1 ' bottom boundry FlushMem ; Flip ; Until KeyDown(KEY_ESCAPE)=True ; End '==================================== Function Update() For t:Ttemp=EachIn Ltemp If t.x>640 Then t.x=0 ' loop through the screen t.angle = ATan2((t.Y+t.VY) - t.Y , (t.X+t.VX) - t.X) ' get angle t.waveinc:+1 t.vy=Cos(t.waveinc)*0.8 t.y:+t.vy t.x:+t.vx ' ,move on the x SetRotation t.angle SetColor 255,255,255 ; DrawRect t.x-16,t.y-8,32,16 SetRotation 0 Next End Function '------ Function make(count) For i=1 To count t:Ttemp=New Ttemp ListAddLast Ltemp,t t.x=320-(i*64) t.y=240 t.vx=1 Next End Function |
| ||
To make them start in a wave instead of a line, Change the line: t.y = 240 To: t.y=240 + 80*Sin( 1*(i/count)*360) Where 80 is the altitude (height) of the wave (you pick). If you want the wave to be longer alter my 1* to something smaller like 0.5 Also to make this work you have to set "i" to a float or double: For i# = 1 to count Hope that's solves it. I might have gotten you wrong :) |
| ||
thanks for the try wave ... hehe wave how apt... ive tried that but al it does is move the centre point of each type so they dont follow the same line. Each type as they are created need to be part way through the wave but their centre point the line they follow be he same for all the types. heres a pic to show waht i need. ![]() |
| ||
Try thisFor t:Ttemp=EachIn Ltemp If t.x>640 Then t.x=0 ' loop through the screen t.angle = -Sin(t.x)*50'get angle t.y=240+Cos(t.x)*50 t.x:+1't.vx ' ,move on the x SetRotation t.angle SetColor 255,255,255 ; DrawRect t.x-16,t.y-8,32,16 SetRotation 0 Next |
| ||
yes that sets enm out but problems when you try to move em. It thought all id need to do was to change the t.waveinc to t.waveinc=Cos(i*16)*80 now this work in that it sets them out in the wave pattern but now the wave for each enemy is off from the middle line which they all need to wave through. ![]() |
| ||
If you replace the contents of the Update function with Shamblers code it seems to work quite nicely. Or am I missing something? |
| ||
See this example. If you midhandle the rotation perhaps you can solve it? The problem is normal image midhandle don't work on rects..Graphics 640,480,0,60 X# = 300 Y# = 200 width=32 height=16 Repeat angle:+1 SetRotation angle SetColor 255,255,255 DrawRect X, Y, width, height SetRotation 0 DrawLine X-50, Y, X+50, Y SetColor 255, 0, 0 Plot X, Y Flip;Cls Until KeyDown(key_escape) |
| ||
hum ya right Happy cat, i think i used a modified make function when i tried the code. Wahay thats Shambler and Happycat. *skips around the room like a little girl* |
| ||
*skips around the room like a little girl* You must stop doing that, the neighbours are starting to talk... |