| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Basic4GL Sine Sprites

Page history last edited by matthew 9 years, 2 months ago

Basic4GL Sine Sprites

 

  1.  
  2. ' Don't draw sprites on screen until explicitly told to do so
  3. TextMode (TEXT_BUFFERED)
  4.  
  5. ' Load the ball texture
  6. dim ballTex = LoadTex (".\Data\Ball.png")
  7.  
  8. ' Check to see whether texture loaded correctly
  9. if ballTex = 0 then print "Failed to load texture": end: endif
  10.  
  11. ' Declare variables & Constants for drawing routine here
  12. dim i, texture, y, x, spacing, yPosition
  13.  
  14. const maxBalls = 32 ' Maximum number of balls
  15.  
  16. spacing = 16 ' The amount of empty space between each ball
  17. yPosition = (480 / 2) ' The height placement of each ball
  18.  
  19. ' Ball structure
  20. Struc SBall
  21.     dim sprite ' Number of current sprite
  22.     dim x# ' Horizontal position of current sprite
  23. EndStruc
  24.  
  25. dim SBall balls(maxBalls) ' Use our structure
  26.  
  27. ' Routine to initially draw sprites on screen
  28. for x = 0 to maxBalls
  29.  
  30.     ' Create a sprite for each ball
  31.     balls (i).sprite = NewSprite (ballTex)
  32.  
  33.     ' Position each ball on the screen
  34.     balls (i).x# = (x * spacing) + 64
  35.     SprSetPos (balls (i).x#, yPosition)
  36.  
  37.     ' Get ready to setup the next ball
  38.     i = i + 1
  39.  
  40. next
  41.  
  42.  ' Declare variables for main loop here
  43. dim amplitude, frequency, angle
  44.  
  45. amplitude = 90 ' Height of wave, try using values like, 0, 30, 60, 90.
  46. frequency = 15 ' Number of waves, try using values like 15, 30, 45, 60
  47.  
  48. ' Main game loop
  49. while true
  50.  
  51.     ' Routine which places sprites at new positions
  52.     for i = 0 to maxBalls
  53.  
  54.         ' Reposition the sprite
  55.         BindSprite (balls (i).sprite)
  56.         SprSetY (amplitude * Sind(angle + (frequency * i)) + yPosition)
  57.  
  58.     next
  59.  
  60.     ' Draw the sprites on the screen
  61.     DrawText ()
  62.  
  63.     ' Timing synchronisation
  64.     while SyncTimer (5)
  65.  
  66.         ' Increase the angle otherwise the balls won't move
  67.         angle = (angle % 360) + 1
  68.  
  69.     wend
  70.  
  71. wend
  72.  

 

  • Just copy & paste the above code into the Basic4GL editor and press F5 to run it
  • Code Syntax Highlighting by Quick Highlighter

Comments (0)

You don't have permission to comment on this page.