[REBOL] Re: realtime game controls
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
>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.
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.