# Ahmed Egyptian

Members

32

137 Neutral

• Rank
Member
1. ## Solving state machine problem for a centipede

I just don't need to use a tile map, and a basic centipede movement where I can place the nodes (pictures) with an offset between each node.
2. ## Solving state machine problem for a centipede

Thanks for the inputs.   I have initialized the nodes as follow. The gab can not be defined here, as whatever happens the node's prev position will be copied anyway. How would I set it ?  for (var i:int = 0; i < 5; i++) { var sprite:Node = new Node(); sprite.x = 100 + i * 90; sprite.y = 20; sprite.vx = -1; sprite.vy = 0; sprite.previousDirX = -1; m_nodes.push(sprite); addChild(m_nodes[i]); } Regarding the memorization technique, and the collision I have done that, it works but still a lot of flaws.   Is the algorithm correct ? if (m_nodes[0].x > 750) { delayCounter++; if (delayCounter == 1) { m_nodes[0].previousDirX = m_nodes[0].vx; } m_nodes[0].vx = 0; m_nodes[0].vy = 1; if (delayCounter > 2) { delayCounter = 0; trace("prev" + m_nodes[0].previousDirX); m_nodes[0].vx = -1 * m_nodes[0].previousDirX; m_nodes[0].vy = 0; } } } How did you ident your code that is posted here ? manually ?
3. ## Solving state machine problem for a centipede

I'm not using any tilemap, why should I use a tile map to let the sections not overlap ? the current problem is they are like this xxxx  instead of  x    x    x   x    x  x
4. ## Solving state machine problem for a centipede

Thank you so much!. will follow all things you mentioned.  I have another problem, which is setting an offset between the nodes, they are overlapping each other.
5. ## Setting an offset between centipede nodes

Hi All,   I'm trying to set an offset for a snake or centipede nodes. I don't know the math behind it.  The centipede nodes follow the head, hence the position is copied.    I tried the following idea, but it didnt work for (var i:int = m_nodes.length - 1; i >= 0; --i) { if (i != 0) { /* m_nodes[i].x = m_nodes[i - 1].x; m_nodes[i].y = m_nodes[i - 1].y;*/ var currAngle:int = m_nodes[i].rotation + m_nodes[i-1].rotation; trace("curr Angle"+currAngle); m_nodes[i].x = m_nodes[i - 1].x + Math.cos(currAngle); m_nodes[i].y = m_nodes[i - 1].y + Math.sin(currAngle); } else { m_nodes[0].x += m_nodes[0].vx * (100) * dt; m_nodes[0].y += m_nodes[0].vy * (100) * dt; } }
6. ## Solving state machine problem for a centipede

I debugged it a lot I still can't find where is the problem.  The space between the nodes can not be adjusted correctly relative to the speed and the collision also dismisses at a lot of cases :/
7. ## Solving state machine problem for a centipede

I tried the following approach, but there are a lot of in correct logic.  I also would like to control the displacement between the nodes of the centipede. Kindly find the attached .swf, try to run it, also close it, then re-run it get it different mushrooms.  public function gameLoop(event:Event):void { var t:int = getTimer(); var dt:Number = (t - _t) * 0.001; _t = t; for (var i:int = m_nodes.length - 1; i >= 0; --i) { if (i != 0) { m_nodes[i].x = m_nodes[i - 1].x; m_nodes[i].y = m_nodes[i - 1].y; } else { m_nodes[0].x += m_nodes[0].vx * (100) * dt; m_nodes[0].y += m_nodes[0].vy * (100) * dt; } } for (var i:int = 0; i < m_nodes.length; i++) { var savedDir:int = m_nodes[i].vx; for (var b:int = 0; b < m_bricks.length - 1; b++) { if (m_nodes[0].hitTestObject(m_bricks[b])) { m_nodes[0].vx = 0; m_nodes[0].vy = 1; delayCounter++; if (delayCounter > 5) { delayCounter = 0; m_nodes[0].vx *= -1;  m_nodes[0].vy = 0; } } } if (m_nodes[0].x > 750) { m_nodes[0].vx = 0; m_nodes[0].vy = 1; delayCounter++; if (delayCounter > 5) { delayCounter = 0; m_nodes[0].vx = -1; m_nodes[0].vy = 0; } } else if (m_nodes[0].x < 40 && m_nodes[0].y < 500) { trace("x < "); m_nodes[0].vx = 0; m_nodes[0].vy = 1; delayCounter++; if (delayCounter > 5) { delayCounter = 0; m_nodes[0].vx = 1; m_nodes[0].vy = 0; } } if (m_nodes[0].y < 40 && m_nodes[0].x < 40) { trace("y <  x <"); m_nodes[0].vx = 0; m_nodes[0].vy = 1; delayCounter++; if (delayCounter > 5) { delayCounter = 0; m_nodes[0].vx = 5; m_nodes[0].vy = 0; } } else if (m_nodes[0].y > 560 && m_nodes[0].x > 40) { trace("y > x < "); m_nodes[0].vx = -1; m_nodes[0].vy = 0; } } } }
8. ## Solving state machine problem for a centipede

I found a problem with the above approach ( looping thru all nodes and check if a node collided with a mushroom), which is they are seperated, and if they collided, some times, they get glitches, and all the nodes get their own movement, and like all the nodes are distorted and they are randomly moving.     The problem is the other nodes should really follow the head, correct ?    How is it possible to let each node move down one and reverse the velocity ? and all of them should be synchronized ? for each node {for (var b:int = 0; b < m_bricks.length - 1; b++) { if (m_nodes[i].hitTestObject(m_bricks[b])) { trace("hit"); m_nodes[i].vx = 0; m_nodes[i].vy = 5; m_nodes[i].vx = m_nodes[i].previousDirX*-1; m_nodes[i].vy = 0; } } }
9. ## Probability question

it seems I need to read more in probability, can you suggest a book ? for that kind of problems ?
10. ## Probability question

how did you calculate it ?