| Question | Answer |
| Moving according to arrow keys | if(Greenfoot.isKeyDown("up")){ setLocation(getX(), getY()-1); } if(Greenfoot.isKeyDown("right")){ setLocation(getX()+1, getY()); } |
| Moving around randomly | if(Greenfoot.getRandomNumber(100)<20){ move(2); } if(Greenfoot.getRandomNumber(100)<20){ turn(-90); move(-2); } |
| "Eating" | Actor Zoe = getOneObjectAtOffset(0,0, Food.class); if(isTouching(Food.class)){ HouseWorld houseWorld houseWorld = (HouseWorld)getWorld(); removeTouching(Food.class); } |
| Playing a sound | Greenfoot.playSound("pop.wav"); |
| Counter (at the end of the code for "eating", still in the if statement) | |
| Counter (in the code for the world) |
Want to create your own Flashcards for free with GoConqr? Learn more.