Hello,
Can someone please help me on how to make an actor move in a jagged fashion? I want it to move horizontally with a constant dx, but its y-position should fluctuate a little. Thank you.
Here's the code I'm working on:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Dino here. * * @author (your name) * @version (a version number or a date) */ public class Dino extends Actor { /** * Act - do whatever the Dino wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. int dx = 3 ; int dy = Greenfoot.getRandomNumber( 1 ) - 3 ; setLocation(getX() + dx, getY() + dy); } } |