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
AK Da Realezt




PostPosted: Wed Jun 07, 2006 7:57 am   Post subject: Snake Help

I have to make a snake game for my ISU for school and I cant seem to figure out how to move the snake block by block. I have gotten it to change paths but not block by block therefore, the snake cant die if it hits itself yet

Plz Help Me
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Wed Jun 07, 2006 8:46 am   Post subject: (No subject)

Hello and welcome.

For us to be able to help you, we need something to work with. Please post up any relevant code you have and we will look at it and go from there. Either use [code] tags or attach the file itself.
AK Da Realezt




PostPosted: Wed Jun 07, 2006 10:16 pm   Post subject: (No subject)

code:

setscreen ("offscreenonly")
var oldx, oldy : int := 0
var x, y : int := 50
var a, b : int
var leng : int := 10
var key : array char of boolean
var c : int := 0
var score : int := 0
var lives : int := 3
var up1, down1, left1, right1 : boolean := false
var checkButton : int := 0
randint (a, 200, 600)
randint (b, 150, 300)

procedure up
    y += 1
end up

procedure down
    y -= 1
end down

procedure left
    x -= 1
end left

procedure right
    x += 1
end right

Draw.FillBox (x - 10, y - leng, x + 10, y + leng, blue)
loop
    View.Update
    Input.KeyDown (key)
    c := c + 1
    locate (1, 1)
    put "Score: ", score ..
    locate (2, 1)
    put "Lives: ", lives ..
    if x > oldx or y > oldy or x < oldx or y < oldy then
        Draw.FillBox (oldx - 10, oldy - leng, oldx + 10, oldy + leng, white)
    end if
    Draw.FillBox (a - 10, b - 10, a + 10, b + 10, red)
    oldx := x
    oldy := y
    if x > a - 11 and x < a + 11 and y > b - 11 and y < b + 11 then
        score += 100
        setscreen ("nooffscreenonly")
        cls
        setscreen ("offscreenonly")
        randint (a, 200, 600)
        randint (b, 150, 300)
        leng += 10
    end if

    if checkButton = 1 then
        up
        Draw.FillBox (x - 10, y - leng, x + 10, y + leng, blue)
        delay (50)
    elsif checkButton = 2 then
        down
        Draw.FillBox (x - 10, y - leng, x + 10, y + leng, blue)
        delay (50)
    elsif checkButton = 3 then
        left
        Draw.FillBox (x - leng, y - 10, x + leng, y + 10, blue)
        delay (50)
    elsif checkButton = 4 then
        right
        Draw.FillBox (x - leng, y - 10, x + leng, y + 10, blue)
        delay (50)
    end if

    if up1 = true then
        checkButton := 1
        up
        up1 := false
    elsif down1 = true then
        checkButton := 2
        down
        down1 := false
    elsif left1 = true then
        checkButton := 3
        left
        left1 := false
    elsif right1 = true then
        checkButton := 4
        right
        right1 := false
    end if

    if c = 255 then
        c := 0
    end if

    if key ('w') then
        up1 := true
    elsif key ('s') then
        down1 := true
    elsif key ('a') then
        left1 := true
    elsif key ('d') then
        right1 := true
    end if
end loop
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: