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

2014/4/4

Use Greenfoot.isKeyDown(string) to control objects of different classes

sliu.gsis sliu.gsis

2014/4/4

#
I have programmed a greedy snake game with 2 Actor classes: Head and SnakeBody. The coordinates of the head are added to lists of SnakeBody objects that have been eaten step by step. Each SnakeBody object follows the list of the coordinate so that they all follow the trace of the head. I use isKeyDown() to control the "one-step" movement of head and the SnakeBody (With speed of around 1.5 level). However, I realize only the head is well controlled. For the SnakeBody, I used the following statement (pseudo) if :(Greenfoot.isKeyDown(up) OR Greenfoot.isKeyDown(down) OR Greenfoot.isKeyDown(left) OR Greenfoot.isKeyDown(right)) then: moveAccordingToCoordList(); It seems there are three or four "bubbles" between the head the first eaten SnakeBody and there are occasional "bubbles" between SnakeBody as well. I need urgent help! Thanx
danpost danpost

2014/4/4

#
If you want all snake parts to move at the same time, then they must all be controlled from the same place. When the snake head moves, move the snake body parts. In other words, let the head control the body and not let the body do what it wants (sounds kinda philosophical).
sliu.gsis sliu.gsis

2014/4/4

#
Thank you! You are quick.. The body parts move at the same time though. Please take a look at the screenshots of the game and you will see what I mean.. It seems with speed of 1.5 to 1.7(adjusted by the speed bar on bottom) its better. http://gsistechnology.blogspot.hk/2014/04/greedy-snake-game-programmed-in.html
sliu.gsis sliu.gsis

2014/4/4

#
Okkk, I will clear up the act() of SnakeBody and put the moveAccordingToCoordList() to Head class's act().
You need to login to post a reply.