# Snake game

**URL:** <https://forum.kirupa.com/t/snake-game/7985>\
**Category:** flash\
**Created:** [November 11, 2002, 9:22pm UTC](https://forum.kirupa.com/t/snake-game/7985 "2002-11-11T21:22:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abraxxas](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@Abraxxas](https://forum.kirupa.com/u/Abraxxas)\
**Post date:** [November 11, 2002, 9:22pm UTC](https://forum.kirupa.com/t/snake-game/7985/1 "2002-11-11T21:22:06Z")

</div>

Yeah, I’ve been trying to make a snake game. You know snake as in the Nokia game, right? Well, so I’ve got this little dot movin by my keymoves across the screen, and smaller dots are randomized across the screen. When the two dots collide, 1+ points and a new randomized dot position. Now, i want the snake to grow one module when a dot is “eaten”. I have used

clone++  
duplicateMovieClip("\_root.snake", “slave” add clone, clone);

To create clone-modules named slave1, 2, 3 etc etc. Now, these only appears where they were created, how can i make them follow the master module in a line, as in the real game?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2002, 10:59pm UTC](https://forum.kirupa.com/t/snake-game/7985/2 "2002-11-11T22:59:50Z")

</div>

Now I’m no masta flasha, and I dont know the action script, but you know the \_x and \_y stuff? I think it would involve that, but I dont know.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 12, 2002, 9:15am UTC](https://forum.kirupa.com/t/snake-game/7985/3 "2002-11-12T09:15:25Z")

</div>

Lol, thatz a conclution i reached myself man, but thanks anyway =D

Im quite a newbie to flash myself actually, and somewhy i thought a snake game would be easy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2002, 1:25am UTC](https://forum.kirupa.com/t/snake-game/7985/4 "2002-11-13T01:25:03Z")

</div>

i think if you add this it should work, but i haven’t tried it and am not a masta flasher. it could hurt to try tho right? anywho, add this to the actions of the dot your cloning  
\<hr\>  
onClipEvent(load) {  
num = \_root.clone;  
}

onClipEvent(enterFrame) {  
if (this.\_name != “snake” || this.\_name != “slave1”) {  
this.\_x = \_root[“slave” + (num-1)].\_x;  
this.\_y = \_root[“slave” + (num-1)].\_y;  
} else if (this.\_name == “slave1”) {  
this.\_x = \_root.snake.\_x;  
this.\_y = \_root.snake.\_y;  
}  
}  
\<hr\>

that should do it. lemme know if you need some explaining or if it doesn’t work and i’ll see what i can do.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2002, 6:59am UTC](https://forum.kirupa.com/t/snake-game/7985/5 "2002-11-13T06:59:42Z")

</div>

Thx for that. I can understand the thinking behind what you have written. There’s just one other thing that came to me, though, if  
this.\_x = \_root.snake.\_x;  
and so on, wouldn’t that make the position of Slave1 the EXACT position of the original snake? I might be wrong, though, just a thought. I’m currently accessing this site from my school, however, so I havn’t tried it out yet, but I’ll give it a try. Thanx man!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2002, 7:04am UTC](https://forum.kirupa.com/t/snake-game/7985/6 "2002-11-13T07:04:07Z")

</div>

oh omg! i screwed up this is what i meant:  
\<hr\>  
onClipEvent(load) {  
num = \_root.clone;  
}

onClipEvent(enterFrame) {  
if (this.\_name != “snake” || this.\_name != “slave1”) {  
this.\_x = \_root[“slave” + (num-1)].\_x-20;  
this.\_y = \_root[“slave” + (num-1)].\_y-20;  
} else if (this.\_name == “slave1”) {  
this.\_x = \_root.snake.\_x-20;  
this.\_y = \_root.snake.\_y-20;  
}  
}  
\<hr\>

mess with the value 20 to get the right effect

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2002, 7:26am UTC](https://forum.kirupa.com/t/snake-game/7985/7 "2002-11-13T07:26:23Z")

</div>

But then, wont Slave1.\_x&\_y always be snake.\_x&\_y-20 and so on with Slave2 relative to Slave1 etc etc etc?

Then my snake will be leaning like a slashsign all the time nomatter what direction, right?

Cuz you know whent the snake moves to the right, for example, i want the Slave1 coordinates to be x: snake.\_x-20 y: snake.\_y  
And so on, you follow? Then, a way to solve it could be:

on (keyPress “\<Right\>”) {  
\_root.move = “right”;  
}

and

if (\_root.move == “right”) {  
coordinate conditions  
}

Then i could set it to different coordinates on different directions, but we’d still have a problem: if I’m situated right next to the left border and press the right button all the slaves would be placed in a straight line directly, they wouldnt move there one by one

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2002, 10:01pm UTC](https://forum.kirupa.com/t/snake-game/7985/8 "2002-11-13T22:01:20Z")

</div>

hmm…

good question. like i said i haven’t gotten to really try anything like so…

have you tried it out? if so then post the .fla

if you have then i think the best solution would be to mess around with the whole “\_root.move = ‘right’” and such. i really can’t figure an easy way out of this one. so just try different things and see what happens. if you get stuck post again and i’ll see what i can do.

gl!
