A small snake game
I want to create a small game of snake
The snake is composed of a header and 10 (or more) body members
Each part consists of a circle and covering slightly
The head (yellow) and will move the body (orange) should follow (see attach image)
I spent a lot of time on the examples supplied with Gideros and examples appcodingeasy.com Site
I analyzed:
b2.KINEMATIC_BODY: to have no gravity
b2.DistanceJoint: to keep the elements close
createFixture: I have more trouble
....
I'm sure the program (without moving) must take months to 100 lines, but I can not do
I need your help
AhBadiane
Comments
1. Declare a snake Head circle. Declare others 9 circles, specify their position to form a snake, add these 9 pieces into a sprite group called grpSnakeBody
On ENTER_FRAME event:
1. Move Head by updating its position.
2. Loop through grpSnakeBody, update their movement according to its head.
3. Check if each of circle reach top edge of screen, then update it position to bottom edge, the same if it reach left edge then update its position to right edge.
On MOUSE_UP event:
4. Store event.x and event.y, store the current head position (headX, headY) then move the head to current event.x, event.y position
5. Move all snake body items to the event.x, event.y when ever they reach headX, headY
Ultimate Games on Appstore
Ultimate Games on Google Play
I thought that would DistanceJoint the solution?
not sure i am going to help you or going to make you more confuse
@all
i had made one small example
but now the problem is how can i increase the speed of snake if i change my speed variable x and y to 20 there is a big space between each circle
any idea for this
By changing the function onEnterFrame (), I should do it (avoid gaps or overlaps that gives a tiny snake)
But I remain convinced that the solution lies in http://appcodingeasy.com/Gideros-Mobile/Gideros-Box2d-Chains-and-Elastic-Ropes example, but the code is too complex for me (
But if you want a traditional snake game, then there won't be much of a point from box2d, because you would have to update position of each cell manually (without box2d) in loop, to match position of previous cell, basically what @hgvyas123 did.
So what exactly do you want?
Hope this helps
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Moving snake in shortest possible code?
Using @hgvyas123's method all segments have to be re-calculated every time.
Using my method only the head has to be recalculated unless the snake has changed direction then only one segment needs moving at a time until they are all going in the same direction.
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
@ar2rsawseen, you ask the right question. My snake must control a ball in a breakout. It replaces the classic paddle