Hello :)
i have some problems here, so i try to follow the code from here
http://www.greenfoot.org/topics/58346?offset=0
but its not working .-. here my code
for tower
for projectile
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class Tower1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Tower1 extends Actor
{
/**
* Act - do whatever the Tower1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
boolean weaponStatus = true;
int gerak = 1;
public void act()
{
shootProjectile();
refreshWeapon();
gerak++;
}
public void shootProjectile()
{
List<Minion1> minion = getObjectsInRange(200,Minion1.class);
if(minion.size() > 0 && weaponStatus==true)
{
getWorld().addObject(new Projectile1(),getX(),getY());
weaponStatus = false;
}
}
public void refreshWeapon(){
if(gerak%100==0){
weaponStatus = true;
}
}
}
import greenfoot.*;
import java.util.List;
/**
* Write a description of class Projectile1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Projectile1 extends Actor
{
/**
* Act - do whatever the Projectile1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkHit();
checkProjectile();
hitActor();
}
public void checkHit()
{
List<Minion1> isi = getWorld().getObjects(Minion1.class);
if(isi.size()==0)
{
getWorld().removeObject(this);
}
}
public void checkProjectile()
{
Actor miinion = (Minion1)getWorld().getObjects(Minion1.class).get(0);
turnTowards(miinion.getX(),miinion.getY());
move(5);
if(miinion.getWorld()==null)
{
getWorld().removeObject(this);
}
}
public void hitActor()
{
Actor minion;
minion = getOneObjectAtOffset(0, 0, Minion1.class);
if(minion!=null)
{
getWorld().removeObject(minion);
getWorld().removeObject(this);
}
}
}
