As far as the wall and collision: it is difficult to say why without seeing what collision code you have in the class of the survivors. However, I cannot imagine why you would have walls that large (same size as world).
public void wallDetect()
{
{
if (getOneIntersectingObject(Collision.class) != null)
{
setLocation(x,y);
}
else
{
x = getX();
y = getY();
}
}
}
}
private void walls() //Left, higher = right | Right, lower = up
{
if (canAddWalls()) addObject(new Wall1(), 928, 44);
if (canAddWalls()) addObject(new Wall2(), 100, 44);
}
public boolean canAddWalls()
{
// in the world class, use this line
return getObjects(Collision.class).size() < 1;
}if (canAddWalls()) addObject(new Wall2(), 100, 44);
if (canAddWalls()) {
addObject(new Wall1(), 928, 44);
addObject(new Wall2(), 100, 44);
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Survivor is trying to survive the infection.
*
* Gurveer Mand
* @version 0.01 - 15/04/2016
*/
public class SurvivorWASD extends Survivor
{
private GreenfootImage survivor1r = new GreenfootImage("survivor1r.png");
private GreenfootImage survivor2r = new GreenfootImage("survivor2r.png");
private GreenfootImage survivor3r = new GreenfootImage("survivor3r.png");
private GreenfootImage survivor4r = new GreenfootImage("survivor4r.png");
private GreenfootImage survivor1up = new GreenfootImage("survivor1up.png");
private GreenfootImage survivor2up = new GreenfootImage("survivor2up.png");
private GreenfootImage survivor3up = new GreenfootImage("survivor3up.png");
private GreenfootImage survivor4up = new GreenfootImage("survivor4up.png");
private int frame = 1;
private int animationCounter = 0;
/**
* Act - do whatever the Survivor wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKeys();
wallDetect();
animationCounter ++;
}
/**
* Check whether the control keys are being pressed, and turn if they are.
*/
public void checkKeys()
{
if(Greenfoot.isKeyDown("A"))
{
setRotation(180);
move(2);
if(animationCounter % 10 == 0)
animate();
}
if(Greenfoot.isKeyDown("D"))
{
setRotation(0);
move(2);
if(animationCounter % 10 == 0)
animate();
}
if(Greenfoot.isKeyDown("W"))
{
setRotation(90);
move(-2);
if(animationCounter % 10 == 0)
animate();
}
if(Greenfoot.isKeyDown("S"))
{
setRotation(90);
move(2);
if(animationCounter % 10 == 0)
animate();
}
}
public void animate()
{
if(frame == 1)
{
setImage (survivor1r);
}
else if(frame == 2)
{
setImage (survivor2r);
}
else if(frame == 3)
{
setImage (survivor3r);
}
else if(frame == 4)
{
setImage (survivor4r);
frame =1;
return;
}
frame ++;
}
public void animateUp()
{
if(frame == 1)
{
setImage (survivor1r);
}
else if(frame == 2)
{
setImage (survivor2r);
}
else if(frame == 3)
{
setImage (survivor3r);
}
else if(frame == 4)
{
setImage (survivor4r);
frame =1;
return;
}
frame ++;
}
}
setRotation(-90);
setRotation(270);
move(2);
if(Greenfoot.isKeyDown("V"))
{
shoot();
}
} if("V".equals(Greenfoot.getKey()))
{
shoot();
}
}
/**
* Shoots a lazer.
*/
private void shoot()
{
Lazer lazer = new Lazer();
getWorld().addObject(lazer, getX(), getY());
lazer.setRotation(getRotation());
}