This site requires JavaScript, please enable it in your browser!
Greenfoot back
LobsterL
LobsterL wrote ...

2017/7/13

LineOfSight Method

LobsterL LobsterL

2017/7/13

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Soceror here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Soceror extends Characters
{
    Warrior1 warrior1OnScreen;
    LineOfSight los;
    
    public void addedToWorld(World myWorld)
    {
        if(myWorld instanceof MyWorld)
       {
        MyWorld myworld = (MyWorld)myWorld;
        los = myworld.getLOS();
        warrior1OnScreen = myworld.getWarrior1();
       }
    }
    /**
     * Act - do whatever the Soceror wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       
       
       if(los!=null)
       {
           if(los.clearLineOfSight())
           {
               if(warrior1OnScreen != null && warrior1OnScreen.getWorld()!=null)
               {
                   turnTowards(warrior1OnScreen.getX(), warrior1OnScreen.getY());
                   setRotation(90*Math.round(getRotation()/90));
               }
           }
       }
    }    
    public Soceror()
    {
        GreenfootImage myImage = getImage();
        myImage.scale(100,100);
    }
    
}
LobsterL LobsterL

2017/7/13

#
It says clearLineOfSight isn't a method??
Super_Hippo Super_Hippo

2017/7/13

#
Is there a clearLineOfSight method in your LineOfSight class?
You need to login to post a reply.