How to start a snake game?

Blitz3D Forums/Blitz3D Beginners Area/How to start a snake game?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Thanks for all the advices!! Here's what I have came up with, based on darklordz's suggestion. I'll try implementing yours in a moment, sergio. I'll let you know how it goes.

Graphics 640,480,16,2

Global snakespeed = 5
Global foodx = Rnd(640)
Global foody = Rnd(480)
Global score = 0

Type snakeinfo
	Field xpos
	Field ypos
	Field direction ;1=up,2=right,3=down,4=right
End Type

snake.snakeinfo = New snakeinfo

snake\xpos = 320
snake\ypos = 240
snake\direction = 1

block = CreateImage(10,10)
SetBuffer ImageBuffer(block)
	Rect 0,0,10,10,1
food = CopyImage(block)

SetBuffer BackBuffer()

While Not KeyHit(1)
	Cls
	
	Text 0,0,score
	Select snake\direction
	Case 1 
		snake\ypos = snake\ypos - snakespeed
	Case 2	
		snake\xpos = snake\xpos + snakespeed
	Case 3
		snake\ypos = snake\ypos + snakespeed
	Case 4
		snake\xpos = snake\xpos - snakespeed
	End Select
	
	DrawImage block, snake\xpos, snake\ypos
	DrawImage food, foodx, foody
	
	If ImagesCollide(block,snake\xpos,snake\ypos,0,food,foodx,foody,0) Then
		score = score + 10
		foodx = Rnd(640)
		foody = Rnd(480)
	EndIf
	
	If KeyHit(200) Then
		If snake\direction = 2 Or snake\direction = 4 Then snake\direction = 1
	EndIf
	
	If KeyHit(203) Then
		If snake\direction = 1 Or snake\direction = 3 Then snake\direction = 4
	EndIf

	If KeyHit(205) Then
		If snake\direction = 1 Or snake\direction = 3 Then snake\direction = 2
	EndIf

	If KeyHit(208) Then
		If snake\direction = 2 Or snake\direction = 4 Then snake\direction = 3
	EndIf
	
		
	Flip	
Wend