I want to make a character be able to make a wall and then select a direction to put it in. There are no errors, but when I run the code it freezes. I think there is something wrong with my code.
String key = Greenfoot.getKey();
if (key != null && key.equals("space"))
{
Wall wall = new Wall();
getWorld().addObject(wall, getX(), getY());
}
if(Greenfoot.isKeyDown("space"))
{
int WallX = getX();
int WallY = getY();
if(Greenfoot.isKeyDown("D"))
{
WallX += 50;
}
else if(Greenfoot.isKeyDown("W"))
{
WallY -= 50;
}
else if(Greenfoot.isKeyDown("S"))
{
WallY += 50;
}
else if(Greenfoot.isKeyDown("A"))
{
WallX -= 50;
}
Actor wall;
wall=getOneObjectAtOffset(0,0, Wall.class);
wall.setLocation(WallX,WallY);