Ok, i have this code in which Ive been working on. Its a 2d platformer game. Very simple by the moment.
I reached the point in which i have to bring the first enemies to my hero. My hero moves while the background moves to his opposite side, like it should do. Well, the point is that I dont have problems making a moving sequence like the hero and the background, but now that i have enemies, they got to have their own moving sequence, like... left to right, or, idk, up and down, u know, the way an enemy moves. But idk how i can make him have his own sequence WHILE my hero have also his own when u move it... idk, its hard to explain. What i want is an advice about how can i make the enemies in a game to move and not be interrupted by my hero moves, or backwards, about how to collocate that in the code... This may help:
My code
(Its the entire code, thats why its so big, i just wanna be sure no detail is being forget, and... It have a lot of images because my hero has several actions and i have several backgrounds on it. The enemies are not putted in the code so u can be free about how should i put it
)
Sync on ; sync rate 60
MonitorX=desktop width()
MonitorY=desktop height()
Set display mode MonitorX,MonitorY, 0
color backdrop rgb(50,175,250)
Maximize window
rem Imgenes''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem Imagenes de Wilson
Load image "Media\WilsonPj\Wilson_Animacion_Corre_1.png" ,1
Load image "Media\WilsonPj\Wilson_Animacion_Corre1_izquierda.png" ,18
Load image "Media\WilsonPj\Wilson_Animacion_Corre_2.png" ,2
Load image "Media\WilsonPj\Wilson_Animacion_Corre2_izquierda.png" ,10
Load image "Media\WilsonPj\Wilson_Animacion_Corre_3.png" ,3
Load image "Media\WilsonPj\Wilson_Animacion_Corre3_izquierda.png" ,11
Load image "Media\WilsonPj\Wilson_Animacion_Corre_4.png" ,4
Load image "Media\WilsonPj\Wilson_Animacion_Corre4_izquierda.png" ,12
Load image "Media\WilsonPj\Wilson_Animacion_Corre_5.png" ,5
Load image "Media\WilsonPj\Wilson_Animacion_Corre5_izquierda.png" ,13
Load image "Media\WilsonPj\Wilson_Animacion_Corre_6.png" ,6
Load image "Media\WilsonPj\Wilson_Animacion_Corre6_izquierda.png" ,14
Load image "Media\WilsonPj\Wilson_Animacion_Cola_1.png" ,7
Load image "Media\WilsonPj\Wilson_Animacion_Cola1_izquierda.png" ,15
Load image "Media\WilsonPj\Wilson_Animacion_Cola_2.png" ,8
Load image "Media\WilsonPj\Wilson_Animacion_Cola2_izquierda.png" ,16
Load image "Media\WilsonPj\Wilson_Animacion_Cola_3.png" ,9
Load image "Media\WilsonPj\Wilson_Animacion_Cola3_izquierda.png" ,17
Load image "Media\WilsonPj\WilsonAgachado1.png" ,19
Load image "Media\WilsonPj\WilsonAgachado_izquierda.png" ,20
Load image "Media\WilsonPj\WilsonDuerme1.png" ,21
Load image "Media\WilsonPj\WilsonDuerme_izquierda.png" ,22
Load image "Media\WilsonPj\WilsonMuerde_1.png" ,23
Load image "Media\WilsonPj\WilsonMuerde_2.png" ,24
Load image "Media\WilsonPj\WilsonMuerde_3.png" ,25
Load image "Media\WilsonPj\WilsonMuerde1_izquierda.png" ,26
Load image "Media\WilsonPj\WilsonMuerde2_izquierda.png" ,27
Load image "Media\WilsonPj\WilsonMuerde3_izquierda.png" ,28
rem Escenario
Load image "Media\Escenarios\Playa\WI_Playa.png" , 1000
Sprite 1000, 0, 170, 1000
Set sprite priority 1000, 2
Load image "Media\Escenarios\Playa\WI_Playa_Fondo.png" , 1003
Sprite 1003, -25, 295, 1003
Load image "Media\Escenarios\Playa\WI Playa_Terreno_1.png" ,1001
Sprite 1001,0,580, 1001
Set sprite priority 1001, 1
Load image "Media\Escenarios\Playa\WI Playa_Terreno_2.png" ,1002
Sprite 1002,2480,580, 1002
Set sprite priority 1002, 1
Rem Musica'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
load music "Media\Musica\Playa\WWM_Playa-Jungla1.mp3" ,1
loop music 1
set music volume 1, 50
Rem Sonidos''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Load sound "Media\Sonidos\WilsonSnds\chomp.wav" ,1
Set sound volume 1, 80
Load sound "Media\Sonidos\WilsonSnds\step7.wav" ,2
Set sound volume 2, 90
rem Data ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Fx=X
F2xE=1
F2x=X
Fy=0
Tx=225
Ty=140
X=MonitorX/2/2
Y=200
A=Y
AW=150
YW1=50
YW1O=YW1
YW2O=YW2
aYW=10
FxX=25
F2xX=4
WFxX=31.7
FxDL=MonitorX*-4+175+50
FxIL=-25
WxDL=775
WxIL=50
F2x=-25
F1Primero=1
F1Ultimo=3
F2Primero=1
F2Ultimo=1
FxIM=MonitorX/2
FxDM=MonitorX/2
Mordidas=1
WSpritePrimero=1
WSpriteUltimo=28
TerrenoPrimero=1001
TerrenoUltimo=1002
For WilsonSprites= 1 to 28
Sprite WilsonSprites,0,0,WilsonSprites
Hide sprite WilsonSprites
Set sprite priority WilsonSprites,20
Next WilsonSprites
Dim F1(100)
F1(1)=1000
F1(2)=1001
F1(3)=1002
Dim F1x(100)
F1x(1)=Fx
F1x(2)=0
F1x(3)=2480
Dim F1y(100)
F1y(1)=170
F1y(2)=580
F1y(3)=580
Dim F2(100)
F2(1)=1003
Dim F2y(100)
F2y(1)=295
rem Main loop '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Do
WilsonDerecha:
Do
If inkey$()<>"s"
If inkey$()<>"S"
If rightkey()=1
If leftkey()=1
gosub WD
Else
gosub WCD
Endif
Endif
Endif
Endif
If inkey$()="s" OR inkey$()="S" then gosub WSD
If downkey()=1 then gosub WAD
If inkey$()="a" OR inkey$()="A" then gosub WMD
If rightkey()=0
If leftkey()=1 then gosub WilsonIzquierda
endif
gosub WD
loop
WilsonIzquierda:
Do
If inkey$()<>"s"
If inkey$()<>"S"
If leftkey()=1
If rightkey()=1
gosub WI
else
gosub WCI
Endif
Endif
Endif
Endif
If inkey$()="s" OR inkey$()="S" then gosub WSI
If downkey()=1 then gosub WAI
If inkey$()="a" OR inkey$()="A" then gosub WMI
If leftkey()=0
If rightkey()=1 then goto WilsonDerecha
Endif
gosub WI
loop
Loop
Rem Subrutinas ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Rem Wilson Derecha ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WD:
WCaida=0
Gravedad=10
For WDD=1 to 40
For WDSprites=1 to 4
If WDSprites=1 then WDSprite=7
If WDSprites=2 then WDSprite=8
If WDSprites=3 then WDSprite=7
If WDSprites=4 then WDSprite=9
If Gravedad>20 then YW1=Gravedad*-1 : gosub WCSD
If WCaida=1 AND Gravedad<50 then inc Gravedad, 10
inc Y, Gravedad : WCaida=1
Sprite WDSprite, X, Y, WDSprite
Show sprite WDSprite
sync
Wait 120
Hide sprite WDSprite
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,WDSprite)
if sprhit>0
while pixelcol(Terreno,WDSprite)=1
WCaida=0
Gravedad=10
dec Y, 5
sprite WDSprite,X,Y,WDSprite
endwhile
endif
Next Terreno
If rightkey()=1 then Return
If leftkey()=1 then Return
If inkey$()="s" OR inkey$()="S" then Return
If downkey()=1 then Return
If inkey$()="a" OR inkey$()="A" then Return
Next WDSprites
Next WDD
Rem Wilson Duerme Derecha:
WCaida=0
Gravedad=10
Do
If rightkey()=1 then hide sprite 21 : Return
If leftkey()=1 then hide sprite 21 : Return
If inkey$()="s" OR inkey$()="S" then hide sprite 21 : Return
If downkey()=1 then hide sprite 21 : Return
If inkey$()="a" OR inkey$()="A" then hide sprite 21 : Return
If Gravedad>20 then YW1=0 : gosub WCSD
If WCaida=1 AND Gravedad<50 then inc Gravedad, 10
inc Y, Gravedad : WCaida=1
Sprite 21, X, Y+30, 21
Set Sprite priority 21,20
Show sprite 21
sync
wait 80
hide sprite 21
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,21)
if sprhit>0
while pixelcol(Terreno,21)=1
WCaida=0
Gravedad=10
dec Y, 5
sprite 21,X,Y,21
endwhile
endif
Next Terreno
Loop
Rem Wilson Corre Derecha ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WCD:
WCaida=0
Gravedad=10
Do
For WCDSprite= 2 to 6
If rightkey()=0 then Return
If leftkey()=1 then Return
If inkey$()="s" OR inkey$()="S" then Return
If inkey$()="a" OR inkey$()="A" then Return
If F1x(1)=>FxDL AND X>=FxIM
For F1N=F1Primero to F1Ultimo
dec F1x(F1N), FxX
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
dec F2x, FxX/F2xX
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
If X>=WxDL then return
inc X, WFxX
Endif
If WCDSprite=2 OR WCDSprite=5 then play sound 2
If Gravedad>40 then YW1=0 : gosub WCSD
If WCaida=1 AND Gravedad<50 then inc Gravedad, 10
inc Y, Gravedad : WCaida=1
Sprite WCDSprite, X, Y, WCDSprite
Show sprite WCDSprite
sync
wait 80
hide sprite WCDSprite
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,WCDSprite)
if sprhit>0
while pixelcol(Terreno,WCDSprite)=1
WCaida=0
Gravedad=10
dec Y, 5
sprite WCDSprite,X,Y,WCDSprite
endwhile
endif
Next Terreno
Next WCDSprite
loop
Rem Wilson Salta Derecha ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WSD:
YW1=YW1O
WSDSprite=3
NumMordidas=0
play sound 2
Sprite 1,X+50,Y,1
Set sprite priority 1,20
show sprite 1
sync
Wait 120
hide sprite 1
Play sound 2
WCSD:
Do
If X<WxDL
If rightkey()=1
If F1x(1)=>FxDL AND X>=FxIM
For F1N=F1Primero to F1Ultimo
dec F1x(F1N), FxX
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
dec F2x, FxX/F2xX
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
Inc X,WFxX
Endif
Endif
Endif
If X>WxIL
If rightkey()=0
If leftkey()=1
If F1x(1)=<FxIL AND X<=FxDM
For F1N=F1Primero to F1Ultimo
inc F1x(F1N), FxX/2
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
inc F2x, FxX/F2xX/2
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
Dec X,WFxX/2
Endif
Endif
Endif
Endif
If NumMordidas<>Mordidas
If inkey$()="a" OR inkey$()="A"
YW1=0
gosub WMDS
inc NumMordidas, 1
Endif
Endif
If YW1<=0 then WSDSprite=4
Dec Y,YW1
Sprite WSDSprite,X+50,Y,WSDSprite
Set sprite priority WSDSprite,20
Show sprite WSDSprite
sync
wait 80
hide sprite WSDSprite
If YW1>-50 then dec YW1, aYW
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,WSDSprite)
if sprhit>0
while pixelcol(Terreno,WSDSprite)=1
inc Y, YW1+50
Play sound 2
Return
endwhile
endif
Next Terreno
Loop
Rem Wilson Agachado Derecha '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WAD:
WCaida=0
Gravedad=10
Do
If downkey()=0
Hide sprite 19
return
Endif
If Gravedad>20 then YW1=0 : gosub WCSD
If WCaida=1 AND Gravedad<50 then inc Gravedad, 10
inc Y, Gravedad : WCaida=1
Sprite 19,x+55,y+30,19
Set sprite priority 19,20
Show sprite 19
Sync
wait 80
hide sprite 19
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,19)
if sprhit>0
while pixelcol(Terreno,19)=1
WCaida=0
Gravedad=10
dec Y, 10
sprite 19,X,Y,19
endwhile
endif
Next Terreno
Loop
Rem Wilson Muerde Derecha '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WMD:
Sprite 1,X+75,Y,1
Set sprite priority 1,20
show sprite 1
sync
Wait 120
hide sprite 1
WMDS:
Do
For WMDSSprite=23 to 25
If X<WxDL
If rightkey()=1
If F1x(1)=>FxDL AND X>=FxIM
For F1N=F1Primero to F1Ultimo
dec F1x(F1N), FxX
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
dec F2x, FxX/F2xX
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
inc X,WFxX
Endif
Endif
Endif
If X>WxIL
If rightkey()=0
If leftkey()=1
If F1x(1)=<FxIL AND X<=FxDM
For F1N=F1Primero to F1Ultimo
inc F1x(F1N), FxX/2
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
inc F2x, FxX/F2xX/2
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
Dec X,WFxX/2
Endif
Endif
Endif
Endif
If WMDSSprite=23 then Play sound 1
Sprite WMDSSprite, X+75, Y, WMDSSprite
Set sprite priority WMDSSprite,20
Show sprite WMDSSprite
Sync
Wait 120
Hide sprite WMDSSprite
Next WMDSSprite
Return
loop
Rem Wilson Izquierda ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WI:
WCaida=0
Gravedad=10
For WDI=1 to 40
For WISprites= 1 to 4
If WISprites=1 then WISprite=15
If WISprites=2 then WISprite=16
If WISprites=3 then WISprite=15
If WISprites=4 then WISprite=17
If Gravedad>20 then YW1=0 : gosub WCSI
If WCaida=1 AND Gravedad<50 then inc Gravedad, 10
inc Y, Gravedad : WCaida=1
Sprite WISprite, X, Y, WISprite
Set sprite priority WISprite,20
Show sprite WISprite
Sync
Wait 120
Hide sprite WISprite
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,WISprite)
if sprhit>0
while pixelcol(Terreno,WISprite)=1
WCaida=0
Gravedad=10
dec Y, 5
sprite WISprite,X,Y,WISprite
endwhile
endif
Next Terreno
If leftkey()=1 then Return
If rightkey()=1 then Return
If inkey$()="s" OR inkey$()="S" then Return
If downkey()=1 then Return
If inkey$()="a" OR inkey$()="A" then Return
Next WISprites
Next WDI
Rem Wilson Duerme Izquierda:
WCaida=0
Gravedad=10
Do
If leftkey()=1 then hide sprite 22 : Return
If rightkey()=1 then hide sprite 22 : Return
If inkey$()="s" OR inkey$()="S" then hide sprite 22 : Return
If downkey()=1 then hide sprite 22 : Return
If inkey$()="a" OR inkey$()="A" then hide sprite 22 : Return
If Gravedad>20 then YW1=0 : gosub WCSI
If WCaida=1 AND Gravedad<50 then inc Gravedad, 10
inc Y, Gravedad : WCaida=1
Sprite 22, X, Y+30, 22
Set Sprite priority 22,20
Show sprite 22
sync
Wait 80
Hide sprite 22
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,22)
if sprhit>0
while pixelcol(Terreno,22)=1
WCaida=0
Gravedad=10
dec Y, 5
sprite 22,X,Y,22
endwhile
endif
Next Terreno
Loop
Rem Wilson Corre Izquierda ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WCI:
WCaida=0
Gravedad=10
Do
For WCISprites=10 to 14
If leftkey()=0 then Return
If rightkey()=1 then Return
If inkey$()="s" OR inkey$()="S" then Return
If inkey$()="a" OR inkey$()="A" then Return
If F1x(1)=<FxIL AND X<=FxDM
For F1N=F1Primero to F1Ultimo
inc F1x(F1N), FxX
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
inc F2x, FxX/F2xX
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
If X<=WxIL
Return
Else
Dec X, WFxX
Endif
Endif
If WCISprites=10 OR WCISprites= 13 then play sound 2
If Gravedad>20 then YW1=0 : gosub WCSI
If WCaida=1 AND Gravedad<50 then inc Gravedad, 10
inc Y, Gravedad : WCaida=1
Sprite WCISprites, X, Y, WCISprites
Set sprite priority WCISprites,20
Show sprite WCISprites
Sync
wait 80
hide sprite WCISprites
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,WCISprites)
if sprhit>0
while pixelcol(Terreno,WCISprites)=1
WCaida=0
Gravedad=10
dec Y, 5
sprite WCISprites,X,Y,WCISprites
endwhile
endif
Next Terreno
Next WCISprites
loop
Rem Wilson Salta Izquierda '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WSI:
YW1=YW1O
WSISprite=11
NumMordidas=0
play sound 2
Sprite 18,X-50,Y,18
Set sprite priority 18,20
show sprite 18
sync
Wait 120
hide sprite 18
play sound 2
WCSI:
Do
If X>WxIL
If leftkey()=1
If F1x(1)=<FxIL AND X<=FxDM
For F1N=F1Primero to F1Ultimo
inc F1x(F1N), FxX
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
inc F2x, FxX/F2xX
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
dec X,WFxX
Endif
endif
Endif
If X<WxDL
If leftkey()=0
If Rightkey()=1
If F1x(1)=>FxDL AND X>=FxIM
For F1N=F1Primero to F1Ultimo
dec F1x(F1N), FxX/2
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
dec F2x, FxX/F2xX/2
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
inc X,WFxX/2
Endif
Endif
Endif
Endif
If NumMordidas<>Mordidas
If inkey$()="a" OR inkey$()="A"
YW1=0
gosub WMIS
inc NumMordidas, 1
Endif
Endif
If YW1<=0 then WSISprite=12
Dec Y,YW1
Sprite WSISprite,X-50,Y,WSISprite
Set sprite priority WSISprite,20
Show sprite WSISprite
sync
wait 80
hide sprite WSISprite
If YW1>=-50 then dec YW1, aYW
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,WSISprite)
if sprhit>0
while pixelcol(Terreno,WSISprite)=1
inc Y, YW1+50
Play sound 2
Return
endwhile
endif
Next Terreno
Loop
Rem Wilson Agachado Derecha '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WAI:
WCaida=0
Gravedad=10
Do
If downkey()=0
Hide sprite 20
return
Endif
If Gravedad>20 then YW1=0 : gosub WCSI
If WCaida=1 AND Gravedad<50 then inc Gravedad, 10
inc Y, Gravedad : WCaida=1
Sprite 20,x-55,y+30,20
Set sprite priority 20,20
Show sprite 20
Sync
Wait 80
Hide sprite 20
For Terreno= TerrenoPrimero to TerrenoUltimo
sprhit=sprite collision(Terreno,20)
if sprhit>0
while pixelcol(Terreno,20)=1
WCaida=0
Gravedad=10
dec Y, 10
sprite 20,X,Y,20
endwhile
endif
Next Terreno
Loop
Rem Wilson Muerde Derecha '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WMI:
Sprite 18,X-75,Y,18
Set sprite priority 18,20
show sprite 18
sync
Wait 120
hide sprite 18
WMIS:
Do
For WMISSprites=26 to 28
If X>WxIL
If leftkey()=1
If F1x(1)=<FxIL AND X<=FxDM
For F1N=F1Primero to F1Ultimo
inc F1x(F1N), FxX
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
inc F2x, FxX/F2xX
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
dec X,WFxX
Endif
Endif
Endif
If X<WxDL
If leftkey()=0
If rightkey()=1
If F1x(1)=>FxDL AND X>=FxIM
For F1N=F1Primero to F1Ultimo
dec F1x(F1N), FxX/2
Sprite F1(F1N),F1x(F1N), F1y(F1N), F1(F1N)
Next F1N
If F2xE=1
dec F2x, FxX/F2xX/2
For F2N=F2Primero to F2Ultimo
Sprite F2(F2N),F2x, F2y(F2N), F2(F2N)
Next F2N
Endif
Else
inc X,WFxX/2
Endif
Endif
Endif
Endif
If WMISSprites=26 then Play sound 1
Sprite WMISSprites, X-75, Y, WMISSprites
Set sprite priority WMISSprites,20
Show sprite WMISSprites
Sync
Wait 120
Hide sprite WMISSprites
Next WMISSprites
Return
loop
`=======================================================
`==== PIXEL-PERFECT SPRITE COLLISION BY CLOGGY =========
function pixelcol(sp1,sp2)
`load sprite images into memory
make memblock from image 1,sprite image(sp1)
make memblock from image 2,sprite image(sp2)
`store image sizes
sw1=memblock dword(1,0)
sh1=memblock dword(1,4)
sw2=memblock dword(2,0)
sh2=memblock dword(2,4)
`store image positions
x1=sprite x(sp1)-sprite offset x(sp1)
y1=sprite y(sp1)-sprite offset y(sp1)
x2=sprite x(sp2)-sprite offset x(sp2)
y2=sprite y(sp2)-sprite offset y(sp2)
`calculate collision rectangle
rx1=getmax(x1,x2)
ry1=getmax(y1,y2)
rx2=getmin(x1+sw1-1,x2+sw2-1)
ry2=getmin(y1+sh1-1,y2+sh2-1)
`calculate area of first sprite that has overlapped second
sx1=rx1-x1
sy1=ry1-y1
ex1=rx2-x1
ey1=ry2-y1
`calculate area of second sprite that has overlapped first
sx2=rx1-x2
sy2=ry1-y2
ex2=rx2-x2
ey2=ry2-y2
`check through both sprites to see if any pixels collide
for row=0 to ey1-sy1
for col=0 to ex1-sx1
` bit1=memblock dword(1,12+((row+sy1)*(sw1*4))+((col+sx1)*4))
` bit2=memblock dword(2,12+((row+sy2)*(sw2*4))+((col+sx2)*4))
bit1=memblock byte(1,12+((row+sy1)*(sw1*4))+((col+sx1)*4)+3)
bit2=memblock byte(2,12+((row+sy2)*(sw2*4))+((col+sx2)*4)+3)
` AND bits together to see if a collision has occured
if bit1>0 and bit2>0
`Collision has occured
collision=1
`Clean up memblocks and return
delete memblock 1
delete memblock 2
exitfunction 1
endif
next col
next row
`no collision clean up memblocks and return
delete memblock 1
delete memblock 2
endfunction 0
function getmax(v1,v2)
`Calculate the larger of 2 numbers
if v1>v2
exitfunction v1
else
exitfunction v2
endif
endfunction v1
function getmin(v1,v2)
`calculate the smaller of 2 numbers
if v1<v2
exitfunction v1
else
exitfunction v2
endif
endfunction v1
Ty guys, Ive done a lot because of all of u
(And ty Cloggy too =P)