Learning to Program with the Cybiko Handheld Computer Using B2C

Chapter 15 : Printxy

Printxy is like a combination of the Point function and the Print function.  Printxy allows you to position text anywhere on the Cybiko screen.  The format of the Printxy command is:

printxy x,y, value [, value…]

The text string is composed of the values of the variables after the Y coordinate.  The text string is printed at the coordinates X, Y.  The values will be painted with the X/Y coordinate in the upper left corner of the text.  The values can be any collection of comma-separated variables or literals – just as in Print. 

Our Example Program will print your name on the display and bounce it off the edges of the screen.  Try using shorter names to see how the performance improves.

 

DO THIS

Copy the file "c:\…\B2Cv5\tutorial\ch14.b2c" to "C:\…\B2Cv5\ch14.b2c".  Then execute the command "build ch14.b2c".  Download the ch14.app file to the cybiko.
dim name[32] as char'your name
dim x as int        'x coordinate of your name
dim y as int        'y coordinate of your name
dim dx as int      'direction the name moves in x coord
dim dy as int      'direction the name moves in y coord
input "Enter your name ", name
x = 80-rnd(160)  'random x starting point
y = 43-rnd(86)     'random y starting point
dx = -1  ' moving to the left
dy = -1  'moving up
while 1  'do forever or until ESC is pressed
    cls                          'clear the screen
    printxy x,y, name   'print the name onscreen
    x=x+dx   'move x dir
    y=y+dy   'move y dir
    if x>80 then
      dx=-dx    ' bounce off right side
    end if
    if x<-80 then
      dx=-dx   ' bounce off left side
    end if
    if y>30 then
      dy=-dy   'bounce off bottom
    end if
    if y<-43 then
      dy=-dy  'bounce off top
    end if
wend