Collision(something strange goin'on...)

BlitzPlus Forums/BlitzPlus Programming/Collision(something strange goin'on...)

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I have made a simple prog to test collision(from wich i made my collision routines).
I have the old mouse pointer with a jet,and when i use the right-mouse-button i create an alien ship that go from left to right...
I use images collide and set the energy of the alien...
But something strange goin'on somethimes the alien self-destruct itself (LOL) and somethimes i only need two missile to destroy it (ROFL).
Where's the error?
I think that it's in the variable that contains the x and y location but don't figured out yet -_-'

Here's the code:

Graphics 640,480,32,1
SetBuffer BackBuffer()
Global posizionex
Global posizioney
Global posalienx
Global posalieny
Global aereo=LoadImage("d:\jet1.tga") ;a simple sprite
Global terreno=LoadImage("d:\terreno.bmp") ;a simple texture of 256*256
Global missil=LoadImage("c:\missile2.bmp") ;a simple sprite
Global alien=LoadImage("d:\velivolo1.tga") ;a simple sprite
MidHandle aereo
MidHandle missil
MidHandle alien
HidePointer
Const limite_sx=100
Const limite_dx=540
Global b.alieno
Type missile ;an object called missile
Field posx Field posy Field avanzamento Field contatore
End Type

Type alieno
Field movx,movy,movimento,energia
End Type

Repeat Cls
DrawImage aereo,MouseX(),MouseY()
If MouseHit(2)=1
create_alien()
EndIf
move_alien()
If MouseHit(1)=1 ;if i hit the mouse button i create a missile
create_missile()
EndIf
play_missile() ;this start the missil anim
Flip
Until KeyDown(1)=1
End


Function create_missile()
a.missile=New missile
a\posx=MouseX() ;the x position of missile creation is the mouse coords(the same coords of my jet of course)
a\posy=a\posy+MouseY()-45 ;the missile creation start a bit up to the jet(for simulating the launch-bay hehe)
a\avanzamento=4 ;the speed of the missile
a\contatore=0 ;the starting value of the animation
End Function

Function play_missile()
For a.missile=Each missile
posizionex=a\posx
posizioney=a\posy
DrawImage missil,a\posx,a\posy
a\posy=a\posy-a\avanzamento ;this move the missile up
a\contatore=a\contatore+a\avanzamento ;this start the counter of the missile course
;If a\contatore=> 200 Then Delete a ;if the course reach 200 the missile explode(hehe)
If ImagesCollide(missil,posizionex,posizioney,0,alien,posalienx,posalieny,0)
Delete a ;if the missile collide with the alien the missile stop it's existance :P
EndIf
Next
End Function

Function create_alien()
b.alieno=New alieno
b\movx=100
b\movy=60
b\movimento=1
b\energia=5 ;the "teoric" energy of the alien,from when reach 0 the alien explode
End Function

Function move_alien()
For b.alieno =Each alieno
posalienx=b\movx
posalieny=b\movy
DrawImage alien,b\movx,b\movy
b\movx=b\movx + b\movimento

If b\movx => limite_dx
b\movx=b\movx-b\movimento
b\movimento=-1
EndIf

If b\movx =< limite_sx
b\movx=b\movx+b\movimento
b\movimento=+1
EndIf

If ImagesCollide(missil,posizionex,posizioney,0,alien,posalienx,posalieny,0)
b\energia=b\energia-1 ;if the alien collide with the missile the energy go down of one unit
Text 400,400,b\energia
EndIf
If b\energia=<0 Then Delete b
Next
End Function


I don't need at all costs pixel-perfect collision detection,i think that "rectangle" collision with many rectangle to simulate the "shape" of the object works also very well and is faster;i think correct or wrong?