I tried accessing a boolean method from one of my actor classes 'P1Sword' to use in my actor 'P1'. However when I followed the tutorial #6, I am having trouble adding the new object I created from the P1Sword class into the world. Any Suggestions?
Here is also the code for the actor 'P1' for which im trying to get the 'P1Sword' method into
import greenfoot.*;
public class Yeggland extends World
{
private P1Sword swordTouch;
/**
* Constructor for objects of class MyWorld.
*
*/
public Yeggland()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1400, 800, 1);
addObject (new Ground(), 700, 740);
swordTouch = new P1Sword();
addObject (new swordTouch, 480, 675);
addObject (new P2Sword(), 920, 675);
addObject (new P1(), 400, 675);
addObject (new P2(), 1000, 675);
}
public P1Sword checkTouch()
{
return swordTouch;
}
}
public void checkTouch()
{
Yeggland yegglandWorld = (Yeggland) getWorld();
P1Sword p1Sword = yegglandWorld.checkTouch();
p1Sword.swordTouch();
}
public void swordBump()
{
checkTouch();
}