2 This file is part of Generic Block Game
4 Generic Block Game is free software
: you can redistribute it
and/or modify
5 it under the terms of the GNU General
Public License
as published by
6 the Free Software Foundation
, either version
3 of the License
, or
7 (at your
option) any later version
.
9 Generic Block Game is distributed
in the hope that it will be useful
,
10 but WITHOUT ANY WARRANTY
; without even the implied warranty of
11 MERCHANTABILITY
or FITNESS
FOR A PARTICULAR PURPOSE
. See the
12 GNU General
Public License
for more details
.
14 You should have received a copy of the GNU General
Public License
15 along
with this program
. If not, see
<https
://www
.gnu
.org
/licenses
/>.
20 As Byte row
, column
, border
22 keypress
As String * 2
31 Function isin(xx
As Short
,yy
As Short
,x
As Short
,y
As Short
,w
As UShort
=50,h
As UShort
=50) As Byte
33 in=in And xx
>=x
And xx
<=x
+w
34 in=in And yy
>=y
And yy
<=y
+h
40 Function readtitle(filename
As String) As String
41 Dim As String l
, result
42 Open filename
For Input
As #
1
43 If Err
>0 Then Print
"Error opening the file":End
56 Function drawbutton(text
As String, keypress
As String = "", row
As Byte, column
As Byte = -1, border
As Byte = True, filled
As Byte = False) As button
57 'Draws a button. If column (0 to 4) is present, draws a smaller button in that column
58 Const MAXW
= 299, H
= 40, MARGIN
= 10, PL
= 20, FH
= 8, FW
= 8
59 Dim as Short w
= MAXW
, ox
= 0
61 w
= MAXW
/ 4 - MARGIN
* 0.75
62 ox
= (w
+ MARGIN
) * column
65 Line (ox
, H
*row
+ MARGIN
*row
)-(ox
+ w
, H
*row
+MARGIN
*row
+H
), RGB(0,0,127), bf
67 Line (ox
, H
*row
+ MARGIN
*row
)-(ox
+ w
, H
*row
+MARGIN
*row
+H
), RGB(11,11,11), bf
69 If border
Then Line (ox
, H
*row
+ MARGIN
*row
)-(ox
+ w
, H
*row
+MARGIN
*row
+H
), RGB(127,127,127), b
70 If (Not border
) Or (column
>= 0) Then
71 Draw
String (ox
+ w
/2-Len(text
)*FW
/2, H
*row
+MARGIN
*row
+ H
/2-FH
/2), text
73 Draw
String (ox
+ PL
, H
*row
+MARGIN
*row
+ H
/2-FH
/2), text
75 Return Type(text
, row
, column
, border
, ox
, H
*row
+ MARGIN
*row
, w
, H
, keypress
)
79 Function menumouse(buttons() As button
) As String
81 Dim As Integer mousex
, mousey
, pressed
83 If (ScreenEvent(@e
)) Then
85 Case EVENT_MOUSE_BUTTON_PRESS
87 If e
.button
=2 Then Return Chr(27)
89 GetMouse(mousex
,mousey
)
91 For a
= 0 to UBound(buttons
)
92 If isin(mousex
,mousey
,buttons(a
).x
, buttons(a
).y
,buttons(a
).w
,buttons(a
).h
) Then Return buttons(a
).keypress
95 Case EVENT_MOUSE_BUTTON_RELEASE
99 ScreenControl GET_WINDOW_POS
, mousex
, mousey
100 ScreenControl SET_WINDOW_POS
, mousex
+ e
.dx
, mousey
+ e
.dy
107 Function drawmenu(title
As String, options() As String) As Byte
108 'Draws a menu with 4 options from options array
109 Dim keypress
As String
110 Dim buttons(6) As button
111 Dim selected_button
As Byte = 0
112 Dim As UByte page
= 0
113 Dim maxpage
As UByte
= (UBound(options
)) \
4 + 1
115 resizewindow(300, 300, title
) 'resize or cls
116 drawbutton(title
,,0,,False)
119 Dim As Byte row
= 1, fn
= page
* 4
120 Do While row
<= 4 And fn
<= UBound(options
)
121 buttons(row
) = drawbutton(row
& ". " + options(fn
), Str(row
), row
,,,row
= selected_button
)
125 buttons(5) = drawbutton("prev", "p", 5, 0)
126 buttons(6) = drawbutton("next", "n", 5, 1)
127 drawbutton(page
+ 1 & "/" & maxpage
, , 5, 2, False)
128 buttons(0) = drawbutton("exit", "x", 5, 3)
129 'wait for key or click
132 If keypress
= "" Then keypress
= menumouse(buttons())
133 Loop Until keypress
<> ""
138 If selected_button
> row
- 1 Then selected_button
= 1
139 Case Chr(255)+"M", "n" 'down or right or n
140 page
= (page
+ 1) Mod maxpage
143 If selected_button
< 1 Then selected_button
= row
- 1
144 Case Chr(255)+"K" , "p" 'up or left or p
145 page
= (page
- 1 + maxpage
) Mod maxpage
147 If selected_button
> 0 Then keypress
= Str(selected_button
)
153 'return selected option + page*4 - 1
154 If Val(keypress
) >= 1 And Val(keypress
) <= 4 And Len(options(Val(keypress
) + page
*4 - 1)) Then Return Val(keypress
) + page
*4 - 1
159 Function onoff(what
As Byte) As String
160 If what
Then Return ": on"
166 Dim title
As String = "Settings"
167 Dim options(4) As String
169 options(0) = "Show shadow" + onoff(settings
.show_shadow
)
170 options(1) = "Show speed" + onoff(settings
.show_speed
)
171 options(2) = "Show score" + onoff(settings
.show_score
)
172 options(3) = "Play with mouse" + onoff(settings
.play_mouse
)
173 options(4) = "1st button turning" + onoff(settings
.first_button_turning
)
174 Select Case drawmenu(title
, options())
176 settings
.show_shadow
= Not settings
.show_shadow
178 settings
.show_speed
= Not settings
.show_speed
180 settings
.show_score
= Not settings
.show_score
182 settings
.play_mouse
= Not settings
.play_mouse
184 settings
.first_button_turning
= Not settings
.first_button_turning
192 Function openloader(directory
As String) As String
193 Dim title
As String = "Load Variation"
195 ReDim filenames (0) As String
196 filenames(0) = Dir(directory
+ "/*")
197 Do While Len(filenames(UBound(filenames
)))
198 ReDim Preserve filenames(UBound(filenames
) + 1)
199 filenames(UBound(filenames
)) = Dir()
201 ReDim Preserve filenames(UBound(filenames
) - 1) 'last one was empty
203 Dim titles(UBound(filenames
)) As String
204 Dim As Byte row
= 1, fn
= 0
205 Do While fn
<= UBound(filenames
)
206 titles(fn
) = readtitle(directory
+ "/" + filenames(fn
))
209 'draw menu and return a variation (if any)
210 fn
= drawmenu(title
, titles())
211 If fn
> -1 Then Return directory
+ "/" + filenames(fn
)
216 resizewindow(300,300, "Help")
218 Color
RGB(127,127,127)
219 Print
"Generic Block Game"
221 Print
"This game is free software (GPL3+)."
222 Print
"See fbc.bas for source and details."
224 Color
RGB(255,255,255)
226 Print
"Use left and right arrows to move,"
227 Print
"Up arrow or space to rotate"
228 Print
"Down arrow to lower, Enter to drop,"
230 Print
"Use arrows to move,"
231 Print
"Space to rotate, Enter to fix,"
234 Print
"F1 for help, T to change tileset,"
235 Print
"S to toggle score, O for options,"
236 Print
"+ to increase speed, ESC for menu"
238 Color
RGB(127,127,127)
239 Print
"Help for " + game
.title
240 Color
RGB(255,255,255)
244 For a
= 0 To UBound(help
)
252 Loop Until keypress
<> "" Or e
.type = EVENT_MOUSE_BUTTON_PRESS
260 Dim title
As String = "Menu"
261 Dim options(4) As String
263 options(0) = "Show help"
264 options(1) = "Restart game"
265 options(2) = "Load game"
266 options(3) = "Quit game"
267 options(4) = "Settings"
268 Select Case drawmenu(title
, options())
276 If loadgame(openloader(VARPATH
)) Then Exit Sub 'Don't restore window size