Snake-like movement and animation

Get help using Construct 2

Post » Wed Sep 05, 2012 2:22 pm

I was wondering how can I implement a snake-like movement and animation.
I mean the old snake game found in nokias where you have to catch apples.
Do i use one block and attach one every time i catch and apple? should i make and array?
I'm lost.
B
34
S
4
G
5
Posts: 84
Reputation: 4,835

Post » Wed Sep 05, 2012 5:23 pm

You may do it by the easiest way.

- Make the head and 2 or 3 body parts;
- Set the origin point of each image to be at bottom or right, or left, or up, but keep the same for all of them;
- Add a new point on the opposite side;
- Set their X and Y origin to match the second point of the sequenced body part, example, the first body part will pin to the head, then, ahead;
- Make a number instance variable for the body parts and call it by "ID";
- The body parts and head on the canvas, you'll set their ID manually, but each time the snake eat a apple, you'll need to add one to the ID count and set to create a new body part, attaching it to the body part with the ID-1;

You can improve it by doing a tail on a new frame animation for the body parts, and checking if it's the highest ID, if so, change its sprite number, also, make the animation speed to 0.

For more information, please, read this tutorial, it may help understand how to get a specific item on the canvas and for future projects! =]

http://www.scirra.com/tutorials/361/understanding-uid-iid-health-of-enemies-and-rocket-smoke-trail
ImageImageImageImageImageImage
B
93
S
19
G
12
Posts: 1,209
Reputation: 18,357

Post » Wed Sep 05, 2012 7:44 pm

Snake type game example R101



Use arrow keys to control the snake.

PLAY

DOWNLOAD CAPX

All graphics and textures my be..feel free to use or modify.
B
19
S
6
G
7
Posts: 1,205
Reputation: 7,298

Post » Fri Sep 07, 2012 12:18 am

Wow, thanks both of you!

chrisbros is there a way on your demo to kill the snake when it collides with itself?

TELES0808 Im going to try your method!
B
34
S
4
G
5
Posts: 84
Reputation: 4,835

Post » Fri Nov 02, 2012 8:28 am

Thanks for this. It's a lot better than my attempts with GameMaker and PyGame. GameMaker has a nasty lag problem with keyboard events that ruins games like this.
B
2
Posts: 1
Reputation: 352

Post » Mon Sep 23, 2013 2:14 pm

[QUOTE=chrisbrobs] Snake type game example R101



Use arrow keys to control the snake.

PLAY

DOWNLOAD CAPX

All graphics and textures my be..feel free to use or modify.[/QUOTE]
@chrisbrobs hi, can you reupload? thx
B
12
S
3
G
1
Posts: 347
Reputation: 2,866


Return to How do I....?

Who is online

Users browsing this forum: dieblume86, Kagubro and 2 guests