public class rocket extends Actor
{
int n=0;
/**
* Act - do whatever the laser wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(50);
if(cekmusuh())
{
kenarocket();
}
info();
nyampeujung();
}
public boolean cekmusuh()
{
Actor musuh = getOneObjectAtOffset(0,0,musuh.class);
if(musuh!=null)return(true);else return(false);
}
public void kenarocket(){
Actor musuh = getOneObjectAtOffset(0,0,musuh.class);
if(musuh!=null){
getWorld().removeObject(musuh);
n++;
}
}
public void nyampeujung()
{
if(this.isAtEdge())
{
getWorld().removeObject(this);
}
}
public void info()
{
labelhp lhp = new labelhp();
lhp.setTulisan("n : "+n);
getWorld().addObject(lhp,110,20);[quote]
public class Player extends Actor
{
/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
protected int hp = 500;
private boolean mouseIsDown;
private int counter,HIT,rockets;
public Player()
{
rockets = 25;
counter = 0;
// HIT = 0;
}
public void act()
{
if(hp<=0){
Greenfoot.stop();
lose();
}
tembakrocket();
kenamusuh();
kenaboss();
// info();
}
public void kenamusuh()
{
Actor musuh = getOneObjectAtOffset(0,0,musuh.class);
if(musuh!=null)
{
hp=hp-1;
}
}
public void kenaboss()
{
Actor boss = getOneObjectAtOffset(0,0,boss.class);
if(boss!=null)
{
hp=hp-3;
}
}
// public void info()
// {
// labelhp lhp = new labelhp();
// lhp.setTulisan("HP : "+hp);
// getWorld().addObject(lhp,110,20);
// }
public void tembakrocket()
{
//mendapatkan koordinat kursor, diklik atau tidak, ditekan atau tidaknya klik kiri atau klik kanan
MouseInfo mouse = Greenfoot.getMouseInfo();
if(Greenfoot.mousePressed(null)){mouseIsDown = true;}
else if (Greenfoot.mouseClicked(null)){mouseIsDown = false;}
if(mouseIsDown){
if(counter >= rockets){
//mengeluarkan rocket sesuai mouse info
rocket rc = new rocket();
getWorld().addObject(rc, getX(), getY()-10);
//player mengikuti koordinat dari kursor
if(mouse!=null){rc.turnTowards(mouse.getX(), mouse.getY());}
rc.move(0);
counter = 0;
}
}
counter++; //jeda rocket yang keluar
// if(HIT>0){HIT--;}
}
public void lose()
{
getWorld().showText("========= YOU LOSE =========", 500, 500);
}[/quote]
[code]
{
/**
* Act - do whatever the musuh wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
// private boolean klik=true;
public class musuh extends Actor
public void act()
{
move();
tembakdibase();
}
public void tembakdibase()
{
if(Greenfoot.mousePressed(this))
{
getWorld().removeObject(this);
}
}
public void move(){
musuh m = new musuh();
int x = ((Player)getWorld().getObjects(Player.class).get(0)).getX();
int y = ((Player)getWorld().getObjects(Player.class).get(0)).getY();
turnTowards(x,y);
move(3);
}
}
