
Game Maker Tutorial: Snake Game
Veralos
Views: 31760
Like: 246
A tutorial on how to make a “Snake” game in Game Maker. If you don’t know what Snake is, it’s an old game where you play as a snake. You must collect points while avoiding your tail, which grows longer depending on the score.
This tutorial was requested by halohunter7676.
I would like to have some feedback on this tutorial. Was it too simple or too complex? Did it explain enough or did it explain too much? Should I do tutorials in drag and drop or GML? I want to know what people think, so I can hopefully improve if I make another one in the future.
Wow, it’s been a long time since I last uploaded something…
06.04.2023
hey!, I have a question, why do I keep getting this error : Error in Object obj_head, Event Collision obj_tail, Action 1 at Line 1, Position 1: Unknown function or script: highscore_show ?
Thanks in advance 🙂
Could somebody help me with this error? please
FATAL ERROR in
action number 1
of Step Eventobj_food
for object obj_head:
Push :: Execution Error – Variable Get -1.obj_control(100005, -1)
at gml_Object_obj_head_CollisionEvent_1 (line 8) – obj_control.alarm[0]=30*global.spd
Thank you so much for this, I thought the video was a bit quick for super beginners like me. but I was able to keep up 😀
I ran into an issue with highscore_show
it said it was an invalid command…
I can play the game but there isnt spawned a tail behind the head. Any ideas to fix it?
The snake wont automatically start moving
Good tutorial but when i go up it doesnt go to the bottom but it working for every other side, can you help?
i can't do the last part where i have to fill this in :
draw_set_halign(fa_center)
if alarm[0]>0
draw_text(room_width/3,0,''Special Time: ''+string(ceil(alarm[0]/30)))
draw_text(room_width/3*2,0,''Score: ''+string(global.points))
it says in line 3 position 28 there have to be , or )
but not only there on multipuple spots i have tried it but that didnt work,
Can you help me??
—This is a message sent in reply to Veer Barmi's comments. I thought I'd also add it here so anyone else can see it—
"how do i get the food to stay in one spot?"
"and when you collect it, it will add only one to you and then vanish?"
Remove this from the control object's "create" event:
with (food) {
do
move_random(32, 32)
until
place_empty(32, 32)
}
Remove the same segment from the snake object's "collision with food object" event and replace it with this:
with (other) instance_destroy()
Presumably you want to be able to place where the food starts. To do this, remove the following in the control object's "create" event:
food=instance_create(0,0,obj_food)
You can then place the food wherever you want using the room editor.
In future please enables replies on your comments when asking a question so I can respond to you more easily.
hey! how would i use this to rotate the body sprite?(having trouble getting the sprites to turn only after you turn) and also how would i add another part of the snake?(ie a actual tail)
—This message is in reply to Kalenna Ree's comment. In future please enable replies on your comment when asking a question—
"hey! how would i use this to rotate the body sprite?(having trouble getting the sprites to turn only after you turn) and also how would i add another part of the snake?(ie a actual tail)"
To get the tail parts to rotate, first give the tail sprite a rotation animation similar to the head sprite (four frames, the first pointing right and the rest moved 90 degrees counter-clockwise each time). Then, give the tail object a Create event with this code:
image_speed = 0;
Add this to the end of the head object's Alarm 0 event:
tail.image_index = image_index;
This will set the created tail piece's direction to the head's current direction.
I don't understand the second part of your comment. Could you please clarify what you meant?
Excellent video!!! Thanks so much for uploading!
Thanks for the tutorial i love it. But i have a problem. When i click the "Run the game" button it wont open. At first i comes the CompileForm window, and then a window who stands in it: Made wirh GameMaker studio. But then nothing happens. What should i do? Sorry for my bad Englisch.
When i press play on 4:25 the snake dont move. Help me please!!!
http://i.hizliresim.com/2k5Nk2.png staying here help me please
i am turkish 🙂
_________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_head:
Push :: Execution Error – Variable Get 100000.x32(100003, -2147483648)
at gml_Object_obj_head_CreateEvent_1 (line 7) – tail=instance_create(x32*n,y,obj_tail)
############################################################################################
my snake instanly dies
and the snake disapersed
Hi! so i followed your tutorial, however i want the snake game to be in an enclosed area (surrounded by walls that are solid) in the lowerhalf of my room, and have a sort of logo at the top with the score etc. however, i cant stop the food from spawning outside the walls of the enclosed area. is there a way to make the food spawn randomly in a certain area and not outside that certain area?
SICK video had a few errors but it turned out i had mispelt control haha works perfectly for me!!
please help!!
ERROR in
action number 1
of Alarm Event for alarm 0
for object obj_head:
Error in code at line 2:
tail.alarm[0]=global.spd*(5+floor(global.points/2))
at position 42: Unknown variable points
thank you so much you are a legend
i have a border on the right and the lower wall, where i cant be with my snake, but food spawn there. plz halp
When the snake hits the yellow food nothing happends. What did I wrong?
Hey bud, nice tut! If I might ask, do you happen to know what the "Magic Number" is for have the tail length go up by 1 for every point you get?
When i launch the game i can see only gamemaker studio write on the screen vut nothing launches :/
I have the exact sale thing but it won't work PLEASE HELP MAN
how would you add an object that on collision, would add like 5 tails instantly to your tail
okay, so I'm doing this for school, right. well, I did everything up until the first test of the game correctly. I checked the codes and everything three times even. but when I tested it it only popped up with the even Made with Game Maker Studios and gets stuck. Does that mean I did something wrong somewhere even after checking all that or Game Maker is just screwing up and I have to start over? also, how could I make my snake have like a more realistic tail (y'know, pointed instead of square) cause if I do it this way with the pointed tail the snake will look odd.
I did something wrong?
FATAL ERROR in
action number 1
of Draw Event
for object obj_hud:
global variable points(100001, -2147483648) not set before reading it.
at gml_Object_obj_hud_DrawEvent_1 (line 4) – draw_text(room_width/3*2,0,"Score: "+string(global.points))
You should make a new video about this, seeing how it got tons of views, and please write comments on the code if you do c: I had to do so in my own, because I couldn't tell what was happening most of the time :/ But awesome video dude!
Coders help! Line 9 is giving me a compile error. I have no idea why, and I made sure it's the same code as in the video. I'm still new to GML so if i were more experienced I'd probably understand what happened, but I think that the compiler is generating too many tails :/ PLZ HALP
global.spd = 5
global.canwarp = true //If true, the snake will warp through walls.
canturn = false
image_speed = 0
alarm[0] = global.spd
//Generate a short tail behind the snake when the game starts.
repeat(5) {
tail = instance_create(x-32*n,y,obj_tail)
tail.alarm[0] = global.spd*(6-n)
n-=1
}
Hi,everything else works with your project execpt my snake keeps moving right and then it repeats and repeats:I also cant control it.Please help.
Highscore_show appears to have disappeared in the GML's functions ?
my game fails to load. compiler states "entering main loop" but nothing happens afterwards
when the snake hits the food the head bounces the opposite direction and hits the tail? 🙁
highscore_show doesn't show up?
my body follows the head but it leaves space and if I turn the snake spaces increase more
Hey! Nice video but I have a problem, on the first time you test the game (when you have only the snake), the compile would never finish, it just stayed at the quote, Entering main loop. If you could help me on this I would be very grateful!
how would you reset the high scores?
when I hit the obj_food it shows up the highscore table?
solved! Thx! amazing game!!
_________________________________________
FATAL ERROR in
action number 1
of Draw Event
for object obj_control:
COMPILATION ERROR in code action
Error in code at line 3:
draw_text (room_width/3,0"Special Time: "+string (ceil(alarm[0]/30)))
^
at position 27: Symbol , or ) expected.
_________________________________________
FATAL ERROR in
action number 1
of Alarm Event for alarm 0
for object object0:
COMPILATION ERROR in code action
Error in code at line 1:
tail-instance_create(x,y,sprite1)
^
at position 5: Assignment operator expected.
FATAL ERROR in
action number 1
of Create Event
for object obj_head:
COMPILATION ERROR in code action
Error in code at line 4:
alarm(0)=global.spd
^
at position 2: Unknown function or script: alarm
9:36 special
It was a great tutorial however, I would like the snake to look more real and for you to slow down a bit otherwise it was a very good tutorial…
thank you
i wish that i could see
i tried this but when i run it it creates more parts every time i move insted of when i eat a food object