i am very new to the greenfoot i want some to teach me and help me in this if possible can show me his or her scenario just for references .......thanks in advance
public void moveLeft() {
setLocation(getX() - 1, getY());
}
public void moveRight() {
setLocation(getX() + 1, getY());
}
public void moveUp() {
setLocation(getX() , getY() - 1);
}
public void moveDown() {
setLocation(getX(), getY() + 1);
}public void moveLeft(int left) {
setLocation(getX() - left, getY());
}
public void moveRight(int right) {
setLocation(getX() + right, getY());
}
public void moveUp(int up) {
setLocation(getX() , getY() - up);
}
public void moveDown(int down) {
setLocation(getX(), getY() + down);
}public void move()
{
//movement using the wasd keys
if (Greenfoot.isKeyDown("a"))
{
moveLeft(2);//change number to whatever you like
}
if (Greenfoot.isKeyDown("d"))
{
moveRight(2);//change number to whatever you like
}
if (Greenfoot.isKeyDown("w"))
{
moveUp(2);//change number to whatever you like
}
if (Greenfoot.isKeyDown("s"))
{
moveDown(2);//change number to whatever you like
}
}public void move()
{
int dx = 0, dy = 0;
if (Greenfoot.isKeyDown("right")) dx++;
if (Greenfoot.isKeyDown("left")) dx--;
if (Greenfoot.isKeyDown("down")) dy++;
if (Greenfoot.isKeyDown("up")) dy--;
if (dx*dy == 0 && dx+dy != 0) setLocation(getX()+dx, getY()+dy);
}// change the last line to if (dx !=0 || dy != 0) setLocation(getX()+dx, getY()+dy);
if (!getIntersectingObjects(null).isEmpty()) setLocation(getX()-dx, getY()-dy);
// or
if (!getIntersectingObjects(Some.class).isEmpty() ||
!getIntersectingObjects(Another.class).isEmpty() ||
!getIntersectingObjects(Etc.class).isEmpty())
setLocation(getX()-dx, getY()-dy);private int movingSpeed = 1;
private int actCounter = 0;
public void act() {
if (Greenfoot.isKeyDown("up")) {
moveUp(movingSpeed);
}
//...
actCounter++;
if (actCounter >= 1000) {
actCounter = 0;
movingSpeed++;
}
}private int movingSpeed=1;
private int actCounter=0;
public void Move(int speed,String direction) {
if(direction=="up")
setLocation(getX(), getY()-speed);
else if(direction=="down")
setLocation(getX(), getY()+speed);
else if(direction=="left")
setLocation(getX()-speed, getY());
else if(direction=="right")
setLocation(getX()+speed, getY());
else
//throw new Exception("Incorrect Direction Entered.");
}
public void act()
{
if (Greenfoot.isKeyDown("a"))
Move(movingSpeed,left);
if (Greenfoot.isKeyDown("d"))
Move(movingSpeed,right);
if (Greenfoot.isKeyDown("w"))
Move(movingSpeed,up);
if (Greenfoot.isKeyDown("s"))
Move(movingSpeed,down);
actCounter++;
if(actCounter>=1000) {
actCounter=0;
movingSpeed++;
}
}