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

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




PostPosted: Fri Jul 29, 2005 6:43 pm   Post subject: snake game help

Hi, i need help with my snake game...

code:

%My snake game
View.Set("graphics:500;500,nocursor")

%%%INTRO%%%
var textc: int
var font1 := Font.New ("Impact:30")
var font2 := Font.New ("Comicsans:50")
var font3 := Font.New ("Roman:10")
var text1 := "Welcome    to"
var text2 := "S N A K E"
var text3 := "By: ***** ******"
var text4 := "G A M E"
var text5 := "O V E R"
var width1 := Font.Width (text1,font1)
var width2 := Font.Width (text2,font2)
var width3 := Font.Width (text3,font3)
var width4 := Font.Width (text4,font2)
var width5 := Font.Width (text5,font2)

loop
    randint (textc,1,100)
    Font.Draw (text1, round (maxx / 2 - width1 / 2), 350, font1, textc)
    Font.Draw (text2, round (maxx / 2 - width2 / 2), 200, font2, textc)
    Font.Draw (text3, round (maxx / 2 - width3 / 2), 20, font3, textc)
    delay(50)
    exit when hasch
end loop
cls

%%%GAME%%%
var x, y: int       %%Snake
var x1, y1: int     %%Food
var speed: int := 1
var c: int          %%Color
var snake: array char of boolean
var fs: int := 20   %%Food size

randint(x,20,480)       %%Spawn snake
randint(y,20,480)
randint(x1,20,480)      %%Spawn food
randint(y1,20,480)
randint(c,1,255)
drawfilloval(x,y,5,5,c)

loop
%Moving snake
    Input.KeyDown (snake)

    if snake (KEY_UP_ARROW) then
        y := y + speed
    end if
    if snake (KEY_DOWN_ARROW) then
        y := y - speed
    end if
    if snake (KEY_RIGHT_ARROW) then
        x := x + speed
    end if
    if snake (KEY_LEFT_ARROW) then
        x := x - speed
    end if
    %%Change color of snake
    if snake (' ') then
        randint (c,1,255)
    end if
    if x <= x1 - 5 or y <= y1 - 5 then
        randint(x1,20,480)
        randint(y1,20,480)
        speed := speed + 1
        fs := fs - 1
    end if
   
%Snake Boundry - game over
    if x >= maxx - 5 or x <= 5 or y >= maxy - 5 or y <= 5 then
        exit
    end if
    drawoval(x1,y1,fs,fs,black)
    drawfilloval(x,y,5,5,c)
    delay(10)
    cls
end loop
%Game Over
Font.Draw (text4, round (maxx / 2 - width4 / 2), 300, font2, black)
Font.Draw (text5, round (maxx / 2 - width5 / 2), 200, font2, black)
Font.Draw (text3, round (maxx / 2 - width3 / 2), 20, font3, black)


I dont know how to ADD bodies to follow the head...
i dont know how to keep the snake moving...
i dont know how to eat the foor right when i touch it...

I just need some help, please and thank you...
Should i use arrays??? like

var x: array 1 .. snake of int
snake being how many bodies??? i dont move the extra bodies, soi figured i could just draw them and they'd follow from my leading head...

like say the head is.... x=5 y=5
i put other body at draw... x-5... thats 5-5 = 0, the size of snake is 5, which they would by touching at outer shell i think...

I tryed and failed, my code right now has glitchs....

i tryed to use View.Update it dosn't work, cls is flashy... any help there???

Anyways, thannks..
Sponsor
Sponsor
Sponsor
sponsor
person




PostPosted: Fri Jul 29, 2005 7:10 pm   Post subject: (No subject)

if u look into the source code area, there is a submission of snake made by cervantes

http://www.compsci.ca/v2/viewtopic.php?t=9108
MysticVegeta




PostPosted: Fri Jul 29, 2005 9:01 pm   Post subject: (No subject)

person wrote:
if u look into the source code area, there is a submission of snake made by cervantes

http://www.compsci.ca/v2/viewtopic.php?t=9108


I wouldnt suggest looking at the source code, Xiao, i would rather suggest to look for flexible arrays There is a great tut by Cervantes on them. tokenherb, u can prolly find them on the first page of turing tutorials.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: