Snake

Learn to use DS Game Maker by Example.

Snake

Postby Bobbyloujo » July 11th, 2013, 2:40 am

I've seen it discussed before but never have I seen it done in DSGM. I sorta got it figured out. I just can't figure out what the heck it wrong with it! I'm going to blame it on a DSGM glitch :}

So, here's the deal: the snake starts with one segment. Collect a dot, you get a second segment. Collect another, you get a third. Collect another, a fourth. However, when you are supposed to get a fifth segment, it just freezes up. As far as I can tell, there's no reason the fifth segment should be any different from the 2nd, 3rd, or 4th. It's the same object! The exact same code! I just can't figure out why the fifth one doesn't behave the same. If you want to have look for yourself, I'll post the .dsgm here.

Oh, there's another weird thing about it. Before you compile, you have to open Object_Leader and then click "Accept" in it's window. For some reason, Object_Leader has to be the last window that you "Accept", otherwise the snake won't move.
Attachments
Snake.dsgm
Sauce
(2.86 KiB) Downloaded 286 times
DSGMTempSnake30158351.nds
Build
(288.56 KiB) Downloaded 254 times
Last edited by Bobbyloujo on July 16th, 2013, 2:18 am, edited 1 time in total.
Image
User avatar
Bobbyloujo
Site Admin
 
Posts: 1385
Joined: December 30th, 2010, 8:40 pm
Location: USA

Re: Snake (Incomplete)

Postby Buck_7 » July 11th, 2013, 3:09 am

I was just looking at a snake demo earlier today!

http://www.fampennings.nl/maarten/nds/(scroll all the way to the bottom, go to 6.8).
[EDIT]: Declare your array in a header file. eg. bool moved[128];
now it works ;) .
User avatar
Buck_7
 
Posts: 1460
Joined: February 19th, 2011, 1:44 am

Re: Snake (Incomplete)

Postby Bobbyloujo » July 11th, 2013, 3:22 am

Oh my gosh! Thank you Buck! I was getting so frustrated at this! I always hated DSGM's array declaring thingy. It should let you specify a size. Now that I have that out of the way, I can finish this!

[EDIT] Well, the snake seems to slow down after it gets pretty big. This probably isn't the most efficient engine for this. I'm going to come up with another!
Image
User avatar
Bobbyloujo
Site Admin
 
Posts: 1385
Joined: December 30th, 2010, 8:40 pm
Location: USA

Re: Snake (Incomplete)

Postby Nobody » July 11th, 2013, 4:07 am

I could never make a snake engine. It never worked when I tried. I might have to try again some day
Feel free to ask me for help. I'm on the forum a lot.

Recent Projects:
Retro Ducks: viewtopic.php?f=13&t=3533 (latest)
The Living Dead 2: viewtopic.php?f=13&t=3483
Crafters DS (Minecraft 2D Clone!) viewtopic.php?f=13&t=3082
User avatar
Nobody
 
Posts: 2323
Joined: February 14th, 2011, 12:08 am
Location: United States of America

Re: Snake (Incomplete)

Postby Bobbyloujo » July 11th, 2013, 5:58 am

For some reason, ideas for snake engines have been hitting me all day. I've a much better one almost done. There's just one thing I need to work out.
Image
User avatar
Bobbyloujo
Site Admin
 
Posts: 1385
Joined: December 30th, 2010, 8:40 pm
Location: USA

Re: Snake (Incomplete)

Postby Buck_7 » July 12th, 2013, 12:03 am

I just remembered I used to play this long a go.
User avatar
Buck_7
 
Posts: 1460
Joined: February 19th, 2011, 1:44 am

Re: Snake (Incomplete)

Postby Bobbyloujo » July 12th, 2013, 3:07 am

This is really frustrating me. My algorithm works every time on paper but not when I try to program it.
Image
User avatar
Bobbyloujo
Site Admin
 
Posts: 1385
Joined: December 30th, 2010, 8:40 pm
Location: USA

Re: Snake (Incomplete)

Postby Buck_7 » July 12th, 2013, 3:13 am

The link with the game also comes with the source if that helps anything. Maybe I'll try making a snake game for practice.
User avatar
Buck_7
 
Posts: 1460
Joined: February 19th, 2011, 1:44 am

Re: Snake (Incomplete)

Postby Bobbyloujo » July 16th, 2013, 12:11 am

I DID IT! I feel so accomplished :] Also, Buck, I looked at the source from your link and couldn't understand it. Granted, I didn't look at it very long because I wanted to figure it out myself.

I would explain my algorithm but I have to eat right now so I'm just gonna upload the source. There's one instance where I could think of that there might be a glitch but it would be very difficult to do so I don't think I'll really have to worry about it.

In the demo, press any direction to start. You are the dot closest to the middle. The other dot is the food.
Attachments
Snake.dsgm
source
(3.13 KiB) Downloaded 222 times
Snake.nds
demo
(288.56 KiB) Downloaded 231 times
Image
User avatar
Bobbyloujo
Site Admin
 
Posts: 1385
Joined: December 30th, 2010, 8:40 pm
Location: USA

Re: Snake (Incomplete)

Postby Nobody » July 16th, 2013, 12:38 am

looking at your code really makes sense now. I can't believe I didn't think of this before. And DSGM has a built in next instance function: "NextInstance()"
Feel free to ask me for help. I'm on the forum a lot.

Recent Projects:
Retro Ducks: viewtopic.php?f=13&t=3533 (latest)
The Living Dead 2: viewtopic.php?f=13&t=3483
Crafters DS (Minecraft 2D Clone!) viewtopic.php?f=13&t=3082
User avatar
Nobody
 
Posts: 2323
Joined: February 14th, 2011, 12:08 am
Location: United States of America

Re: Snake (Incomplete)

Postby Buck_7 » July 16th, 2013, 12:45 am

Nice work
User avatar
Buck_7
 
Posts: 1460
Joined: February 19th, 2011, 1:44 am

Re: Snake (Incomplete)

Postby Bobbyloujo » July 16th, 2013, 12:53 am

Nobody wrote:looking at your code really makes sense now. I can't believe I didn't think of this before. And DSGM has a built in next instance function: "NextInstance()"

Yeah I used it. If you look at the declaration of "next" it's like this:

next
int
NextInstance()

It's just kinda left over code. I used a variable in case I needed to know which instance ID I just created. I ended up not using it so that variable could be removed and the Instance ID of the new segments could just be NextInstance().

Buck_7 wrote:Nice work

Thanks!
Image
User avatar
Bobbyloujo
Site Admin
 
Posts: 1385
Joined: December 30th, 2010, 8:40 pm
Location: USA

Re: Snake (Incomplete)

Postby Nobody » July 16th, 2013, 2:08 am

ah, that makes since bobby
Feel free to ask me for help. I'm on the forum a lot.

Recent Projects:
Retro Ducks: viewtopic.php?f=13&t=3533 (latest)
The Living Dead 2: viewtopic.php?f=13&t=3483
Crafters DS (Minecraft 2D Clone!) viewtopic.php?f=13&t=3082
User avatar
Nobody
 
Posts: 2323
Joined: February 14th, 2011, 12:08 am
Location: United States of America

Re: Snake

Postby Bobbyloujo » July 19th, 2013, 7:18 pm

After playing around with this some more, I've noticed that occasionally a segment will still get left behind. This happens when the newest segment is still looking for it's place in line and switches with the next segment to be moved to the front of the line. I thought I had accounted for this but I guess not. I'm still working on it because I would like to make a complete game out of this.
Image
User avatar
Bobbyloujo
Site Admin
 
Posts: 1385
Joined: December 30th, 2010, 8:40 pm
Location: USA

Re: Snake

Postby Bobbyloujo » July 19th, 2013, 11:50 pm

Double posting because screw the rules.

This is the last one! I promise! It works every time. I ended up going back to my original idea. Starting at the tail, each segment takes the place of the one in front of it. The head then moves in the direction the snake is moving. This time, I used a loop inside the controller object to move all of the segments rather than having each segment move itself. To do this, I had to loop backwards so I made my own loop action and called it "Advanced Loop". I'll upload it.

I'm not happy that I had to resort to moving every segment every time the snake moves but by doing it in a loop in a single object it doesn't appear to slow down as the snake gets really long. I got it up to at least 53 segments and it didn't slow down. I wish I could've gotten my other method working, but for some reason a single segment would sometimes get left behind. It happened whenever the newest segment was still trying to find it's place and it switched with the next segment to be moved. I accounted for this and it worked almost every time but sometimes that last segment would still get left behind. :evil:

Anyway, here is my new example. It is more complete with better graphics, the ability to lose, and score.
Attachments
Snake.dsgm
source
(4.03 KiB) Downloaded 228 times
Snake.nds
demo
(291.56 KiB) Downloaded 238 times
Advanced Loop.action
Custom "Advanced Loop" action
(178 Bytes) Downloaded 224 times
Image
User avatar
Bobbyloujo
Site Admin
 
Posts: 1385
Joined: December 30th, 2010, 8:40 pm
Location: USA

Re: Snake

Postby Buck_7 » July 20th, 2013, 6:57 pm

Cool. I got up to 45 testing it out. In your game the head or tail graphic does not show at either ends.
User avatar
Buck_7
 
Posts: 1460
Joined: February 19th, 2011, 1:44 am

Re: Snake

Postby Bobbyloujo » July 20th, 2013, 11:13 pm

Buck_7 wrote:Cool. I got up to 45 testing it out. In your game the head or tail graphic does not show at either ends.

Yeah I know. I made the graphics but never actually implemented it. Actually the graphics need to be reworked a bit because they look offset at some angles.
Image
User avatar
Bobbyloujo
Site Admin
 
Posts: 1385
Joined: December 30th, 2010, 8:40 pm
Location: USA


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron