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

2021/12/24

Actor touching another actor

1
2
xixEmilyxix xixEmilyxix

2021/12/24

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class BeeWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class BeeWorld extends World
{
    //declare variables
    int beeValue;
    int weatherValue;
    public static Flower flower;
    int dayValue;
    int honeyValue;
    Actor btnAddDay, btnHelp, btnEndSimulation;
    private static final String[] FLOWER_COLOR = { "pink", "purple", "yellow" };
    /**
     * Constructor for objects of class BeeWorld.
     * 
     */
    public BeeWorld(int weatherVal)
    {
        //set background to main screen when button is pressed
        super(864, 540, 1);
        setPaintOrder(Buttons.class);
        
        //set nectar value
        Forager.nectarValue = 0;
        
        setBackground(new GreenfootImage("Background.png"));
        
        //run new day
        newDay();       
        
        //add the counter for the bee value
        showText("Bees: ",  810, 20);
                    
        //declare weatherValue 
        weatherValue = weatherVal;

                
        //set honey value
        honeyValue = 0;       
        showText("Honey: " + honeyValue,  810, 110); 
    }
    
    public void act()
    {
        if (Greenfoot.mouseClicked(btnAddDay))
        {
           newDay();
        }
        if (Greenfoot.mouseClicked(btnHelp))
        {
           help();
        }
        if(Greenfoot.mouseClicked(btnEndSimulation))
        {
           endSimulation();
        }
    }
    
    private void endSimulation()
    {
        Greenfoot.setWorld(new EndScreen()); 
    }
    
    private void help()
    {
        //add help menu
        HelpMenu HelpMenu = new HelpMenu();
        addObject (HelpMenu, getWidth(), getHeight());
        HelpMenu.setLocation(650,200);
        
        //button to be able to remove help menu
        RemoveMenu RemoveMenu = new RemoveMenu();
        addObject (RemoveMenu, getWidth(), getHeight());
        RemoveMenu.setLocation(900,200);
    }
    
    public void runSimulation()
    {
        if(weatherValue >= -40 && weatherValue <= 15)
         {
             //if the weather value is between -40 and 15 then the low temp simulation will run
             lowTemperature();
         } else if(weatherValue >= 16 && weatherValue <= 27)
         {
             //if the weather value is between 16 and 27 then the regular temp simulation will run
             regularTemperature();
         } else if(weatherValue >= 28 && weatherValue <= 40)
         {
             //if the weather value is between 28 and 40 then the high temp simulation will run
             highTemperature();
         }     
    }
    
    public void lowTemperature()
    {
        //add random coloured flowers to the bee world
        int flowerColorNum = Greenfoot.getRandomNumber(FLOWER_COLOR.length);
        Actor flower = new Flower(FLOWER_COLOR[flowerColorNum]);
        addObject(new Flower(), 500, 500);
        addObject(new Flower(), 100, 300);
        addObject(new Flower(), 200, 400);
        addObject(new Flower(), 100, 100);
        addObject(new Flower(), 700, 400);
        addObject(new Flower(), 800, 200);
        
        //add bees to the bee world
        Worker Worker = new Worker ();
        Queen Queen = new Queen ();
        Forager Forager = new Forager ();
        addObject(new Queen(), 500, 250);
        addObject(new Forager(), 400, 150);
        addObject(new Forager(), 450, 200);
        addObject(new Forager(), 500, 220);
        addObject(new Forager(), 550, 250);
        
        //add the hive to the bee world
        Hive Hive = new Hive ();
        addObject(new Hive(), 650, 400);        
    }
    
    public void regularTemperature()
    {
        //add random coloured flowers to the bee world
        int flowerColorNum = Greenfoot.getRandomNumber(FLOWER_COLOR.length);
        Actor flower = new Flower(FLOWER_COLOR[flowerColorNum]);
        addObject(new Flower(), 500, 500);
        addObject(new Flower(), 100, 300);
        addObject(new Flower(), 200, 400);
        addObject(new Flower(), 100, 100);
        addObject(new Flower(), 700, 400);
        addObject(new Flower(), 800, 200);
        addObject(new Flower(), 600, 100);
        addObject(new Flower(), 400, 700);        
        
        //add bees to the bee world
        Worker Worker = new Worker ();
        Queen Queen = new Queen ();
        Forager Forager = new Forager ();
        addObject(new Queen(), 500, 250);
        addObject(new Forager(), 400, 150);
        addObject(new Forager(), 450, 200);
        addObject(new Forager(), 500, 220);
        addObject(new Forager(), 550, 250);
        addObject(new Forager(), 520, 175);
        addObject(new Queen(), 500, 250);
        
        //add the hive to the bee world
        Hive Hive = new Hive ();
        addObject(new Hive(), 650, 400);       
    }
    
    public void highTemperature()
    {
        //add random coloured flowers to the bee world
        int flowerColorNum = Greenfoot.getRandomNumber(FLOWER_COLOR.length);
        Actor flower = new Flower(FLOWER_COLOR[flowerColorNum]);
        addObject(new Flower(), 500, 500);
        addObject(new Flower(), 100, 300);
        addObject(new Flower(), 200, 400);
        addObject(new Flower(), 100, 100);
        addObject(new Flower(), 700, 400);
        addObject(new Flower(), 800, 200);        
        
        //add bees to the bee world
        Worker Worker = new Worker ();
        Queen Queen = new Queen ();
        Forager Forager = new Forager ();
        addObject(new Queen(), 500, 250);
        addObject(new Forager(), 400, 150);
        addObject(new Forager(), 450, 200);
        addObject(new Forager(), 500, 220);
        addObject(new Forager(), 550, 250);
        addObject(new Forager(), 520, 175);
        addObject(new Queen(), 500, 250);
        
        //add the hive to the bee world
        Hive Hive = new Hive ();
        addObject(new Hive(), 650, 400);        
    } 
  
        
    public void updateDay()
    {
        //update what day it is and run the next day when the day button is clicked
        dayValue = dayValue +1;
        showText("Day: " + dayValue, 810, 50);
        newDay();
    }
    
    private void newDay()
    {
        //start new day
        //remove all objects
        List objects = getObjects(null);
        removeObjects(objects);
        
        //increase day value
        dayValue++;
        
        //increase honey value
        updateHoney();
        
        //add buttons
        btnAddDay = new Buttons();
        btnAddDay.setImage(new GreenfootImage("addDaybutton.png"));
        btnHelp = new Buttons();
        addObject(btnAddDay, 820, 500);
        btnHelp.setImage(new GreenfootImage("helpButton.png"));
        addObject(btnHelp, 100, 190);
        btnEndSimulation = new Buttons();
        btnEndSimulation.setImage(new GreenfootImage("EndSimulationbutton.png"));
        addObject(btnEndSimulation, 50, 500);
        
        //run simulation again
        runSimulation();
        
        //random chance to see if bee dies
        
        //add bee every 5 days
        if (dayValue%5 == 0)
        {
           addObject(new Forager(), 550, 250);           
        }
    }
    
    public void beeTouchingFlower(final Bee touchingBee, final Flower touchingFlower)
    {
        //when bee touches flower:
        //stop bee moving
        touchingBee.stop();
        touchingFlower.removeObject(this);
    }   
    
    public void updateHoney()
    {
        //take away from nectar value
        nectarValue = nectarValue - 2;
        
        //increase honey value
        honeyValue = honeyValue + 2;
        
        //add the counter for the honey value
        showText("Honey: " + honeyValue,  810, 110);
    }   
}

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

/**
 * Write a description of class Forager here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Forager extends Bee
{
    public static int nectarValue;
    public Forager()
    {
        //set image of forager
        setImage(new GreenfootImage("foragerBee.png"));
        GreenfootImage image = getImage();  
        image.scale(image.getWidth() - 1350, image.getHeight() - 750);  
        setImage(image);
    }

    public void act()
    {
        //walk randomly
        randomWalk();
        findFlower();
    }
    
    public void findFlower()
    {
        if (isTouching(Flower.class))
        {
            removeTouching(Flower.class);
            nectarValue += 2;
            getWorld().showText("Nectar: " +nectarValue, 810, 80);
        }
    }
}
mport greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.Random;

/**
 * A pile of food. The pile consists initially of 100 crumbs of food.
 * 
 * @author Michael Kolling
 * @version 1.1
 */
public class Flower extends Actor
{
    //create variable to be able to change colour of flowers
    public String colour;
    
    public Flower(String pigment)
    {
        //set image of flowers
        colour = pigment;
        GreenfootImage image = new GreenfootImage(colour+"Flower.png");  
        image.scale(image.getWidth() - 500, image.getHeight() - 500);  
        setImage(image);
    }
    
    public void act()
    {
        //check if bee is touching flower
        beeTouchingFlower();        
    }
    
        public void beeTouchingFlower()
    {
        //check if bee is touching flower
       final touchingBee = this.getOneIntersectingObject(Bee.class);
       final touchingFlower = this.getOneIntersectingObject(Flower.class);
       if (touchingBee != null)
          {
             //run beeTouchingFlower in world class
             BeeWorld b = (BeeWorld) getWorld();
             b.beeTouchingFlower(touchingBee);
             b.removeObject(this);
           }
    }
    
    public boolean touchingForager()
    {
        //check if touching bee then return it
        return isTouching(Forager.class);        
    }
}
mport greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bee here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bee extends Actor
{
    //maximum movement speed
    private static final int SPEED = 2;

    //current movement and offset
    private int coordX;
    private int coordY;


    public Bee()
    {
        //neutral movement
        coordX = 0;
        coordY = 0;
    }
    
    public void randomWalk()
    {
        //walk around randomly (random direction and speed)
        if (randomChance(15)) 
        {  
            coordX = adjustSpeed(coordX);
            coordY = adjustSpeed(coordY);
        }
        walk();
    }
    
    public void walk()
    {
        //walk forward in the current direction with the current speed
        setLocation(getX() + coordX, getY() + coordY);
        setRotation((int) (180 * Math.atan2(coordY, coordX) / Math.PI));
    }
    
    public int stop(int speed)
    {
        speed = 0;
        return capSpeed(speed);
    }
    
    public void goHome()
    {
        coordX = 0;
        coordY = 0;
        setLocation(getX() + coordX, getY() + coordY);
        setRotation((int) (180 * Math.atan2(coordY, coordX) / Math.PI));
    }

    private int adjustSpeed(int speed)
    {
        //adjust speed randomly
        speed = speed + Greenfoot.getRandomNumber(2 * SPEED - 1) - SPEED + 1;
        return capSpeed(speed);
    }

    private int capSpeed(int speed)
    {
        //make sure the speed returned is in the range
        if (speed < -SPEED)
            return -SPEED;
        else if (speed > SPEED)
            return SPEED;
        else
            return speed;
    }

    private boolean randomChance(int percent)
    {
        return Greenfoot.getRandomNumber(100) < percent;
    }
}
Error message on addObject(new Flower() lines = constructor Flower in class Flower cannot be applied to given types; required java.lang.String found: no arguments reason: actual and formal arguments lists differ in lengths Error message on nectarValue = nectarValue -2; line = cannot find symbol - variable nectarValue Error message on touchingBee.stop = method stop in class Bee cannot be applied to given types; required: int found: no arguments reason: actual and formal argument lists differ in length Error message on touchingFlower.removeObject - cannot find symbol - method removeObject(BeeWorld)
danpost danpost

2021/12/24

#
In BeeWorld, remove line 14.
xixEmilyxix wrote...
Error message on addObject(new Flower() lines = constructor Flower in class Flower cannot be applied to given types; required java.lang.String found: no arguments reason: actual and formal arguments lists differ in lengths
You need to see this post.
Error message on nectarValue = nectarValue -2; line = cannot find symbol - variable nectarValue
That should be:
Forager.nectarValue -= 2;
// or
Forager.nectarValue = Forager.nectarValue - 2;
Error message on touchingBee.stop = method stop in class Bee cannot be applied to given types; required: int found: no arguments reason: actual and formal argument lists differ in length
Change line 44 in Bee class to this:
public void stop()
Error message on touchingFlower.removeObject - cannot find symbol - method removeObject(BeeWorld)
Remove lines 232 through 239 in BeeWorld class. Remove lines 23 through 48 in Flower class.
xixEmilyxix xixEmilyxix

2021/12/26

#
This has fixed the addObject and nectarValue errors, thanks! the errors i am still getting are the ones in the flower class:
        public void beeTouchingFlower()
    {
        //check if bee is touching flower
       final touchingBee = this.getOneIntersectingObject(Bee.class);
       final touchingFlower = this.getOneIntersectingObject(Flower.class);
       if (touchingBee != null)
          {
             //run beeTouchingFlower in world class
             BeeWorld b = (BeeWorld) getWorld();
             b.beeTouchingFlower(touchingBee);
             b.removeObject(this);
           }
    }
and in the bee world:
    public void beeTouchingFlower(final Bee touchingBee, final Flower touchingFlower)
    {
        //when bee touches flower:
        //stop bee moving
        touchingBee.stop();
        touchingFlower.removeObject(this);
    }  
(the removeObject(this) part where im trying to remove the flower that the bee touched ) and this one in the bee class:
    public void stop()
    {
        speed = 0;
        return capSpeed(speed);
    }
where it says it cannot find symbol variable speed
danpost danpost

2021/12/26

#
xixEmilyxix wrote...
the ones in the flower class: << Code Omitted >>
Move the bee vs. flower collision codes to the Bee class:
if (isTouching(Flower.class))
{
    removeTouching(Flower.class);
    stop();
}
and in the bee world: << Code Omitted >> (the removeObject(this) part where im trying to remove the flower that the bee touched )
This code can be deleted (with the above change).
and this one in the bee class: << Code Omitted >> where it says it cannot find symbol variable speed
The variable speed is not declared in the class.
xixEmilyxix xixEmilyxix

2021/12/26

#
danpost wrote...
xixEmilyxix wrote...
the ones in the flower class: << Code Omitted >>
Move the bee vs. flower collision codes to the Bee class:
if (isTouching(Flower.class))
{
    removeTouching(Flower.class);
    stop();
}
and in the bee world: << Code Omitted >> (the removeObject(this) part where im trying to remove the flower that the bee touched )
This code can be deleted (with the above change).
and this one in the bee class: << Code Omitted >> where it says it cannot find symbol variable speed
The variable speed is not declared in the class.
So I changed my mind what i wanted it to do when it found a flower and changed the stop() to my goHome() method. I put that code into my Bee class and im still getting the same errors in this code in my Flower class:
        public void beeTouchingFlower()
    {
        //check if bee is touching flower
       final touchingBee = this.getOneIntersectingObject(Bee.class);
       final touchingFlower = this.getOneIntersectingObject(Flower.class);
       if (touchingBee != null)
          {
             //run beeTouchingFlower in world class
             BeeWorld b = (BeeWorld) getWorld();
             b.beeTouchingFlower(touchingBee);
             b.removeObject(this);
           }
    }
this is what my bee class, flower class and beeworld class look like now: beeworld:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class BeeWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class BeeWorld extends World
{
    //declare variables
    int beeValue;
    int weatherValue;
    public static Flower flower;
    int dayValue;
    int honeyValue;
    Actor btnAddDay, btnHelp, btnEndSimulation;
    private static final String[] FLOWER_COLOR = { "pink", "purple", "yellow" };
    /**
     * Constructor for objects of class BeeWorld.
     * 
     */
    public BeeWorld(int weatherVal)
    {
        //set background to main screen when button is pressed
        super(864, 540, 1);
        setPaintOrder(Buttons.class);
        
        //set nectar value
        Forager.nectarValue = 0;
        
        setBackground(new GreenfootImage("Background.png"));
        
        //run new day
        newDay();       
        
        //add the counter for the bee value
        showText("Bees: ",  810, 20);
                    
        //declare weatherValue 
        weatherValue = weatherVal;

                
        //set honey value
        honeyValue = 0;       
        showText("Honey: " + honeyValue,  810, 110); 
    }
    
    public void act()
    {
        if (Greenfoot.mouseClicked(btnAddDay))
        {
           newDay();
        }
        if (Greenfoot.mouseClicked(btnHelp))
        {
           help();
        }
        if(Greenfoot.mouseClicked(btnEndSimulation))
        {
           endSimulation();
        }
    }
    
    private void endSimulation()
    {
        Greenfoot.setWorld(new EndScreen()); 
    }
    
    private void help()
    {
        //add help menu
        HelpMenu HelpMenu = new HelpMenu();
        addObject (HelpMenu, getWidth(), getHeight());
        HelpMenu.setLocation(650,200);
        
        //button to be able to remove help menu
        RemoveMenu RemoveMenu = new RemoveMenu();
        addObject (RemoveMenu, getWidth(), getHeight());
        RemoveMenu.setLocation(900,200);
    }
    
    public void runSimulation()
    {
        if(weatherValue >= -40 && weatherValue <= 15)
         {
             //if the weather value is between -40 and 15 then the low temp simulation will run
             lowTemperature();
         } else if(weatherValue >= 16 && weatherValue <= 27)
         {
             //if the weather value is between 16 and 27 then the regular temp simulation will run
             regularTemperature();
         } else if(weatherValue >= 28 && weatherValue <= 40)
         {
             //if the weather value is between 28 and 40 then the high temp simulation will run
             highTemperature();
         }     
    }
    
    private Actor getRandomFlower()
    {
        int colorNum = Greenfoot.getRandomNumber(FLOWER_COLOR.length);
        return new Flower(FLOWER_COLOR[colorNum]);
    }
    
    public void lowTemperature()
    {
        //add random coloured flowers to the bee world
        addObject(getRandomFlower(), 500, 500);
        addObject(getRandomFlower(), 100, 300);
        addObject(getRandomFlower(), 200, 400);
        addObject(getRandomFlower(), 100, 100);
        addObject(getRandomFlower(), 700, 400);
        addObject(getRandomFlower(), 800, 200);
        
        //add bees to the bee world
        Worker Worker = new Worker ();
        Queen Queen = new Queen ();
        Forager Forager = new Forager ();
        addObject(new Queen(), 500, 250);
        addObject(new Forager(), 400, 150);
        addObject(new Forager(), 450, 200);
        addObject(new Forager(), 500, 220);
        addObject(new Forager(), 550, 250);
        
        //add the hive to the bee world
        Hive Hive = new Hive ();
        addObject(new Hive(), 650, 400);        
    }
    
    public void regularTemperature()
    {
        //add random coloured flowers to the bee world
        addObject(getRandomFlower(), 500, 500);
        addObject(getRandomFlower(), 100, 300);
        addObject(getRandomFlower(), 200, 400);
        addObject(getRandomFlower(), 100, 100);
        addObject(getRandomFlower(), 700, 400);
        addObject(getRandomFlower(), 800, 200);
        addObject(getRandomFlower(), 600, 100);
        addObject(getRandomFlower(), 400, 700);        
        
        //add bees to the bee world
        Worker Worker = new Worker ();
        Queen Queen = new Queen ();
        Forager Forager = new Forager ();
        addObject(new Queen(), 500, 250);
        addObject(new Forager(), 400, 150);
        addObject(new Forager(), 450, 200);
        addObject(new Forager(), 500, 220);
        addObject(new Forager(), 550, 250);
        addObject(new Forager(), 520, 175);
        addObject(new Queen(), 500, 250);
        
        //add the hive to the bee world
        Hive Hive = new Hive ();
        addObject(new Hive(), 650, 400);       
    }
    
    public void highTemperature()
    {
        //add random coloured flowers to the bee world
        addObject(getRandomFlower(), 500, 500);
        addObject(getRandomFlower(), 100, 300);
        addObject(getRandomFlower(), 200, 400);
        addObject(getRandomFlower(), 100, 100);
        addObject(getRandomFlower(), 700, 400);
        addObject(getRandomFlower(), 800, 200);        
        
        //add bees to the bee world
        Worker Worker = new Worker ();
        Queen Queen = new Queen ();
        Forager Forager = new Forager ();
        addObject(new Queen(), 500, 250);
        addObject(new Forager(), 400, 150);
        addObject(new Forager(), 450, 200);
        addObject(new Forager(), 500, 220);
        addObject(new Forager(), 550, 250);
        addObject(new Forager(), 520, 175);
        addObject(new Queen(), 500, 250);
        
        //add the hive to the bee world
        Hive Hive = new Hive ();
        addObject(new Hive(), 650, 400);        
    } 
  
        
    public void updateDay()
    {
        //update what day it is and run the next day when the day button is clicked
        dayValue = dayValue +1;
        showText("Day: " + dayValue, 810, 50);
        newDay();
    }
    
    private void newDay()
    {
        //start new day
        //remove all objects
        List objects = getObjects(null);
        removeObjects(objects);
        
        //increase day value
        dayValue++;
        
        //increase honey value
        updateHoney();
        
        //add buttons
        btnAddDay = new Buttons();
        btnAddDay.setImage(new GreenfootImage("addDaybutton.png"));
        btnHelp = new Buttons();
        addObject(btnAddDay, 820, 500);
        btnHelp.setImage(new GreenfootImage("helpButton.png"));
        addObject(btnHelp, 100, 190);
        btnEndSimulation = new Buttons();
        btnEndSimulation.setImage(new GreenfootImage("EndSimulationbutton.png"));
        addObject(btnEndSimulation, 50, 500);
        
        //run simulation again
        runSimulation();
        
        //random chance to see if bee dies
        
        //add bee every 5 days
        if (dayValue%5 == 0)
        {
           addObject(new Forager(), 550, 250);           
        }
    }     
    
    public void updateHoney()
    {
        //take away from nectar value
        Forager.nectarValue = Forager.nectarValue - 2;
        
        //increase honey value
        honeyValue = honeyValue + 2;
        
        //add the counter for the honey value
        showText("Honey: " + honeyValue,  810, 110);
    }   
}

Flower class:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.Random;

/**
 * A pile of food. The pile consists initially of 100 crumbs of food.
 * 
 * @author Michael Kolling
 * @version 1.1
 */
public class Flower extends Actor
{
    //create variable to be able to change colour of flowers
    public String color;
    
    public Flower(String pigment)
    {
        //set image of flowers
        color = pigment;
        GreenfootImage image = new GreenfootImage(color+"Flower.png");  
        image.scale(image.getWidth() - 500, image.getHeight() - 500);  
        setImage(image);
    }
    
    public void act()
    {
        //check if bee is touching flower
        //beeTouchingFlower();        
    }
    
        public void beeTouchingFlower()
    {
        //check if bee is touching flower
       final touchingBee = this.getOneIntersectingObject(Bee.class);
       final touchingFlower = this.getOneIntersectingObject(Flower.class);
       if (touchingBee != null)
          {
             //run beeTouchingFlower in world class
             BeeWorld b = (BeeWorld) getWorld();
             b.beeTouchingFlower(touchingBee);
             b.removeObject(this);
           }
    }
    
    public boolean touchingForager()
    {
        //check if touching bee then return it
        return isTouching(Forager.class);        
    }
}

Bee c;lass:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bee here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bee extends Actor
{
    //maximum movement speed
    private static final int SPEED = 2;

    //current movement and offset
    private int coordX;
    private int coordY;


    public Bee()
    {
        //neutral movement
        coordX = 0;
        coordY = 0;
    }
    
    public void randomWalk()
    {
        //walk around randomly (random direction and speed)
        if (randomChance(15)) 
        {  
            coordX = adjustSpeed(coordX);
            coordY = adjustSpeed(coordY);
        }
        walk();
    }
    
    public void walk()
    {
        //walk forward in the current direction with the current speed
        setLocation(getX() + coordX, getY() + coordY);
        setRotation((int) (180 * Math.atan2(coordY, coordX) / Math.PI));
    }
    
    
    public void beeTouchFlower()
    {
        if (isTouching(Flower.class))
        {
           removeTouching(Flower.class);
           goHome();
        }
    }
    
    public void goHome()
    {
        coordX = 0;
        coordY = 0;
        setLocation(getX() + coordX, getY() + coordY);
        setRotation((int) (180 * Math.atan2(coordY, coordX) / Math.PI));
    }

    private int adjustSpeed(int speed)
    {
        //adjust speed randomly
        speed = speed + Greenfoot.getRandomNumber(2 * SPEED - 1) - SPEED + 1;
        return capSpeed(speed);
    }

    private int capSpeed(int speed)
    {
        //make sure the speed returned is in the range
        if (speed < -SPEED)
            return -SPEED;
        else if (speed > SPEED)
            return SPEED;
        else
            return speed;
    }

    private boolean randomChance(int percent)
    {
        return Greenfoot.getRandomNumber(100) < percent;
    }
}
danpost danpost

2021/12/27

#
xixEmilyxix wrote...
im still getting the same errors in this code in my Flower class: << Code Omitted >>
Remove that code from your Flower class.
xixEmilyxix xixEmilyxix

2021/12/27

#
I did this and all my buttons work again. However, when i run the simulation its like the simulation automatically counts the beees touching the flowers and changes the nectar value even though no bees have touched any. They must disappear as soon as they spawn in and update the nectar aswell. I havent changed any code except taking out that flower code
danpost danpost

2021/12/27

#
xixEmilyxix wrote...
the simulation automatically counts the beees touching the flowers and changes the nectar value even though no bees have touched any.
Just to be sure, use a graphics editor to re-scale the flower images. Then remove the re-scaling code from the Flower constructor.
xixEmilyxix xixEmilyxix

2021/12/28

#
danpost wrote...
xixEmilyxix wrote...
the simulation automatically counts the beees touching the flowers and changes the nectar value even though no bees have touched any.
Just to be sure, use a graphics editor to re-scale the flower images. Then remove the re-scaling code from the Flower constructor.
What do you mean graphics ediitor to rescale the images? i did them in paint
danpost danpost

2021/12/28

#
xixEmilyxix wrote...
What do you mean graphics ediitor to rescale the images? i did them in paint
Ah, but I see you are re-scaling the flowers' image sizes in code, reducing their widths and heights by 500 each (Flower : 20). How huge are the images saved in the files?
xixEmilyxix xixEmilyxix

2021/12/28

#
1590x859 is the whole canvas but the picture takes up 159x283 (px). I removed the background using paint 3D
danpost danpost

2021/12/28

#
Transparent background is still considered actor image and will be included in collision. That is, if the bee touches any part of the image of a flower, transparencies included, a collision is determined to have occurred.
xixEmilyxix xixEmilyxix

2021/12/28

#
danpost wrote...
Transparent background is still considered actor image and will be included in collision. That is, if the bee touches any part of the image of a flower, transparencies included, a collision is determined to have occurred.
ahhh right, ive done that with my bees aswell. Ill change both of them and hopefully it will be working properly - thank you for the help
You need to login to post a reply.
1
2