seperate controls - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

seperate controls

Hadji_13Hadji_13 Posts: 274Member
Hello world
I'm making a game in QBasic with two bats (rectangles), it's for two players. When one person is holding a key it stops the other person from moving, is there any way round this?
I've used SELECT CASE and an INKEY statments if that's any help.
Ta

Comments

  • DymanicDymanic Posts: 63Member
    : Hello world
    : I'm making a game in QBasic with two bats (rectangles), it's for two players. When one person is holding a key it stops the other person from moving, is there any way round this?
    : I've used SELECT CASE and an INKEY statments if that's any help.
    : Ta
    :


  • Hadji_13Hadji_13 Posts: 274Member
    : : Hello world
    : : I'm making a game in QBasic with two bats (rectangles), it's for two players. When one person is holding a key it stops the other person from moving, is there any way round this?
    : : I've used SELECT CASE and an INKEY statments if that's any help.
    : : Ta
    : :
    :
    :
    Can u expand on that?
    I don't know how to use ON KEY statments.

  • DymanicDymanic Posts: 63Member
    ...it can solve certain problems.
    First, you have to tell QB (well, I use QB) that you want to use ON KEY:

    KEY(0) on 'this activates the function keys
    Then you put:
    ON KEY(1) GOSUB FOOBAR 'for example - this is the F1 key.
    'KEY(2) is F2, etc.
    Now you have to write a GOSUB called FOOBAR (well, you don't actually HAVE to call it that) - you have to use GOSUB rather than a SUB or (heaven forbid) GOTO.

    FOOBAR: '<-here's the GOSUB
    put whatever code you want here
    RETURN 'don't forget the return

    You have to handle other keys individually - this is the nuisance part I mentioned. It's in HELP. There's no easier way than fiddling with it until you get how to do it.
    You can set up any key you want as a "user-defined" key, including multiple-keypresses (this is what will help most with your specific problem).
    The nice thing about ON KEY is that (unlike $INKEY), it acts like an interrupt, rather than having to poll the keyboard (that's what makes action jerky, etc., as the program has to wait till it encounters $INKEY statement - ON KEY will jump right out from anywhere).

Sign In or Register to comment.