Because I'm an extremely bored individual, with not much to do at the moment, I made this.
Rem Project: Snake
Rem Created: Sunday, April 29, 2012 // Note : If you want to understard this, read the code, not the annotations ^^
// A "jump label" thing so the game can restart when you die
main:
//variables
global debug = 0
r = 0
new_food = 1
global food_x = rnd(62)+1
global food_y = rnd(46)+1
global snake_length = 10 //the length of the snake at the start (also determinds the speed)
//arrays
dim row$(100)
dim logo$(100,100)
dim grid(64,48) //0 = empty | 1 = solid | 2 = snake | 3 = food
dim snake$(300) //an array to store the x and y positions (in the grid) of each segment of the snake
for n = 1 to 300
snake$(n) = ""
next n
//data for the title screen
for x = 1 to 64
row$(x)="#oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo#"
NEXT
row$(1)="################################################################"
row$(64)="################################################################"
row$(3)="#ooooooooooo#######################################oooooooooooo#"
row$(11)="#ooooooooooo#######################################oooooooooooo#"
row$(5)="#ooooooooooooooo#####oo#ooo#oooo#oooo#oo#oo####oooooooooooooooo#"
row$(6)="#ooooooooooooooo#oooooo##oo#oooo#oooo#o#ooo#ooooooooooooooooooo#"
row$(7)="#ooooooooooooooo#####oo#o#o#ooo#o#ooo##oooo####oooooooooooooooo#"
row$(8)="#ooooooooooooooooooo#oo#oo##oo#o#o#oo#o#ooo#ooooooooooooooooooo#"
row$(9)="#ooooooooooooooo#####oo#ooo#o#ooooo#o#oo#oo####oooooooooooooooo#"
//makes a 2 dimentional array(x and y) from the data above
for x = 1 to 64
for y = 1 to 48
logo$(x,y) = mid$(row$(y),x)
next y
next x
//draws the title thing
draw_grid(0,0,640,480,64,48,rgb(70,70,70)) //makes a cool bacground
draw_grid(5,5,640,480,64,48,rgb(40,40,40)) //makes said cool background cooler
//sets the font and color for the title text
set text font "Lucida Console"
set text size 20
ink rgb(200,200,200)
//draws the text of wich the font and color was previously set for ^^
text 190,130,"Press any key to start."
text 180,170,"-- [use wasd to move] --"
//makes the actual title
for x = 1 to 64
for y = 1 to 48
if logo$(x,y) = "#" then c=rnd(20)+150 : box x*10-10,y*10-10,x*10,y*10,rgb(c,c,c)
next y
wait 21 // a small delay so it loads in rows, just to make it look cooler ;)
next x
//waits untill a key is pressed
wait key
//fades out the screen(kinda)
for n = 1 to 10
for x = 1 to 64
for y = 1 to 48
if logo$(x,y) = "#" then c=rnd(20)+150-n*10 : box x*10-10,y*10-10,x*10,y*10,rgb(c,c,c)
next y
next x
wait 10
next n
//makes the borders of the level
for x = 1 to 64
for y = 1 to 48
if y = 1 or x = 1 or x = 64 or y = 48 then grid(x,y)=1
next y
next x
//puts the snake in the level
for x = 1 to snake_length
snake$(x) = str$(32)+","+str$(25-x)
NEXT
//calls the functions
draw_grid(0,0,640,480,64,48,rgb(70,70,70))
update()
draw()
set text font "arial"
set text size 10
move = 0
move_timer = timer()
direction$ = "down"
//starts a loop
do
//clears the screen
cls
//sets the speed acording to how fat the snake is -.-
move_speed = 30-snake_length/10
if new_food = 1
food_x = rnd(60)+3 : food_y = rnd(42)+3
new_food = 0
endif
//movement..... and stuff
if move_timer+move_speed < timer() // <basic timer based movement system
//user imput
if keystate(17) = 1 and direction$ <> "down" then direction$ = "up" else if keystate(30) = 1 and direction$ <> "right" then direction$ = "left" else if keystate(31) = 1 and direction$ <> "up" then direction$ = "down" else if keystate(32) = 1 and direction$ <> "left" then direction$ = "right"
move_timer = timer() // resets the timer
for x = 1 to snake_length-1
o = snake_length-x+1 //used to count backwards >.>
snake$(o) = snake$(o-1) //moves every segment one square furthur along the path
NEXT x
//finds the "," in the string
for x=1 to len(snake$(1))
if asc(mid$(snake$(1),x)) = 44 then midpoint = x
next x
//uses the position of the comma to get x and y values out of the string
x = val(left$(snake$(1),midpoint-1))
y = val(right$(snake$(1),len(snake$(1))-midpoint))
// takes the user imput and moves the snake
if direction$ = "down" then y=y+1
if direction$ = "up" then y=y-1
if direction$ = "left" then x=x-1
if direction$ = "right" then x=x+1
// if the snake eats food make him fat -.-
if x=food_x and y=food_y then inc snake_length,3 : new_food = 1
// if you die then you die :p
if grid(x,y) = 1 or grid(x,y) = 2 then goto main
// make a string from the x and y values (eg. "23,54", x=23 and y=54)
snake$(1) = str$(x)+","+str$(y)
endif
// calls the functions to update + draw the level
draw_grid(0,0,640,480,64,48,rgb(70,70,70))
update()
draw()
//draws the numbers of each tile on the tile (Dunno wy I left it in, but oh well :p)
if debug = 1
for x = 1 to 64
for y = 1 to 48
text 10*x-7,10*y-9,str$(grid(x,y))
next y
next x
endif
//loops the loop that was previously started
LOOP
// >.>
wait key
end
///////// FUNCTIONS (that I can't be bothered annotataing 'cos noone will read this anyway ^^) ////////////
function draw_grid(start_x,start_y,end_x,end_y,grid_size_x,grid_size_y,colour)
ink colour,0
box_size_x = (end_x-start_x)/grid_size_x
for x = 1 to grid_size_x
x_line_pos = box_size_x*x-box_size_x+start_x
line x_line_pos,start_y,x_line_pos,end_y
next x
box_size_y = (end_y-start_y)/grid_size_y
for y = 1 to grid_size_y
y_line_pos = box_size_y*y-box_size_y+start_y
line start_x,y_line_pos,end_x,y_line_pos
next y
line start_x,end_y,end_x,end_y
line end_x,start_y,end_x,end_y
ENDFUNCTION
Function draw()
for x = 1 to 64
for y = 1 to 48
if grid(x,y) = 1 then c=rnd(10) : box x*10-10,y*10-10,x*10,y*10,rgb(180+c,180+c,180+c)
if grid(x,y) = 2 then c=rnd(10) : box x*10-10,y*10-10,x*10,y*10,rgb(220+c,220+c,220+c)
if grid(x,y) = 3 then c=rnd(10) : box x*10-10,y*10-10,x*10,y*10,rgb(0,225+c,225+c)
next y
next x
endfunction
function update()
for x = 1 to 64
for y = 1 to 48
if y = 1 or x = 1 or x = 64 or y = 48 then grid(x,y)=1 else grid(x,y)=0
next y
next x
for n = 1 to snake_length
for x=1 to len(snake$(n))
if asc(mid$(snake$(n),x)) = 44 then midpoint = x
next x
x = val(left$(snake$(n),midpoint-1))
y = val(right$(snake$(n),len(snake$(n))-midpoint))
grid(x,y) = 2
NEXT n
grid(food_x,food_y) = 3
ENDFUNCTION
Yup, It's just snake, with all the usual stuff, and an interesting way of storing co-ordinates in a path (snake$(n) = str$(x)+","+str$(y)) ^^
It uses timer based movement and arrays to hold positions of stuff. all the usual.
Now, back to 3D
Hope you have a good day!
lewis