Advertisement
Mysoft

Untitled

Jul 12th, 2024
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '/ Block Breaker V1.0 by Mysoft /'    
  2.  
  3. #include "MyTDT\GfxResize.bas"                
  4. #include "windows.bi"                  
  5. #include "win\uxtheme.bi"
  6. #Include "fbgfx.bi"
  7. #include "crt.bi"
  8.  
  9. 'macros / constants / types / globals better be here at the start
  10.  
  11. #define KEY_ARROW_LEFT 255+75*256
  12. #define KEY_ARROW_UP 255+72*256
  13. #define KEY_ARROW_DOWN 255+80*256
  14. #define KEY_ARROW_RIGHT 255+77*256
  15. #define IsKey(_N) -fb.##_N
  16. #define cx(_N) (((_N)-1)*8)
  17. #define cy(_N) (((_N)-1)*8)
  18.  
  19. const ScrWid=40 , ScrHei=30
  20. const CursorColor = 0 , FlashColor = 15
  21.  
  22. type Game
  23.   as long Column,Row
  24.   as long FlashCol,FlashRow
  25. end type
  26.  
  27. dim shared as unsigned byte g_Screen(ScrWid,ScrHei)
  28.  
  29. '#include for the other files can then be done here
  30.  
  31. sub RandomizeColor( Row as long , Column as long )
  32.    do
  33.       var iColumn = cint(int(1+rnd*8))
  34.          if Column>1 andalso g_Screen(Column-1,Row)=iColumn then continue do
  35.          if Column<ScrWid andalso g_Screen(Column+1,Row)=iColumn then continue do
  36.          if Row>1 andalso g_Screen(Column,Row-1)=iColumn then continue do
  37.          if Row<ScrHei andalso g_Screen(Column,Row+1)=iColumn then continue do
  38.             color iColumn
  39.             g_Screen(Column,Row)=iColumn
  40.       exit sub
  41.    loop
  42. end sub
  43.  
  44. sub SetScreenMode()                     ' Define a subroutine to set the screen mode
  45.    Gfx.PreResize()                     ' Prepare the graphics library for resizing
  46.       screenres ScrWid*8,ScrHei*8 : width ScrWid,ScrHei   ' Set the screen resolution and text width
  47.       dim as any ptr pWnd                 ' Declare a pointer to store the window handle
  48.          screencontrol(fb.GET_WINDOW_HANDLE,*cptr(unsigned integer ptr,@pWnd))  ' Get the window handle
  49.       SetWindowTheme( pWnd , "" , "" )    ' Remove the window theme
  50.    Gfx.Resize(ScrWid*16,ScrHei*16)             ' Resize the graphics window
  51.  
  52.          palette 1,255,0,0 'red
  53.          palette 2,0,255,0 'green
  54.          palette 3,0,0,255 'blue
  55.          palette 4,255,255,0 'yellow
  56.          palette 5,255,0,255 'pink
  57.          palette 6,128,64,0 'brown
  58.          palette 7,255,128,0 'orange
  59.          palette 8,128,0,255 'purple               ' Set the color palette
  60. end sub
  61.  
  62. function HandleInput( byref GameState as Game ) as boolean
  63.   with GameState 'all variables with just .name are inside the GameState structure
  64.     do
  65.       dim iKey as long , sKey as string = inkey()
  66.       If len(sKey)=0 then exit do 'done when no more keys to process
  67.       iKey = sKey[0] : if iKey=255 then iKey=-sKey[1] '>0 = char , <0 = code
  68.       line( cx(.Column) , cy(.Row) )-step(7,7),g_Screen(.Column,.Row),b
  69.       Select Case iKey
  70.           case 27,-asc("k") 'escape/X button
  71.             return false
  72.           case asc(" ") 'space
  73.             if .FlashCol<>0 then 'it's flashing... stop flashing
  74.               line( cx(.FlashCol) , cy(.FlashRow) )-step(7,7),g_Screen(.Column,.Row),bf
  75.               .FlashCol = 0 'no more flashing
  76.             else
  77.               .FlashCol = .Column
  78.               .FlashRow = .Row
  79.             end if            
  80.           case IsKey(SC_LEFT)
  81.               if .column>1 then .column -= 1
  82.           case IsKey(SC_RIGHT)
  83.               if .column<ScrWid then .column += 1
  84.           case IsKey(SC_UP)
  85.               if .row>1 then .row -= 1
  86.           case IsKey(SC_DOWN)
  87.               if .row<ScrHei then .row += 1
  88.       End Select
  89.       line( cx(.Column) , cy(.Row) )-step(7,7),CursorColor,b
  90.       ' Display current position
  91.       Locate 1, 1 : Printf !"Column: %i Row: %i\r",.Column,.Row
  92.     loop
  93.   end with
  94.   return true 'keys processed just fine
  95. end function
  96.  
  97. sub main()                              
  98.    
  99.    dim g as Game
  100.    g.Column = 1 : g.Row = 1
  101.    g.FlashCol = 0 'not flashing
  102.    
  103.    SetScreenMode()                    
  104.    Randomize()                                ' Randomize the random number generator seed
  105.    for FillHeight as long = 1 to ScrHei step 1    ' Loop through each row of the screen
  106.       for FillWidth as long = 1 to ScrWid step 1  ' Loop through each column of the screen
  107.          RandomizeColor(FillHeight , FillWidth)          
  108.          print chr(219);            
  109.       next                            
  110.    next          
  111.  
  112.    line( (g.Column-1)*8 , (g.Row-1)*8 )-step(7,7),CursorColor,b 'draws initial cursor only
  113.    while HandleInput(g)
  114.      
  115.       if g.FlashCol<>0 then 'something is flashing        
  116.         static as long FlashState
  117.         FlashState += 1 : if FlashState = 4 then FlashState=0
  118.         dim as long CurFlashColor = g_Screen(g.Column,g.Row)
  119.         if FlashState=1 then CurFlashColor = FlashColor
  120.         if FlashState=3 then CurFlashColor = CursorColor
  121.         line( (g.FlashCol-1)*8 , (g.FlashRow-1)*8 )-step(7,7),CurFlashColor,bf
  122.       end if
  123.      
  124.       sleep 30
  125.      
  126.    wend
  127. end sub
  128.  
  129. main()
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement