
-----------------------------------
kytes
Sat May 03, 2008 11:26 am

Help needed with snake game
-----------------------------------
i have this much of the game so far...im having trouble with the snake eating the apple and then the apple coming up in a new spot. if someone could please tell me how to do this, i would greatly appreciate it. just reply with the new code that will work with my program. thanks alot

ps. the apple code is between the lines of stars





const LEFT_ARROW := chr (203)
const RIGHT_ARROW := chr (205)
const UP_ARROW := chr (200)
const DOWN_ARROW := chr (208)

var BLOCKER_ROW := 12
var ss1, ss2 : int
var Blocker_Column := 38
var Key : string (1)
var x2, y2 : int
var x1, y1 : int
var diff : int
var U, R, L, D : int := 0
var arrows : array char of boolean
ss1 := 20
ss2 := 20
x2 := ss1
y2 := ss2
colourback (green)
setscreen ("graphics:600;400")
setscreen ("nocursor")
randint (x1, 1, maxx - 10)
randint (y1, 1, maxy - 10)

loop



    drawfillbox (x2, y2, x2 + 10, y2 + 10, white)
    drawfillbox (ss1, ss2, ss1 + 10, ss2 + 10, black)
    
    

    x2 := ss1
    y2 := ss2
    delay (50)
    Input.KeyDown (arrows)
    locate (BLOCKER_ROW, Blocker_Column)
    if arrows (KEY_RIGHT_ARROW) then
        L := 0
        D := 0
        R := 1
        U := 0
    elsif arrows (KEY_LEFT_ARROW) then
        L := 1
        D := 0
        R := 0
        U := 0
    elsif arrows (KEY_DOWN_ARROW) then
        L := 0
        D := 1
        R := 0
        U := 0
    elsif arrows (KEY_UP_ARROW) then
        L := 0
        D := 0
        R := 0
        U := 1
    end if

    if U = 1 then
        ss2 := ss2 + 10
    elsif R = 1 then
        ss1 := ss1 + 10
    elsif D = 1 then
        ss2 := ss2 - 10
    elsif L = 1 then
        ss1 := ss1 - 10

    end if

    if ss1 >= maxx - 10 then
        exit
    elsif ss1 < 1 then
        exit
    elsif ss2 >= maxy - 10 then
        exit
    elsif ss2 < 1 then
        exit
    end if
%*************************************
    drawfillbox (x1, y1, x1+10, y1+10, red)
    for i : 1..10
    if ss1 + i = x1 then
    drawfillbox (x1, y1, x1+10, y1+10, white)
    drawfillbox (x1, y1, x1+10, y1+10, red)
    elsif ss2 + i = y1 then
    drawfillbox (x1, y1, x1+10, y1+10, white)
    drawfillbox (x1, y1, x1+10, y1+10, red)
    end if
    end for
%***************************************

end loop

cls
locate (12, 35)
put "GAME OVER"

-----------------------------------
josh_65665
Sat May 03, 2008 1:41 pm

try this
-----------------------------------
give this a try




drawfillbox (x1, y1, x1+10, y1+10, red) 
if  ss1 > x1-10 and ss1 < x1+10 and ss2 >y1-10 and ss2 