home *** CD-ROM | disk | FTP | other *** search
/ Game Programming for Teens / GameProgrammingForTeens.iso / Source / chapter06 / demo06-03.bb < prev    next >
Encoding:
Text File  |  2003-04-06  |  844 b   |  51 lines

  1. ;demo06-03.bb - The working animated ship.
  2. ;Initialize the Graphics
  3. Graphics 800,600
  4.  
  5.  ;load the ship image
  6. shipimage = LoadImage("ship.bmp")
  7.  
  8. ;Seed the random generator
  9. SeedRnd(MilliSecs())
  10.  
  11.  
  12. ;create a ship type
  13. Type ship 
  14.     Field x,y   ;the x and y coords
  15. End Type
  16.  
  17.  
  18.  
  19. ;create the ship
  20. ship.ship = New ship 
  21.  
  22. ;position the ship randomly
  23. ship\x = Rand(0,800) 
  24. ship\y = Rand(0,600)
  25.  
  26. While Not KeyDown(1) 
  27.     ;Clear the screen
  28.     Cls
  29.     
  30.     ;move ship left and right
  31.     ship\x = ship\x + Rand(-8,8) 
  32.  
  33.     ;Move ship up And down
  34.     ship\y = ship\y + Rand(-8,8) 
  35.     
  36.     ;If ship goes off screen, move it back on
  37.     If ship\x < 0
  38.         ship\x = 15
  39.     ElseIf ship\x > 800
  40.         ship\x = 790
  41.     ElseIf ship\y < 0
  42.         ship\y = 10
  43.     ElseIf ship\y >600
  44.         ship\y = 590
  45.     EndIf
  46.     
  47.     ;Draw the ship
  48.     DrawImage(shipimage,ship\x,ship\y)
  49.     Flip
  50.     
  51. Wend