so all the the movement methods in Schip need to have this code but the (getX() - speed, getY()) need to be adjusted different depending on the direction it goes?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Schip extends Actor
{
private Platform platform = null;
private int speed = 3;
public void act()
{
if(Greenfoot.isKeyDown("left"))
{
moveLeft();
}
if(Greenfoot.isKeyDown("right"))
{
moveRight();
}
if(Greenfoot.isKeyDown("up"))
{
moveUp();
}
if(Greenfoot.isKeyDown("down"))
{
moveDown();
}
}
public void moveRight()
{
setLocation(getX() + speed, getY());
setRotation(180);
if (platform != null)
{
platform.setSchip(null);
platform = null;
}
Platform p = (Platform)getOneIntersectingObject(Platform.class);
if (p != null)
{
setLocation(getX() - speed, getY());
platform = p;
p.setSchip(this);
}
}
public void moveLeft()
{
setLocation(getX() - speed, getY());
setRotation(0);
if (platform != null)
{
platform.setSchip(null);
platform = null;
}
Platform p = (Platform)getOneIntersectingObject(Platform.class);
if (p != null)
{
setLocation(getX() + speed, getY());
platform = p;
p.setSchip(this);
}
}
public void moveUp()
{
setLocation(getX(), getY() - speed);
setRotation(90);
if (platform != null)
{
platform.setSchip(null);
platform = null;
}
Platform p = (Platform)getOneIntersectingObject(Platform.class);
if (p != null)
{
setLocation(getX(), getY() + speed);
platform = p;
p.setSchip(this);
}
}
public void moveDown()
{
setLocation(getX(), getY() + speed);
setRotation(270);
if (platform != null)
{
platform.setSchip(null);
platform = null;
}
Platform p = (Platform)getOneIntersectingObject(Platform.class);
if (p != null)
{
setLocation(getX(), getY() - speed);
platform = p;
p.setSchip(this);
}
}
public Kratten kratten = null;
public void setKratten(Kratten k)
{
kratten = k;
}
public Kratten getKratten()
{
return kratten;
}
}
public Platform()
{
GreenfootImage pImg = getImage();
GreenfootImage image = new GreenfootImage(251, 251);
for (int i=0; i<4; i++) for (int j=0; j<3; j++)
{
image.drawImage(pImg, 72*i, 72*j);
}
setImage(image);
}Platform platform = new Platform(); addObject(platform, 391, 729); Platform platform2 = new Platform(); addObject(platform2, 391, 657); Platform platform3 = new Platform() addObject(platform3, 391, 585);
Platform platform = new Platform(); addObject(platform, 391, 674);
private void prepare()
{
Platform platform = new Platform();
addObject(platform, 408, 729);
Platform platform2 = new Platform();
addObject(platform2, 550, 657);
Platform platform3 = new Platform();
addObject(platform3, 730, 585);
Platform platform4 = new Platform();
addObject(platform4, 408, 729);
Platform platform5 = new Platform();
addObject(platform5, 550, 657);
Platform platform6 = new Platform();
addObject(platform6, 408, 585);
platform4.setLocation(449, 756);
platform.setLocation(333, 756);
platform5.setLocation(333, 684);
platform2.setLocation(449, 684);
platform3.setLocation(449, 612);
platform6.setLocation(333, 612);
vrachtwagenplek vrachtwagenplek = new vrachtwagenplek();
addObject(vrachtwagenplek, 275, 60);
vrachtwagenplek vrachtwagenplek2 = new vrachtwagenplek();
addObject(vrachtwagenplek2, 402, 67);
vrachtwagenplek vrachtwagenplek3 = new vrachtwagenplek();
addObject(vrachtwagenplek3, 540, 75);
vrachtwagenplek vrachtwagenplek4 = new vrachtwagenplek();
addObject(vrachtwagenplek4, 282, 116);
vrachtwagenplek vrachtwagenplek5 = new vrachtwagenplek();
addObject(vrachtwagenplek5, 427, 129);
vrachtwagenplek vrachtwagenplek6 = new vrachtwagenplek();
addObject(vrachtwagenplek6, 571, 136);
vrachtwagenplek.setLocation(275, 53);
vrachtwagenplek2.setLocation(382, 53);
vrachtwagenplek3.setLocation(489, 53);
vrachtwagenplek5.setLocation(381, 125);
vrachtwagenplek6.setLocation(489, 125);
vrachtwagenplek4.setLocation(275, 125);
public Platform()
{
GreenfootImage base = getImage();
GreenfootImage image = new GreenfootImage(252, 216);
for (int i=0; i<252; i+=72) for (int j=0; j<216; j+=72)
{
image.drawImage(base, 72*i, 72*j);
}
setImage(image);
}public vrachtwagenplek()
{
GreenfootImage base = getImage();
GreenfootImage image = new GreenfootImage(468, 252);
for (int i=0; i<468; i+=72) for (int j=0; j<252; j+=72)
{
image.drawImage(base, 72*i, 72*j);
}
setImage(image);
}Platform platform = new Platform(); addObject(platform, 380, 652); vrachtwagenplek vrachtwagenplek = new vrachtwagenplek(); addObject(vrachtwagenplek, 380, 126);