Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '/ Block Breaker V1.0 by Mysoft /'
- #include "MyTDT\GfxResize.bas"
- #include "windows.bi"
- #include "win\uxtheme.bi"
- #Include "fbgfx.bi"
- #include "crt.bi"
- 'macros / constants / types / globals better be here at the start
- #define KEY_ARROW_LEFT 255+75*256
- #define KEY_ARROW_UP 255+72*256
- #define KEY_ARROW_DOWN 255+80*256
- #define KEY_ARROW_RIGHT 255+77*256
- #define IsKey(_N) -fb.##_N
- #define cx(_N) (((_N)-1)*8)
- #define cy(_N) (((_N)-1)*8)
- const ScrWid=40 , ScrHei=30
- const CursorColor = 0 , FlashColor = 15
- type Game
- as long Column,Row
- as long FlashCol,FlashRow
- end type
- dim shared as unsigned byte g_Screen(ScrWid,ScrHei)
- '#include for the other files can then be done here
- sub RandomizeColor( Row as long , Column as long )
- do
- var iColumn = cint(int(1+rnd*8))
- if Column>1 andalso g_Screen(Column-1,Row)=iColumn then continue do
- if Column<ScrWid andalso g_Screen(Column+1,Row)=iColumn then continue do
- if Row>1 andalso g_Screen(Column,Row-1)=iColumn then continue do
- if Row<ScrHei andalso g_Screen(Column,Row+1)=iColumn then continue do
- color iColumn
- g_Screen(Column,Row)=iColumn
- exit sub
- loop
- end sub
- sub SetScreenMode() ' Define a subroutine to set the screen mode
- Gfx.PreResize() ' Prepare the graphics library for resizing
- screenres ScrWid*8,ScrHei*8 : width ScrWid,ScrHei ' Set the screen resolution and text width
- dim as any ptr pWnd ' Declare a pointer to store the window handle
- screencontrol(fb.GET_WINDOW_HANDLE,*cptr(unsigned integer ptr,@pWnd)) ' Get the window handle
- SetWindowTheme( pWnd , "" , "" ) ' Remove the window theme
- Gfx.Resize(ScrWid*16,ScrHei*16) ' Resize the graphics window
- palette 1,255,0,0 'red
- palette 2,0,255,0 'green
- palette 3,0,0,255 'blue
- palette 4,255,255,0 'yellow
- palette 5,255,0,255 'pink
- palette 6,128,64,0 'brown
- palette 7,255,128,0 'orange
- palette 8,128,0,255 'purple ' Set the color palette
- end sub
- function HandleInput( byref GameState as Game ) as boolean
- with GameState 'all variables with just .name are inside the GameState structure
- do
- dim iKey as long , sKey as string = inkey()
- If len(sKey)=0 then exit do 'done when no more keys to process
- iKey = sKey[0] : if iKey=255 then iKey=-sKey[1] '>0 = char , <0 = code
- line( cx(.Column) , cy(.Row) )-step(7,7),g_Screen(.Column,.Row),b
- Select Case iKey
- case 27,-asc("k") 'escape/X button
- return false
- case asc(" ") 'space
- if .FlashCol<>0 then 'it's flashing... stop flashing
- line( cx(.FlashCol) , cy(.FlashRow) )-step(7,7),g_Screen(.Column,.Row),bf
- .FlashCol = 0 'no more flashing
- else
- .FlashCol = .Column
- .FlashRow = .Row
- end if
- case IsKey(SC_LEFT)
- if .column>1 then .column -= 1
- case IsKey(SC_RIGHT)
- if .column<ScrWid then .column += 1
- case IsKey(SC_UP)
- if .row>1 then .row -= 1
- case IsKey(SC_DOWN)
- if .row<ScrHei then .row += 1
- End Select
- line( cx(.Column) , cy(.Row) )-step(7,7),CursorColor,b
- ' Display current position
- Locate 1, 1 : Printf !"Column: %i Row: %i\r",.Column,.Row
- loop
- end with
- return true 'keys processed just fine
- end function
- sub main()
- dim g as Game
- g.Column = 1 : g.Row = 1
- g.FlashCol = 0 'not flashing
- SetScreenMode()
- Randomize() ' Randomize the random number generator seed
- for FillHeight as long = 1 to ScrHei step 1 ' Loop through each row of the screen
- for FillWidth as long = 1 to ScrWid step 1 ' Loop through each column of the screen
- RandomizeColor(FillHeight , FillWidth)
- print chr(219);
- next
- next
- line( (g.Column-1)*8 , (g.Row-1)*8 )-step(7,7),CursorColor,b 'draws initial cursor only
- while HandleInput(g)
- if g.FlashCol<>0 then 'something is flashing
- static as long FlashState
- FlashState += 1 : if FlashState = 4 then FlashState=0
- dim as long CurFlashColor = g_Screen(g.Column,g.Row)
- if FlashState=1 then CurFlashColor = FlashColor
- if FlashState=3 then CurFlashColor = CursorColor
- line( (g.FlashCol-1)*8 , (g.FlashRow-1)*8 )-step(7,7),CurFlashColor,bf
- end if
- sleep 30
- wend
- end sub
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement