I would like to return actor yellow1 with arrows right and left
im a beginner
public void act() { int r=0; if (Greenfoot.isKeyDown("left")) r-=2; if (Greenfoot.isKeyDown("right")) r+=2; if (r != 0) turn(r); }
int x = getX(); int y = getY(); if(Greenfoot.mouseClicked("right"))x=x+1; if(Greenfoot.mouseClicked("left"))y=y+1; setLocation(x,y);
public void act () { int button = 0; int x = 0; int y = 0; { MouseInfo mouseInfo = new Greenfoot.getMouseInfo(); if(mouseInfo!=null) { button = mouseInfo.getButton(); if(button == 1 || button == 3) { x = mouseInfo.getX(); y = mouseInfo.getY(); setLocation(x,y); } } } }
int direction; public void act() { MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse != null) { if (direction == 0 && Greenfoot.mousePressed(null)) direction = (mouse.getButton()-2)%2; else if (direction != 0 && Greenfoot.mouseClicked(null) && direction == (mouse.getButton()-2)%2) direction = 0; else if (direction != 0 && Greenfoot.mousePressed(null)) direction = -direction; } setLocation(getX()+direction, getY()); }