
Advertisement
Ahmed Egyptian
Member
Content Count
32 
Joined

Last visited
Community Reputation
137 NeutralAbout Ahmed Egyptian

Rank
Member

Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
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. 
Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
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 ? 
Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
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 
Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
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. 
Setting an offset between centipede nodes
Ahmed Egyptian posted a topic in General and Gameplay Programming
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[i1].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; } } 
Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
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 :/ 
Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
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 rerun 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; } } } } 
Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
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; } } } 
it seems I need to read more in probability, can you suggest a book ? for that kind of problems ?

how did you calculate it ?

Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
any idea please ? 
Sorry guys about not asking a clear question. Lets say I have just one column of 3 dices x1, x2, x3 but I only will generate a random number from 1 >3 for each x what is the probability that when I do that, I get the same previous generated numbers for example random numbers from 1 > 3 first toss x1 = 2 x2= 2 x3 = 3 second time x1 = 2 x2= 3 x3 = 1 what is the probability to get the same first toss results or the same results again ?

Consider that I have two columns 1 6 2 9 5 10 If each elemtn from the first column I generate a random number from 1  > 3 and for each element for the 2nd column I generate a number from 4 >6 What is the probability that I get again the same numbers that was generated before and for how many times ?

Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
Thanks, I'm trying to have a better way for controlling the directions of the segments. so I added those xdir, ydir, initialized to 1,1. I don't know how to set a flexible directions. if (m_nodes[i].x > 750){ m_nodes[i].ydir = 1; m_nodes[i].xdir = 0; } in game loop m_nodes[i].x += m_nodes[i].vx*m_nodes[i].xdir; m_nodes[i].y += m_nodes[i].vy*m_nodes[i].ydir; 
Solving state machine problem for a centipede
Ahmed Egyptian replied to AhmedCoeia's topic in General and Gameplay Programming
@paradigm Can you tell me what do you mean by move down 1 block ? should I make the game as tile maps ? or you mean just move an amount of pixels ?

Advertisement