
-----------------------------------
vagyb
Fri Apr 30, 2004 9:24 am

Help with snake game and corrections
-----------------------------------
hey i just started using turing and i'm making a very sad attempt at making a snake game. i started making it today and i got to the part of controlling the snake (moving it around). I would ask someone to be kind enough to help me plz make the controls more normal. Rite now you have to press up/down/left/rite arrow keys to move the snake, but i'd like someone to tell me how to make it go up automatically, and when i press left it goes left automatically. 
any suggestions are welcome (lol i need to fix up the snake too)


import GUI
setscreen ("graphics:400;400")

var font : int
var font2 : int
font := Font.New ("Times new roman:28")
colorback (42)
cls
drawfillbox (149, 214, 232, 178, 64)
Font.Draw ("SNAKE", 130, 220, font, blue)


var quitButton : int := GUI.CreateButton (155, 185, 0, "START", GUI.Quit)
loop
    exit when GUI.ProcessEvent
end loop



cls
locate (12, 24)
put "3"
delay (1000)
locate (12, 24)
put "2"
delay (1000)
locate (12, 24)
put "1"
delay (1000)
locate (12, 24)
put "START!!"
delay (500)
cls


setscreen ("graphics:400;400")

var x, y : int
x := 200
y := 210

var chars : array char of boolean
loop
    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        y := y + 1
    end if
    if chars (KEY_RIGHT_ARROW) then
        x := x + 1
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 1
    end if
    if chars (KEY_DOWN_ARROW) then
        y := y - 1
    end if

    drawfillbox (x, y, x + 15, y + 40, blue)
    delay (10)
    cls

end loop


-----------------------------------
Delos
Fri Apr 30, 2004 9:27 am


-----------------------------------
Wrong forum.

Nicely ask a mod to move this to the [Help] section.

Thank you.

-----------------------------------
Tony
Fri Apr 30, 2004 10:16 am


-----------------------------------
what you do is you have a memory variable to keep track of the last input and if there're no keys pressed then you move in the direction of the memory variable

-----------------------------------
vagyb
Fri Apr 30, 2004 10:57 am


-----------------------------------
oh sorry, can u move it to that section plz. also this is the first time im using turing so i didn't understand most of the things u said tony. so could u plz try to explain in more simpler words or give like an example of the code or a code?
thx

-----------------------------------
vagyb
Fri Apr 30, 2004 11:55 am


-----------------------------------
okay i finally figured out how to use whatdotcolor :D (i think, so here is the new code). The problem is that only the bottom part of the snake stops from going over the boarder. so if someone could run the code and tell me how i could improve it i would appreicate it alot.

(and again this is my first program i made, i just started learning turing a week or less ago so try using simple words lol :S)


setscreen ("graphics:400;400") 
var x, y : int 
x := 100 
y := 100 

locate (12, 24)
put "3"
delay (1000)
locate (12, 24)
put "2"
delay (1000)
locate (12, 24)
put "1"
delay (1000)
locate (12, 24)
put "START!!"
delay (500)
cls
var chars : array char of boolean 
setscreen ("graphics:400;400,offscreenonly") 
loop 
    drawfillbox (0, 0, maxx, maxy, black) 
    drawfillbox (5, 5, maxx - 5, maxy - 5, 0) 

    Input.KeyDown (chars) 

    if chars (KEY_UP_ARROW) then 
        if whatdotcolor (x, y + 13) = 0 
                then 
            y := y + 5 
        end if 
    end if 
    if chars (KEY_RIGHT_ARROW) then 
        if whatdotcolor (x + 13 , y) = 0 then 
            x := x + 5 
        end if 
    end if 
    if chars (KEY_LEFT_ARROW) then 
        if whatdotcolor (x - 13, y) = 0 then 
            x := x - 5 
        end if 
    end if 
    if chars (KEY_DOWN_ARROW) then 
        if whatdotcolor (x, y - 13) = 0 then 
            y := y - 5 
        end if 
    end if 

       drawfillbox (x, y, x + 15, y + 60, blue)
    View.Update
     delay (10)
    cls 
    
end loop 




-----------------------------------
Tony
Fri Apr 30, 2004 3:47 pm


-----------------------------------
dont use delays like that
don't use whatdotcolor

take a look at zylum's [url=http://www.compsci.ca/v2/viewtopic.php?t=4462#42461]snake

-----------------------------------
vagyb
Sat May 01, 2004 3:53 am


-----------------------------------
oh i c :S lol aight thx for advice
