Author Topic: Poke to screen 0 for speed  (Read 16793 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Poke to screen 0 for speed
« Reply #30 on: August 15, 2018, 09:25:23 am »
thank you for your tips. i found the keyboard routine over the net somewhere. i auctaully need the key left and right if pressed with space bar (space bar + left or space bar + right) to grab the diamond two spaces over so as to take a diamond without the rock in center falling in...


......O......
..D.v.......   so if spacebar pressed and direction will grab diamond without moving




Well _keydown can catch multiple keys but it will have you dancing around the spot you want to stop at.

You could set a diamond grabbing mode with one key press make the grab the next and then set the mode off automatically when a diamond is grabbed. Just add code for arrow keys when diamond grabbing mode is on.

A spacebar press could just toggle the mode on but you would probably like it to toggle diamond grabbing mode between on/off.
« Last Edit: August 15, 2018, 09:30:13 am by bplus »

FellippeHeitor

  • Guest
Re: Poke to screen 0 for speed
« Reply #31 on: August 15, 2018, 09:40:56 am »
If _KEYDOWN is too fast, reduce _LIMIT.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Poke to screen 0 for speed
« Reply #32 on: August 15, 2018, 09:58:12 am »
AH, could check _keydown on spacebar while handling the arrow keys with inkey$ or_keyhit.

Is there a rule of thumb when to use INKEY$ and when to use _KEYHIT?
« Last Edit: August 15, 2018, 10:03:33 am by bplus »

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #33 on: August 15, 2018, 10:11:59 am »
i want to change a little thing with the keyboard input. i want to hold shit and arrow to pull a single rock. with my keyboard routine how can i use the shift with the arrow.
MackyWhite

FellippeHeitor

  • Guest
Re: Poke to screen 0 for speed
« Reply #34 on: August 15, 2018, 10:13:31 am »
INKEY$ works as it did in Qbasic.

_KEYHIT has the advantage of returning both positive (pressed) and negative (released) key codes as well as extended codes for CTRL, SHIFT, etc.

In the end, there's no rule of thumb. You must evaluate your need for detail in the input.

FellippeHeitor

  • Guest
Re: Poke to screen 0 for speed
« Reply #35 on: August 15, 2018, 10:16:41 am »
i want to change a little thing with the keyboard input. i want to hold shit and arrow to pull a single rock. with my keyboard routine how can i use the shift with the arrow.

Detect if SHIFT is being held down with _KEYDOWN:

Code: QB64: [Select]
  1. IF _KEYDOWN(100303) OR _KEYDOWN(100304) THEN PRINT "SHIFT is being held down"

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Poke to screen 0 for speed
« Reply #36 on: August 15, 2018, 10:32:21 am »
Oh released is a different number than holding with _keyhit, that is useful!

That is important difference. That would be good for stepping with arrow keys (check when they are released).
At that moment, check is _KEYDOWN(shift key or spacebar) for handling the special functions.



Psuedo code outline for handling key hits

KH& = _KEYHIT
If KH& < 0 then 'released keys check the arrow numbers
     SB% = _KEYDOWN(32) 'spacebar
     SHFT% = _KEYDOWN(shift&)
     if KH& = rightarrow& then
          if SB% then 'do right arrow + spacebar stuff
          if SHFT% then 'do right arrow +shift stuff
     end if
end if

look OK?

FellippeHeitor

  • Guest
Re: Poke to screen 0 for speed
« Reply #37 on: August 15, 2018, 10:37:17 am »
Looks convoluted, but looks aren't important if it works, right? Let us know.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #38 on: August 15, 2018, 10:40:31 am »
very interesting. have moved my maps to a data file also. so no more mess in the main.
MackyWhite

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Poke to screen 0 for speed
« Reply #39 on: August 15, 2018, 11:00:54 am »
Oh released is a different number than holding with _keyhit, that is useful!

That is important difference. That would be good for stepping with arrow keys (check when they are released).
At that moment, check is _KEYDOWN(shift key or spacebar) for handling the special functions.



Psuedo code outline for handling key hits

KH& = _KEYHIT
If KH& < 0 then 'released keys check the arrow numbers
     SB% = _KEYDOWN(32) 'spacebar
     SHFT% = _KEYDOWN(shift&)
     if KH& = rightarrow& then
          if SB% then 'do right arrow + spacebar stuff
          if SHFT% then 'do right arrow +shift stuff
     end if
end if

look OK?

Why not just set a flag and check it?

K = _KEYHIT
IF K = ArrowCodeWanted AND ArrowFlagSet = 0 THEN
   'Do Arrow Stuff
   ArrowFlagSet = -1 'Set the flag
END IF

IF K = -ArrowCodeWanted THEN ArrowFlagSet = 0 'Let go of arrow key before accepting its input again

Now you only deal with arrow keys which are pushed down manually and not just held down.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Poke to screen 0 for speed
« Reply #40 on: August 15, 2018, 11:08:18 am »
Right just tested throwing out if HB% < 0 line:

Code: QB64: [Select]
  1. DEFINT A-Z: DIM screenmem%(22, 12)
  2. GOSUB readlev: GOSUB displaymap: GOSUB animate: score = 0
  3.  
  4.     screenmem%(mx%, my%) = 1
  5.     GOSUB animate
  6.     screenmem%(mx%, my%) = 32
  7.     KH& = _KEYHIT
  8.     SB% = _KEYDOWN(32) 'spacebar
  9.     SHFT% = _KEYDOWN(100303) OR _KEYDOWN(100304)
  10.  
  11.     IF KH& = -18432 THEN 'up
  12.         IF screenmem%(mx%, my% - 1) = 32 OR screenmem%(mx%, my% - 1) = 176 THEN my% = my% - 1
  13.  
  14.     END IF
  15.  
  16.     IF KH& = -20480 THEN 'down
  17.         IF screenmem%(mx%, my% + 1) = 32 OR screenmem%(mx%, my% + 1) = 176 THEN my% = my% + 1
  18.         IF screenmem%(mx%, my% + 1) = 4 THEN my% = my% + 1: score = score + 1
  19.  
  20.     END IF
  21.  
  22.     IF KH& = -19200 THEN 'left
  23.         IF screenmem%(mx% - 1, my%) = 32 OR screenmem%(mx% - 1, my%) = 176 THEN mx% = mx% - 1
  24.         IF screenmem%(mx% - 1, my%) = 79 AND screenmem%(mx% - 2, my%) = 32 THEN screenmem%(mx% - 2, my%) = 79: screenmem%(mx% - 1, my%) = 32: mx% = mx% - 1
  25.         IF screenmem%(mx% - 1, my%) = 4 THEN mx% = mx% - 1: score = score + 1
  26.  
  27.     END IF
  28.  
  29.  
  30.     IF KH& = -19712 THEN 'right
  31.         IF screenmem%(mx% + 1, my%) = 32 OR screenmem%(mx% + 1, my%) = 176 THEN mx% = mx% + 1
  32.         IF screenmem%(mx% + 1, my%) = 79 AND screenmem%(mx% + 2, my%) = 32 THEN screenmem%(mx% + 2, my%) = 79: screenmem%(mx% + 1, my%) = 32: mx% = mx% + 1
  33.         IF screenmem%(mx% + 1, my%) = 4 THEN mx% = mx% + 1: score = score + 1
  34.  
  35.     END IF
  36.  
  37.     _LIMIT 400
  38. LOOP UNTIL _KEYDOWN(27) 'escape
  39.  

It steps beautifully at any _LIMIT!

PMACKAY will have to fill in code when SB% and when SHFT% keys are also being held at time of arrow key release.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #41 on: August 15, 2018, 11:10:45 am »
this is the keyboard routine

 k = INP(&H60): kbd(k AND 127) = keystate(k)
    xv = kbd(77) - kbd(75)
    yv = kbd(80) - kbd(72)
    GOSUB animate
    screenmem%(mx%, my%) = 32
    IF xv = -1 AND screenmem%(mx% - 1, my%) = 32 THEN mx% = mx% - 1
    IF xv = 1 AND screenmem%(mx% + 1, my%) = 32 THEN mx% = mx% + 1
    IF yv = -1 AND screenmem%(mx%, my% - 1) = 32 THEN my% = my% - 1
    IF yv = 1 AND screenmem%(mx%, my% + 1) = 32 THEN my% = my% + 1
    IF xv = -1 AND screenmem%(mx% - 1, my%) = 176 THEN mx% = mx% - 1: GOTO skp
    IF xv = 1 AND screenmem%(mx% + 1, my%) = 176 THEN mx% = mx% + 1: GOTO skp
    IF yv = -1 AND screenmem%(mx%, my% - 1) = 176 THEN my% = my% - 1: GOTO skp
    IF yv = 1 AND screenmem%(mx%, my% + 1) = 176 THEN my% = my% + 1: GOTO skp
    IF xv = -1 AND screenmem%(mx% - 1, my%) = 79 AND screenmem%(mx% - 2, my%) = 32 THEN screenmem%(mx% - 2, my%) = 79: screenmem%(mx% - 1, my%) = 32: mx% = mx% - 1
    IF xv = 1 AND screenmem%(mx% + 1, my%) = 79 AND screenmem%(mx% + 2, my%) = 32 THEN screenmem%(mx% + 2, my%) = 79: screenmem%(mx% + 1, my%) = 32: mx% = mx% + 1
    IF xv = -1 AND screenmem%(mx% - 1, my%) = 4 THEN mx% = mx% - 1: score = score + 1
    IF xv = 1 AND screenmem%(mx% + 1, my%) = 4 THEN mx% = mx% + 1: score = score + 1
    IF yv = 1 AND screenmem%(mx%, my% + 1) = 4 THEN my% = my% + 1: score = score + 1
    skp:
    _DELAY 0.10

i am just not sure how to mod it to accept the left control and arrow together

    IF xv = -1 AND (cntrl pressed) and screenmem%(mx% + 1, my%) = 79 AND screenmem%(mx% - 1, my%) = 32 THEN 'control + left to pull rock on right  (i can work out what to swap myself)
    IF xv = 1 AND (cntrl pressed) and screenmem%(mx% - 1, my%) = 79 AND screenmem%(mx% +1, my%) = 32 THEN 'control + right to pull rock on left    (just the keyboard routine im lost)
MackyWhite

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #42 on: August 15, 2018, 11:15:00 am »
your programing is so nice....
MackyWhite

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Poke to screen 0 for speed
« Reply #43 on: August 15, 2018, 11:22:27 am »
:)  PMACKAY do you know where the key code numbers are coming from?

I think we might have worked out way to get the control you want in post #40, catch all the individual keys you want to do combos with _KEYDOWN(keycode number)  when you get the KH& =_KEYHIT  number and still make steps with each arrow key press (and release).

It was tricky business.
« Last Edit: August 15, 2018, 11:26:43 am by bplus »

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #44 on: August 15, 2018, 11:26:44 am »
i think i kind of know where the key codes are. i could work out the arrows and stuff but could not work out multi key.
MackyWhite