Advertisement
Mysoft

Untitled

Nov 3rd, 2016
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define fbc -s console
  2.  
  3. #include "MyTDT\ConsoleEmu.bas"
  4.  
  5. #define CharPtr(X, Y) *(pScreen + (((X) + ((Y) * SCREEN_WIDTH)) shl 1))
  6. #define AttrPtr(X, Y) *(pScreen + (((X) + ((Y) * SCREEN_WIDTH)) shl 1)+1)
  7. Const SCREEN_WIDTH = 80, SCREEN_HEIGHT = 25
  8. Dim as Integer BallX, BallY, MoveX, MoveY
  9. Dim as Integer OldX, OldY
  10.  
  11. Dim as uByte Ptr pScreen
  12. pScreen = pCon.Create(SCREEN_WIDTH,SCREEN_HEIGHT,fb.gfx_fullscreen)
  13.  
  14. MoveX = 1: MoveY = 1
  15. BallX = 9: BallY = 9
  16. dim as integer ChangeDirection
  17.  
  18. pCon.Lock()
  19. for C as integer = 0 to 99
  20.   var X = cint(int(rnd*80)),Y = cint(int(rnd*25))  
  21.   CharPtr(X,Y)=219: AttrPtr(X,Y)=&h1C
  22. next C
  23. pCon.Unlock()
  24.  
  25. Do
  26.     'Move ball
  27.     BallX += MoveX: BallY += MoveY
  28.     'If we hit a wall, bounce
  29.    
  30.     'If BallX = 0 or BallX = SCREEN_WIDTH-1 Then MoveX = -MoveX: ChangeDirection = -1
  31.     'If BallY = 0 or BallY = SCREEN_HEIGHT-1 Then MoveY = -MoveY: ChangeDirection = -1
  32.     If cuint(BallX-1) >= SCREEN_WIDTH-2 Then MoveX = -MoveX: ChangeDirection = -1
  33.     If cuint(BallY-1) >= SCREEN_HEIGHT-2 Then MoveY = -MoveY: ChangeDirection = -1
  34.    
  35.     'Check for collision with text
  36.     If ChangeDirection=0 Then      
  37.       #if 1
  38.         If CharPtr(BallX+MoveX, BallY) > 32 Then MoveX = -MoveX
  39.         If CharPtr(BallX, BallY+MoveY) > 32 Then MoveY = -MoveY      
  40.       #else
  41.         If CharPtr(BallX+MoveX, BallY+MoveY) > 32 Then
  42.           '...
  43.         end if
  44.       #endif
  45.     End If
  46.    
  47.     'Render Screen
  48.     pCon.Lock()
  49.     CharPtr(OldX, OldY) = 07    'Remove old ball  
  50.     CharPtr(BallX, BallY) = 02    'Draw new ball
  51.     pCon.Unlock()
  52.    
  53.     OldX = BallX: OldY = BallY
  54.     ChangeDirection = 0
  55.    
  56.     Sleep 50,1
  57. Loop until Inkey = Chr(27)'<> ""
  58.  
  59. pCon.Destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement