I changed the value of Distance to 1000.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Stage1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Stage1 extends World
{
int[]WayX;
int[]WayY;
int index=0;
public static int hp;
public static int speed;
private int counter=0;;
private static final int max=20;
private int spawn=0;
private static int level = 1;
/**
* Constructor for objects of class Stage1.
*
*/
public Stage1()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 425, 2);
setBackground("Stage1f.png");
prepare();
}
public int getLevel()
{
return level;
}
public void act(int hp,int speed)
{
counter++;
if((counter>=20)&&(spawn<=max))
{
System.out.println("Test");
addObject(new Creepers(hp,speed,level),0,108);
spawn();
spawn++;
waypoints();
counter=0;
}
}
public void spawn()
{
int random= (int)((Math.random()*3) + 1);
if(random==1)
{
addObject(new Small(level),0,108);
}
if(random==2)
{
addObject(new Medium(level),0,108);
}
if(random==3)
{
addObject(new Heavy(level),0,108);
}
System.out.println(random);
}
public void waypoints()
{
WayX= new int[]{94,94,188,188,281,281,374,374,467,467,563,563,599};
WayY= new int[]{108,223,223,28,28,372,372,83,83,314,314,140,140};
index++;
}
public void prepare()
{
Counter counter = new Counter();
addObject(counter, 123, 416);
counter.setLocation(120, 415);
Counter2 counter2 = new Counter2();
addObject(counter2, 240, 415);
counter2.setLocation(237, 414);
NormalButton nbutton = new NormalButton(counter2);
addObject(nbutton, 15, 416);
nbutton.setLocation(12, 414);
IceButton ibutton = new IceButton(counter2);
addObject(ibutton, 26, 409);
ibutton.setLocation(49, 413);
ibutton.setLocation(51, 413);
ibutton.setLocation(48, 413);
FireButton fbutton = new FireButton(counter2);
addObject(fbutton, 31, 415);
fbutton.setLocation(30, 414);
fbutton.setLocation(31, 414);
fbutton.setLocation(31, 414);
SniperButton sbutton = new SniperButton(counter2);
addObject(sbutton, 70, 415);
sbutton.setLocation(66, 414);
sbutton.setLocation(69, 414);
BombButton bbutton = new BombButton(counter2);
addObject(bbutton, 89, 417);
bbutton.setLocation(85, 414);
Money money = new Money();
addObject(money, 195, 409);
money.setLocation(193, 414);
Lives lives = new Lives();
addObject(lives, 424, 395);
lives.setLocation(112, 415);
counter.setLocation(145, 414);
counter.setLocation(149, 414);
lives.setLocation(117, 414);
counter.setLocation(151, 414);
counter2.setLocation(237, 413);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class Creepers here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Creepers extends Actor
{
public static int type;
int[]WayX;
int[]WayY;
int index=0;
double distance=150;
int count=0;
private int max=20;
private int spawn=0;
public static int hp;
public static int speed;
static Counter counter;
private int level;
public Creepers(int hp,int speed, int lv)
{
level = lv;
hp=hp;
speed=speed;
setRotation(90);
if(type==1) setImage("Enemy-small.png");
if(type==2) setImage("Enemy-medium.png");
if(type==3) setImage("Enemy-heavy.png");
if (IntroScreen.level==3)
{
setRotation(180);
}
}
public void Act()
{
Move();
// Waypoints();
}
// public void Waypoints()
// {
//
// if(Stage1.getLevel()== 1)
// {
//
//
// WayX= new int[]{94,94,188,188,281,281,374,374,467,467,563,563,599};
// WayY= new int[]{108,223,223,28,28,372,372,83,83,314,314,140,140};
// Move();
// }
// if (IntroScreen.level == 2){
// WayX= new int[] {478,487,272,272,599};
// WayY= new int[]{171,380,380,19,19};
// }
// if (IntroScreen.level == 3){
// WayX=new int[] {355,246,246,463,463,134,134,572,572,27,27};
// WayY=new int[] {248,248,115,115,314,314,49,49,381,381,10};
// }
// if (IntroScreen.level == 4){
// WayX= new int[]{319,319,56,56,431,431,525,525,599};
// WayY= new int[]{376,21,21,288,288,21,21,375,375};
// }
// }
public void Move()
{
move(1);
double theDistance = (int)(Math.hypot(WayX[index] - getX(), WayY[index] - getY()));
if (theDistance < 1 )
{
for (int i=0;i<theDistance;i++)
{
distance=theDistance;
}
}
turnTowards(WayX[index], WayY[index]);
if(count>=598&&spawn>=598)
{
getWorld().removeObject(this);
}
}
public void Death()
{
World world = getWorld();
Actor bullet = getOneIntersectingObject(Bullets.class);
// if (getIntersectingObjects(Bullets.class)!=null)
// {
// getWorld().removeObject(this);
// }
}
}
this.hp = hp; this.speed = speed;