Hi,
I have created a scrolling game in which there is a person(called Toby) and a wall block(Block) I am trying to make it so that upon collision of the block and Toby, the Block tells Toby they have collided, so Toby moves backward. The problem is that Toby is a subclass of Scroll-actor, so when I try and call a method from the Block, it gives me an error. Here is the Block code:
I don't know if you would need this, but here is the Toby code:
Please tell me how I can do this, or if there is an easier way of executing the method.
import greenfoot.*;
/**
* Write a description of class Block here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Block extends ScrollActor
{
/**
* Act - do whatever the Block wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
Toby toby;
toby = getOneIntersectingObject(ScrollActor.class);
if (toby != null
{
toby.Collide();
}
}import greenfoot.*;
/**
* An demo class which is meant to be a camera follower.
* It moves to face your mouse cursor, and it can move
* back and forward.
*
* @author Sven van Nigtevecht
* @version 1.0
*/
public class Toby extends ScrollActor
{
/** The number of cells we move forward and backword */
int speed = 5;
/**
* Move to face the mouse,
* and listen to the up and down keys.
*/
public void act()
{
if (Greenfoot.isKeyDown("a")) {
getWorld().setCameraLocation(getWorld().getCameraX() -speed,getWorld().getCameraY());
}
if (Greenfoot.isKeyDown("d")) {
getWorld().setCameraLocation(getWorld().getCameraX() +speed,getWorld().getCameraY());
}
if (Greenfoot.isKeyDown("w")) {
getWorld().setCameraLocation(getWorld().getCameraX(),getWorld().getCameraY() -speed);
}
if (Greenfoot.isKeyDown("s")) {
getWorld().setCameraLocation(getWorld().getCameraX(),getWorld().getCameraY() +speed);
}
}
public void Collide()
{
speed-=5;
}

