Strange things about moving object

BlitzPlus Forums/BlitzPlus Programming/Strange things about moving object

Hallo to all.
I have a problem with my movements function.
I have tried to modify my functions with the various hint from my previous posts(about the function that return multiple values...)but when i execute my program...something goes very wrong.
I have 3 function that made different movements:up&down,left&right,circular.
Here's the code.....i don't know how to explayn the effects,but if you cut&paste the code and you press the mouse button....well.....i don't know why the speed movements double itself!!!

Type alieno
	Field posizionex#
	Field posizioney#
	Field velocita#
	Field percorso
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
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(r1)*100
					
					
	ypos#=a\posizioney+Cos(r1)*100
	speed1#=a\velocita
	DrawImage enemys,xpos,ypos
	r1=r1+speed1#
	If r1=>359 Then r1=0
End Function
;------------------------------------
;Forward & Backward Motion
Function strightMov()
	xpos#=a\posizionex+Sin(r2)*100
	ypos#=a\posizioney
	speed2#=a\velocita
	DrawImage enemys,xpos#,ypos#
	r2=r2+speed2#
	If r2=>359 Then r2=0
End Function
;------------------------------------
;Up & Down Motion
Function updownMov()
	xpos#=a\posizionex
	ypos#=a\posizioney+Cos(r3)*100
	speed3#=a\velocita
	DrawImage enemys,xpos#,ypos#
	r3=r3+speed3#
	If r3=>359 Then r3=0
End Function




I can call crea_alieno many times,but if i call crea_alieno with the same movement function.....it seems that the alien add their speed and go at speed=alien1speed+alien2speed
I also don't know if the position are correctly calculated.....
I hope i have translated well,and that the effect i'm trying to explain is visible to all.
Thanks

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:

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.

Glad that you fixed it by yourself :)
It seems I am not the only Italian here :)

Ciao!

Ciao anche a te!
It's easy for me to make error in such things,because i don't know what must be inside and what outside the type o_O