Advertisement
OgreVorbis

Aspirin V1.7

Oct 22nd, 2021 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IncludeFile "Macros.pbi"
  2. Global X.w = 0
  3. Global Y.w = 0
  4.  
  5. Global p1X.w = 0
  6. Global p1Y.w = 0
  7. Global p2X.w = 0
  8. Global p2Y.w = 0
  9.  
  10. Global SoundEnabled.a = #True
  11. Global ScreenWidth.w = 1024
  12. Global ScreenHeight.w = 768
  13. Global Dead.a = #False
  14. Global FontSize.w = 14
  15. Global Score.w = 0
  16. Global ShieldEnabled.a = #False
  17. Global ShieldTimer.i = 0
  18. Global GameTicks.i = 1
  19.  
  20. UseMouse.a = #False
  21. PlayerSpeed.a = 4
  22.  
  23. #GameTitle = "Aspirin V1.7"
  24. #DeadBeef = "WASTED"
  25. #PausedGame = "PAUSED"
  26. #PlayAgain = "Play again (Y/N)?_"
  27. #ShieldWarnStr = "SHIELD DEPLETING"
  28. #FontType = "Terminal"
  29. #P1_Size = 8
  30. #P2_Size = 8
  31. #BulletSpeed = 5
  32. #BulletLength = 32
  33. #BerryStartSpeed = 3000
  34. #BerryStopSpeed = 256
  35. #ShieldStartSpeed = 5000
  36. #ShieldStopSpeed = 512
  37. #ShieldUseTime = 1000
  38. #ShieldWarningTime = 256
  39. #BlueEaterSpeed = 3500
  40. #RedEaterSpeed = 2500
  41. #TopBorder = 20
  42. #StarCount = 2048
  43.  
  44. ; **************** SCROLL DOWN FOR PROGRAM ENTRY POINT ******************
  45. ; ************ THIS IS LIKE C LANGUAGE - PROCS COME FIRST ***************
  46.  
  47. Structure Bullet
  48.     X.w
  49.     Y.w
  50.     Horz.a
  51. EndStructure
  52.  
  53. Global Dim TheBullets.Bullet(ScreenWidth)
  54.  
  55. Structure Eater
  56.     X.w
  57.     Y.w
  58.     DestX.w
  59.     DestY.w
  60.     GettingBall.a
  61.     Enabled.a
  62.     Frame.a
  63.     SpriteNo.a
  64.     LeftSide.a
  65. EndStructure
  66.  
  67. Global RedEater.Eater
  68. Global BlueEater.Eater
  69.  
  70. Structure BonusItem
  71.     X.w
  72.     Y.w
  73.     Ticks.i
  74.     SpriteNo.a
  75. EndStructure
  76.  
  77. Global TheShield.BonusItem
  78. Global TheBerry.BonusItem
  79.  
  80. Structure Star
  81.     X.f
  82.     Y.f
  83.     Z.f
  84.     ZV.f
  85. EndStructure
  86.  
  87. Global Dim Stars.Star(#StarCount)
  88.  
  89. Macro Sound(SoundNo)
  90.     If SoundEnabled = #True
  91.         PlaySound(SoundNo)
  92.     EndIf
  93. EndMacro
  94.  
  95. Procedure InitStarfield()
  96.     For i = 0 To #StarCount
  97.         Stars(i)\x  = Random(1000) - 500
  98.         Stars(i)\y  = Random(1000) - 500
  99.         Stars(i)\z  = 100 + Random(900)
  100.         Stars(i)\zv = 0.5 + Random(45) / 10
  101.     Next
  102. EndProcedure
  103.  
  104. Procedure DrawStarfield()
  105.     TheColor.a
  106.     SX.i
  107.     SY.i
  108.     For i = 0 To #StarCount
  109.         Stars(i)\Z = Stars(i)\Z - Stars(i)\ZV
  110.         SX = Stars(i)\X / Stars(i)\Z * 100 + (ScreenWidth / 2)
  111.         SY = Stars(i)\Y / Stars(i)\Z * 100 + (ScreenHeight / 2)
  112.         If SX < 0 Or SY < 0 Or SX >= ScreenWidth Or SY >= ScreenHeight Or Stars(i)\Z < 1
  113.             Stars(i)\X = Random(1000) - 500
  114.             Stars(i)\Y = Random(1000) - 500
  115.             Stars(i)\Z = 100 + Random(900)
  116.             Stars(i)\ZV = 0.5 + (Random(45) / 10)
  117.         Else
  118.             TheColor = 128 - (Stars(i)\Z * 0.128)
  119.             Plot(SX, SY, RGB(TheColor, TheColor, TheColor + 64))
  120.         EndIf
  121.     Next
  122. EndProcedure
  123.  
  124. Procedure.a GotRedBalls()
  125.     If p1X <= X + SpriteWidth(0) + #P1_Size And p1X >= X - #P1_Size
  126.         If p1Y <= Y + SpriteHeight(0) + #P1_Size And p1Y >= Y - #P1_Size
  127.             ProcedureReturn #True
  128.         EndIf
  129.     EndIf
  130.     ProcedureReturn #False
  131. EndProcedure
  132.  
  133. Procedure.a GotBlueBalls()
  134.     If p2X <= X + SpriteWidth(0) + #P2_Size And p2X >= X - #P2_Size
  135.         If p2Y <= Y + SpriteHeight(0) + #P2_Size And p2Y >= Y - #P2_Size
  136.             ProcedureReturn #True
  137.         EndIf
  138.     EndIf
  139.     ProcedureReturn #False
  140. EndProcedure
  141.  
  142. Procedure RandomizeBlueBalls()
  143.     p2X = Random(ScreenWidth - (#P2_Size * 2), #P2_Size * 2)
  144.     p2Y = Random(ScreenHeight - (#P2_Size * 2), (#P2_Size * 2) + #TopBorder)
  145. EndProcedure
  146.  
  147. Procedure RandomizeRedBalls()
  148.     p1X = Random(ScreenWidth - (#P1_Size * 2), #P1_Size * 2)
  149.     p1Y = Random(ScreenHeight - (#P1_Size * 2), (#P1_Size * 2) + #TopBorder)
  150. EndProcedure
  151.  
  152. Procedure StartNextBullet(h.a)
  153.     ; H IS FOR HORIZONTAL. HORIZ BULLETS SET THEIR Y COORD TO A RANDOM CONSTANT POSITION
  154.     If h = #True
  155.         For i = 0 To ArraySize(TheBullets())
  156.             If TheBullets(i)\Y = 0
  157.                 TheBullets(i)\Y = Random(ScreenHeight, #TopBorder)
  158.                 TheBullets(i)\Horz = #True
  159.                 ProcedureReturn
  160.             EndIf
  161.         Next
  162.     Else
  163.         For i = 0 To ArraySize(TheBullets())
  164.             If TheBullets(i)\X = 0
  165.                 TheBullets(i)\X = Random(ScreenWidth, 1)
  166.                 TheBullets(i)\Horz = #False
  167.                 ProcedureReturn
  168.             EndIf
  169.         Next
  170.     EndIf
  171. EndProcedure
  172.  
  173. Procedure UpdateHorzBullets()
  174.     ; WE KNOW IF HORZ WAS SET, THAT A NEW BULLET'S Y POSITION HAS BEEN INITIALIZED
  175.     ; SO IF THE BULLET IS NOT GOING OFF-SCREEN, THEN UPDATE ITS POSITION
  176.     For i = 0 To ArraySize(TheBullets())
  177.         If TheBullets(i)\Horz = #True
  178.             If TheBullets(i)\X >= ScreenWidth - #BulletLength
  179.                 TheBullets(i)\X = 0
  180.             Else
  181.                 TheBullets(i)\X + #BulletSpeed
  182.             EndIf
  183.         EndIf
  184.     Next
  185. EndProcedure
  186.  
  187. Procedure UpdateVertBullets()
  188.     ; HORZ IS FALSE BY DEFAULT, SO WE DON'T KNOW IF A NEW BULLET WAS INITIALIZED, WE NEED TO CHECK
  189.     ; IF THE BULLET X WAS INITED, THEN UPDATE THE BULLET, FIRST CHECKING IF IT'S GOING OFF SCREEN
  190.     For i = 0 To ArraySize(TheBullets())
  191.         If TheBullets(i)\Horz = #False
  192.             If TheBullets(i)\X <> 0
  193.                 If TheBullets(i)\Y >= ScreenHeight - #BulletLength
  194.                     TheBullets(i)\Y = #TopBorder
  195.                 Else
  196.                     TheBullets(i)\Y + #BulletSpeed
  197.                 EndIf
  198.             EndIf
  199.         EndIf
  200.     Next
  201. EndProcedure
  202.  
  203. Procedure CheckEaterHits(*theEater.Eater, i)
  204.     If *theEater\Enabled = #True
  205.         If TheBullets(i)\X <= *theEater\X + 32 And TheBullets(i)\X + #BulletLength >= *theEater\X
  206.             If TheBullets(i)\Y < *theEater\Y + 32 And TheBullets(i)\Y >= *theEater\Y
  207.                 StartDrawing(ScreenOutput())
  208.                     Circle(*theEater\X + 16, *theEater\Y + 16, 32, #Blue)
  209.                 StopDrawing()
  210.                 If SoundStatus(4) = #PB_Sound_Stopped
  211.                     Sound(4)
  212.                 EndIf
  213.                 If TheBullets(i)\Horz = #True
  214.                     TheBullets(i)\X = 0
  215.                 Else
  216.                     TheBullets(i)\Y = #TopBorder
  217.                 EndIf
  218.             EndIf
  219.         EndIf
  220.     EndIf
  221. EndProcedure
  222.  
  223. Procedure DrawPersonalShield()
  224.     StartDrawing(ScreenOutput())
  225.         Circle(X + (SpriteWidth(0) / 2), Y + (SpriteHeight(0) / 2), 32, #Blue)
  226.     StopDrawing()
  227.     If SoundStatus(4) = #PB_Sound_Stopped
  228.         Sound(4)
  229.     EndIf
  230. EndProcedure
  231.  
  232. Procedure CheckHits()
  233.     ; CHECK HORZ HITS
  234.     For i = 0 To ArraySize(TheBullets())
  235.         If TheBullets(i)\Horz = #True
  236.             If TheBullets(i)\X <= X + SpriteWidth(0) And TheBullets(i)\X + #BulletLength >= X
  237.                 If TheBullets(i)\Y < Y + SpriteHeight(0) And TheBullets(i)\Y >= Y
  238.                     If ShieldEnabled = #True
  239.                         DrawPersonalShield()
  240.                     Else
  241.                         Dead = #True
  242.                     EndIf
  243.                 EndIf
  244.             EndIf
  245.             CheckEaterHits(RedEater, i)
  246.             CheckEaterHits(BlueEater, i)
  247.         Else
  248.             If TheBullets(i)\X <> 0
  249.                 If TheBullets(i)\Y <= Y + SpriteHeight(0) And TheBullets(i)\Y + #BulletLength >= Y
  250.                     If TheBullets(i)\X < X + SpriteWidth(0) And TheBullets(i)\X >= X
  251.                         If ShieldEnabled = #True
  252.                             DrawPersonalShield()
  253.                         Else
  254.                             Dead = #True
  255.                         EndIf
  256.                     EndIf
  257.                 EndIf
  258.                 CheckEaterHits(RedEater, i)
  259.                 CheckEaterHits(BlueEater, i)
  260.             EndIf
  261.         EndIf
  262.     Next
  263. EndProcedure
  264.  
  265. Procedure.a CheckBonusHits(objNo.w, objX.w, objY.w)
  266.     If SpriteCollision(0, X, Y, objNo, objX, objY)
  267.         Select objNo
  268.             Case 4 ; THIS IS THE BONUS BERRY
  269.                 Score + 5
  270.                 StartNextBullet(#True)
  271.                 StartNextBullet(#False)
  272.                 Sound(0)
  273.             Case 5 ; THIS IS THE BONUS SHIELD
  274.                 Score + 2
  275.                 ShieldEnabled = #True
  276.                 ShieldTimer = GameTicks
  277.                 Sound(6)
  278.         EndSelect
  279.         ProcedureReturn #True
  280.     EndIf
  281.     ProcedureReturn #False
  282. EndProcedure
  283.  
  284. Procedure UpdateBonus(*theBonus.BonusItem)
  285.     RequiredScore.w = 0
  286.     StartTime.i = 0
  287.     EndTime.i = 0
  288.     Select *theBonus\SpriteNo
  289.         Case 4 ; THIS IS THE BONUS BERRY
  290.             RequiredScore = 10
  291.             StartTime = #BerryStartSpeed
  292.             EndTime = #BerryStopSpeed
  293.         Case 5 ; THIS IS THE BONUS SHIELD
  294.             RequiredScore = 16
  295.             StartTime = #ShieldStartSpeed
  296.             EndTime = #ShieldStopSpeed
  297.     EndSelect
  298.     If Score > RequiredScore And *theBonus\Ticks = 0
  299.         If (GameTicks % StartTime) = 0
  300.             *theBonus\Ticks = GameTicks
  301.             *theBonus\X = Random(ScreenWidth - SpriteWidth(*theBonus\SpriteNo))
  302.             *theBonus\Y = Random(ScreenHeight - SpriteHeight(*theBonus\SpriteNo), #TopBorder)
  303.             Sound(5)
  304.         EndIf
  305.     EndIf
  306.     If *theBonus\Ticks > 0
  307.         If *theBonus\Ticks = (GameTicks - EndTime)
  308.             *theBonus\Ticks = 0
  309.         Else
  310.             If CheckBonusHits(*theBonus\SpriteNo, *theBonus\X, *theBonus\Y)
  311.                 *theBonus\Ticks = 0
  312.             EndIf
  313.             DisplayTransparentSprite(*theBonus\SpriteNo, *theBonus\X, *theBonus\Y)
  314.         EndIf
  315.     EndIf
  316. EndProcedure
  317.  
  318. Procedure StartEater(*theEater.Eater)
  319.     If *theEater\LeftSide = #True
  320.         *theEater\X = -64
  321.     Else
  322.         *theEater\X = ScreenWidth + 64
  323.     EndIf
  324.     *theEater\Y = Random(ScreenHeight, #TopBorder + 32)
  325.     *theEater\Enabled = #True
  326.     *theEater\GettingBall = #True
  327. EndProcedure
  328.  
  329. Procedure EndEater(*theEater.Eater)
  330.     If *theEater\LeftSide = #True
  331.         *theEater\DestX = ScreenWidth + 64
  332.     Else
  333.         *theEater\DestX = -64
  334.     EndIf
  335.     *theEater\DestY = Random(ScreenHeight, #TopBorder + 32)
  336.     *theEater\GettingBall = #False
  337. EndProcedure
  338.  
  339. Procedure UpdateEater(*theEater.Eater)
  340.     If *theEater\Enabled = #True
  341.         If *theEater\GettingBall = #True
  342.             If *theEater\LeftSide = #True
  343.                 *theEater\DestX = p1X - 32
  344.                 *theEater\DestY = p1Y - 16
  345.             Else
  346.                 *theEater\DestX = p2X - 16
  347.                 *theEater\DestY = p2Y - 16
  348.             EndIf
  349.             If *theEater\X = *theEater\DestX And *theEater\Y = *theEater\DestY
  350.                 If *theEater\LeftSide = #True
  351.                     RandomizeRedBalls()
  352.                 Else
  353.                     RandomizeBlueBalls()
  354.                 EndIf
  355.                 If Score > 0
  356.                     Score - 1
  357.                 EndIf
  358.                 Sound(2)
  359.                 EndEater(*theEater)
  360.             EndIf
  361.         Else
  362.             If *theEater\X = *theEater\DestX And *theEater\Y = *theEater\DestY
  363.                 *theEater\Enabled = #False
  364.             EndIf
  365.         EndIf
  366.         If *theEater\X < *theEater\DestX
  367.             *theEater\X + 1
  368.         ElseIf *theEater\X > *theEater\DestX
  369.             *theEater\X - 1
  370.         EndIf
  371.         If *theEater\Y < *theEater\DestY
  372.             *theEater\Y + 1
  373.         ElseIf *theEater\Y > *theEater\DestY
  374.             *theEater\Y - 1
  375.         EndIf
  376.         If *theEater\Frame >= 3
  377.             *theEater\Frame = 0
  378.         EndIf
  379.         ClipSprite(*theEater\SpriteNo, *theEater\Frame * 32, 0, 32, 32)
  380.         DisplayTransparentSprite(*theEater\SpriteNo, *theEater\X, *theEater\Y)
  381.     EndIf
  382. EndProcedure
  383.  
  384. Procedure ResetGame()
  385.     Dim TheBullets.Bullet(ScreenWidth)
  386.     X = (ScreenWidth / 2) - (SpriteWidth(0) / 2)
  387.     Y = (ScreenHeight / 2) - (SpriteHeight(0) / 2)
  388.     RandomizeBlueBalls()
  389.     RandomizeRedBalls()
  390.     Score = 0
  391.     Dead = #False
  392.     RedEater\Enabled = #False
  393.     BlueEater\Enabled = #False
  394.     RedEater\GettingBall = #False
  395.     BlueEater\GettingBall = #False
  396.     TheBerry\Ticks = 0
  397.     TheShield\Ticks = 0
  398. EndProcedure
  399.  
  400. Procedure ShowShieldDepleting()
  401.     StartDrawing(ScreenOutput())
  402.         DrawingFont(FontID(2))
  403.         WarnX.w = (ScreenWidth / 2) - TextWidth(#ShieldWarnStr) / 2
  404.         DrawText(WarnX, ScreenHeight / 3, #ShieldWarnStr, #Red)
  405.     StopDrawing()
  406.     FlipBuffers()
  407.     Sleep(2000)
  408. EndProcedure
  409.  
  410. Procedure ShowDead()
  411.     FinalScore.s = "Your final score was: " + Str(Score) + " | "
  412.     Repeat
  413.         StartDrawing(ScreenOutput())
  414.             DrawStarfield()
  415.             DrawingFont(FontID(2))
  416.             DrawingMode(#PB_2DDrawing_Transparent)
  417.             DeadX.w = (ScreenWidth / 2) - TextWidth(#DeadBeef) / 2
  418.             BeerX.w = DeadX + TextWidth(#DeadBeef)
  419.             DrawText(DeadX, ScreenHeight / 3, #DeadBeef, #Red)
  420.             DrawingFont(FontID(1))
  421.             DrawText((ScreenWidth / 2) - TextWidth(FinalScore + #PlayAgain) / 2, ScreenHeight / 2, FinalScore + #PlayAgain, #White)
  422.         StopDrawing()
  423.         DisplayTransparentSprite(1, DeadX - SpriteWidth(1), ScreenHeight / 3)
  424.         DisplayTransparentSprite(1, BeerX, ScreenHeight / 3)
  425.         FlipBuffers()
  426.         Event = WindowEvent()
  427.         ExamineKeyboard()
  428.         If KeyboardPushed(#PB_Key_Y)
  429.             ResetGame()
  430.             Break
  431.         ElseIf KeyboardPushed(#PB_Key_N) Or Event = #PB_Event_CloseWindow
  432.             End
  433.         EndIf
  434.     ForEver
  435. EndProcedure
  436.  
  437. Procedure ShowPause()
  438.     Sleep(128)
  439.     Repeat
  440.         StartDrawing(ScreenOutput())
  441.             DrawStarfield()
  442.             DrawingFont(FontID(2))
  443.             DrawingMode(#PB_2DDrawing_Transparent)
  444.             PauseX.w = (ScreenWidth / 2) - TextWidth(#PausedGame) / 2
  445.             DrawText(PauseX, ScreenHeight / 3, #PausedGame, #Magenta)
  446.         StopDrawing()
  447.         FlipBuffers()
  448.         Event = WindowEvent()
  449.         ExamineKeyboard()
  450.     Until KeyboardPushed(#PB_Key_P) Or Event = #PB_Event_CloseWindow
  451. EndProcedure
  452.  
  453. Procedure ShowHelp()
  454.     theSizeX.w = ScreenWidth / 4
  455.     theSizeY.w = ScreenHeight / 4
  456.     theStepX.w = FontSize - 4
  457.     theStepY.w = FontSize
  458.     StartDrawing(ScreenOutput())
  459.         Box(theSizeX, theSizeY, theSizeX * 2, theSizeY * 2, #Blue)
  460.         DrawingFont(FontID(1))
  461.         DrawText((theSizeX * 3) + theStepX, (theSizeY * 3) + theStepY, Chr(177), #Gray)
  462.         i = theSizeX
  463.         While i <= theSizeX * 3
  464.             If i <> theSizeX
  465.                 DrawText(i, (theSizeY * 3) + theStepY, Chr(177), #Gray)
  466.             EndIf
  467.             DrawText(i, theSizeY, Chr(205), #Yellow)
  468.             DrawText(i, theSizeY * 3, Chr(205), #Yellow)
  469.             i + theStepX
  470.         Wend
  471.         i = theSizeY
  472.         While i <= theSizeY * 3
  473.             If i <> theSizeY
  474.                 DrawText((theSizeX * 3) + theStepX, i, Chr(177), #Gray)
  475.             EndIf
  476.             DrawText(theSizeX, i, Chr(186), #Yellow)
  477.             DrawText(theSizeX * 3, i, Chr(186), #Yellow)
  478.             i + theStepY
  479.         Wend
  480.         DrawText(theSizeX, theSizeY, Chr(201), #Yellow)
  481.         DrawText(theSizeX * 3, theSizeY, Chr(187), #Yellow)
  482.         DrawText(theSizeX, theSizeY * 3, Chr(200), #Yellow)
  483.         DrawText(theSizeX * 3, theSizeY * 3, Chr(188), #Yellow)
  484.         DrawingMode(#PB_2DDrawing_Transparent)
  485.         theSizeX + FontSize
  486.         DrawText(theSizeX, theSizeY + 20, "< GAME HELP >", #White)
  487.         DrawText(theSizeX, theSizeY + 56, "'S' - turn sound on and off", #White)
  488.         DrawText(theSizeX, theSizeY + 74, "'M' - toggle between mouse control/keyboard", #White)
  489.         DrawText(theSizeX, theSizeY + 92, "'-' - decrease player speed (keyboard)", #White)
  490.         DrawText(theSizeX, theSizeY + 110, "'+' - increase player speed (keyboard)", #White)
  491.         DrawText(theSizeX, theSizeY + 128, "'N' - start a new game", #White)
  492.         DrawText(theSizeX, theSizeY + 146, "'P' - pause game", #White)
  493.         DrawText(theSizeX, theSizeY + 182, "Use XRes [SPACE] YRes as command parameter...", #White)
  494.         If FontSize >= 10
  495.             DrawText(theSizeX, theSizeY + 200, "to change the game window resolution.", #White)
  496.             DrawText(theSizeX, theSizeY + 218, "Ex:  'Aspirin.exe 1920 1080' in .BAT file.", #White)
  497.         EndIf
  498.         DrawText(theSizeX, (theSizeY * 3) - 38, "(C) 2021 DosaidSoft(.com)", $C0C0C0)
  499.         DrawText(theSizeX, (theSizeY * 3) - 20, "Press H again to close window.", $C0C0C0)
  500.     StopDrawing()
  501.     FlipBuffers()
  502.     Sleep(256)
  503.     Repeat
  504.         Event = WindowEvent()
  505.         ExamineKeyboard()
  506.     Until KeyboardPushed(#PB_Key_H) Or Event = #PB_Event_CloseWindow
  507. EndProcedure
  508.  
  509. Procedure DrawIntro()
  510.     StartDrawing(ScreenOutput())
  511.         DrawingFont(FontID(1))
  512.         DrawText(0, 0, "Loading advanced DOS/5GW 64-bit engine framework V1337.7.7", #White)
  513.         DrawText(0, 18, "(C) 2021 DosaidSoft(.com)", #White)
  514.         DrawText(0, 54, "*** PRESS 'H' KEY IN GAME FOR HELP/SETTINGS ***", #White)
  515.     StopDrawing()
  516.     FlipBuffers()
  517.     For i = 0 To 7
  518.         StartDrawing(ScreenOutput())
  519.             DrawingFont(FontID(1))
  520.             DrawText(1, 72, Chr(22), #White)
  521.         StopDrawing()
  522.         FlipBuffers()
  523.         ;WindowEvent()
  524.         Sleep(500)
  525.         StartDrawing(ScreenOutput())
  526.             DrawingFont(FontID(1))
  527.             DrawText(1, 72, " ", #White)
  528.         StopDrawing()
  529.         FlipBuffers()
  530.         Sleep(500)
  531.     Next
  532.     For i = 0 To 16
  533.         FlipBuffers()
  534.         StartDrawing(ScreenOutput())
  535.             DrawingFont(FontID(1))
  536.             ;DrawingMode(#PB_2DDrawing_Transparent)
  537.             For j = 0 To 512
  538.                 DrawText(Random(ScreenWidth), Random(ScreenHeight), Chr(Random(254, 1)), RGB(Random(255),Random(255),Random(255)))
  539.             Next
  540.         StopDrawing()
  541.     Next
  542. EndProcedure
  543.  
  544. ; ======================================================================================
  545. ; PROGRAM ENTRY POINT
  546. ; ======================================================================================
  547. If InitSprite() = 0 Or InitKeyboard() = 0 Or InitSound() = 0 Or InitMouse() = 0
  548.   MessageRequester("Error", "Sub-system can't be initialized", 0)
  549.   End
  550. EndIf
  551.  
  552. ; WE NEED TO CHECK OUR COMMAND LINE PARAMS I.E. ASPIRIN.EXE [X RES] [Y RES]
  553. If CountProgramParameters() <> 0
  554.     ScreenWidth = Val(ProgramParameter())
  555.     ScreenHeight = Val(ProgramParameter())
  556. EndIf
  557.  
  558. ; SET UP OUR WINDOW AT EITHER LOADED OR DEFAULT RES AND LOAD ALL OUR EMBEDDED RESOURCES
  559. OpenWindow(0, 0, 0, ScreenWidth, ScreenHeight, #GameTitle, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  560. OpenWindowedScreen(WindowID(0), 0, 0, ScreenWidth, ScreenHeight)
  561. UsePNGImageDecoder()
  562. UseOGGSoundDecoder()
  563. CatchSprite(0, ?Dude, #PB_Sprite_AlphaBlending)
  564. CatchSprite(1, ?Beer, #PB_Sprite_AlphaBlending)
  565. CatchSprite(2, ?EaterImg, #PB_Sprite_AlphaBlending)
  566. CatchSprite(3, ?RightEaterImg, #PB_Sprite_AlphaBlending)
  567. CatchSprite(4, ?BerryImg, #PB_Sprite_AlphaBlending)
  568. CatchSprite(5, ?ShieldImg, #PB_Sprite_AlphaBlending)
  569. CatchSound(0, ?PointSound, ?EndPtr - ?PointSound)
  570. CatchSound(1, ?DeadSound, ?PointSound - ?DeadSound)
  571. CatchSound(2, ?LoseSound, ?DeadSound - ?LoseSound)
  572. CatchSound(3, ?SafeSound, ?LoseSound - ?SafeSound)
  573. CatchSound(4, ?HitSound, ?SafeSound - ?HitSound)
  574. CatchSound(5, ?BonusSound, ?HitSound - ?BonusSound)
  575. CatchSound(6, ?GetShieldSound, ?BonusSound - ?GetShieldSound)
  576. CatchSound(7, ?LoseShieldSound, ?GetShieldSound - ?LoseShieldSound)
  577. SoundVolume(0, 32)
  578. SoundVolume(1, 32)
  579. SoundVolume(2, 32)
  580. SoundVolume(3, 32)
  581. SoundVolume(4, 32)
  582. SoundVolume(5, 48)
  583. SoundVolume(6, 48)
  584. SoundVolume(7, 48)
  585.  
  586. RandomizeBlueBalls()
  587. RandomizeRedBalls()
  588.  
  589. ; SET UP EATER SPRITES
  590. RedEater\SpriteNo = 2
  591. RedEater\LeftSide = #True
  592. BlueEater\SpriteNo = 3
  593. BlueEater\LeftSide = #False
  594. TheBerry\SpriteNo = 4
  595. TheShield\SpriteNo = 5
  596.  
  597. ; PUT THE DUDE AT THE CENTER SCREEN
  598. X = (ScreenWidth / 2) - (SpriteWidth(0) / 2)
  599. Y = (ScreenHeight / 2) - (SpriteHeight(0) / 2)
  600.  
  601. ; CHECK THE SCREEN RES AND LOWER FONT SIZE (SET TO 14PT BY DEFAULT ABOVE)
  602. If ScreenWidth <= 320
  603.     FontSize = 6
  604. ElseIf ScreenWidth <= 640
  605.     FontSize = 8
  606. ElseIf ScreenWidth <= 800
  607.     FontSize = 10
  608. EndIf
  609. LoadFont(1, #FontType, FontSize)
  610. LoadFont(2, #FontType, 48, #PB_Font_Bold)
  611. LoadFont(3, #FontType, 10)
  612.  
  613. ; DRAW INTRO SCREEN
  614. DrawIntro()
  615.  
  616. InitStarfield()
  617.  
  618. ; MAIN GAME LOOP
  619. Repeat
  620.     Event = WindowEvent()
  621.     ExamineKeyboard()
  622.    
  623.     ; COPY OUR BACK BUFFER TO THE SCREEN AND CLEAR
  624.     FlipBuffers()
  625.     ClearScreen(#Black)
  626.    
  627.     ; DRAW THE CIRCLES TO CAPTURE BY THE DUDE
  628.     ; LOOP AND DRAW ALL BULLETS
  629.     StartDrawing(ScreenOutput())
  630.         DrawStarfield()
  631.         DrawingFont(FontID(1))
  632.         If SoundEnabled = #True
  633.             DrawText(0, 0, #GameTitle + "  " + Chr(13) + Chr(13), #White)
  634.         Else
  635.             DrawText(0, 0, #GameTitle, #White)
  636.         EndIf
  637.         DrawText(ScreenWidth - 168, 0, "Score: " + Str(Score), #White)
  638.         Box(0, #TopBorder - 2, ScreenWidth, 2, #White)
  639.         Circle(p1X + 2, p1Y + 2, #P1_Size, $404080)
  640.         Circle(p2X + 2, p2Y + 2, #P1_Size, $808040)
  641.         Circle(p1X, p1Y, #P1_Size, #Red)
  642.         Circle(p2X, p2Y, #P2_Size, #Cyan)
  643.         DrawingFont(FontID(3))
  644.         For i = 0 To ArraySize(TheBullets())
  645.             If TheBullets(i)\Horz = #True
  646.                 DrawText(TheBullets(i)\X - 10, TheBullets(i)\Y - 5, Chr(15), #Yellow)
  647.                 DrawText(TheBullets(i)\X + #BulletLength, TheBullets(i)\Y - 5, Chr(62), #Cyan)
  648.                 Line(TheBullets(i)\X, TheBullets(i)\Y, #BulletLength, 1, #Cyan)
  649.             Else
  650.                 If TheBullets(i)\X <> 0
  651.                     DrawText(TheBullets(i)\X - 4, TheBullets(i)\Y - 10, Chr(15), #Yellow)
  652.                     DrawText(TheBullets(i)\X - 3, TheBullets(i)\Y + #BulletLength, "V", #Red)
  653.                     Line(TheBullets(i)\X, TheBullets(i)\Y, 1, #BulletLength, #Red)
  654.                 EndIf
  655.             EndIf
  656.         Next
  657.     StopDrawing()
  658.    
  659.     ; CHECK IF THE PLAYER COLLIDED WITH THE BALLS AND SPAWN A NEW BULLET
  660.     ; BLUE BALL IS HORIZONTAL, ETC.
  661.     If GotBlueBalls() = #True
  662.         ; IF WE GOT THE BALL FIRST AND THE EATER IS TRYING TO GET IT, DISABLE HIM
  663.         If BlueEater\GettingBall = #True
  664.             EndEater(BlueEater)
  665.             Sound(3)
  666.         Else
  667.             Sound(0)
  668.         EndIf
  669.         Score + 1
  670.         RandomizeBlueBalls()
  671.         StartNextBullet(#True)
  672.     EndIf
  673.     If GotRedBalls() = #True
  674.         If RedEater\GettingBall = #True
  675.             EndEater(RedEater)
  676.             Sound(3)
  677.         Else
  678.             Sound(0)
  679.         EndIf
  680.         Score + 1
  681.         RandomizeRedBalls()
  682.         StartNextBullet(#False)
  683.     EndIf
  684.    
  685.     ; SHOW THE BONUS BERRY AT SPECIFIED INTERVALS
  686.     UpdateBonus(TheBerry)
  687.    
  688.     ; SHOW THE BONUS SHIELD AT SPECIFIED INTERVALS
  689.     UpdateBonus(TheShield)
  690.     If ShieldEnabled = #True
  691.         If GameTicks = ShieldTimer + #ShieldUseTime
  692.             ShieldEnabled = #False
  693.             Sound(7)
  694.         EndIf
  695.         ; WARN THE PLAYER IF THE SHIELD HAS ALMOST DEPELETED
  696.         If GameTicks = ShieldTimer + (#ShieldUseTime - #ShieldWarningTime)
  697.             ShowShieldDepleting()
  698.         EndIf
  699.     EndIf
  700.        
  701.     ; CHECK IF THE GUY OR THE EATER HAS BEEN HIT BY THE BULLETS
  702.     CheckHits()
  703.     If KeyboardPushed(#PB_Key_0)
  704.         Dead = #False
  705.     EndIf
  706.     If Dead = #True
  707.         Sound(1)
  708.         ShowDead()
  709.         GameTicks = 1
  710.     EndIf
  711.     UpdateHorzBullets()
  712.     UpdateVertBullets()
  713.    
  714.     ; DISPLAY OUR CHARACTER
  715.     DisplayTransparentSprite(0, X, Y)
  716.    
  717.     ; CHECK OUR GAME TICKS TO DETERMINE IF THE EATERS SHOULD APPEAR
  718.     ; GAME TICKS NEVER GET RESET, SO WE DO REMAINDER DIVISION (EATER WILL APPEAR ONLY IF THE TICKS ARE DIVISABLE)
  719.     If (GameTicks % #RedEaterSpeed) = 0
  720.         StartEater(RedEater)
  721.     EndIf
  722.     If (GameTicks % #BlueEaterSpeed) = 0
  723.         StartEater(BlueEater)
  724.     EndIf
  725.     If (GameTicks % 15) = 0
  726.         If RedEater\Enabled = #True
  727.             RedEater\Frame + 1
  728.         EndIf
  729.         If BlueEater\Enabled = #True
  730.             BlueEater\Frame + 1
  731.         EndIf
  732.     EndIf
  733.     UpdateEater(RedEater)
  734.     UpdateEater(BlueEater)
  735.    
  736.     ; MOVE OUR MAIN DUDE WITH ARROW KEYS OR MOUSE
  737.     If UseMouse = #False
  738.         If KeyboardPushed(#PB_Key_Right)
  739.             X + PlayerSpeed
  740.         ElseIf KeyboardPushed(#PB_Key_Left)
  741.             X - PlayerSpeed
  742.         EndIf
  743.         If KeyboardPushed(#PB_Key_Up)
  744.             Y - PlayerSpeed
  745.         ElseIf KeyboardPushed(#PB_Key_Down)
  746.             Y + PlayerSpeed
  747.         EndIf
  748.     Else
  749.         ExamineMouse()
  750.         X = MouseX()
  751.         Y = MouseY()
  752.     EndIf
  753.     If X > ScreenWidth - SpriteWidth(0)
  754.         X = ScreenWidth - SpriteWidth(0)
  755.     ElseIf X < 0
  756.         X = 0
  757.     EndIf
  758.     If Y > ScreenHeight - SpriteHeight(0)
  759.         Y = ScreenHeight - SpriteHeight(0)
  760.     ElseIf Y < #TopBorder
  761.         Y = #TopBorder
  762.     EndIf
  763.    
  764.     ; CHECK ALL OUR OPTION KEYS
  765.     If KeyboardPushed(#PB_Key_H)
  766.         ShowHelp()
  767.         Sleep(256)
  768.     EndIf
  769.     If KeyboardPushed(#PB_Key_Minus)
  770.         If PlayerSpeed > 0
  771.             PlayerSpeed - 1
  772.             Sleep(128)
  773.         EndIf
  774.     ElseIf KeyboardPushed(#PB_Key_Equals)
  775.         If PlayerSpeed < 32
  776.             PlayerSpeed + 1
  777.             Sleep(128)
  778.         EndIf
  779.     EndIf
  780.     If KeyboardPushed(#PB_Key_M)
  781.         If UseMouse = #False
  782.             UseMouse = #True
  783.             ExamineMouse()
  784.             ReleaseMouse(#False)
  785.             MouseLocate(X, Y)
  786.             Sleep(256)
  787.         Else
  788.             UseMouse = #False
  789.             ReleaseMouse(#True)
  790.             Sleep(256)
  791.         EndIf
  792.     EndIf
  793.     If KeyboardPushed(#PB_Key_N)
  794.         ResetGame()
  795.         GameTicks = 1
  796.         Sleep(256)
  797.     EndIf
  798.     If KeyboardPushed(#PB_Key_S)
  799.         ; WAY TO INVERT A VARIABLE TRUE/FALSE
  800.         SoundEnabled = ~ SoundEnabled
  801.         Sleep(256)
  802.     EndIf
  803.     If KeyboardPushed(#PB_Key_P)
  804.         ShowPause()
  805.         Sleep(256)
  806.     EndIf
  807.    
  808.     GameTicks + 1
  809.    
  810. Until Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
  811.  
  812. End
  813.  
  814. DataSection
  815.     Dude:
  816.     IncludeBinary "dude.png"
  817.     Beer:
  818.     IncludeBinary "beer.png"
  819.     EaterImg:
  820.     IncludeBinary "eater.png"
  821.     RightEaterImg:
  822.     IncludeBinary "righteater.png"
  823.     BerryImg:
  824.     IncludeBinary "bonus.png"
  825.     ShieldImg:
  826.     IncludeBinary "shield.png"
  827.     LoseShieldSound:
  828.     IncludeBinary "loseshield.ogg"
  829.     GetShieldSound:
  830.     IncludeBinary "getshield.ogg"
  831.     BonusSound:
  832.     IncludeBinary "bonus.ogg"
  833.     HitSound:
  834.     IncludeBinary "ping.ogg"
  835.     SafeSound:
  836.     IncludeBinary "safe.ogg"
  837.     LoseSound:
  838.     IncludeBinary "lose.ogg"
  839.     DeadSound:
  840.     IncludeBinary "dead.ogg"
  841.     PointSound:
  842.     IncludeBinary "point.ogg"
  843.     EndPtr:
  844. EndDataSection
  845. ; IDE Options = PureBasic 5.73 LTS (Windows - x64)
  846. ; Folding = -----
  847. ; EnableXP
  848. ; UseIcon = pills2.ico
  849. ; Executable = B:\Aspirin17.exe
  850. ; IncludeVersionInfo
  851. ; VersionField0 = 1,7,0,0
  852. ; VersionField1 = 1,7,0,0
  853. ; VersionField2 = DosaidSoft
  854. ; VersionField3 = Aspirin
  855. ; VersionField4 = 1.7
  856. ; VersionField5 = 1.7
  857. ; VersionField6 = Aspirin Video Game from TI-83 Plus
  858. ; VersionField7 = ASPIRIN
  859. ; VersionField8 = ASPIRIN
  860. ; VersionField9 = (C) 2021 DosaidSoft
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement