I would like to make 2 forms of gold income, one by gaining a certain amount of gold my pressing spacebar(gold/action) and the other one is gaining gold at a steady pace(gold/min). anyone has any idea how to do that?
private float preciseGold = 0;
public int gold = 0;
private boolean once = false;
private int moneyPerMin = 80;
private int moneyPerAct = 10;
private void gainMoney() {
if(Greenfoot.isKeyDown("space") && !once) {
preciseGold += moneyPerAct;
once = true;
} else if(!Greenfoot.isKeyDown("space) && once) once = false;
// assuming greenfoot's speed is 50
// if you want to make sure it stays at 50, uncomment the next line
// Greenfoot.setSpeed(50);
preciseGold += moneyPerMin / 60f / 50;
gold = (int) preciseGold;
// When buying something, only subtract the price from preciseGold!
}GreenfootImage image = new GreenfootImage("Yen: " + DYen, 20, Color.BLACK, Color.WHITE);
setImage(image);GreenfootImage image = new GreenfootImage("Yen: " + DYen, 20, Color.BLACK, Color.WHITE);
setImage(image);import greenfoot.*;
public class Item extends Actor
{
private GreenfootImage graphics;
public void act() {
gainMoney();
graphics = new GreenfootImage("Yen: " + gold, 20, Color.BLACK, Color.WHITE);
setImage(graphics);
}
private float preciseGold = 0;
public int gold = 0;
private boolean once = false;
private int moneyPerMin = 80;
private int moneyPerAct = 10;
private void gainMoney() {
if(Greenfoot.isKeyDown("space") && !once) {
preciseGold += moneyPerAct;
once = true;
} else if(!Greenfoot.isKeyDown("space") && once) once = false;
preciseGold += moneyPerMin / 60f / 50;
gold = (int) preciseGold;
}
}import greenfoot.*;
public class Umaru extends Actor
{
public void act()
{
GainYen();
}
public int DYen = 0;
private float AYen = 0;
private boolean HoldSpaceBuff = false;
private int YenPerMin = 90;
private int YenPerAct = 1;
public void GainYen()
{
if(Greenfoot.isKeyDown("space") && !HoldSpaceBuff)
{
AYen += YenPerAct;
HoldSpaceBuff = true;
}
else if(!Greenfoot.isKeyDown("space") && HoldSpaceBuff)
{
HoldSpaceBuff = false;
Greenfoot.setSpeed(50);
AYen += YenPerMin / 60f / 50;
}
DYen = (int) AYen;
// When buying something, only subtract the price from AGold!
}
}import greenfoot.*;
public class Gold extends Actor
{
public int DYen = 0;
public void act()
{
GreenfootImage image = new GreenfootImage("Yen: " + DYen, 20, Color.BLACK, Color.WHITE);
setImage(image);
}
}Gold g = new Gold(); addObject(g, /**x-coord, y-coord*/); addObject(new Umaru(g), /**x-coord, y-coord*/);
//Gold class
public void updateImage(int yen)
{
setImage(new GreenfootImage("Yen: " + yen, 20, Color.BLACK, Color.WHITE));
}//in Umaru class
private Gold gold;
public Umaru(Gold g)
{
gold = g;
}
//after a change to DYen was made:
gold.updateImage(DYen);private Umaru umaru = null;
public Gold(Umaru umaru) {
this.umaru = umaru;
}public void addedToWorld(World world) {
world.addObject(new Gold(this), 100, 100);
}//in Umaru class
private Gold gold;
public Umaru(Gold g)
{
gold = g;
}
//after a change to DYen was made:
gold.updateImage(DYen);private Umaru umaru = null;
public Gold(Umaru umaru) {
this.umaru = umaru;
}public void addedToWorld(World world) {
world.addObject(new Gold(this), 100, 100);
}//in Umaru class
private Gold gold;
public Umaru(Gold g)
{
gold = g;
}
//after a change to DYen was made:
gold.updateImage(DYen);