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

2015/2/6

maze-walkers "Missing Methods"

1
2
danpost danpost

2015/2/12

#
plant wrote...
So does your player automatically move or do you have to move it
Instead of asking what that code does (which may or may not be what you want), just let us know what you want. It appears his code, however, will have the actor move only when a direction (arrow) key is down. Also, you could just test it to find out (if it runs properly).
plant wrote...
What is the significance of putting a return true or false statement in a Boolean method? Let's say canMove()==true, would I return true just to confirm the previous true value
To answer this question, let me just say that the following methods are equivalent (the first being in the code above):
public boolean wallFront()
{
    Actor Block2 = getOneObjectAtOffset(1, 0, Block.class);
    if (Block2 == null)
    {
        return false;
    }
    else
    {
        return true;
    }
}

// is the same as
public boolean wallFront()
{
    Actor Block2 = getOneObjectAtOffset(1, 0, Block.class);
    return Block2 != null;
}
// is the same as
public boolean wallFront()
{
    return getOneObjectAtOffset(1, 0, Block.class) != null;
}
and line 7:
else if (Greenfoot.isKeyDown("right") && !wallFront())
// could be written as the following without the use of the 'wallFront' method
else if (Greenfoot.isKeyDown("right") && getOneObjectAtOffset(1, 0, Block.class) == null)
plant plant

2015/2/14

#
Ok that makes a little more sense, thanks.
DoctorMitch DoctorMitch

2015/2/17

#
plant wrote...
So does your player automatically move or do you have to move it
You move it with the arrow keys, seen via act. The set of 90 degree turns on either side of the move(1) keep the character facing the same direction at all times, and prevent the character from constantly turning left when pressing up, or right when down
You need to login to post a reply.
1
2