This site requires JavaScript, please enable it in your browser!
Greenfoot back
xJesterPROx
xJesterPROx wrote ...

2015/1/14

Array Problems

xJesterPROx xJesterPROx

2015/1/14

#
I am making a Snake like game for a school project and i need to use an array to make the body parts to the Snake follow the head. Can someone help me please?
xJesterPROx xJesterPROx

2015/1/15

#
Right now the Snake body and Snake Head are two different classes
danpost danpost

2015/1/15

#
Was it part of the assignment that you must use an array? Do your SnakeBody and SnakeHead classes extend Actor or Snake?
xJesterPROx xJesterPROx

2015/1/15

#
no, but i heard that if you want to make the body follow the snake, you should use an array. and they both extend from the Actor class, but i can change that if needed.
danpost danpost

2015/1/15

#
xJesterPROx wrote...
no, but i heard that if you want to make the body follow the snake, you should use an array.
The problem with using an array is that arrays have a fixed length and your snake will probably be growing. And even if it does not grow right now, you may want to implement that later. I have several snake demos on the site with source available for different working methods of doing this. Click on my user profile image to go to my page; on the lower right, select the 'Demos by danpost' collection. You will find 3 snake demos with source.
xJesterPROx xJesterPROx

2015/1/16

#
ya, i looked at them before, but i have no idea what the code in the classes actually mean, and I want to learn about this, not just copy and paste it, is there anyway that i could have any, preferably all, of that code explained?
danpost danpost

2015/1/16

#
If you post what code you want explained and tell me which demo and class it came from, sure.
xJesterPROx xJesterPROx

2015/1/16

#
In your second Demo, can you explain to me how the tail knows how to follow the head? I would post the code that covers things like direction and spawning the tail is almost the entire snake class.
You need to login to post a reply.