
-----------------------------------
zylum
Fri Apr 09, 2004 6:30 pm

snake game
-----------------------------------
here's a snake game i made, choose a difficulty, the higher the difficulty the more points youll get... ill post the source later cuz there are some members that like to alter the source to get high scores.... *cough*short1*/cough*

-zylum

-----------------------------------
Paul
Fri Apr 09, 2004 6:56 pm


-----------------------------------
I got 200 using level 5

-----------------------------------
Tony
Fri Apr 09, 2004 9:24 pm


-----------------------------------
looks nice and simple :D it's just a bit hard to turn :lol:

oh yeah, I got to 350 or something :? might have been more, there's no pause when game ends

-----------------------------------
guruguru
Fri Apr 09, 2004 11:42 pm


-----------------------------------
Good job. Works very well. Like it a lot. One suggestion is to have a game over scene where teh snake blows up, it tells u ure score, and then asks if u want to continue. Great job.

-----------------------------------
zylum
Sat Apr 10, 2004 12:58 pm


-----------------------------------
im glad you guys like it... btw the game keeps track of your highscore so just start a new game and it will be above your current score. 

i got something like 1240 on level 4 and like 850 on level 5 so try and beat that! :lol:

ill post the source later tonight :wink:

-----------------------------------
white_dragon
Sat Apr 10, 2004 1:29 pm


-----------------------------------
har har har!  i got soooooooooooooo close to zylum's score!!!!!!!!!! i was off by bout hundred points on lvl 4!!!!!!!! grrrrrrrrrrrrrrrrrrrrrrrrrrrrr :evil:  :evil:

-----------------------------------
zylum
Sun Apr 11, 2004 1:55 pm


-----------------------------------
anyways, here's the source for whoever's interested

-----------------------------------
josh
Mon Apr 12, 2004 5:46 pm


-----------------------------------
this is a really neat game. It is addictive. Kudos.

-----------------------------------
valor
Mon Apr 19, 2004 8:05 pm


-----------------------------------
cool game i got 400 and something anyway...i found that the controls were a little sticky might just be my computer though. but i doubt it

-----------------------------------
vorl0n
Thu Sep 20, 2007 10:32 am

RE:snake game
-----------------------------------
Amazing, can someone paste the source here, i have problems with downloading files atm.

thanks

-----------------------------------
Dan
Thu Sep 20, 2007 10:47 am

Re: snake game
-----------------------------------
This topic is a bit old, it is from 2004.

Here is the code any how tho:


setscreen ("graphics:320;350,nooffscreenonly,nobuttonbar")

type snakeCoords :
    record
	x : int
	y : int
    end record

type snakeData :
    record
	dx : int
	dy : int
	speed : int
	clr : int
    end record

type gridData :
    record
	size : int
	width : int
	clr : int
    end record

const foodClr := RGB.AddColor (0.9, 0.1, 0.1)

var grdData : gridData
grdData.size := 30
grdData.width := 10
grdData.clr := RGB.AddColor (0.2, 0.9, 0.2)

var grid : array 1 .. grdData.size, 1 .. grdData.size of int
var snake : flexible array 1 .. 5 of snakeCoords
var snkData : snakeData
var keysDown : array char of boolean
var score, highScore, scoreInc : int := 0
var foodx, foody : int
snkData.clr := RGB.AddColor (0.3, 0.7, 0.3)


proc resetData
    cls
    var temp : int
    score := 0

    snkData.dx := 0
    snkData.dy := -1

    setscreen ("graphics:320;350,nooffscreenonly,nobuttonbar")
    put "what is the difficulty? (1-5)"
    get temp
    cls
    locate (maxrow div 2, maxcol div 2)
    put "3"
    delay (1000)
    cls
    locate (maxrow div 2, maxcol div 2)
    put "2"
    delay (1000)
    cls
    locate (maxrow div 2, maxcol div 2)
    put "1"
    delay (1000)
    cls
    setscreen ("graphics:320;350,offscreenonly,nobuttonbar")
    cls

    if temp > 5 then
	temp := 5
    elsif temp < 1 then
	temp := 1
    end if

    scoreInc := temp ** 2

    snkData.speed := (6 - temp) * 10 + 10

    new snake, 5

    for i : 1 .. upper (snake)
	snake (i).x := grdData.size div 2
	snake (i).y := grdData.size
    end for
end resetData

proc moveFood
    var done : boolean
    loop
	done := true
	foodx := Rand.Int (1, grdData.size)
	foody := Rand.Int (1, grdData.size)
	for i : 1 .. upper (snake)
	    if snake (i).x = foodx and snake (i).y = foody then
		done := false
	    end if
	end for
	exit when done = true
    end loop
end moveFood

proc moveSnake
    var tempx, tempy : int
    if snake (1).x = foodx and snake (1).y = foody then
	score += scoreInc
	moveFood
	new snake, upper (snake) + 1
    end if
    tempx := snake (1).x
    tempy := snake (1).y
    for decreasing i : upper (snake) .. 2
	snake (i).x := snake (i - 1).x
	snake (i).y := snake (i - 1).y
    end for
    snake (1).x := tempx + snkData.dx
    snake (1).y := tempy + snkData.dy
end moveSnake

proc updateSnakeData
    Input.KeyDown (keysDown)
    if keysDown (KEY_RIGHT_ARROW) and snkData.dx not= -1 then
	snkData.dx := 1
	snkData.dy := 0
    elsif keysDown (KEY_LEFT_ARROW) and snkData.dx not= 1 then
	snkData.dx := -1
	snkData.dy := 0
    elsif keysDown (KEY_UP_ARROW) and snkData.dy not= -1 then
	snkData.dx := 0
	snkData.dy := 1
    elsif keysDown (KEY_DOWN_ARROW) and snkData.dy not= 1 then
	snkData.dx := 0
	snkData.dy := -1
    end if
end updateSnakeData

proc drawGrid
    drawfillbox (grdData.width, grdData.width, grdData.size * grdData.width + grdData.width, grdData.size * grdData.width + grdData.width, grdData.clr)
    drawfillbox (foodx * grdData.width, foody * grdData.width, foodx * grdData.width + grdData.width, foody * grdData.width + grdData.width, foodClr)
    for i : 1 .. upper (snake)
	drawfillbox (snake (i).x * grdData.width, snake (i).y * grdData.width, snake (i).x * grdData.width + grdData.width, snake (i).y * grdData.width + grdData.width, snkData.clr)
    end for
end drawGrid

proc checkIfDead
    for i : 2 .. upper (snake)
	if (snake (1).x = snake (i).x and snake (1).y = snake (i).y) or snake (1).x < 1 or snake (1).x > grdData.size or snake (1).y < 1 or snake (1).y > grdData.size then
	    if score > highScore then
		highScore := score
	    end if
	    resetData
	    moveFood
	    return
	end if
    end for
end checkIfDead

resetData
moveFood
loop
    updateSnakeData
    moveSnake
    drawGrid
    checkIfDead
    locate (1, 1)
    put "HIGH:  ", highScore
    put "SCORE: ", score
    View.Update
    delay (snkData.speed)
    cls
end loop



Note: this is not my code and i was no way inlvoed in making it.

-----------------------------------
petree08
Thu Sep 20, 2007 5:34 pm

RE:snake game
-----------------------------------
yeah this is an old post, still its kinda neat. mind you theres been A LOT cooler stuff you could have pulled up. still its nice to see people look that far back lol.

-----------------------------------
allrace1337
Thu Sep 20, 2007 9:01 pm

RE:snake game
-----------------------------------
Thanks for sharing! Now I have something to do in class... it is so boring, we're still learning about var and if stuff
