Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Snake Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
upthescale




PostPosted: Thu May 04, 2006 2:45 pm   Post subject: Snake Help

You know when you hit a key and the snake wil move...well for me the snake only moves when i hit the key, how can i do it so when i key an arrow key, he will go...because he only goes when i hold down!
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Thu May 04, 2006 3:03 pm   Post subject: (No subject)

think about it, if it is going to move continuously without input, what do you need? a loop. have an if condition then go into the loop. simple

Turing:

var keys:array char of boolean
loop
    Input.KeyDown(keys)
    if keys(%whatever arrow) then
        loop
            %make coordinate changes in the loop(continuous without input)
        end if
        exit when hasch
end loop
upthescale




PostPosted: Thu May 04, 2006 3:05 pm   Post subject: (No subject)

my box doesn't even move now that it is in a loop!!!
upthescale




PostPosted: Thu May 04, 2006 3:09 pm   Post subject: (No subject)

ok it werks,,, thanks man +5 bits!!!!
Clayton




PostPosted: Thu May 04, 2006 3:14 pm   Post subject: (No subject)

Turing:

var keys : array char of boolean
View.Set ("graphics,offscreenonly")
var x, y : int := 0
const size : int := 20
y := maxy - size
loop
    Input.KeyDown (keys)
    if keys (KEY_DOWN_ARROW) then
        loop
            y -= 1
            Draw.Cls
            Draw.FillBox (x, y, x + size, y + size, black)
            View.Update
            delay (200)
            exit when hasch
        end loop
    end if
end loop
Delos




PostPosted: Thu May 04, 2006 3:17 pm   Post subject: (No subject)

SuperFreak82 wrote:

Turing:

var keys:array char of boolean
loop
    Input.KeyDown(keys)
    if keys(%whatever arrow) then
        loop
            %make coordinate changes in the loop(continuous without input)
        end if
        exit when hasch
end loop


A nested loop eh? Not a bad idea, and functional. However, using this approach you'll be left with 4 instances of such loops within your main loop. This might just me being picky, but I would far prefer to use a vectors-and-components approch.
Simply break down your snake movement into its components (in this case very, very simple). If the left button is pressed, the movement components would become (-1, 0); this can then be used in the main loop to change the position of the snake.
And yes, you would end up with 4 instances of these assignments - but this just strikes me as a simpler route to creating the constant motion here.
Clayton




PostPosted: Thu May 04, 2006 3:41 pm   Post subject: (No subject)

i was thinking more of a procedural approach where you could get the input and pass that to a procedure and run the loop, i just did that to show him the concept of what to do really
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: