realtime game controls
[1/6] from: anohin:va::gmail at: 23-Sep-2007 11:46
Dear friends, please show me a way to make better controls for simple game. Now I have a code like that: vis/feel: make vis/feel [ detect: func [face event][ if event/type = 'key [ switch event/key [ left [ x: x - 2 ] right [ x: x + 2 ] up [ y: y - 2 ] down [ y: y + 2 ] #"q" [ quit] ] ] face/effect: make-draw blk x y show face event ] ] But controlled face is moving jerky and control keys are "sticky", so when a control is pressed and then is unpressed, face is still moving. Is there a way to do real-time controls? Rebol's truly, Bakava.
[2/6] from: carl:cybercraft at: 23-Sep-2007 21:42
On Sunday, 23-September-2007 at 11:46:38 Anohin Vladimir wrote,
>Dear friends, >please show me a way to make better controls for simple game. Now I
<<quoted lines omitted: 17>>>But controlled face is moving jerky and control keys are "sticky", so >when a control is pressed and then is unpressed, face is still moving.
I'm not sure of a way around the sticky keys problem, but I would suggest you only do a 'show face' if X or Y have been altered. Currently it's happening with any event, which could be slowing things down. ie, something like this... moved: false if event/type = 'key [ switch event/key [ left [ x: x - 2 moved: true] right [ x: x + 2 moved: true] up [ y: y - 2 moved: true] down [ y: y + 2 moved: true] #"q" [ quit] ] ] face/effect: make-draw blk x y if moved [show face]
>Is there a way to do real-time controls?
With the mouse it's quite easy, but keys are either down/up or down/slight-wait/repeat-until-up... It just depends what kind of control you need. If you don't want the repeating keys effect, you'd need to include a check for the key not being pressed after you've first detected it's been pressed. -- Carl Read.
[3/6] from: anton::wilddsl::net::au at: 23-Sep-2007 22:21
Hi Anohin, Currently in R2 we can't detect key-up events. In my little games, I tried to use only the Ctrl and Shift keys, whose state can be detected continually with time events, and the mouse. But you have to think creatively to make a decent interface that way. A way to detect keys is probably to use a paid-for View/Pro or View/Command to get external library access, and link to SDL http://www.libsdl.org/ I haven't tried this myself, though. Regards, Anton.
[4/6] from: anohin::va::gmail::com at: 23-Sep-2007 13:25
Hello, Anton, and thanks for help.
> Currently in R2 we can't detect key-up events.
It's strange and pity. BR, Anohin.
[5/6] from: anohin:va:gma:il at: 23-Sep-2007 13:29
Carl, thank you for help and relevant answer. The face showing "by request" is great, jerky sprite flies smoothly now. It's a shame that R2 has no key-up or key-down events, but we will try something else to make controls. Thank you again. Anohin
[6/6] from: ale870::gmail::com at: 25-Sep-2007 11:31
Hello, when creating game controls, it is not a good solution using a SWITCH statement, since the players could decide (generally speaking) to push more than one key at once. So usually the check is performed with several IF statements. Example: if event/key = left [ .... ] if event/key = right [ .... ] if event/key = up [ .... ] if event/key = down [ .... ] In this way the game can check if the user push UP and LEFT. (I worked creating some little games in 3D Game Studio, Blizmax, and more, so I learned some tricks :-) On 9/23/07, Anohin Vladimir <anohin.va-gmail.com> wrote:
> Carl, thank you for help and relevant answer. > The face showing "by request" is great, jerky sprite flies smoothly now.
<<quoted lines omitted: 5>>> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- //Alessandro http://sguish.wordpress.com http://laccio.wordpress.com
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted