
-----------------------------------
kar
Fri Feb 24, 2012 5:49 pm

Need help on character control using the Input.Down and delay
-----------------------------------
What is it you are trying to achieve?
trying to control a character using the arrow keys for my snake game 


What is the problem you are having?
if a key is pressed during the "delay" the action does not take place

Describe what you have tried to solve this problem
no clue how to solve it 


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




% Snake game
var x, y, r, t : int
var vDir, hDir : int
var score : int := 0
var chars : array char of boolean
var snake : int


View.Set ("graphics,offscreenonly")


x := 320
y := 200

r := Rand.Int (10, 630)
t := Rand.Int (10, 390)


procedure draw
    drawfilloval (x, y, 20, 20, yellow)
    delay (150)
    cls
end draw




vDir := 0
hDir := 0

snake := 0

loop

    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) and vDir ~= -1 then
        vDir := 1
        hDir := 0
    end if

    if chars (KEY_DOWN_ARROW) and vDir ~= 1 then
        vDir := -1
        hDir := 0
    end if

    if chars (KEY_LEFT_ARROW) and hDir ~= 1 then
        vDir := 0
        hDir := -1
    end if

    if chars (KEY_RIGHT_ARROW) and hDir ~= -1 then
        vDir := 0
        hDir := 1
    end if

    x := x + (20 * hDir)
    y := y + (20 * vDir)



    if x >= 640 then
        x := 0
    elsif y >= 400 then
        y := 0
    elsif x 