Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define fbc -s gui
  2. #include "Console.bas"
  3.  
  4. #define CharPtr(X, Y) *(pScreen + ((X + (Y * SCREEN_WIDTH)) SHL 1))
  5. #define AttrPtr(X, Y) *(pScreen + (X + (Y * SCREEN_WIDTH)))
  6. Const SCREEN_WIDTH = 80, SCREEN_HEIGHT = 25
  7. Dim as Integer BallX, BallY, MoveX, MoveY
  8. Dim as Integer OldX, OldY
  9.  
  10. Dim as uByte Ptr pScreen
  11. pScreen = pCon.Create(SCREEN_WIDTH,SCREEN_HEIGHT,fb.gfx_fullscreen)
  12.  
  13. MoveX = 1: MoveY = 1
  14. BallX = 9: BallY = 9
  15. Dim as Integer ChangeDirection
  16.  
  17. Cls
  18. Do
  19.     'Move ball
  20.     BallX += MoveX: BallY += MoveY
  21.  
  22.     'If we hit a wall, bounce
  23.     If BallX = 0 or BallX = SCREEN_WIDTH-1 Then MoveX = -MoveX: ChangeDirection = -1
  24.     If BallY = 0 or BallY = SCREEN_HEIGHT-1 Then MoveY = -MoveY: ChangeDirection = -1
  25.  
  26.     'Check for collision with text
  27.     If Not ChangeDirection Then
  28.         If CharPtr(BallX+MoveX, BallY) <> 32 Then MoveX = -MoveX
  29.         If CharPtr(BallX, BallY+MoveY) <> 32 Then MoveY = -MoveY    
  30.     End If
  31.    
  32.     'Render Screen
  33.     pCon.Lock()
  34.     CharPtr(OldX, OldY) = 00    'Remove old ball  
  35.     CharPtr(BallX, BallY) = 07    'Draw new ball
  36.    
  37.     pCon.Unlock()
  38.    
  39.     OldX = BallX: OldY = BallY
  40.     ChangeDirection = 0
  41.    
  42.     Sleep 50,1
  43. Loop until Inkey = Chr(27)'<> ""
  44.  
  45. Screen 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement