' Waggler ' ======= ' An example of how to implement a simple bar showing how fast ' you are alternating between 2 different buttons/keys. ' The faster you go, the higher the bar rises. ' You may have played games like Decathlon/Hypersports which ' required you to 'waggle' the joystick as fast as you could. ' This is a similar method using the keyboard. ' Use Joystick or Keys (L-Ctrl and L-Alt) ' The prodedure used prevents the player from cheating. ' Holding down one or both keys will not increase the bar. ' Nor will clocking one key by itself. ' To increase the bars length follow this procedure: ' 1) Press and release only ONE of the keys (or Joystick direction) ' 2) Press and release the other key (or switch Joystick direction) ' 3) Repeat process at stage 1 ' =========================================================== DECLARE FUNCTION keystat% (ky%) DEF SEG = &H0 SCREEN 12 CONST kb = &H417, key1 = &H4, key2 = &H8 'which keys to scan CONST by = 160, bzoom = 4 'bars ypos and zoom factor flag = 0: barval = 0 COLOR 3: PRINT "Waggler - By J Brown (May 2000)": PRINT : COLOR 2 PRINT "Choose 'waggle' method:" PRINT "-----------------------" PRINT "1) Keys (L-Ctrl & L-Alt)" PRINT "2) Joystick Buttons (A & B)" PRINT "3) Joystick Direction (Left & Right)" COLOR 10: INPUT "-> Choice: ", method IF method < 1 OR method > 3 THEN method = 1 SELECT CASE method CASE 1: b1$ = "L-Ctrl": b2$ = "L-Alt" CASE 2: b1$ = "JoyA": b2$ = "JoyB" CASE 3: b1$ = "JoyLEFT": b2$ = "JoyRIGHT" END SELECT COLOR 6: LOCATE 14, 1 PRINT "Alternate between `"; b1$; "' and `"; b2$; "' to increase the bar" COLOR 3: PRINT : PRINT "Can you reach 100 ? (ESC=Exit)" ' ===================================== ' Main Loop ' ===================================== DO pass = 0 'check status of input 'pass=1 if button1=1 and button2=0 or vice-versa SELECT CASE method CASE 1 IF keystat(key1) = 1 - flag AND keystat(key2) = flag THEN pass = 1 CASE 2 IF -STRIG(1) = 1 - flag AND -STRIG(3) = flag THEN pass = 1 CASE 3 IF -(STICK(0) < 100) = 1 - flag AND -(STICK(0) > 100) = flag THEN pass = 1 END SELECT IF pass = 1 THEN barval = barval + 6 'increase barval flag = 1 - flag 'toggle keyflag END IF GOSUB updatebar 'update and draw the bar GOSUB prtval 'display the value of barval WAIT &H3DA, 8 'wait for display sync LOOP UNTIL INKEY$ = CHR$(27) 'quit loop on ESC key END updatebar: barval = barval - (barval / 65) 'reduce barval (higher=more) IF barval < 0 THEN barval = 0 'keep barval 0 to 100 IF barval > 100 THEN barval = 100 LINE (0, by)-(barval * bzoom, by + 8), 5, BF 'draw main bar LINE (barval * 4, by)-(100 * bzoom, by + 8), 0, BF 'erase after end of bar LINE (0, by + 5)-(100 * bzoom, by + 5), 7 'grey centre line FOR x = 0 TO 100 STEP 10 LINE (x * bzoom, by)-(x * bzoom, by + 8), 7 'markers every 10 units NEXT x RETURN prtval: COLOR 15: LOCATE 12, 1 PRINT "Value="; INT(barval); " " 'show the value of barval RETURN ' Returns 1 if key tested is pressed down ' FUNCTION keystat% (ky%) IF PEEK(kb) AND ky% THEN keystat% = 1 END FUNCTION