Whenever I have this object in the world it gradually slows the program until it is cleared and then it returns to normal.
This is the code. Anyone idea why this is?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class CavernTank here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class TankBoss extends SmoothMovement
{
private GreenfootImage image1;
private GreenfootImage image2;
private GreenfootImage image3;
int imgFrame = 0; //This keeps track of which image frame it is currently showing
private boolean swordeInRange = false;
private int dmgDone;
private boolean dashOn = false;
private int dashCoolDown;
private int tankDash = 50;
private int dashCount;
private int dashLength = 10;
private int dashSound = 40;
public TankBoss()
{
image1 = new GreenfootImage("Cavern Tank0.png");
image2 = new GreenfootImage("Cavern Tank1.png");
image3 = new GreenfootImage("Cavern Tank2.png");
}
public void act()
{
checkCollision();
move();
moveImage();
findSworde();
dashCoolDown++;
death();
}
public void death()
{
if (dmgDone == 200)
{
Greenfoot.playSound("explosion_x.wav");
getWorld().removeObject(TankBoss.this);
}
}
public void checkCollision()
{
Sworde sworde = (Sworde) getOneIntersectingObject(Sworde.class);
if (sworde != null)
{
dmgDone += 10;
}
}
public void moveImage() //This would be a loop going constantly to animate it
{
imgFrame++;
if (imgFrame == 4)
{
imgFrame = 1;
}
if (imgFrame == 1)
{
setImage(image2);
}
if (imgFrame == 2)
{
setImage(image3);
}
if (imgFrame == 3)
{
setImage(image1);
}
}
public void findSworde()
{
move(1);
int checkTurn = Greenfoot.getRandomNumber(10);
if (!getObjectsInRange(300, Sworde.class).isEmpty())
{
swordeInRange = true;
dash();
}
else
{
swordeInRange = false;
}
if (swordeInRange)
{
Actor sworde = (Actor)getWorld().getObjects(Sworde.class).get(0);
turnTowards(sworde.getX(), sworde.getY());
}
else
if (checkTurn > 8)
{
turn(5);
}
if (checkTurn < 2)
{
turn(-5);
}
}
public void dashLength()
{
if (dashCount <= dashLength)
{
move(10);
dashCount++;
}
if (dashCount >= dashLength)
{
dashOn = false;
dashCount = 0;
}
}
public void dash()
{
if (dashOn)
{
dashLength();
dashSound += 10;
}
if (dashSound >= 40)
{
Greenfoot.playSound("tank.wav");
dashSound = 0;
}
if (dashCoolDown >= tankDash)
{
dashCoolDown = 0;
DashTrail2 dashtrail = new DashTrail2 (getVelocity(), getRotation());
getWorld().addObject (dashtrail, getX(), getY());
dashOn = true;
}
}
}
