Game and keys

Discussion in 'Questions (Windows Mobile)' started by pmu5757, May 14, 2008.

  1. pmu5757

    pmu5757 Member Licensed User

    Hello
    I intend to make a little game, and I wonder what is the best way to move for example a starship with keyboard keys.

    Thank you.
     
  2. Cableguy

    Cableguy Expert Licensed User

    Use tha Sprite dll, wichcan detect colisions with other sprite objects, and wiht edges or specific coordinates....
     
  3. pmu5757

    pmu5757 Member Licensed User

    Thank you,
    Ok I'll use it.
    And how do I know which key the player has pressed ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. pmu5757

    pmu5757 Member Licensed User

    Ok, that's for the device...
    And if I want to make such an application for the desktop ?
    Thank you.
     
  6. Cableguy

    Cableguy Expert Licensed User

    Them use the keyPress event and use/look for the ASCII key value....
    For instance, chr13 is the enter key...
    Google a bit and you will find a complete reference to the ASCII key map...
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    It should also work on the desktop.
     
  8. pmu5757

    pmu5757 Member Licensed User

    Ok for the keypressed event and the ascii table.
    But what object must I choose for the keypressed event ?
    I tried with the whole form, but with a form, I only have the "special keys" of the device.

    Thank you

    Pascal.
     
  9. Cableguy

    Cableguy Expert Licensed User

    The only two standart control in B4PPc that suport "keyPress Event" are the Button and the Textbox.
    Other controls have similar events...

    You can change the default event triggered by adding an event...

    For instance you want the same code to de used in more than one event, but That would cause too much code lines...
    so just add an extra event that will overRide the default event of the control:

    AddEvent("Button1",KeyPress,"MySub")
    AddEvent("TextBox1",KeyPress,"MySub")

    This will cause that both keypress events will be "linking" to the same Sub...
     
  10. pmu5757

    pmu5757 Member Licensed User

    Thank you Cableguy, but I still have a question : what are ascii codes for the arrows of the desktop keyboard ?

    Thank you.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    The values are: cUpKey, cDownKey, cLeftKey, cRightKey
     
  12. pmu5757

    pmu5757 Member Licensed User

    Thank you Erel, but I don't succeed in coding that.
    Here is my code (in fact too attempts in the same code but neither the one nor the other works).
    Could you tell me what's wrong : I just want to make the button move by typing on the arrows.
    Thank you.

    Code:
    Sub Globals
       
    'Declare the global variables here.

    End Sub

    Sub App_Start
       Form1.Show
       Button1.Focus
       
    End Sub


    Sub Button1_KeyPress (key)
       
    If Key=cUpKey Then
          Button1.Top=Button1.Top+
    5
       
    End If
    End Sub

    Sub Form1_KeyPress (specialKey)
       
    Select SpecialKey
     
    Case cUpKey
      Button1.Top=Button1.Top+
    5
     
    Case cDownKey
     Button1.Top=Button1.Top-
    5
    End Select
    End Sub
     
  13. Erel

    Erel Administrator Staff Member Licensed User

  14. pmu5757

    pmu5757 Member Licensed User

    Thank you, it works very well !
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice