Lavenger wrote...
it seems like I'm having troubles getting the debugger to show, so I can't see the actTimer value. it says "Thread is running. Threads must be stopped to view details." any idea on how to fix that?
import greenfoot.*;
public class MiniTaihei extends greenfoot.Actor
{
int nx = 0, ny = 0, fx = 0, fy = 0;
Timer actTimer = new Timer(40);
private boolean once = false;
private boolean run = false;
public MiniTaihei()
{
getImage().scale(30, 30);
}
public void act()
{
if (actTimer.iterating()) return;
if(Wall.class == null)
{
if (Greenfoot.isKeyDown("a")&&(getOneObjectAtOffset(fx - 1, fy, Wall.class) == null))
{fx--;}
if (Greenfoot.isKeyDown("d")&&(getOneObjectAtOffset(fx + 1, fy, Wall.class) == null))
{fx++;}
if (Greenfoot.isKeyDown("w")&&(getOneObjectAtOffset(fx, fy - 1, Wall.class) == null))
{fy--;}
if (Greenfoot.isKeyDown("s")&&(getOneObjectAtOffset(fx, fy + 1, Wall.class) == null))
{fy++;}
if (fx*fy == 0 && fx+fy != 0)
{
nx = fx;
ny = fy;
setLocation(getX()+nx, getY()+ny);
actTimer.start();
}
}
else if (isTouching(MiniKirie.class))
{
getWorld().removeObjects(getWorld().getObjects(Actor.class));
}
}
}import greenfoot.*;
public class MyWorld extends World
{
// fields usually (by convention) go first
//For GIF background stuff
GifImage gifImg = new GifImage("Umaru.gif");
//For Timing stuff
private Actor TimeDisplay = new SimpleActor(), Cooldown = new SimpleActor();
private int frames;
private int Cframes = (3+Greenfoot.getRandomNumber(5))*55;
//For Yen stuff
public float AYen; //precise
public int DYen; //rounded
public Yen YenDisplay = new Yen();
public int getHeight = 552 ;
public int getWidth = 1200 ;
//For Buttons stuff
public Actor MKButton = new SimpleActor(), HButton = new SimpleActor(), BButton = new SimpleActor(), AButton = new SimpleActor(), SButton = new SimpleActor(), KButton = new SimpleActor(), EButton = new SimpleActor(), TButton = new SimpleActor();
public Actor Buttons[] = {MKButton, HButton, BButton, AButton, SButton, KButton, EButton, TButton};
private String ButtonImages[] = {"MKButton", "HButton", "BButton", "AButton", "SButton", "KButton", "EButton", "TButton"};
private int ButtonsArraySize = Buttons.length;
//For PIP stuff
PIP pip;
World minor;
public Boolean setActiveState = false;
Actor mouseActor; // holds the actor being dragged
int mouseOffX, mouseOffY; // holds the offsets of mouse location from center of object being dragged
// class constructors usually (by convention) go next
//To construct MyWorld
public MyWorld()
{
//For building the world window size
super(1400, 675, 1);
//For updating the Yen Display
adjustYen(0); // to initialize image
prepare();
addObject(YenDisplay, 1265, 50); // wherever
//For updating the time display
updateTimeDisplay();
addObject(TimeDisplay, 1265, 20);
//For triggering the minigame
updateCooldownDisplay();
addObject(Cooldown, 1265, 35);
//For adding in the buttons to add the actors into the world
for( int i = 0; i < ButtonsArraySize; i++)
{
Buttons[i].setImage(ButtonImages[i] + ".png"); Buttons[i].getImage().scale(70, 70); addObject(Buttons[i], 1175, (120 + (i*50)));
i++;
Buttons[i].setImage(ButtonImages[i] + ".png"); Buttons[i].getImage().scale(70, 70); addObject(Buttons[i], 1325, (120 + ((i-1)*50)));
}
}
//For GIF background
private void gifAnimation()
{
for (Object obj : gifImg.getImages()) ((GreenfootImage)obj).scale(getWidth(), getHeight());
setBackground(gifImg.getCurrentImage());
}
// methods (by convention) go last
//For executing all preccesses in MyWorld
public void act()
{
//For GIF background
gifAnimation();
//For buying the Characters
if(Greenfoot.mouseClicked(MKButton) && AYen >= 100 && (getObjects(MgrKanau.class).isEmpty())) {AYen -= 100; addObject(new MgrKanau(), 600, 600);}
if(Greenfoot.mouseClicked(HButton) && AYen >= 200 && (getObjects(Hikari.class).isEmpty())) {AYen -= 200; addObject(new Hikari(), 600, 600);}
if(Greenfoot.mouseClicked(AButton) && AYen >= 400 && (getObjects(Alex.class).isEmpty())) {AYen -= 400; addObject(new Alex(), 600, 600);}
if(Greenfoot.mouseClicked(SButton) && AYen >= 800 && (getObjects(Sylphynford.class).isEmpty())) {AYen -= 800; addObject(new Sylphynford(), 600, 600);}
if(Greenfoot.mouseClicked(BButton) && AYen >= 1600 && (getObjects(Bomba.class).isEmpty())) {AYen -= 1600; addObject(new Bomba(), 600, 600);}
if(Greenfoot.mouseClicked(KButton) && AYen >= 3200 && (getObjects(Kirie.class).isEmpty())) {AYen -= 3200; addObject(new Kirie(), 600, 600);}
if(Greenfoot.mouseClicked(EButton) && AYen >= 6400 && (getObjects(Ebina.class).isEmpty())) {AYen -= 6400; addObject(new Ebina(), 600, 600);}
if(Greenfoot.mouseClicked(TButton) && AYen >= 12800 && (getObjects(Taihei.class).isEmpty())) {AYen -= 12800; addObject(new Taihei(), 600, 600);}
//For updating the Timing stuff
if ((++frames)%55 == 0) updateTimeDisplay();
if ((--Cframes)%55 == 0) updateCooldownDisplay();
if (Cframes == 0)
{
Minigame();
Cframes += ((3+Greenfoot.getRandomNumber(5))*55); //chooses a cooldown time between 3-7 minutes randomly
}
// control dragging of PIP objects
if (Greenfoot.mousePressed(null) && mouseActor == null)
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse.getActor() == null || mouse.getActor().getClass() != PIP.class) return;
mouseActor = mouse.getActor();
mouseOffX = mouseActor.getX()-mouse.getX();
mouseOffY = mouseActor.getY()-mouse.getY();
removeObject(mouseActor);
addObject(mouseActor, mouse.getX()+mouseOffX, mouse.getY()+mouseOffY);
}
if (mouseActor != null && Greenfoot.mouseDragged(mouseActor))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
mouseActor.setLocation(mouse.getX()+mouseOffX, mouse.getY()+mouseOffY);
}
if (mouseActor != null && Greenfoot.mouseClicked(mouseActor)) mouseActor = null;
//for removing ended Minigames
if (pip != null && pip.getWorld() == this && minor.getObjects(null).isEmpty())
{
removeObject(pip);
}
}
//For Yen Display stuff
public int getAccumulatedYen()
{
return DYen;
}
public void adjustYen(float adjustment)
{
AYen += adjustment;
DYen = (int) AYen;
YenDisplay.setImage(new GreenfootImage("Yen: "+DYen+"¥", 20, Color.BLACK, new Color(0, 0, 0, 0)));
}
//For Time Display stuff
private void updateTimeDisplay()
{
int Time = frames/55; // total seconds
int TotalMinutes = Time/60; // total minutes
String hours = "0"+(TotalMinutes/60); // string total hours
String minutes = "0"+(TotalMinutes%60); // string remaining minutes
String seconds = "0"+(Time%60); // string remaining seconds
String hrs = hours.substring(hours.length()-2); // hour output string
String mins = minutes.substring(minutes.length()-2); // minutes output string
String secs = seconds.substring(seconds.length()-2); // seconds output string
String TimeFormat = "Time: "+hrs+"hrs "+mins+"mins "+secs+"secs"; //Preview: Time: 12345hrs 12mins 12secs
TimeDisplay.setImage(new GreenfootImage(TimeFormat, 20, Color.BLACK, new Color(0, 0, 0, 0)));
}
//Minigame stuff
//For timing the appearance of the Minigame
private void updateCooldownDisplay()
{
int Time = Cframes/55;
String minutes = "0"+(Time/60); // string remaining minutes
String seconds = "0"+(Time%60); // string remaining seconds
String mins = minutes.substring(minutes.length()-2); // minutes output string
String secs = seconds.substring(seconds.length()-2); // seconds output string
String TimeFormat = "Minigame countdown: "+mins+"mins "+secs+"secs"; //Preview: Time: 12345hrs 12mins 12secs
Cooldown.setImage(new GreenfootImage(TimeFormat, 20, Color.BLACK, new Color(0, 0, 0, 0)));
}
//For choosing and calling out the Minigame
private void Minigame()
{
if (pip != null && pip.getWorld() != null) return; // will not add new pip if one is already in world
minor = null;
switch (Greenfoot.getRandomNumber(3))
{
case 0: if (!getObjects(Taihei.class).isEmpty()) minor = new Minigame1(); break;
case 1: if (!getObjects(Sylphynford.class).isEmpty()) minor = new Minigame2(); break;
case 2: if (!getObjects(Ebina.class).isEmpty()) minor = new Minigame3(); break;
case 3: if (!getObjects(Alex.class).isEmpty()) minor = new Minigame4(); break;
case 4: if (!getObjects(Bomba.class).isEmpty()) minor = new Minigame5(); break;
}
if (minor != null)
{
pip = new PIP(minor, new Class[] {});
pip.setActiveState(true);
addObject(pip, 690, 110);
}
}
private void prepare()
{
addObject(new Umaru(), 700, 338);
}
}public class Timer
{
private int delayAmount; // the number of steps to complete one cycle
private int counter; // the current value of the timer
private boolean paused; // the current paused state of the timer
private boolean looping; // the looping state of the timer
/**
* this secondary constructor creates a timer object that does not loop automatically
*
* @param amount the number of steps to complete one cycle
*/
public Timer(int amount)
{
this(amount, false); // calls the primary constructor with a looping value of false
}
/**
* this primary constructor sets up a timer object
*
* @param amount the number of steps to complete one cycle
* @param toLoop a flag indicating whether the timer should loop automatically or not
*/
public Timer(int amount, boolean toLoop)
{
delayAmount = amount; // number of steps to delay
looping = toLoop; // save looping state
if (looping) counter = -1; // adjust counter if looping (looping counters must be explicitly started)
}
/**
* usually called by the object that created the timer to execute one step and return a boolean value
* indicating whether the timer is still running or not; a paused state is a busy state and returns a
* true value just as if the timer was still running
*
* @return a boolean value indicating whether the timer is paused or has not completed a cycle, or not
*/
public boolean iterating()
{
if (paused) return true; // timer is paused
if (counter == 0 && looping) counter = delayAmount; // reset counter if end of cycle and looping
if (counter > 0) counter--; // decrement counter
return counter > 0; // return true if cycle is not complete
}
/**
* stops the timer
*/
public void stop()
{
counter = -1; // sets counter value to one indicating the timer is stopped
paused = true; // sets paused flag to true
}
/**
* starts the timer
*/
public void start()
{
paused = false; // sets pausd flag to false
counter = looping ? 0 : delayAmount; // sets counter to an appropriate value depending on looping state
}
/**
* un-pauses the timer
*/
public void resume()
{
paused = false; // sets paused flag to false
}
/**
* pauses the timer
*/
public void pause()
{
paused = true; // sets paused flag to true
}
}actTimer = new Timer(40);
actTimer = new Timer(40);
if (fx*fy == 0 && fx+fy != 0 && getOneObjectAtOffset(fx, fy, Wall.class) == null)
int fx = 0, fy = 0;