Hi there, so i'm making tower defense game, i want to add a tower to platform. I have 6 platform instances and 3 tower, when i click 1 of the platform and click one of the tower, the tower will be added to the platform that i clicked earlier. i can't figure that, here some of my code.
public class MyWorld extends World
{
Platform platform = new Platform();
addObject(platform,90,355);
Platform platform2 = new Platform();
addObject(platform2,90,215);
Platform platform3 = new Platform();
addObject(platform3,300,215);
Platform platform4 = new Platform();
addObject(platform4,300,355);
Platform platform5 = new Platform();
addObject(platform5,550,355);
Platform platform6 = new Platform();
addObject(platform6,550,215);
}public class Platform extends Actor
{
public int ind;
public void checkInd() {
if(!getWorld().getObjects(Platform.class).isEmpty()) {
if(getX() == 550 && getY() == 215) {
ind = 5;
}
else if(getX() == 550 && getY() == 355) {
ind = 4;
}
else if(getX() == 300 && getY() == 355) {
ind = 3;
}
else if (getX() == 300 && getY()== 215) {
ind = 2;
}
else if (getX() == 90 && getY() == 215) {
ind = 1;
}
else if (getX() == 90 && getY() == 355) {
ind = 0;
}
}
}
public int getInd() {
return ind;
}
}public class BuyArcher extends Platform
{
public BuyArcher() {
GreenfootImage myImage = getImage();
int myWidth = (int)myImage.getWidth();
int myHeight = (int)myImage.getHeight();
myImage.scale(myWidth, myHeight);
}
public void act()
{
checkClicked();
}
public void checkClicked() {
if (Greenfoot.mouseClicked(this)) {
if(!getWorld().getObjects(Platform.class).isEmpty()) {
Platform plat = (Platform) getWorld().getObjects(Platform.class).get(ind);
int platX = plat.getX();
int platY = plat.getY();
Archer archer = new Archer();
getWorld().addObject(archer,platX, platY);
}
}
}
}