I have three class right there for make this one.
But when i run this project, object "Life" automatically disappears from MyWorld before my main object is touched by enemy
1st, Nyawa.class
2nd, Life.class
3rd Enemy3.class
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Nyawa here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Nyawa extends Actor
{
/**
* Act - do whatever the Nyawa wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public static int nyawa=1;
public void act()
{
// Add your action code here.
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Life here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Life extends Actor
{
public void act()
{
if(Nyawa.nyawa == 0);
{
World world;
world = getWorld();
world.removeObject(this);
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Enemy3 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Enemy3 extends Actor
{
/**
* Act - do whatever the Enemy3 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int direction = 5;
public void act()
{
// Add your action code here.
gerak();
damage();
}
public void gerak()
{
move(direction);
if (isAtEdge()) direction = -direction;
}
public void damage()
{
Actor Alien;
Alien = getOneObjectAtOffset(0,0,Alien.class);
if (Alien != null)
{
Nyawa.nyawa--;
}
}
}
