home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / axscript / spruuids / game3.txt < prev    next >
Encoding:
Text File  |  1996-07-15  |  5.0 KB  |  195 lines

  1. $OBJECT=ShipClass
  2. $OBJECT=BubbleClass
  3. $OBJECT=AmmoClass
  4.  
  5. Option Explicit
  6.  
  7. '----------------------------------------------------------------------------
  8. ' Game3.txt
  9. '----------------------------------------------------------------------------
  10. ' Use path to this file as parameter to Sprite.exe.  E.g.:
  11. '    Sprite C:\Tmp\Game3.txt
  12. ' See "Game.Pix" for list of images available, numbered 0-n.
  13. '----------------------------------------------------------------------------
  14.  
  15. Dim sShip               'Player's ship
  16.  
  17.  
  18. '----------------------------------------------------------------------------
  19. ' GAME events
  20. '
  21. Sub Game_NewGame()
  22. '   ------------
  23.     'Sprites Bounce on inner border:
  24.     ShipClass.Border   = 15
  25.     BubbleClass.Border = 15
  26.     AmmoClass.Border   = 15
  27.  
  28.     'Setup Collision possibilities.  Bit 1 is reserved for hitting same-kind objects.
  29.     ShipClass.Collide   = 2
  30.     BubbleClass.Collide = 2 + 4
  31.     AmmoClass.Collide   =     4
  32.  
  33.     'Setup Standard images for the different classes of sprites
  34.     ShipClass.Image   = 32        'Ship
  35.     BubbleClass.Image = 60        'Small bubble
  36.     AmmoClass.Image   = 35        'Ammo
  37.  
  38.     'Extra Ship Info
  39.     Game.ScoreFirst1Up = 250
  40.     Game.DScoreNext1Up = 500
  41.  
  42.     ShipClass.Friction = 0.981
  43.     Set sShip = ShipClass.CreateSprite(Game.Width / 2, Game.Height / 2, 0)
  44.     BubbleClass.CreateSprite 0, 0, 0
  45. End Sub
  46.  
  47.  
  48. Sub Game_KeyDown(ByVal ch)
  49. '   ------------
  50.     Dim sT
  51.  
  52.     'Too many shots on screen already?
  53.     If AmmoClass.SpriteCount > 5 Then Exit Sub
  54.  
  55.     'Game Over?
  56.     If Game.ShipCount <= 0 Then Exit Sub
  57.  
  58.     'Up
  59.     If ch = 38 Then
  60.         sShip.Image = 24
  61.         Set sT = AmmoClass.CreateSprite(sShip.Left + sShip.Width / 2, sShip.Top, 0)
  62.         sT.Vx = 0 : sT.Vy = -5
  63.         sShip.Vy = sShip.Vy + 1
  64.     End If
  65.  
  66.     'Down
  67.     If ch = 40 Then
  68.         sShip.Image = 8
  69.         Set sT = AmmoClass.CreateSprite(sShip.Left + sShip.Width / 2, sShip.Top + sShip.Height, 0)
  70.         sT.Vx = 0 : sT.Vy = 5
  71.         sShip.Vy = sShip.Vy - 1
  72.     End If
  73.  
  74.     'Left
  75.     If ch = 37 Then
  76.         sShip.Image = 16
  77.         Set sT = AmmoClass.CreateSprite(sShip.Left, sShip.Top + sShip.Height / 2, 0)
  78.         sT.Vx = -5 : sT.Vy = 0
  79.         sShip.Vx = sShip.Vx + 1
  80.     End If
  81.  
  82.     'Right
  83.     If ch = 39 Then
  84.         sShip.Image = 0
  85.         Set sT = AmmoClass.CreateSprite(sShip.Left + sShip.Width, sShip.Top + sShip.Height / 2, 0)
  86.         sT.Vx = 5 : sT.Vy = 0
  87.         sShip.Vx = sShip.Vx - 1
  88.     End If
  89. End Sub
  90.  
  91.  
  92. Sub DoShipHit()      'Decrease # ships, end game if none left
  93. '   ---------
  94.     sShip.Image = 32
  95.     Game.ShipCount = Game.ShipCount - 1
  96.     If Game.ShipCount <= 0 Then
  97.         Game.EndGame
  98.     Else
  99.         sShip.Vx = 0
  100.         sShip.Vy = 0
  101.         sShip.MoveTo Game.Width / 2, Game.Height / 2
  102.     End If
  103. End Sub
  104.  
  105.  
  106. Sub DoNewBubble(ByVal left, ByVal top, ByVal vx, ByVal vy)
  107. '   -----------
  108.     Dim sT
  109.  
  110.     Set sT = BubbleClass.CreateSprite(left, top, 1)
  111.     sT.Vx  = vx * 0.5 + 4 * Rnd() - 2
  112.     sT.Vy  = vy * 0.5 + 4 * Rnd() - 2
  113. End Sub
  114.  
  115.  
  116. Sub Game_Collide(ByVal sLowId, ByVal sHighId, ByVal coll)
  117. '   ------------
  118.     Dim ship
  119.     Dim bubble
  120.     Dim ammo
  121.     Dim sT
  122.  
  123.     Select Case coll
  124.         Case 2
  125.             Set ship   = sLowId
  126.             Set bubble = sHighId
  127.             If ship.Image <> 32 Then
  128.                 'Ship Hit Bubble
  129.                 Call DoShipHit
  130.             End If
  131.  
  132.     Case 4
  133.             Set bubble = sLowId
  134.             Set ammo   = sHighId
  135.             ammo.Remove
  136.             If bubble.Image <= 57 Then
  137.                 Game.AddScore 50
  138.                 bubble.Remove
  139.                 DoNewBubble bubble.Left, bubble.Top, bubble.Vx - ammo.Vx, bubble.Vy - ammo.Vy
  140.                 DoNewBubble bubble.Left, bubble.Top, bubble.Vx + ammo.Vx, bubble.Vy + ammo.Vy
  141.             Else
  142.                 bubble.Image = bubble.Image - 1
  143.                 Game.AddScore 5
  144.             End If
  145.     End Select
  146. End Sub
  147.  
  148.  
  149. '----------------------------------------------------------------------------
  150. ' ShipClass events
  151. '
  152. Sub ShipClass_Init(ByVal s, ByVal u)
  153.     s.TickEvent = 5
  154. End Sub
  155.  
  156. Sub ShipClass_Border(ByVal s, ByVal brd)
  157.     'Randomize velocity, then bounce ship
  158.     s.Vx = s.Vx + 6 * Rnd() - 3
  159.     s.Vy = s.Vy + 6 * Rnd() - 3
  160.     Game.StdBorderBounce s, brd
  161. End Sub
  162.  
  163.  
  164. '----------------------------------------------------------------------------
  165. ' BubbleClass events
  166. '
  167. Sub BubbleClass_Init(ByVal s, ByVal u)
  168.     If s.Left = 0 Then
  169.         'New Bubble, so start it at an edge, and give it a random direction
  170.         Game.StdInitEdge s, u
  171.         s.Vx = 12 * Rnd() - 6
  172.         s.Vy = 12 * Rnd() - 6
  173.     End If
  174. End Sub
  175.  
  176. Sub BubbleClass_Border(ByVal s, ByVal brd)
  177.     Game.StdBorderBounce s, brd
  178. End Sub
  179.  
  180. 'If no more enemies, create some
  181. Sub BubbleClass_LastTerm()
  182. '   --------------------
  183.     BubbleClass.CreateSprite 0, 0, 0
  184. End Sub
  185.  
  186.  
  187. '----------------------------------------------------------------------------
  188. ' AmmoClass events
  189. '
  190. Sub AmmoClass_Border(ByVal s, ByVal brd)
  191.     s.Remove
  192. End Sub
  193.  
  194. '--- EOF ---
  195.