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

2015/1/10

Command doesn't work + don't know how to use a command

beliuga beliuga

2015/1/10

#
Okay It's me again! (sorry for spamming the discussions walls)
    public void act() 
    {
    
        if ( canSee(lily1.class)) 
        {
        eat(lily1.class); 
        lily1Eaten = lily1Eaten + 1; 
        Greenfoot.playSound("slurp.wav");
        }
        if ( canSee(lily2.class))
        {
            eat(lily2.class);
            lily2Eaten = lily2Eaten + 2; 
            Greenfoot.playSound(".wav");
        }
        if ( canSee(lily3.class))
         { 
             eat(lily3.class);
             lily3Eaten = lily3Eaten + 3;
             Greenfoot.playSound(".wav");
            }     
         if (liliesEaten == 10) 
        { 
            Greenfoot.playSound("fanfare.wav"); 
            Greenfoot.stop();
        }    
        if (Greenfoot.isKeyDown("left"))
        {
            turn(-4);
        }
        if (Greenfoot.isKeyDown("right"))
        {
            turn(4);
        }
        if (Greenfoot.isKeyDown("up"))
        {  
            move(4);
        }
        if (Greenfoot.isKeyDown("down"))
        {
            move(-4);
        }
    }    
}
for this code, It says that it "cannot find symbol : method canSee(java.lang.Class<lily1>) for my little crab scenario it worked perfectly fine but not in this scenario? and I was reading one of the discussions (is there any way to have a dead spot that actors can't enter) I want to use the code getObjectsInRange(int radius, java.lang.Class cls) Return all objects within range 'radius' around this object. but I have no idea how?? please help!
beliuga beliuga

2015/1/10

#
oh, and the "liliesEaten" don't work either (it says that can't find variable "liliesEaten" what I'm trying to do is make the background calculate how many lilies did the player pick up and if it picks up 10 then the player wins.
beliuga beliuga

2015/1/10

#
and I know I didn't put a audio file so it won't compile anyway, but it's because I haven't put my audio file in my folder yet. but that isn't the problem
danpost danpost

2015/1/10

#
beliuga wrote...
for this code, It says that it "cannot find symbol : method canSee(java.lang.Class<lily1>) for my little crab scenario it worked perfectly fine but not in this scenario?
The Crab class in the little crab scenario probably was extending the Animal class which has the 'canSee' and 'eat' methods in it. These methods, however, are obsolete. Since Greenfoot version 2.3.0, the Actor class contains the equivalent methods 'isTouching(Class)' and 'removeTouching(Class)'.
it says that can't find variable "liliesEaten"
Sounds like you have yet to declare the field within the class:
private int lilliesEaten;
I want to use the code getObjectsInRange(int radius, java.lang.Class cls) Return all objects within range 'radius' around this object. but I have no idea how??
How are you going to put the method to use?? Do you just need to know that an object is near or will you need to acquire more information about any object that is near? (and what more would you need, if so)
beliuga beliuga

2015/1/10

#
I want to use the method because I have 3 boxes to prevent any of the lily actors from entering the start area (the start area is a very big box but I covered everywhere apart from the actors in order for the lily actos to not come in) and I want the 3 boxes to block off the lily actors from coming in the area.
beliuga beliuga

2015/1/10

#
I changed all the "canSees" into "isTouching" but now It's not letting me compile because of eat. What would I replace eat with?
danpost danpost

2015/1/10

#
beliuga wrote...
I changed all the "canSees" into "isTouching" but now It's not letting me compile because of eat. What would I replace eat with?
Re-read my last post. Let me ponder on what you just wrote about the boxes.
danpost danpost

2015/1/10

#
Is there a reason you cannot use the start box itself as a barrier for the lilies (using 'isTouching' for collision checking)?
beliuga beliuga

2015/1/10

#
Yes, because if I use the big box as itself, then it would also block out my player actors on the big box itself, that's why I want to use the small boxes to leave a small space for the player actors to start out.
beliuga beliuga

2015/1/10

#
Unless there's some way to exempt the command from two actors...?
danpost danpost

2015/1/10

#
Alright. Well, anyway, it appears that the lilies only need to know whether a box is in range or not. So, 'getObjectsInRange' should work for you. You will need to post the code of the class for your lilies. Also, give the name of the class the you will use for the boxes.
danpost danpost

2015/1/10

#
beliuga wrote...
Unless there's some way to exempt the command from two actors...?
There probably is. But, without seeing any code, no suggestions are forthcoming.
beliuga beliuga

2015/1/10

#
There's no code in all 3 lily's act codes for now. Later, I want to make them randomly move around but I know how to do that The name for the big box is "bigbarrier", small box 1 "smallbarrier" and small box 2 "smallbarrier2" However, this is the code for my background, if that helps?
        super(650, 600, 1); 
        woodplatform wood = new woodplatform(); 
        addObject(wood,329,565);
        
        // a platform for both of the players to start in 
        
        prince1 prince = new prince1();
        addObject(prince,139,507);
        
        // player one's starting postion 
        
        prince2 princess = new prince2();
        addObject(princess,515,515);
        
        // player two's starting position 
        
        bigbarrier big = new bigbarrier();
        addObject(big,326,517); 
        
        // big barrier to stop the flowers from entering the starting zone
        
        smallbarrier small = new smallbarrier();
        addObject(small,46,512); 
        
        // left small barrier to stop the flowers from entering the starting zone 
        
        smallbarrier2 barrier = new smallbarrier2();
        addObject(barrier,605,513); 
        
        
        // right small barrier to stop the flowers from entering the starting zone
        
        for(int i=0; i<4; i++)
        {
            addObject(new lily1(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); 
        }
        
        // code taken from little-crab scenario. Populating the world with 4 random positioned level 1 lilies  
        
        for(int i=0; i<4; i++) 
        {
            addObject(new lily2(), Greenfoot.getRandomNumber(getWidth()),Greenfoot.getRandomNumber(getHeight())); 
        }
        
        // code taken from little-crab scenario. Populating the world with 4 random positioned level 2 lilies 
        
        for(int i=0; i<4; i++)
        {
            addObject(new lily3(), Greenfoot.getRandomNumber(getWidth()),Greenfoot.getRandomNumber(getHeight())); 
        }
        
        // code taken from little-crab scenario. Populating the world with 4 random positioned level 3 liles 
                
    }
    }
danpost danpost

2015/1/10

#
First, I will try to make things a little easier (so you do not have to keep copy/pasting code from one class to another). Create a new subclass of Actor and call it 'Lily' and instead of having the 3 classes, lily1, lily2 and lily3 extend Actor, have them extend the new Lily class. Next, create a new subclass of Actor called 'Obstacle' and instead of the 3 classes, bigbarrier, smallbarrier and barrier extend Actor, have them extend the new Obstacle class. Now, the reason I suggest this for the lily classes is so you only need to create the code once for all three classes by putting the code in the new Lily class; and the reason I suggest this for the barrier classes is so you can refer to all 3 types with the one class name 'Obstacle'. Now, when the lilys move, you would check for intersecting Obstacle objects and undo the move and turn if any are found. Code the movement in the Lily class only.
You need to login to post a reply.