View difference between Paste ID: CNnSrwWK and QZMvqBd0
SHOW: | | - or go back to the newest paste.
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 IsKey(_N) 255+fb.##_N*256
14+
15-
          
15+
#define IsKey(_N) -fb.##_N
16
#define cx(_N) (((_N)-1)*8)
17
#define cy(_N) (((_N)-1)*8)
18-
                
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-
sub MoveCursor( byref Column as long , byref Row as long )
52+
53-
  dim as long key = GetKey()  ' Check for key press
53+
54-
  If key <> 0 Then  ' Handle arrow keys
54+
55-
      line( (Column-1)*8 , (Row-1)*8 )-step(7,7),g_Screen(Column,Row),bf
55+
56-
      Select Case key
56+
57
         palette 6,128,64,0 'brown
58-
            for N as long = 0 to 2
58+
59-
              line( (Column-1)*8 , (Row-1)*8 )-step(7,7),FlashColor,bf
59+
60-
              sleep 50
60+
61-
              line( (Column-1)*8 , (Row-1)*8 )-step(7,7),CursorColor,bf
61+
62-
              sleep 50
62+
function HandleInput( byref GameState as Game ) as boolean
63-
              line( (Column-1)*8 , (Row-1)*8 )-step(7,7),g_Screen(Column,Row),bf
63+
  with GameState 'all variables with just .name are inside the GameState structure
64-
            next N
64+
    do
65
      dim iKey as long , sKey as string = inkey()
66-
              if column>1 then column -= 1
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-
              if column<ScrWid then column += 1
68+
      line( cx(.Column) , cy(.Row) )-step(7,7),g_Screen(.Column,.Row),b
69
      Select Case iKey
70-
              if row>1 then row -= 1
70+
          case 27,-asc("k") 'escape/X button
71
            return false
72-
              if row<ScrHei then row += 1
72+
73
            if .FlashCol<>0 then 'it's flashing... stop flashing 
74-
      line( (Column-1)*8 , (Row-1)*8 )-step(7,7),CursorColor,b
74+
              line( cx(.FlashCol) , cy(.FlashRow) )-step(7,7),g_Screen(.Column,.Row),bf
75-
  End If
75+
              .FlashCol = 0 'no more flashing
76
            else 
77-
  ' Display current position
77+
              .FlashCol = .Column 
78-
  Locate 1, 1
78+
              .FlashRow = .Row
79-
  Printf !"Column: %i Row: %i\n",Column,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-
   dim Column as unsigned long = 1
85+
              if .row>1 then .row -= 1
86-
   dim Row as unsigned long = 1  
86+
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-
   line( (Column-1)*8 , (Row-1)*8 )-step(7,7),CursorColor,b 'draws initial cursor only
97+
98
   
99-
      MoveCursor(Column,Row)
99+
   dim g as Game
100
   g.Column = 1 : g.Row = 1
101
   g.FlashCol = 0 'not flashing
102
   
103-
main()                                  
103+
104-
sleep                         
104+
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