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

2014/5/2

Class not recognizing another actor

Daringa Daringa

2014/5/2

#
Its a maze game that uses an actor as the walls so it can be reset upon touching the Actor, except it doesn't recognize the actor
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Character here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Character extends Actor
{
    /**
     * Act - do whatever the Character wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(Greenfoot.isKeyDown("left")){
        move(-1);}
        if(Greenfoot.isKeyDown("right")){
            move(1);}
        if(Greenfoot.isKeyDown("down")){
            setRotation(90);
            move(1);
            setRotation(0);
    }    
    if(Greenfoot.isKeyDown("up")){
        setRotation(270);
        move(1);
        setRotation(0);
    }
   touching();
}
        public void touching()
{
Actor Wall =getOneObjectAtOffset(0, 0, Character.class);
if(Wall != null){
 setLocation(getX()-5, getY());
}
}

}
  

    
Thanks, Dar
You need to login to post a reply.