Re: TIB: GetKey


[Prev][Next][Index][Thread]

Re: TIB: GetKey




>Best way I see is:
>
>Lbl A
>0
>While ans = 0
>getkey
>End
>if ans=1
>Then
>...
>...
>...
>End
>if ans=2
>then
>...
>...
>...
>End
>goto A
>
>Storing the getkey into ans saves the time it would take to store it
>to a variable, not to mention a couple of lines of code.
>
>Philipp Keller
>
>

Philipp has the right Idea, but there is a faster way.  Lets say that 
you want to make a pixle move based on the arrow keys.  Here is one of 
the most efficient ways to do it:

10->A                           \
10->B                            *** Sets the starting cordinants
ClrDraw                         *** Clears the screen
Lbl T                             *** Defines the start of the loop
Repeat Ans                   *** Starts the Main loop (use Repeat its 
faster)
Getkey                          *** Gathers keypress
End                               *** Checks for keypress
If Ans>25                       *** Determines which secondary loop to 
use
Goto B                          *** If Last line true, then shuttles to 
loop
If Ans==24                     *** Start of secondary loop
then                               *** If last line true, then executes 
command
B-1->B                           *** Command
Else                               *** If test (If Ans==24) is false, 
then executes 
A-1->A                           *** Command        
End                                *** Ends secondary loop 
Pxlon(A,B                       *** updates graph
GotoT                            *** Returns to Main loop
Lbl B                              *** Defines the start of the loop
If Ans==26                      *** Start of secondary loop
Then                              *** If last line true, then executes 
command 
B+1->B                           *** Command 
Else                               *** If test (If Ans==24) is false, 
then executes  
A+1->A                          *** Command  
End                                *** Ends secondary loop  
Pxlon(A,B                      *** updates graph    
Goto T                          *** Returns to Main loop   

Of course you can use more then one pixle, but for explination this 
works.  I am working on an even faster way, but don't know when it will 
be done.  Maby if I get some inspiration soon...  If you still have 
questions about this last routine, just ask.

Josh Cunningham

P.S.  Send me ideas for the RPG engine!

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com