INCLUDE "sw.inc"
' *************
FUNCTION CircleCollide(x1, y1, r1, x2, y2, r2)
' *************
IF SQR((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) < r1 + r2 THEN
CircleCollide = 1
END IF
END FUNCTION
' ******
SUB Timer1
' ******
dv = dv + 0.1
IF dv >= 1 THEN
dv = 0
zFrame = zFrame + 1
IF zFrame = 8 THEN zFrame = 0
END IF
END SUB
' ******
SUB Timer2
' ******
jv = jv + 1
IF jv = 50 THEN
jv = 0
jx = jx + 1
IF jx = 21 THEN jx = 0
END IF
END SUB
' ******
SUB Timer3
' ******
Drop = SW_Rnd(0,40)
END SUB
' ******
SUB Timer4
' ******
IF Ok = 1 THEN EXIT SUB
za += .2
IF za >= 5 THEN
za = 0
count = count - 1
IF count <= 0 THEN count = 0
END IF
END SUB
' *********
SUB SetExplos(xx, yy, ii)
' *********
FOR iDx = 0 TO 39
IF yBum[iDx] = 0 THEN
xBum[iDx] = xx
yBum[iDx] = yy
iBum[iDx] = ii
EXIT SUB
END IF
NEXT
END SUB
' **********
SUB ShowExplos
' **********
FOR iDx = 0 TO 39
IF iBum[iDx] = 1 THEN
SW_DrawTile bmap, xBum[iDx], yBum[iDx], 64, 64, zBum[iDx], 1
vBum[iDx] = vBum[iDx] + 0.1
IF vBum[iDx] >= 1 THEN
vBum[iDx] = 0
zBum[iDx] = zBum[iDx] + 1
END IF
IF zBum[iDx] = 8 THEN
zBum[iDx] = 0
yBum[iDx] = 0
iBum[iDx] = 0
vBum[iDx] = 0
END IF
END IF
NEXT
END SUB
' *********
SUB SetRocket(xx, yy)
' *********
FOR iAx = 0 TO 39
IF yRok[iAx] = 0 THEN
xRok[iAx] = xx
yRok[iAx] = yy
rRok[iAx] = 1
EXIT SUB
END IF
NEXT
END SUB
' **********
SUB ScanRocket
' **********
FOR iAx = 0 TO 39
IF rRok[iAx] = 1 AND yRok[iAx] <= -32 THEN
rRok[iAx] = 0
yRok[iAx] = 0
END IF
NEXT
END SUB
' **********
SUB ShowRocket
' **********
FOR iAx = 0 TO 39
IF rRok[iAx] = 1 THEN
SW_DrawTile bmap, xRok[iAx], yRok[iAx], 64, 64, zFrame, 0
yRok[iAx] = yRok[iAx] - 4
IF yRok[iAx] = 400 THEN zRak = 0
END IF
NEXT
END SUB
' **********
SUB ScanRakete
' **********
IF rRak = 5 THEN EXIT SUB
IF SW_Key(32) AND SW_Key(39) AND zRak = 0 THEN
SetRocket(xRak, yRak)
rRak = 1
zRak = 1
SW_PlayWav w1
ELSE IF SW_Key(32) AND SW_Key(37) AND zRak = 0 THEN
SetRocket(xRak, yRak)
rRak = 2
zRak =1
SW_PlayWav w1
ELSE IF SW_Key(32) AND zRak = 0 THEN
SetRocket(xRak, yRak)
zRak = 1
SW_PlayWav w1
ELSE IF SW_Key(39) AND xRak < 736 THEN
rRak = 1
ELSE IF SW_Key(37) AND xRak > 0 THEN
rRak = 2
ELSE
rRak = 0
END IF
END SUB
' **********
SUB ShowRakete
' **********
IF rRak = 0 THEN
SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
ELSE IF rRak = 1 THEN
SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
xRak = xRak + 1
ELSE IF rRak = 2 THEN
SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
xRak = xRak - 1
END IF
END SUB
' ***************
SUB RocketCollision
' ***************
FOR iBx = 0 TO uz
FOR iCx = 0 TO 39
IF rRok[iCx] > 0 AND rUfo[iBx] > 0 THEN
IF CircleCollide(xRok[iCx] + 32, yRok[iCx] + 32, 16, xUfo[iBx] + 32, yUfo[iBx] + 32, 16) = 1 THEN
SetExplos(xUfo[iBx], yUfo[iBx], 1)
rRok[iCx] = 0
yRok[iCx] = 0
rUfo[iBx] = 0
yUfo[iBx] = 0
SW_PlayWav w2
sc = sc + 25
EXIT SUB
END IF
END IF
NEXT
NEXT
END SUB
' ***************
SUB RaketeCollision
' ***************
IF Ok = 1 THEN EXIT SUB
FOR iAx = 0 TO 40
IF yMeg[iAx] > 0 THEN
IF CircleCollide(xRak, yRak, 16, xMeg[iAx], yMeg[iAx], 16) = 1 THEN
SetExplos(xRak, yRak, 1)
rRak = 5
Ok = 1
SW_PlayWav w3
EXIT SUB
END IF
END IF
NEXT
END SUB
' *******
SUB SetUfos
' *******
FOR iAx = 0 TO uz
xUfo[iAx] = SW_Rnd(16,736)
yUfo[iAx] = SW_Rnd(16,300)
rUfo[iAx] = SW_Rnd(1,4)
zUfo[iAx] = 0
nUfo[iAX] = 0
NEXT
END SUB
' ********
SUB ScanUfos
' ********
FOR iBx = 0 TO uz
IF rUfo[iBx] = 1 AND xUfo[iBx] >= 736 THEN
rUfo[iBx] = 2
ELSE IF rUfo[iBx] = 2 AND xUfo[iBx] <= 0 THEN
rUfo[iBx] = 1
ELSE IF rUfo[iBx] = 3 AND yUfo[iBx] <= 0 THEN
rUfo[iBx] = 4
ELSE IF rUfo[iBx] = 4 AND yUfo[iBx] >= 350 THEN
rUfo[iBx] = 3
ELSE IF jx = 5 AND rUfo[iBx] = 4 THEN
rUfo[iBx] = SW_Rnd(1,4)
ELSE IF jx = 10 AND rUfo[iBx] = 3 THEN
rUfo[iBx] = SW_Rnd(1,4)
ELSE IF jx = 15 AND rUfo[iBx] = 2 THEN
rUfo[iBx] = SW_Rnd(1,4)
ELSE IF jx = 20 AND rUfo[iBx] = 1 THEN
rUfo[iBx] = SW_Rnd(1,4)
END IF
NEXT
END SUB
' ********
SUB ShowUfos
' ********
FOR iBx = 0 TO uz
IF rUfo[iBx] = 1 THEN
SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
xUfo[iBx] = xUfo[iBx] + 1
ELSE IF rUfo[iBx] = 2 THEN
SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
xUfo[iBx] = xUfo[iBx] - 1
ELSE IF rUfo[iBx] = 3 THEN
SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
yUfo[iBx] = yUfo[iBx] - 1
ELSE IF rUfo[iBx] = 4 THEN
SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
yUfo[iBx] = yUfo[iBx] + 1
END IF
NEXT
END SUB
' *******
SUB SetData
' *******
xRak = 384
yRak = 536
rRak = 0
za = 0
uz = 40
sc = 0
Ok = 0
zFrame = 0
count = 300
SetUfos
FOR iBx = 0 TO 40
yMeg[iBx] = 0
xMeg[iBx] = 0
NEXT
END SUB
' ********
SUB TestUfos
' ********
FOR iAx = 0 TO 40
IF yUfo[iAx] > 0 OR Ok = 1 THEN EXIT SUB
NEXT
Ok = 1
sc += count
END SUB
' ************
SUB ScanUfoBombs
' ************
FOR iAx = 0 TO drop STEP 2
IF rUfo[iAx] > 0 THEN
IF yMeg[iAx] = 0 THEN
xMeg[iAx] = xUfo[iAx]
yMeg[iAx] = yUfo[iAx] + 32
END IF
END IF
NEXT
END SUB
' ********
SUB UfoBombs
' ********
FOR iDx = 0 TO 40
IF yMeg[iDx] > 0 THEN
IF iDx < 20 THEN
SW_DrawTile bmap, xMeg[iDx], yMeg[iDx], 64, 64, zFrame, 3
ELSE IF iDx >= 20 THEN
SW_DrawTile bmap, xMeg[iDx], yMeg[iDx], 64, 64, zFrame, 3
END IF
yMeg[iDx] = yMeg[iDx] + 1
IF yMeg[iDx] >= 600 THEN yMeg[iDx] = 0
END IF
NEXT
END SUB
' *******
' MAIN *
' *******
SW_Window 800, 600, 1
SW_SetFPS 60
SW_SetFont 28, 48, 0, ""
bmap = SW_LoadTile("bmp/bitmap.bmp", 8, 5)
w1 = "bmp/shoot.wav"
w2 = "bmp/explo.wav"
w3 = "bmp/xship.wav"
SW_ShowMouse 0
SetData
WHILE SW_Key(27) = 0
SW_Cls 0
SW_SetCaption "Frames " & SW_ShowFPS()
IF Ok = 1 THEN
SW_SetText 460, 0, "SCORE " & sc, SW_RGB(255,255,255)
ELSE IF Ok = 0 THEN
SW_SetText 460, 0, "SCORE " & sc, SW_RGB(255,255,255)
END IF
ScanUfos
ShowUfos
ScanRocket
ShowRocket
ScanRakete
ShowRakete
ScanUfoBombs
UfoBombs
ShowExplos
RocketCollision
RaketeCollision
TestUfos
Timer1
Timer2
Timer3
Timer4
IF Ok = 1 THEN
SW_SetText 240, 300, "ONCE AGAIN?", SW_RGB(255,255,255)
SW_SetText 240, 344, "HIT [c] KEY", SW_RGB(255,255,255)
IF SW_Key(67) THEN SetData
END IF
SW_SetText 16, 0, "BONUS " & count, SW_RGB(255,255,255)
SW_Sync
WEND
SW_Quit