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

2014/2/19

grow snake

akshay akshay

2014/2/19

#
i want to grow my snake everytime i eat the object, can anyone help me with the code.??
JetLennit JetLennit

2014/2/19

#
I think that it would help if you posted what code you currently have
akshay akshay

2014/2/20

#
public void act() { //to move the snake move(9); if(Greenfoot.isKeyDown("up")){ setRotation(-90); } if(Greenfoot.isKeyDown("down")){ setRotation(90); } if(Greenfoot.isKeyDown("left")){ setRotation(180); } if(Greenfoot.isKeyDown("right")){ setRotation(0); } //to eat the burger if(isTouching(burger.class)){ started(); removeTouching(burger.class); ((background) getWorld()).counter(); getWorld().addObject(new burger(), Greenfoot.getRandomNumber(595), Greenfoot.getRandomNumber(395)); } //stop the game if snake touches the edges if (getY()== 0) { ((background)getWorld()).gameOver(); } if (getX()==0) { ((background)getWorld()).gameOver(); } if (getY()>398) { ((background)getWorld()).gameOver(); } if(getX()>598){ ((background)getWorld()).gameOver(); } } public void started(){ { Greenfoot.playSound("chord.wav"); } this is the code to move the snake as well as eat the object when it touches it, i hav read other post regarding growing the snake using arrays like snakeBody.length, i needed a simpler one if possible without the use of arrays!!
You need to login to post a reply.