Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [LOCKED] THE GAME OF SNAKE

Author
Message
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 6th Sep 2004 13:28
HEY GUYS I JUST GOT DONE PROGRAMING SNAKE TODAY I AM GLAD IT TOOK ME ALMOST 1 WEEK TO PROGRAM IT IM KINDA NEW TO DARKBASIC LOL BUT IM GETING USE TO IT NOW IF U HAVE AND INPROVMENTS PLEASE TELL ME

WILL
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Sep 2004 21:14 Edited at: 6th Sep 2004 21:14
I would suggest buying yourself a Gameboy, better use of your time.

Unless it's just this site that has deleted your code.

BatVink
http://biglaugh.co.uk/catalog AMD 3000+ Barton, 512Mb Ram, 120 Gig Drive space, GeForce 5200 FX 128 Mb, Asus A7N8X Mobo.
Terms & Conditions apply
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 6th Sep 2004 22:59
this is my first post im still learning how to do it sorry

WILL
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 6th Sep 2004 23:40
i will just post the code in the message u can copy and past it



sync rate 0
sync on
hide mouse

` our snake sprite

ink rgb(255,255,255),0
box 1,1,15,15
get image 1,0,0,16,16

` our fruit

ink rgb(255,0,0),0
box 1,1,15,15
get image 2,0,0,16,16

` our border

ink rgb(0,0,255),0
box 1,1,15,15
get image 3,0,0,16,16

` "where is the snake?" array
` because the snake is 16x16 in size the game grid is 40x30

dim grid(40,30)

` add the border to the array

for a=0 to 40
grid(a,0) = 1201
grid(a,29) = 1201
next a

for a=0 to 30
grid(0,a) = 1201
grid(39,a) = 1201
next a

` initial variables

` d = direction (1=up, 2=right,3=down,4=left)
` x and y are starting location for the snake (must be offset of 16)
` eaten is the fruit value (1 = onscreen, 0 = eaten)
` speed is the delay between the snake moving in ms, decrese for speed!

d = 2
x = 320
y = 240
eaten = 1
score = 0
speed = 75
length = 2
placed = 0
t = timer() + speed

set text opaque
ink rgb(255,255,255),0

create bitmap 1,640,480

` the main loop

do

cls 0

if upkey() and d<>3 then d=1
if downkey() and d<>1 then d=3
if leftkey() and d<>2 then d=4
if rightkey() and d<>4 then d=2

` if it's time to redraw the snake then do so here

if timer()>t

if d=1 then dec y,16
if d=2 then inc x,16
if d=3 then inc y,16
if d=4 then dec x,16

if grid(x/16,y/16) > 0 and grid(x/16,y/16) < 1500
goto dead
endif

` have we hit some fruit? If so increase length and score

if grid(x/16,y/16) = 1500
inc length
grid(x/16,y/16) = length
eaten = 1
inc score,25
else
grid(x/16,y/16) = length
endif

t = timer() + speed

` length cascade

for a=0 to 40
for b=0 to 30
if grid(a,b) > 0 and grid(a,b) < 1201
temp = grid(a,b)
dec temp
grid(a,b) = temp
endif
next b
next a

endif

` new fruit (make sure it's not placed on an already occupied location)

if eaten = 1

repeat

fx = 2 + rnd(37)
fy = 2 + rnd(27)

if grid(fx,fy) = 0 then placed = 1

until placed = 1

grid(fx,fy) = 1500
eaten = 0
placed = 0

endif

` draw the game grid - this draws the game screen each sync

for a=0 to 40
for b=0 to 30

tempg = grid(a,b)
if tempg > 0
if tempg = 1500 then paste image 2,a*16,b*16
if tempg = 1201 then paste image 3,a*16,b*16
if tempg < 1201 then paste image 1,a*16,b*16
endif

next b
next a

` un-comment this line to see the debug information instead of the score
` t$ = "X: " + str$(x/16) + " Y: " + str$(y/16) + " FPS: " + str$(screen fps()) + " Length: " + str$(length) + " "
t$ = "SCORE: " + str$(score) + " "
text 0,0,t$

copy bitmap 1,0
sync

loop


dead:

blur bitmap 0,2
set current bitmap 0

repeat

center text 320,240,"haha u lose!"
sync

until spacekey()=1

end

WILL
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 7th Sep 2004 00:26
hey guys i just came out with a easyer version of it that the first one was to fast and i like the color and the shapes of this one beter here is the code for it


sync rate 0
sync on
hide mouse

` our snake sprite

ink rgb(225,345,345),0
box 2,3,4,5
get image 1,0,0,16,16

` our fruit

ink rgb(250,350,450),0
box 8,9,10,14
get image 2,0,0,16,16

` our border

ink rgb(150,250,350),0
box 5,8,10,14
get image 3,0,0,16,16

` "where is the snake?" array
` because the snake is 16x16 in size the game grid is 40x30

dim grid(40,30)

` add the border to the array

for a=0 to 40
grid(a,0) = 1201
grid(a,29) = 1201
next a

for a=0 to 30
grid(0,a) = 1201
grid(39,a) = 1201
next a

` initial variables

` d = direction (1=up, 2=right,3=down,4=left)
` x and y are starting location for the snake (must be offset of 16)
` eaten is the fruit value (1 = onscreen, 0 = eaten)
` speed is the delay between the snake moving in ms, decrese for speed!

d = 2
x = 320
y = 240
eaten = 1
score = 500
speed = 150
length = 2
placed = 0
t = timer() + speed

set text opaque
ink rgb(255,255,255),0

create bitmap 1,640,480

` the main loop

do

cls 0

if upkey() and d<>3 then d=1
if downkey() and d<>1 then d=3
if leftkey() and d<>2 then d=4
if rightkey() and d<>4 then d=2

` if it's time to redraw the snake then do so here

if timer()>t

if d=1 then dec y,16
if d=2 then inc x,16
if d=3 then inc y,16
if d=4 then dec x,16

if grid(x/16,y/16) > 0 and grid(x/16,y/16) < 1500
goto dead
endif

` have we hit some fruit? If so increase length and score

if grid(x/16,y/16) = 1500
inc length
grid(x/16,y/16) = length
eaten = 1
inc score,25
else
grid(x/16,y/16) = length
endif

t = timer() + speed

` length cascade

for a=0 to 40
for b=0 to 30
if grid(a,b) > 0 and grid(a,b) < 1201
temp = grid(a,b)
dec temp
grid(a,b) = temp
endif
next b
next a

endif

` new fruit (make sure it's not placed on an already occupied location)

if eaten = 1

repeat

fx = 2 + rnd(37)
fy = 2 + rnd(27)

if grid(fx,fy) = 0 then placed = 1

until placed = 1

grid(fx,fy) = 1500
eaten = 0
placed = 0

endif

` draw the game grid - this draws the game screen each sync

for a=0 to 40
for b=0 to 30

tempg = grid(a,b)
if tempg > 0
if tempg = 1500 then paste image 2,a*16,b*16
if tempg = 1201 then paste image 3,a*16,b*16
if tempg < 1201 then paste image 1,a*16,b*16
endif

next b
next a

` un-comment this line to see the debug information instead of the score
` t$ = "X: " + str$(x/16) + " Y: " + str$(y/16) + " FPS: " + str$(screen fps()) + " Length: " + str$(length) + " "
t$ = "SCORE: " + str$(score) + " "
text 0,0,t$

copy bitmap 1,0
sync

loop


dead:

blur bitmap 0,2
set current bitmap 0

repeat

center text 320,240,"haha u lose!"
sync

until spacekey()=1

end

WILL
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 7th Sep 2004 19:32
This isn't your code, it's Rich's.

For comparison purposes



Partly because this isn't a your code snippet, you're a theif and leaving this open will only incite trouble (and I'm itching to get locking something) this is locked. (don't think Rich'll mind too much )

Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"

Login to post a reply

Server time is: 2024-11-23 19:54:26
Your offset time is: 2024-11-23 19:54:26