360 snake movement
Posted
by
Darius Janavicius
on Game Development
See other posts from Game Development
or by Darius Janavicius
Published on 2012-10-19T16:44:57Z
Indexed on
2012/10/19
17:19 UTC
Read the original article
Hit count: 314
actionscript-3
I'm trying to do 360 degree snake game in actionscript 3. Here is my movement code:
//head movement
head.x += snake_speed*Math.cos((head.rotation) * (Math.PI /180));
head.y += snake_speed*Math.sin((head.rotation) * (Math.PI /180));
if (dir == "left") head.rotation -= snake_speed*2;
if (dir == "right") head.rotation +=snake_speed*2;
//Body part movement
for(var i:int = body_parts.length-1; i>0; i--)
{
var angle = (body_parts[i-1].rotation)*(Math.PI/180);
body_parts[i].y = body_parts[i-1].y - (25 * Math.sin(angle));
body_parts[i].x = body_parts[i-1].x - (25 * Math.cos(angle));
body_parts[i].rotation = body_parts[i-1].rotation;
}
With this code head moves just like I want it to move, but body parts have the same angle as head and it looks wrong. What I want to achieve is to make body parts to move like in game "Ultimate snake". Here is a link to that game: http://armorgames.com/play/387/ultimate-snake
P.S. I saw similar question here "How to approach 360 degree snake" but didnt understand the answer :/
© Game Development or respective owner