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.

2D All the way! / SNAKE GAME

Author
Message
Crazy Programmer
AGK Developer
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 6th Sep 2004 23:13
SORRY GUYS THE FIRST ONE DIDNT COME OUT RIGHT I AM NEW TO THE FORMS I JUST JOINED YESTER DAY IM STILL GETING USE TO THEM LOL LETS SEE IF THIS COPY OF SNAKE WORKS
PLEAS TELL ME IF U HAVE AND INPROVMENTS THANK YOU


[email]

WILL
Crazy Programmer
AGK Developer
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 6th Sep 2004 23:38
i dont know y but it wont let me post my sourse code i will just put it in the message here it is just copy and past it thank you



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
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 7th Sep 2004 02:33 Edited at: 7th Sep 2004 02:38
Please do not post the same thing in multiple places.
http://forum.thegamecreators.com/?m=forum_view&t=38627&b=6

You can use code tags in your post. Like this but without the spaces.
[ code ]
some code
[ /code ]

eg


One improvement would be to stop the snake from reversing into its self.
For instance when the snake is traveling to the right and quickly press the up key then the left key you die.


it's cool to hate
Crazy Programmer
AGK Developer
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 7th Sep 2004 04:39
thank u for that i will try to fix it

WILL
Crazy Programmer
AGK Developer
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 7th Sep 2004 05:03
how do i use code tags i wonder if this works



WILL
Crazy Programmer
AGK Developer
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 7th Sep 2004 06:54
ok i will try not to put the same thing

WILL
Dot Merix
22
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 7th Sep 2004 13:19
Also, it has been mentioned by Richard Davey that this is his code.. with removed copyright and mentionings of tgc, or himself.

- Merix

Athlon xp 2400+, 1.0GB Ram, Radeon 9800PRO 128mb
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th Sep 2004 22:12
Crazykid,
I see you paid no attention to your other post or the comments there-in.

Please don't post other peoples work unless your gonna credit them, or leave the credits in the source.

Please don't make multiple posts of the same thing.

Please don't use capitals as it indicates aggression.

Please use the edit function, it keeps your topic much neater.


A word of warning to those looking for snake source for the TGC compo - Rich knows this code inside and out, so expand on it as much as you can, or use it as a guide for your own version - submitting this with some new graphics and a menu won't cut it.


Van-B


Muhahahahaha.
Crazy Programmer
AGK Developer
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 11th Sep 2004 06:53
hey guys im sorry i posted this on the 6th and it just now came out and i dont know y

Will
Crazy Programmer
AGK Developer
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 2nd Oct 2004 12:09
[img] http://runescape.com/ [/img]

crzy programer
Crazy Programmer
AGK Developer
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 2nd Oct 2004 12:10
still cant load a pic

crzy programer
1tg46
22
Years of Service
User Offline
Joined: 1st Feb 2004
Location: I dont know!
Posted: 3rd Oct 2004 04:44
Don't post a messgae right after the other a minute later. I see the time difference of the previous two posts of yours are 1 minute apart which is why I said this.

If you want to add something to a post you just made click edit (if available, may not be their if you are a noob), then edit the message adding what you wanted in edit tags (you need to make these manually their is no button to insert these) [edit] [/edit].


1tg46 is my name coding is my game.
Ooska
21
Years of Service
User Offline
Joined: 29th Aug 2004
Location:
Posted: 6th Oct 2004 10:07
How do you make a sprite move using the arrow keys?

Weird = Unique. Unique = Human.
Crazy Programmer
AGK Developer
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 6th Oct 2004 20:58
u can use riches code for example

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

crzy programer

Login to post a reply

Server time is: 2026-06-11 17:33:57
Your offset time is: 2026-06-11 17:33:57