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

Report as inappropriate.

TheGoldenProof
TheGoldenProof presents ...

2018/10/11

Can't figure out why its not working

Trying to make snake a more advanced way than the other people in my class but im running into a problem. Right now, I have a list of snake blocks and I want them to use whatever block is infront of them to determine where to go, but for some reason it only works for the first block. I dont understand why the first works and the others don't. can someone help?

You have to add Food manually.

1847 views / 10 in the last 7 days

Tags: None

open in greenfoot
Your browser does not support the canvas tag.
Super_HippoSuper_Hippo

2018/10/12

I am not exactly sure what causes it, but you are making it harder than it is. If your Body/Head extend Snake, you should not have fields with the same name as in the Snake class. How I just made it work: Remove all "direction" variables, the "go" and "calcV" methods, simply turn the actor in the direction it should move and move it with the move method. Then when adding a new body part, you can add it to the world with the same rotation as the last one and move it back one cell. Save the "prevdir" at the beginning of the act method of Body/Head.

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.