|
Declare Sub StartGame(level As Integer) Declare Sub UpdatePlayer() Declare Sub Display() Declare Sub SpawnChaser(num As Integer) Declare Sub UpdateChaser() Declare Sub SpawnResource(num As Integer) Declare Sub BlastEmToHell() Declare Sub LoseGame() Declare Sub WaitForKeyRelease() Declare Function Collision (x1 As Integer,y1 As Integer,r1 As Integer,x2 As Integer,y2 As Integer,r2 As Integer) As Byte Declare Function Distance (x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer) As Integer Declare Function Angle(x1 As Integer,y1 As Integer,x2 As Integer,y2 As Integer) As Integer
Type ChaserType x As Integer y As Integer lastUpdate As Double lastDamage As Double End Type
Type ResourceType x As Integer y As Integer End Type
Type GameType health As Integer button As Byte lastButton As Double lastX As Integer lastY As Integer currentPage As Byte level As Uinteger chaserSpeed As Integer chaserAmount As Integer resourceAmount As Integer resourceNeeded As Integer resourceHave As Integer resourceRate As Integer lastResource As Double difficulty As Integer End Type
Const False = 0 Const True = Not(False) Const Used = 4 Const r2d = .01745329252
Dim Shared As GameType game Dim Shared As ResourceType resource(9) Dim Shared As ChaserType chaser(499)
Dim As Integer tempfps, _ fps, _ tempX, _ tempY, _ tempButtons, _ tempAngle, _ tempDistance Dim As Double fpsTimer Dim As String tempDifficulty
SCREENRES 640,480,32,2 Randomize Timer Input "Difficulty? (1=easy, higher = harder)"; tempDifficulty game.difficulty = Int(Val(tempDifficulty) * 10) WaitForKeyRelease() game.resourceRate = 100 / game.difficulty StartGame(1) SCREENSET currentPage, -(currentPage-1) SETMOUSE ,,0 'hide the cursor fpsTimer = Timer
Do UpdatePlayer() UpdateChaser() Cls Display() 'LOCATE 3,1: PRINT "FPS: "+str$(fps) currentPage = -(currentPage-1) SCREENSET currentPage, -(currentPage-1) 'tempfps += 1 'IF TIMER - fpsTimer >= 1 THEN ' fps = tempfps ' tempfps=0 ' fpsTimer = TIMER 'END IF Loop Until MULTIKEY(1) End
Sub StartGame(level As Integer) Dim As String CKEY Dim As Integer tempButtons, tempX, tempY SCREENSET 0,0 Cls If level <> 1 Then Print "Level"; level - 1; " Finished!" Print "Press Any Key To Continue to Level (or any mouse button ;) )"; level Else Print "Press Any Key To Start Game! (or any mouse button ;) )" game.resourceHave = Int(500/game.difficulty) End If Do 'wait for keypress For tempCount = 0 To 127 If MULTIKEY(tempCount) = -1 Then Exit Do Next GETMOUSE tempX,tempY,,tempButtons If tempButtons > 0 Then Exit Do CKEY = Inkey$ Loop Until CKEY = Chr$(255) + "X" WaitForKeyRelease() game.level = level game.chaserAmount = game.level * game.difficulty If game.chaserAmount > 500 Then game.chaserAmount = 500 game.chaserspeed = 5 * game.difficulty + game.level * 10 game.resourceAmount = 10 - game.level \ 5 If game.resourceAmount < 1 Then game.resourceAmount = 1 game.resourceNeeded += (5 * game.difficulty + game.level * 2.5 * game.difficulty) SpawnChaser(game.chaserAmount) SpawnResource(game.resourceAmount) End Sub
Sub UpdatePlayer() Dim As Integer tempCount, tempX, tempY, tempButtons GETMOUSE tempX, tempY, ,tempButtons game.button = False If (tempButtons And 1) And Not(tempX = -1) Then game.button = True Else game.button = False End If For tempCount = 0 To game.resourceAmount - 1 If Collision(tempX, tempY, 10, resource(tempCount).x, resource(tempCount).y, 5) = True Then If (Timer - game.lastResource) >= 1 Then game.resourceHave += game.resourceRate game.lastResource = Timer Elseif (Timer - game.lastResource) * game.resourceRate >= .5 Then game.resourceHave += (Timer - game.lastResource) * game.resourceRate game.lastResource = Timer End If End If Next If game.resourceHave >= game.resourceNeeded Then StartGame(game.level + 1) If game.button = True Then 'if left mouse If (Timer - game.lastButton) >= game.difficulty\2-1 Then BlastEmToHell() 'launch weapon End If End If For tempCount = 0 To game.chaserAmount - 1 If Collision(tempX, tempY, 10, chaser(tempCount).x, chaser(tempCount).y, 6) = True Then Circle(0,0),144,rgb(255,0,255) If (Timer - chaser(tempCount).lastDamage) > 1 Then game.resourceHave -= game.resourceRate * 2 chaser(tempCount).lastDamage = Timer Elseif (Timer - chaser(tempCount).lastDamage) * game.resourceRate * 2 > .5 Then game.resourceHave -= game.resourceRate * 2 * (Timer - chaser(tempCount).lastDamage) chaser(tempCount).lastDamage = Timer End If End If Next If game.resourceHave <= 0 Then LoseGame() End Sub
Sub Display() Dim As Integer tempCount, tempX, tempY, tempButtons, tempColor For tempCount = 0 To game.resourceAmount - 1 Circle(resource(tempCount).x,resource(tempCount).y), 5, RGB(0,0,192) Next For tempCount = 0 To game.chaserAmount - 1 If chaser(tempCount).lastUpdate < Timer Then Circle(chaser(tempCount).x,chaser(tempCount).y), 6, RGB(255,32,1) Else If (Int(Timer*10)) And 1 _ Then Circle(chaser(tempCount).x,chaser(tempCount).y), 6, RGB(128,16,1) End If Next If (Timer - game.lastButton) < (2.2 / game.difficulty) Then For tempX = 120 To (((Timer - game.lastButton) / (22 / game.difficulty))*1200) Step -10 tempColor = ((Timer - game.lastButton) / (22 / game.difficulty)) * 255 tempColor = RGB(255,240-tempX*2, 0)'RGB(tempX*2,240-tempX*2, 0) Circle(game.lastX, game.lastY), tempX, tempColor Next End If GETMOUSE TempX, TempY, , TempButtons Circle(tempX, tempY), 10, RGB(0,255,0) Locate 1,52:Print "Peta-blast" tempColor = (Timer - game.lastButton)/(game.difficulty\2-1) * 255 If tempColor >= 255 Then tempColor = RGB(255,255,0) Color RGB(255,0,0) If Int(Timer) And 1 Then Locate 2,54: Print "READY!" Color RGB(224,224,224) Else tempColor = RGB(255,tempColor,0) Locate 2,52: Color RGB(0,0,255) If (((Int(Timer*5)Shl 29)Shr 29)+4)\2 = 0 Then Print "CHARGING." Elseif (((Int(Timer*5)Shl 29)Shr 29)+4)\2 = 1 Then Print "CHARGING.. " Elseif (((Int(Timer*5)Shl 29)Shr 29)+4)\2 = 2 Then Print "CHARGING..." Else Print "CHARGING " End If Color RGB(224,224,224) End If Line(500, 0)-(500+140*(Timer - game.lastButton)/(game.difficulty\2-1),7),tempColor,BF Locate 1,1 If (game.resourceHave/game.resourceNeeded)< .1 Then tempColor = RGB(255,0,0) Color tempColor If Int(Timer * 2) And 1 Then Print "MegaChow:";game.resourceHave; " out of:";game.resourceNeeded Else Print "MegaChow:";game.resourceHave; " out of:";game.resourceNeeded End If End Sub
Sub BlastEmToHell() Dim As Integer tempCount, tempX, tempY, tempButtons, tempAngle If game.resourceHave <= game.resourceRate * 5 Then Exit Sub game.resourceHave -= game.resourceRate * 5 'it costs a ton for this GETMOUSE tempX, tempY,,tempButtons game.lastX = tempX game.lastY = tempY For tempCount = 0 To game.chaserAmount - 1 If Collision(chaser(tempCount).x, chaser(tempCount).y, 6, tempX, tempY, 120 ) Then tempAngle = Angle(tempX,tempY,chaser(tempCount).x, chaser(tempCount).y) chaser(tempCount).x = Cos(tempAngle * r2d) * 110 + chaser(tempCount).x If chaser(tempCount).x < 0 Then chaser(tempCount).x += 640 Elseif chaser(tempCount).x > 639 Then chaser(tempCount).x -= 640 End If chaser(tempCount).y = Sin(tempAngle * r2d) * 110 + chaser(tempCount).y If chaser(tempCount).y < 0 Then chaser(tempCount).y += 480 Elseif chaser(tempCount).x > 479 Then chaser(tempCount).x -= 480 End If chaser(tempCount).lastUpdate = 23/game.difficulty If chaser(tempCount).lastUpdate < .5 Then chaser(tempCount).lastUpdate = .5 chaser(tempCount).lastUpdate += Timer End If Next game.lastButton = Timer End Sub
Sub SpawnChaser(num As Integer) Dim As Integer tempCount, tempX, tempY, tempButtons For tempCount = 0 To num - 1 SETCOORD: chaser(tempCount).x = Int(Rnd * 640) chaser(tempCount).y = Int(Rnd * 480) chaser(tempCount).lastUpdate = Timer GETMOUSE tempX, tempY,,tempButtons If Distance(tempX, tempY, chaser(tempCount).x, chaser(tempCount).y) < 80 Then Goto SETCOORD Next End Sub
Sub UpdateChaser() Dim As Integer tempAngle, tempCount,tempNum Dim As Integer tempX, tempY, tempButtons Dim As Integer tempLowestIndex, tempLowestValue GETMOUSE tempX, tempY,,tempButtons tempLowestValue = 2000 tempLowestIndex = -1 For tempCount = 0 To game.resourceAmount - 1 tempDistance = Distance(tempX, tempY, resource(tempCount).x, resource(tempCount).y) If tempDistance < tempLowestValue Then tempLowestIndex = tempCount tempLowestValue = tempDistance End If Next For tempCount = 0 To game.chaserAmount - 1 If ((Timer - chaser(tempCount).lastUpdate) * game.chaserSpeed) >= 1 Then GETMOUSE tempX, tempY,,tempButtons tempDistance = Distance(chaser(tempCount).x,chaser(tempCount).y, tempX, tempY) tempNum = 10 + tempDistance\25 If tempDistance < 150 Or Int(Rnd * tempNum)=0 Then tempDistance = Distance(resource(tempLowestIndex).x, resource(tempLowestIndex).y, chaser(tempCount).x, chaser(tempCount).y) If tempDistance > tempLowestValue Then tempX = resource(tempLowestIndex).x tempY = resource(tempLowestIndex).y End If tempAngle = Angle(chaser(tempCount).x,chaser(tempCount).y,tempX,tempY) Else tempAngle = Int(Rnd * 360) End If chaser(tempCount).lastUpdate = (Timer - chaser(tempCount).lastUpdate) If chaser(tempCount).lastUpdate > 1 Then chaser(tempCount).lastUpdate = 1 chaser(tempCount).x += Cos(tempAngle * r2d) * (game.chaserSpeed * chaser(tempCount).lastUpdate) * (Int(Rnd * 50)+75)/100 chaser(tempCount).y += Sin(tempAngle * r2d) * (game.chaserSpeed * chaser(tempCount).lastUpdate) * (Int(Rnd * 50)+75)/100 If chaser(tempCount).x < 0 Then chaser(tempCount).x = 0 If chaser(tempCount).y < 0 Then chaser(tempCount).y = 0 If chaser(tempCount).x > 639 Then chaser(tempCount).x = 639 If chaser(tempCount).y > 479 Then chaser(tempCount).y = 479 chaser(tempCount).lastUpdate = Timer End If Next End Sub
Sub SpawnResource(num As Integer) For tempCount = 0 To num - 1 resource(tempCount).x = Int(Rnd * 640) resource(tempCount).y = Int(Rnd * 480) Next End Sub
Sub LoseGame() SCREENSET 0,0 Cls Dim As Integer tempCount, tempKey Print "YOU HAVE FAILED TO SURVIVE. YOUR CARCASS IS NOW DINNER FOR THE KILOTWERPS." Do For tempCount = 0 To 127 If MULTIKEY(tempCount) Then Exit Do End If Next Loop End END Sub
Sub WaitForKeyRelease() Dim As Integer tempCount, tempKey Dim As Integer tempButtons, tempX, tempY Do tempKey = 0 For tempCount = 0 To 127 If MULTIKEY(tempCount) Then tempKey +=1 Exit For End If Next GETMOUSE tempX,tempY,,tempButtons If tempButtons > 0 Then tempKey += 1 If tempKey = 0 Then Exit Sub Loop End Sub
Function Collision (x1 As Integer,y1 As Integer,r1 As Integer,x2 As Integer,y2 As Integer,r2 As Integer) As Byte Dim As Integer tempDistance tempDistance = Distance(x1,y1,x2,y2) If tempDistance <= (r1+r2) Then Return True Return False End Function
Function Distance (x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer) As Integer Return Int(Sqr( ( x1 - x2 ) ^ 2 + ( y1 - y2 ) ^ 2 )) End Function 'x1 and y1 are your starting coords, x2 and y2 your dest coords Function Angle(x1 As Integer,y1 As Integer,x2 As Integer,y2 As Integer) As Integer Dim As Integer tempAngle, tempY, tempX tempX = x1 - x2 tempY = y1 - y2 tempAngle = ( Atn ( tempY / tempX ) ) / r2d If tempX < 0 Xor tempY < 0 Then tempAngle = tempAngle + 180 If tempY >= 0 Then tempAngle = tempAngle + 180 Return tempAngle End Function |