I have made an anim of when i destroy an alien he explode,but...the explode anim is a bit too fast to see o_O'
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
Global explosion=LoadAnimImage("d:\explode.bmp",64,64,0,9);an animstrip of 10 frames
MidHandle explosion
MidHandle aereo
MidHandle missil
MidHandle alien
HidePointer
Const limite_sx=100
Const limite_dx=540
Global b.alieno
Global c.esplosione
Type missile ;an object called missile
Field posx Field posy Field avanzamento Field contatore
Field image
End Type
Type alieno
Field movx,movy,movimento,energia,image
End Type
Type esplosione
Field posizionex,posizioney,frame
End Type
;MAIN
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
;END MAIN
Function create_missile()
a.missile=New missile
a\image=missil
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
DrawImage a\image,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)
For b.alieno=Each alieno
If ImagesCollide(a\image,a\posx,a\posy,0,b\image,b\movx,b\movy,0) ;if the alien collide with the missile the energy go down of one unit
b\energia=b\energia-1
If b\energia=<0 Then
;Delete b
crea_esplosione()
esplosione()
Delete b
EndIf
Delete a;if the missile collide with the alien the missile stop it's existance :P
Exit ;exit loop if missile is dead. will cause error as they's no missile to check against the aliens
EndIf
Next
Next
End Function
Function create_alien()
b.alieno=New alieno
b\image=alien
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 b\image,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
Text b\movx,b\movy-20,b\energia
Next
End Function
Function crea_esplosione()
c.esplosione=New esplosione
c\posizionex=b\movx
c\posizioney=b\movy
c\frame=0
End Function
Function esplosione()
For c.esplosione=Each esplosione
DrawImage explosion,b\movx,b\movy,c\frame
c\frame=c\frame+1
If c\frame=9 Then Delete c
Next
End Function
How i can repair this problem?
And...there's a better method of doing an animation??
Thanks
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
Global explosion=LoadAnimImage("d:\explode.bmp",64,64,0,9);an animstrip of 10 frames
MidHandle explosion
MidHandle aereo
MidHandle missil
MidHandle alien
HidePointer
Const limite_sx=100
Const limite_dx=540
Global b.alieno
Global c.esplosione
Type missile ;an object called missile
Field posx Field posy Field avanzamento Field contatore
Field image
End Type
Type alieno
Field movx,movy,movimento,energia,image
End Type
Type esplosione
Field posizionex,posizioney,frame
End Type
;MAIN
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
;END MAIN
Function create_missile()
a.missile=New missile
a\image=missil
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
DrawImage a\image,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)
For b.alieno=Each alieno
If ImagesCollide(a\image,a\posx,a\posy,0,b\image,b\movx,b\movy,0) ;if the alien collide with the missile the energy go down of one unit
b\energia=b\energia-1
If b\energia=<0 Then
;Delete b
crea_esplosione()
esplosione()
Delete b
EndIf
Delete a;if the missile collide with the alien the missile stop it's existance :P
Exit ;exit loop if missile is dead. will cause error as they's no missile to check against the aliens
EndIf
Next
Next
End Function
Function create_alien()
b.alieno=New alieno
b\image=alien
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 b\image,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
Text b\movx,b\movy-20,b\energia
Next
End Function
Function crea_esplosione()
c.esplosione=New esplosione
c\posizionex=b\movx
c\posizioney=b\movy
c\frame=0
End Function
Function esplosione()
For c.esplosione=Each esplosione
DrawImage explosion,b\movx,b\movy,c\frame
c\frame=c\frame+1
If c\frame=9 Then Delete c
Next
End Function
How i can repair this problem?
And...there's a better method of doing an animation??
Thanks