March 28, 2024, 07:42:15 am
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
Forever
Login with username, password and session length
News
: Want to see a specific Tutorial? ASK!
Home
Help
Search
Arcade
Links
Staff List
Login
Register
QBasics_Chapt 12_part 3
Weekly Qbasic and Qb64 Lesson Topics
>
Forum
>
QB64 lessons and tutorials,Games
>
Weekly Lesson
>
QBasics_Chapt 12_part 3
Pages: [
1
]
« previous
next »
Print
Author
Topic: QBasics_Chapt 12_part 3 (Read 993 times)
GarrisonRicketson
Admin
Administrator
Hero Member
Posts: 583
QBasics_Chapt 12_part 3
«
on:
September 29, 2011, 07:06:38 pm »
Thanks to "Clippy", I now have this,..
Code:
'SCREEN 7
'I remarked out screen 7 because it is kind of small,With qb64 it come up bigger 'with no screen selection.
'BGround
' BGround gets invalid syntex in qb64
tmp$ = " CHR$(###),\\,\ \ "
tmp2$ = " CHR$(0) + CHR$(###) \ \"
DO
COLOR 14: LOCATE 3, 3: PRINT "The code can tell what key is pressed"
COLOR 12: LOCATE 5, 3: PRINT " "; CHR$(3); " ";
COLOR 13: PRINT CHR$(5); " ";
COLOR 12: PRINT CHR$(4);
COLOR 13: PRINT " "; CHR$(6)
COLOR 10
LOCATE 11, 1: PRINT SPACE$(20)
LOCATE 7, 4: PRINT " Hit a key to find the ASCII Code"
key$ = SPACE$(9)
i% = 6
a$ = ""
'Delay .5
DO: a$ = INKEY$: LOOP UNTIL a$ <> ""
IF ASC(a$) > 0 THEN
code% = ASC(a$) 'normal codes
SELECT CASE code%
CASE 7: key$ = "Beep"
CASE 8: key$ = "Backspace"
CASE 9: key$ = "Tab Key"
CASE 10: key$ = "Line Feed"
CASE 12: key$ = "Form Feed"
CASE 13: key$ = "Enter"
CASE 27: key$ = "Escape"
CASE 32: key$ = "Space Bar"
CASE 48 TO 57: key$ = "Number"
CASE 65 TO 90: key$ = "Uppercase"
CASE 97 TO 122: key$ = "Lowercase"
CASE ELSE: key$ = ""
END SELECT
SELECT CASE code% 'unprintable control characters
CASE 9 TO 13: Kcode% = 32
CASE 28 TO 31: Kcode% = 32
CASE ELSE: Kcode% = code%
END SELECT
LOCATE 9, 20: PRINT SPACE$(2)
COLOR 9: LOCATE 10, 7: PRINT USING tmp$; code%; CHR$(Kcode%); key$;
SELECT CASE code%
'CASE 7: SetCHR 5, 20, 12, code%
'CASE 9 TO 13: SetCHR 5, 21, 12, code%
'CASE 28 TO 31: SetCHR 5, 21, 12, code%
END SELECT
END IF
IF ASC(a$) = 0 THEN ' 2 byte codes
code% = ASC(RIGHT$(a$, 1))
SELECT CASE code%
CASE 16 TO 50: key$ = "Alt+ letter"
CASE 72: key$ = CHR$(24) + " Arrow"
CASE 77: key$ = CHR$(26) + " Arrow"
CASE 80: key$ = CHR$(25) + " Arrow"
CASE 75: key$ = CHR$(27) + " Arrow"
CASE 83: key$ = "Delete"
CASE 59: key$ = "F1"
CASE 60: key$ = "F2"
CASE 61: key$ = "F3"
CASE 62: key$ = "F4"
CASE 63: key$ = "F5"
CASE 64: key$ = "F6"
CASE 65: key$ = "F7"
CASE 66: key$ = "F8"
CASE 67: key$ = "F9"
CASE 68: key$ = "F10"
CASE 71: key$ = "Home"
CASE 79: key$ = "End"
CASE 73: key$ = "Page " + CHR$(24)
CASE 81: key$ = "Page " + CHR$(25)
CASE 82: key$ = "Insert"
CASE 83: key$ = "Delete"
CASE 84 TO 93: key$ = "Shift+ F"
CASE 94 TO 103: key$ = "Ctrl+ F"
CASE 104 TO 113: key$ = "Alt+ F"
CASE 114 TO 119: key$ = "Ctrl + pad"
CASE 120 TO 129: key$ = "Alt+ number"
CASE 132: key$ = "Ctrl + pad"
CASE 133: key$ = "F11"
CASE 134: key$ = "F12"
CASE 135: key$ = "Shift+ F11"
CASE 136: key$ = "Shift+ F12"
CASE 137: key$ = "Ctrl+ F11"
CASE 138: key$ = "Ctrl+ F12"
CASE 139: key$ = "Alt+ F11"
CASE 140: key$ = "Alt+ F12"
CASE ELSE: key$ = ""
END SELECT
LOCATE 10, 7: PRINT USING tmp2$; code%; key$
END IF
COLOR 5
LOCATE 13, 1: PRINT " Codes below 33 are called control keys"
LOCATE 15, 1: PRINT " CHR$(0) + are 2 byte Extended key codes"
COLOR 13: LOCATE 17, 1: PRINT " Try some Ctrl, Alt, or Shift Combo's"
COLOR 5: LOCATE 19, 1: PRINT " INKEY$ is used to detect the key entry"
COLOR 2: LOCATE 21, 1: PRINT " "; CHR$(1); " "; CHR$(2)
COLOR 4: LOCATE 23, 10: PRINT "To Quit hit the TAB key"
LOOP UNTIL a$ = CHR$(9)
SOUND 400, 4
Taken from: Chapt 12 part 3 of
Teds ("Clippy") QBASICS.zip (download)
.
This code works fine with qb64, giveing you a little program, that when you type a key, it shows the CHR$ equivilant. For me this is very useful, because I never can remember them. There is alot more on ascii codes,etc in this chapter.
from Garry
EDITED: Note this also looks a lot nicer if you use SCREEN 12,..You can experiment with various screens, 0 - 13 , some times certain ones don't work with some code,...that is a whole nother subject.
Screens thread
from Garry
«
Last Edit: October 03, 2011, 09:00:02 pm by GarrisonRicketson
»
Report Spam
Logged
From Garry
http://www.garryricketsonartworks.com/SMF
http://www.garryricketsonartworks.com/phpbbforum
http://www.garryricketsonartworks.org
http://www.garryspages.webs.com
http://wittywittywhatisthat.freesmfhosting.com/index.php
http://www.garryricketsonartworks.com/FluxBB
GarrisonRicketson
Admin
Administrator
Hero Member
Posts: 583
Re: QBasics_Chapt 12_part 3
«
Reply #1
on:
October 03, 2011, 06:37:53 pm »
In chapter 12, there is a game, of sorts, to demonstrate, various keyboard functions, movement, It is pretty neat,
Code:
'Code by "Clippy" Ted Weisenburger,From Qbasics.zip,chapt 12 modified some what by garry
SCREEN 12
DEFINT A-Z
DECLARE SUB Align (Tclr, Trow, txt$)
DECLARE FUNCTION ScanKey% (scancode%)
DECLARE SUB GameExample ()
DECLARE SUB SetBell ()
DIM SHARED Matrix(1 TO 30, 1 TO 80) AS INTEGER
DIM SHARED Qt AS STRING * 1
Try% = 0
Qt = CHR$(34) 'quotation character
Prt$ = "PRINT " + Qt$ 'print command for display
Inp$ = "INPUT " + Qt$ 'input command
COLOR 10
LOCATE 5, 4: PRINT "To create a maze for the character to move in, we can use the IBM extended"
LOCATE 6, 4: PRINT "characters that are used to create borders. First we need to make a DATA"
LOCATE 7, 4: PRINT "field consisting of just 1's and 0's. The field is 30 by 80 for SCREEN 12."
LOCATE 8, 4: PRINT "The data is READ and the characters for each value are printed to the"
LOCATE 9, 4: PRINT "screen. The DATA is also saved into an array so that the character can "
LOCATE 10, 4: PRINT "only move where there is a value of 0 in the array. "
COLOR 15: LOCATE 12, 4: PRINT " DIM Map(1 TO 30, 1 TO 80) AS INTEGER 'array to determine moves"
LOCATE 13, 4: PRINT " FOR r% = 1 TO 30 'rows of DATA"
LOCATE 14, 4: PRINT " FOR c% = 1 TO 80 'columns of DATA"
LOCATE 15, 4: PRINT " READ maze% 'get data"
LOCATE 16, 4: PRINT " Map(r%, c%) = maze% 'put DATA into Map array"
LOCATE 17, 4: PRINT " IF maze% = 1 THEN 'print the walls(1) and cherries(0)"
LOCATE 18, 4: PRINT " COLOR 9: LOCATE r%, c%: PRINT CHR$(177); 'walls ";: COLOR 9: PRINT CHR$(177)
COLOR 15: LOCATE 19, 4: PRINT " ELSE : COLOR 12: LOCATE r%, c%: PRINT CHR$(249); 'cherries ";: COLOR 12: PRINT CHR$(249)
COLOR 15: LOCATE 20, 4: PRINT " END IF"
LOCATE 21, 4: PRINT " NEXT: NEXT 'actual data field is 30 DATA statements, 80 data values each"
LOCATE 22, 4: PRINT "DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"
LOCATE 23, 4: PRINT "DATA 1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,1"
COLOR 10: LOCATE 25, 4: PRINT "The 0's are changed to 1 when the character moves so that it cannot move"
LOCATE 26, 4: PRINT "to that place again in the rest of the code. The arrow key routine is the"
LOCATE 27, 4: PRINT "same as the previous page. There also is a Score to count the dots eaten."
LOCATE 28, 4: PRINT "Try to see how many cherries you can eat before you run out of moves!"
COLOR 13: LOCATE 29, 4: PRINT " Hit any key to play the game!";
'---------------------------
SLEEP
CLS
RESTORE GameData
FOR r% = 1 TO 30
FOR c% = 1 TO 80
READ maze%
Matrix(r%, c%) = maze%
IF maze% = 1 THEN
COLOR 9: LOCATE r%, c%: PRINT CHR$(177);
ELSE: COLOR 12: LOCATE r%, c%: PRINT CHR$(249);
END IF
NEXT: NEXT
r% = 2: c% = 2: Score% = 0
COLOR 11: LOCATE 1, 2: PRINT "START";
COLOR 13: LOCATE 29, 30: PRINT "Hit Escape key to Quit!";
DECLARE SUB GameExample ()
COLOR 14: LOCATE r%, c%: PRINT CHR$(1);
DO
COLOR 11: LOCATE 1, 65: PRINT "Score:"; Score%;
DO: arrow$ = INKEY$: LOOP UNTIL arrow$ <> ""
SELECT CASE arrow$
CASE CHR$(0) + CHR$(72): IF Matrix(r% - 1, c%) = 0 THEN r% = r% - 1: blank% = 1 'up arrow
CASE CHR$(0) + CHR$(75): IF Matrix(r%, c% - 1) = 0 THEN c% = c% - 1: blank% = 2 'left
CASE CHR$(0) + CHR$(77): IF Matrix(r%, c% + 1) = 0 THEN c% = c% + 1: blank% = 3 'right
CASE CHR$(0) + CHR$(80): IF Matrix(r% + 1, c%) = 0 THEN r% = r% + 1: blank% = 4 'down
END SELECT
IF blank% > 0 THEN
SELECT CASE blank%
CASE 1: LOCATE r% + 1, c%: PRINT SPACE$(1);
CASE 2: LOCATE r%, c% + 1: PRINT SPACE$(1);
CASE 3: LOCATE r%, c% - 1: PRINT SPACE$(1);
CASE 4: LOCATE r% - 1, c%: PRINT SPACE$(1);
END SELECT
COLOR 14: LOCATE r%, c%: PRINT CHR$(1);
IF Matrix(r%, c%) = 0 THEN Matrix(r%, c%) = 1: Score% = Score% + 1
IF Matrix(r% + 1, c%) = 1 AND Matrix(r% - 1, c%) = 1 AND Matrix(r%, c% + 1) = 1 AND Matrix(r%, c% - 1) = 1 THEN EXIT DO
blank% = 0
END IF
LOOP UNTIL arrow$ = CHR$(27)
COLOR 12: LOCATE 14, 35: PRINT "Game Over!"
SOUND 800, 4: SOUND 700, 6: SOUND 600, 8
DIM Map(1 TO 30, 1 TO 80) AS INTEGER 'array to determine moves
FOR r% = 1 TO 30 'rows of DATA
FOR c% = 1 TO 80 'columns of DATA
Map(r%, c%) = maze% 'put DATA into Map array
IF maze% = 1 THEN 'print the walls(1) and cherries(0)
COLOR 9: LOCATE r%, c%:
PRINT CHR$(177);: COLOR 9: PRINT CHR$(177);: COLOR 9: PRINT CHR$(177)
ELSE: COLOR 12: LOCATE r%, c%: PRINT CHR$(249);: COLOR 12: PRINT CHR$(249)
END IF
NEXT
NEXT
GameData:
DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DATA 1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,1
DATA 1,0,1,1,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,0,1
DATA 1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,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1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
SUB Align (Tclr, Trow, txt$)
Tcol = 41 - (LEN(txt$) \ 2)
COLOR Tclr: LOCATE Trow, Tcol: PRINT txt$;
END SUB
'-----------------------
I had some trouble, figureing out exactly which code, I needed to copy to run the game by itself, out side of the tutorial, but I finally got it,..It was a interesting "project" and helped me understand more about this.
This now is a QB64 program, all though most of the code is qbasic, or for qb4.5.
The best thing to do is get, QBASICS.ZIP
DownLoad
qbasics.zip, and read chapt 12,..you will get to the game,...
EDITED: I added SCREEN 12,..if you are just learning, you might want to try it with out the SCREEN 12, just to see the difference it makes.
This is more about screen modes
Screens thread
from Garry
«
Last Edit: October 03, 2011, 08:59:26 pm by GarrisonRicketson
»
Report Spam
Logged
From Garry
http://www.garryricketsonartworks.com/SMF
http://www.garryricketsonartworks.com/phpbbforum
http://www.garryricketsonartworks.org
http://www.garryspages.webs.com
http://wittywittywhatisthat.freesmfhosting.com/index.php
http://www.garryricketsonartworks.com/FluxBB
GarrisonRicketson
Admin
Administrator
Hero Member
Posts: 583
Re: QBasics_Chapt 12_part 3
«
Reply #2
on:
October 03, 2011, 09:58:05 pm »
Same Game, modified again,...
Code:
'Code by "Clippy" Ted Weisenburger,From Qbasics.zip,chapt 12 modified some what by garry
SCREEN 12
DEFINT A-Z
DECLARE SUB Align (Tclr, Trow, txt$)
DECLARE FUNCTION ScanKey% (scancode%)
DECLARE SUB GameExample ()
DECLARE SUB SetBell ()
DIM SHARED Matrix(1 TO 30, 1 TO 80) AS INTEGER
DIM SHARED Qt AS STRING * 1
Try% = 0
Qt = CHR$(34) 'quotation character
Prt$ = "PRINT " + Qt$ 'print command for display
Inp$ = "INPUT " + Qt$ 'input command
COLOR 10
LOCATE 5, 4: PRINT "To create a maze for the character to move in, we can use the IBM extended"
LOCATE 6, 4: PRINT "characters that are used to create borders. First we need to make a DATA"
LOCATE 7, 4: PRINT "field consisting of just 1's and 0's. The field is 30 by 80 for SCREEN 12."
LOCATE 8, 4: PRINT "The data is READ and the characters for each value are printed to the"
LOCATE 9, 4: PRINT "screen. The DATA is also saved into an array so that the character can "
LOCATE 10, 4: PRINT "only move where there is a value of 0 in the array. "
COLOR 15: LOCATE 12, 4: PRINT " DIM Map(1 TO 30, 1 TO 80) AS INTEGER 'array to determine moves"
LOCATE 13, 4: PRINT " FOR r% = 1 TO 30 'rows of DATA"
LOCATE 14, 4: PRINT " FOR c% = 1 TO 80 'columns of DATA"
LOCATE 15, 4: PRINT " READ maze% 'get data"
LOCATE 16, 4: PRINT " Map(r%, c%) = maze% 'put DATA into Map array"
LOCATE 17, 4: PRINT " IF maze% = 1 THEN 'print the walls(1) and cherries(0)"
LOCATE 18, 4: PRINT " COLOR 9: LOCATE r%, c%: PRINT CHR$(177); 'walls ";: COLOR 9: PRINT CHR$(177)
COLOR 15: LOCATE 19, 4: PRINT " ELSE : COLOR 12: LOCATE r%, c%: PRINT CHR$(249); 'cherries ";: COLOR 12: PRINT CHR$(249)
COLOR 15: LOCATE 20, 4: PRINT " END IF"
LOCATE 21, 4: PRINT " NEXT: NEXT 'actual data field is 30 DATA statements, 80 data values each"
LOCATE 22, 4: PRINT "DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"
LOCATE 23, 4: PRINT "DATA 1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,1"
COLOR 10: LOCATE 25, 4: PRINT "The 0's are changed to 1 when the character moves so that it cannot move"
LOCATE 26, 4: PRINT "to that place again in the rest of the code. The arrow key routine is the"
LOCATE 27, 4: PRINT "same as the previous page. There also is a Score to count the dots eaten."
LOCATE 28, 4: PRINT "Try to see how many cherries you can eat before you run out of moves!"
COLOR 13: LOCATE 29, 4: PRINT " Hit any key to play the game!";
'---------------------------
SLEEP
CLS
RESTORE GameData
FOR r% = 1 TO 30
FOR c% = 1 TO 80
READ maze%
Matrix(r%, c%) = maze%
IF maze% = 1 THEN
COLOR 9: LOCATE r%, c%: PRINT CHR$(177);
ELSE: COLOR 12: LOCATE r%, c%: PRINT CHR$(249);
END IF
NEXT: NEXT
r% = 2: c% = 2: Score% = 0
COLOR 11: LOCATE 1, 2: PRINT "START";
COLOR 13: LOCATE 29, 30: PRINT "Hit Escape key to Quit!";
COLOR 14: LOCATE r%, c%: PRINT CHR$(1);
DO
COLOR 11: LOCATE 1, 65: PRINT "Score:"; Score%;
DO: arrow$ = INKEY$: LOOP UNTIL arrow$ <> ""
SELECT CASE arrow$
CASE CHR$(0) + CHR$(72): IF Matrix(r% - 1, c%) = 0 THEN r% = r% - 1: blank% = 1 'up arrow
CASE CHR$(0) + CHR$(75): IF Matrix(r%, c% - 1) = 0 THEN c% = c% - 1: blank% = 2 'left
CASE CHR$(0) + CHR$(77): IF Matrix(r%, c% + 1) = 0 THEN c% = c% + 1: blank% = 3 'right
CASE CHR$(0) + CHR$(80): IF Matrix(r% + 1, c%) = 0 THEN r% = r% + 1: blank% = 4 'down
END SELECT
IF blank% > 0 THEN
SELECT CASE blank%
CASE 1: LOCATE r% + 1, c%: PRINT SPACE$(1);
CASE 2: LOCATE r%, c% + 1: PRINT SPACE$(1);
CASE 3: LOCATE r%, c% - 1: PRINT SPACE$(1);
CASE 4: LOCATE r% - 1, c%: PRINT SPACE$(1);
END SELECT
COLOR 14: LOCATE r%, c%: PRINT CHR$(1);
IF Matrix(r%, c%) = 0 THEN Matrix(r%, c%) = 1: Score% = Score% + 1
IF Matrix(r% + 1, c%) = 1 AND Matrix(r% - 1, c%) = 1 AND Matrix(r%, c% + 1) = 1 AND Matrix(r%, c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was still some code that had not been necessary that I removed, from Garry
Report Spam
Logged
From Garry
http://www.garryricketsonartworks.com/SMF
http://www.garryricketsonartworks.com/phpbbforum
http://www.garryricketsonartworks.org
http://www.garryspages.webs.com
http://wittywittywhatisthat.freesmfhosting.com/index.php
http://www.garryricketsonartworks.com/FluxBB
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> Useful Information ,Rules,FAQs,LINKS,etc.
===> INTRODUCE Yourself
=> General QB64 Forum
=> MS DOS, FREE DOS, ANY DOS
-----------------------------
QB64 lessons and tutorials,Games
-----------------------------
=> Lesson Disussion
=> Weekly Lesson
=> Games
-----------------------------
TUTORIALS
-----------------------------
=> QB64 Tutorials
=> Text Adventure
=> QBasic Tutorials
=> Other Tutorials
-----------------------------
UNSEENS GDK+SFML Librarys
-----------------------------
=> Discussions on GDK+SFML
=> GDK+SFML Demos, and projects
-----------------------------
DEMOS
-----------------------------
=> Working QB64 Demos
=> QB64 Games
=> QB64 Programs You Are Proud Of.
=> Function + SUB Club
-----------------------------
OFF TOPIC,and Off The wall
-----------------------------
=> OffTopic and Off the Wall
Powered by
EzPortal
Loading...