Hi guys and gals
Here I post a demonstration to show how to use IMP in the logical managing of the move of a character on the screen and the alternative more known OR. In the top left corner you can see the result of detector FUNCTION, in the Top Right corner you can see the type of detector FUNCTION at work, in the bottom of the window you can read the help for user, the title of window remembers you that it is a Demo.
' Demo in two languages / Dimostrazione in due linguaggi
Screen 0 'screen text mode / modalit… schermo solo testo _Title "Demo OR and IMP to move a character on screen" ' setting title of window / impostare il titolo della finestra ' defining useful constants / definire costanti utili
Const X
= 1, Y
= 2, Life
= 3, True
= -1, False
= 0, ModeOr
= 10, ModeImp
= 20 ' defining variables and arrays / definire variabili ed array
'initialization of variables / inizializzazione delle variabili
Hero(Life) = True
Limit(1, X) = 10
Limit(1, Y) = 2
Limit(2, X) = 70
Limit(2, Y) = 19
ModeEvaluation = ModeImp
' main loop /ciclo principale
Cls ' refresh screen / ripulisce lo schermo
' manage evaluation mode and its results / gestisce la modalit… di valutazione e i suoi risultati
If ModeEvaluation
= ModeImp
Then If outheRange
(Limit
(1, X
), Limit
(2, X
), Hero
(X
)) Or outheRange
(Limit
(1, Y
), Limit
(2, Y
), Hero
(Y
)) Then Print "Out of game" Else Print " In game"
If IntheRange
(Limit
(1, X
), Limit
(2, X
), Hero
(X
)) And IntheRange
(Limit
(1, Y
), Limit
(2, Y
), Hero
(Y
)) Then Print " In Game" Else Print "Out Of Game"
' border of game field / bordo del campo di gioco
Locate Limit
(1, Y
), Limit
(1, X
) Locate Limit
(2, Y
), Limit
(1, X
)
'hero / l'eroe
'Helpscreen / la guida a schermo
Locate 24, 1:
Print " cursors to move Hero, Enter key to switch ModeEvaluation, Space to quit";
' input and command manager / gestore dell'input e dei comandi
If Hero
(X
) < 80 Then Hero
(X
) = Hero
(X
) + 1 If Hero
(Y
) > 1 Then Hero
(Y
) = Hero
(Y
) - 1 If Hero
(Y
) < 25 Then Hero
(Y
) = Hero
(Y
) + 1 If Hero
(X
) > 1 Then Hero
(X
) = Hero
(X
) - 1 Hero(Life) = False
If ModeEvaluation
= ModeImp
Then ModeEvaluation
= ModeOr
Else ModeEvaluation
= ModeImp
_Limit 20 ' save CPU / risparmia la CPU End ' Endo of program /fine del programma
' SUB and FUNCTION area / area delle SUB e delle FUNCTION
outheRange
= (min
< value
Imp value
> max
)
If min
> Value
Or max
< Value
Then IntheRange
= 0 Else IntheRange
= -1
As you can observe, if you run the demo, there is a little difference between detection using IMP and using OR, but for all values inner to the range, that's no matter, while the difference is visible on the borderline, so each tecnique need an adjustment to be more accurate.
Thanks to read and to try