I think i have individuated the error!!!
I have to declare the variable that control the angle INTO the type!
Else at every call to a function the angle sum itself with the precedent angle...argh
Here's the correct function:
(a question:what's the forum command to highlight the code in green?)
(edited:i have found the command :P )
I hope that is the definitive version.
I have to declare the variable that control the angle INTO the type!
Else at every call to a function the angle sum itself with the precedent angle...argh
Here's the correct function:
Type alieno Field posizionex# Field posizioney# Field velocita# Field percorso Field angolo# End Type Function crea_alieno(xpos,ypos,speed,movimento) a.alieno=New alieno a\posizionex=xpos a\posizioney=ypos a\velocita#=speed a\percorso=movimento a\angolo=0 ;new entry!!! End Function Function muovi_alieno() For a.alieno=Each alieno Select a\percorso Case 1 circleMov() Case 2 strightMov() Case 3 updownMov() End Select Next End Function Global a.alieno Const scrX=640,scrY=480 ;------------------------------------ ;Global r1#,r2#,r3# ;------------------------------------ ;setup Graphics scrX,scrY,32,2 SetBuffer BackBuffer() ;------------------------------------ AutoMidHandle True ;loadgrafx Global backGnd=LoadImage("go.bmp") Global enemys=LoadImage("enemy.bmp") ;------------------------------------ ;loop ;crea_alieno(100,300,4,1) ;crea_alieno(15,15,1,1) While Not KeyDown(1) If MouseHit(1)=True crea_alieno(50,50,1,1) crea_alieno(200,400,1,1) crea_alieno(200,200,2,2) crea_alieno(100,100,4,3) EndIf Cls TileImage backGnd,ixTim,iyTim muovi_alieno() Flip Wend End ;Circle Motion Function circleMov() xpos#=a\posizionex+Sin(a\angolo)*100 ypos#=a\posizioney+Cos(a\angolo)*100 speed1#=a\velocita DrawImage enemys,xpos,ypos a\angolo=a\angolo+speed1# If a\angolo=>359 Then a\angolo=0 End Function ;------------------------------------ ;Forward & Backward Motion Function strightMov() xpos#=a\posizionex+Sin(a\angolo)*100 ypos#=a\posizioney speed2#=a\velocita DrawImage enemys,xpos#,ypos# a\angolo=a\angolo+speed2# If a\angolo=>359 Then a\angolo=0 End Function ;------------------------------------ ;Up & Down Motion Function updownMov() xpos#=a\posizionex ypos#=a\posizioney+Cos(a\angolo)*100 speed3#=a\velocita DrawImage enemys,xpos#,ypos# a\angolo=a\angolo+speed3# If a\angolo=>359 Then a\angolo=0 End Function
(a question:what's the forum command to highlight the code in green?)
(edited:i have found the command :P )
I hope that is the definitive version.