I have an actor called "RootedCorpse" and I want it to apply a rooted condition that halves the speed of any actor it touches in the "Pedestrian" class. However, when i try to apply the root status, instead of halving the actors speed, it ends up just stopping the actor completely, or sets its speed to 0.
Heres my pedestrian code:
And heres the code for my RootedCorpse:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* A Pedestrian that tries to walk across the street
*/
public abstract class Pedestrian extends SuperSmoothMover
{
protected double speed;
protected double maxSpeed;
protected int direction; // direction is always -1 or 1, for moving down or up, respectively
protected boolean awake;
public Pedestrian()
{
this(1);
}
public Pedestrian(int direction) {
// choose a random speed
maxSpeed = Math.random() * 2 + 1;
speed = maxSpeed;
// start as awake
awake = true;
this.direction = direction;
}
/**
* Act - do whatever the Pedestrian wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void move()
{
// If there is a v
if (awake){
if (getOneObjectAtOffset(0, (int)(direction * getImage().getHeight()/2 + (int)(direction * speed)), Vehicle.class) == null){
setLocation (getX(), getY() + (int)(speed*direction));
}
if (direction == -1 && getY() < 100){
getWorld().removeObject(this);
} else if (direction == 1 && getY() > 550){
getWorld().removeObject(this);
}
}
}
/**
* Method to cause this Pedestrian to become knocked down - stop moving, turn onto side
*/
public void knockDown () {
speed = 0;
setRotation (90);
awake = false;
}
public void rooted ()
{
speed = maxSpeed/2;
}
/**
* Method to allow a downed Pedestrian to be healed
*/
public void healMe () {
speed = maxSpeed;
setRotation (0);
awake = true;
}
public boolean isAwake () {
return awake;
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class RootedCorpse here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class RootedCorpse extends Vehicle
{
/**
* Act - do whatever the RootedCorpse wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public RootedCorpse(VehicleSpawner origin) {
super(origin); // call the superclass' constructor
GreenfootImage image = getImage();
image.scale(image.getWidth() - 70, image.getHeight() - 120);
setImage(image);
maxSpeed = 1.5 + ((Math.random() * 30)/5);
speed = maxSpeed;
yOffset = 0;
}
public void act()
{
drive();
checkHitPedestrian();
if (checkEdge()){
getWorld().removeObject(this);
}
}
/**
* When a Car hit's a Pedestrian, it should knock it over
*/
public boolean checkHitPedestrian () {
Pedestrian p = (Pedestrian)getOneObjectAtOffset((int)speed + getImage().getWidth()/2, 0, Pedestrian.class);
if (p != null){
p.rooted();
return true;
}
return false;
}
}

