I'm thinking that my issue is when you switch worlds back to the Dock world after purchasing the next level in the Shop world, the boolean values reset? I tried changing it and put them in the shop world instead, but had the same issue, and then I tried putting it into the "FishShad" actor. I have tried other solutions, but that would make for a lengthy list.
Apologies for the lack of comments in my code, but it should be straightforward enough to understand. I can explain what it's meant to do if needed. I mostly cut all the irrelevant bits of it, and I also reverted it to the state it was before I tried any fixes.
public class RodOneBuy extends BuyButtons
{
/**
* Act - do whatever the RodOneBuy wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
purchase();
}
public void purchase()
{
if(Dock.moneyVar >= 25 && Greenfoot.mouseClicked(this) && Dock.rodNo==true && Dock.rodLow==false)
{
Dock.moneyVar -= 25;
Dock.rodLow=true;
Dock.rodNo=false;
}
}
}public class Dock extends World
{
public static int moneyVar=0;
public static int energyVar=100;
public int timer=0;
public static boolean baitNo=true;
public static boolean rodNo=true;
public static boolean baitLow=false;
public static boolean rodLow=false;
public static boolean baitMed=false;
public static boolean rodMed=false;
public static boolean baitHigh=false;
public static boolean rodHigh=false;
/**
* Constructor for objects of class Dock.
*
*/
public Dock()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
setBackground(new GreenfootImage("dockbg.png"));
prepare();
Greenfoot.start();
}public class FishShad extends Actor
{
/**
* Act - do whatever the FishShad wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
swim();
escape();
caught();
}
public void caught()
{
if(Greenfoot.mouseClicked(this) && Dock.rodNo==true && Dock.baitNo==true && Dock.energyVar>0)
{
Can can = new Can();
getWorld().addObject(can, 300, 200);
Dock.energyVar-=5;
getWorld().removeObject(this);
return;
}
else if(Greenfoot.mouseClicked(this) && Dock.rodLow==true && Dock.baitNo==true && Dock.energyVar>0)
{
Can can = new Can();
getWorld().addObject(can, 297, 200);
getWorld().addObject(can, 303, 198);
Dock.energyVar-=5;
getWorld().removeObject(this);
return;
}
}
