Beep
B2C includes a simple command for making sound. It is different from the beep command in CyBasic2. The Beep command causes the speaker to make a single tone. Beep takes values from 1 (low-pitch) to 63 (high-pitch). Beep 0 will result in silence.
Wait
There are 2 ways to create a delay in B2C. One way is to write a For loop which does nothing:
for i=0 to 100 next i
This is not recommended. It is sloppy coding and will be unpredictable in the event that Cybiko, Inc releases a newer, faster Cybiko. The alternative is the Wait command. The parameter is a number of tenths of seconds to wait. So, to wait one second:
wait 10
Key
The Key command has two modes. In the first, it acts like a variable.
x = key
It returns the value of the last key pressed on the keypad. This is very useful for writing interactive games because it does not stop the action like the Input statement does. At the end of this chapter is a table of all the values the Key variable can return. To use the table, find the key you want to check against and add the values in the corresponding row and column. For example, the letter 'a' is 90+7=97.
The other format for the key command is as a function to check a single key:
x = key(#KEY_ENTER)
In this mode you specify the key you want to check and key() returns True or False. Here is a listing of some of the constants you may use (note, these must be in uppercase)
#KEY_A - #KEY_Z #KEY_0 - #KEY_9 #KEY_UP #KEY_DOWN #KEY_LEFT #KEY_RIGHT #KEY_ENTER #KEY_SPACE #KEY_INS #KEY_DEL
|
Key Values |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
|
30 |
|
space |
|
|
|
|
|
|
|
quote |
||
40 |
|
|
|
|
comma |
dash |
period |
/ |
0 |
1 |
||
50 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
|
semi-colon |
||
60 |
|
= |
|
|
|
|
|
|
|
|
||
90 |
|
( |
\ |
) |
|
|
back- quote |
a |
b |
c |
||
100 |
d |
e |
f |
g |
h |
i |
j |
k |
l |
m |
||
110 |
n |
o |
p |
q |
r |
s |
t |
u |
v |
w |
||
120 |
x |
y |
z |
|
|
|
|
|
|
|
||
260 |
|
|
|
|
left-arrow |
up-arrow |
right-arrow |
down-arrow |
ins |
del |
||
270 |
tab |
select |
enter |
bspc |
|
shift |
fn |
|
|
|
||
DO THIS |
Copy the
file "c:\
\B2Cv5\tutorial\ch16.b2c" to "C:\
\B2Cv5\ch16.b2c".
Then execute the command build ch16.b2c Download the ch16.app
file to the cybiko.
Here is an example of a program that moves a dot left or right: dim x as int 'horizontal component of the dot dim y as int 'vertical component of the dot dim z as int 'the key pressed x=0 'initial x position of the dot y=0 'initial y position of the dot cls 'clear screen point x,y 'show the dot for i=0 to 1 step 0 'loop forever z = key 'save off the key because it changes if z = 264 then 'left key ink 0 point x,y ink 3 x=x-1 'move left point x,y 'print new dot elseif z = 266 then' right key ink 0 point x,y ink 3 x=x+1 ' move right point x,y ' print new dot end if next 'end of forever loop
|