how can i use the greenfoot package that you use in above,,i am trying to use that package but that give me an error that-"package greenfoot dose not exist"
public class towerAttacks extends Actor
{
/**
* Act - do whatever the towerAttacks wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
tower t;
public towerAttacks(tower T)
{
t = T;
}
public towerAttacks()
{
}
public void act()
{
// Add your action code here.
//t.attack();
moveToEnemy();
isHit();
}
public void moveToEnemy()
{
int x = t.enemyPosX();
int y = t.enemyPosY();
//turnTowards(x, y); //could use if school comps had greenfoot 2.2
int dx = x - getX();
int dy = y - getY();
double angle = Math.toDegrees(Math.atan2(dy, dx));
double distance = Math.sqrt((dx*dx) + (dy*dy));
int z = (int) angle;
setRotation(z);
move(1);
}
public void isHit()
{
if(getOneObjectAtOffset(0, 0, enemies.class) != null)
{
//do attack damage
getWorld().removeObject(this);
}
if(getX() <=0 || getX() >= getWorld().getWidth() || getY() <= 0 || getY() >= getWorld().getHeight())
{
getWorld().removeObject(this);
}
}
}public class tower extends Actor
{
/**
* Act - do whatever the tower wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
/**be sure to use the radius method of the world/actor class to see around the tower a certain
* distance. also add radius upon upgrading the towers. figure out a way to show the radius
*/
public int attack;
public int attspd; //in milliseconds
public int range;
public int attTimer;
private long count = 0;
private long aTime = 0;
public int price;
public int x = 0;
public int y = 0;
//private int wave = 1; //have wave class come in as well
public int lvl = 1;
public void act()
{
// Add your action code here.
/**
* create the levels of the towers in here. possibly make the attack spd and damage in here
* as well, in which case also special effects. also put radius of each tower in here for sight
* or in each specific tower.
*/
placing();
attack();
}
public void attack()
{
//List<enemies> e = getObjectsInRange(range, enemies.class);
//if(canAttack() && !e.isEmpty())
if(canAttack() && !getObjectsInRange(range, enemies.class).isEmpty())
{
/** attack first enemy.
* if(clock)
* {
* e(0).health - attack;
*}
*
**/
//enemies temp = e.get(0);
enemies temp = (enemies)getObjectsInRange(range, enemies.class).get(0);
x = temp.getX();
y = temp.getY();
shoot();
temp.decHealth(); /**change to a method like:
* public void attack()
*{
* temp.decHealth(attack) <---would have to change the
* decHealth method to accept an int and
* would lower the health not by decreasing by
* 1, but by 1*the int (attack of each tower)
*}
**/
attTimer = attspd;
}
}
private boolean canAttack()
{
if(attTimer > 0)
{
attTimer --;
}
return attTimer == 0;
}
public void shoot()
{
}
public int enemyPosX()
{
return x;
}
public int enemyPosY()
{
return y;
}
public int getPrice()
{
return price;
}
public void placing()
{
if(Greenfoot.mouseClicked(this))// && Greenfoot.mouseDragged(null))
{
// // MouseInfo m = Greenfoot.getMouseInfo();
// // setLocation(m.getX(), m.getY());
// }
if(Greenfoot.mouseMoved(null) && Greenfoot.mouseClicked(this))
{
MouseInfo m = Greenfoot.getMouseInfo();
setLocation(m.getX(), m.getY());
}
}
}
}public class fasttower extends tower
{
/**
* Act - do whatever the fasttower wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
//att lv 1/2/3 1/2/4/8
//att spd lv 1/2/3 1/.75/.5/.35
//price 5
//upgrade price 10
//private int attack = 1;
//private long attspd = 1000; //milliseconds
//private int range = 5;
//private int lvl = 1;
//private long count = 0;
//private long aTime = 0;
// private int wave = 1; //have wave class come in as well
//private minion1 m1;
//private Object unit;
// public fasttower(minion1 M1)
// {
// m1 = M1;
// }
public fasttower()
{
attack = 1;
attspd = 60;
range = 55;
attTimer = 0;
price = 5;
}
public void act()
{
// Add your action code here.
//use getObjectsInRange() method for actors to make a radius for towers
//update();
attack();
//shoot();
}
private void update()
{
/**if have minerals and click on tower, upgrade to next lv
* will have to add a minerals class and have it seen in every class.
*if(minerals == 10 && clickontower && (lv <= 4))
*{
* lvl++;
* attack += (attack*lvl);
* attspd = attspd - 200;
* range += (range*lvl);
*}
**/
}
public void shoot()
{
int X = getX();
int Y = getY();
((tdpath)getWorld()).addObject(new fastAttack(), X, Y);
}
}public class fastAttack extends towerAttacks
{
/**
* Act - do whatever the fastAttack wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
//damage 1/2/4
//att spd .75/.5/.35 sec
int x, y;
public fastAttack(int X, int Y)
{
x = X;
y = Y;
}
public fastAttack()
{
}
public void act()
{
// Add your action code here.
moveTo(x, y);
isHit();
}
private void moveTo(int x, int y)
{
double xX = x - getX();
double yY = y - getY();
double angle = Math.atan2(yY, xX)*180/Math.PI;
setRotation( (int) angle);
move(2);
}
}public class towerAttacks extends Actor
{
/**
* Act - do whatever the towerAttacks wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
tower t;
public towerAttacks(tower T)
{
t = T;
}
public towerAttacks()
{
}
public void act()
{
// Add your action code here.
//t.attack();
moveToEnemy();
isHit();
}
public void moveToEnemy()
{
int x = t.enemyPosX();
int y = t.enemyPosY();
//turnTowards(x, y); //could use if school comps had greenfoot 2.2
int dx = x - getX();
int dy = y - getY();
double angle = Math.toDegrees(Math.atan2(dy, dx));
double distance = Math.sqrt((dx*dx) + (dy*dy));
int z = (int) angle;
setRotation(z);
move(1);
}
public void isHit()
{
if(getOneObjectAtOffset(0, 0, enemies.class) != null)
{
//do attack damage
getWorld().removeObject(this);
}
else if(getX() <=0 || getX() >= getWorld().getWidth() || getY() <= 0 || getY() >= getWorld().getHeight())
{
getWorld().removeObject(this);
}
}
}if (enemy.getWorld() == null)