I want my "MeanBird" to decrease int variable "oneup" by one each time it eats a turtle.
This is the bird's code:
And this is the world code:
and this is the "Indic" indicator code:
----
I need the Indic to change to smiley or sad based upon how many "Turdle"s there are in the world. Every time a MeanBird eats a Turdle, it should drop by one, and every time a Turdle is spawned, it should grow by one.
{
/**
* Act - do whatever the MeanBird wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{ move(5);
Actor TURDLE;
TURDLE = getOneObjectAtOffset(0, 0, TURDLE.class);
if (TURDLE != null)
{
World world;
world= getWorld();
world.removeObject(TURDLE);
oneup = oneup - 1;
}
if (TURDLE != null)
{
move(-10);
}
else
{TURDLE player = (TURDLE) getWorld().getObjects(TURDLE.class).get(0);
turnTowards(player.getX(), player.getY());
}
}
} * @author (your name)
* @version (a version number or a date)
*/
public class TurdleWurdle extends World
{
public int score = 15;
public int oneup = 0;
/**
* Constructor for objects of class TurdleWurdle.
*
*/
public TurdleWurdle()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
addObject(new TURDLE(), 50, 200);
addObject(new TURDLE(), 50, 175);
addObject(new TURDLE(), 50, 150);
addObject(new TURDLE(), 50, 125);
addObject(new TURDLE(), 50, 100);
addObject(new TURDLE(), 50, 75);
addObject(new TURDLE(), 50, 50);
addObject(new TURDLE(), 50, 25);
addObject(new TURDLE(), 50, 225);
addObject(new TURDLE(), 50, 250);
addObject(new TURDLE(), 50, 275);
addObject(new TURDLE(), 50, 300);
addObject(new TURDLE(), 50, 325);
addObject(new TURDLE(), 50, 350);
addObject(new TURDLE(), 50, 375);
addObject(new MeanBird(), 200, 50);
addObject(new MeanBird(), 100, 50);
addObject(new You(), 200, 200);
addObject(new Indic(), 500, 100);
int counter = 0;
}
public void act()
{
if ( Greenfoot.getRandomNumber(100) < 10 )
{
addObject(new TURDLE(), 50, 200);
score = score + 1;
}
if ( Greenfoot.getRandomNumber(100) < 5 )
{
addObject(new MeanBird(), 50, 200);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Indic here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Indic extends Actor
{
/**
* Act - do whatever the Indic wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private GreenfootImage smiley1;
private GreenfootImage smiley2;
private GreenfootImage smiley3;
private GreenfootImage smiley4;
public void act()
{
if(oneup > 0) {
updateImageBad();
}
if(oneup > 16) {
updateImageOkay();
}
if(oneup > 24) {
updateImageGood();
}
{
//why are you not working???
}
}
private void updateImageGood()
{
setImage(smiley2);
}
private void updateImageOkay()
{
setImage(smiley4);
}
private void updateImageBad()
{
setImage(smiley3);
}
}
