I know this topic has been made a lot however I cannot open scenarios on my boarding school's due to java on the internet being blocked therefore i cannot actually view the scenario on HpBars. Is there anyone someone could show me how to make one without the scenario? my code is pretty simple, usual private int for health and then health = X-20
Any help is appricated!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class Survivor here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Survivor extends Actor
{
private int counter = 0;
private int counter1 = 0;
private int health = 60;
/**
* Act - do whatever the Survivor wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
shoot();
move();
Helper();
Healer();
shooter();
HealthKit();
HealthKit1();
ZombieHit();
ZombieHit1();
ZombieHit2();
SurvivorZombieHit();
SurvivorZombieHit1();
SurvivorZombieHit2();
MouseInfo m = Greenfoot.getMouseInfo();
if(m != null)
turnTowards(m.getX(), m.getY());
}
public void HealthKit()
{
Actor zombie;
zombie = getOneObjectAtOffset(0, 0, HealthKit.class);
if (zombie != null && (health == 40))
{
World world;
world = getWorld();
world.removeObject(zombie);
health = 40 + 20;
}
}
public void HealthKit1()
{
Actor zombie;
zombie = getOneObjectAtOffset(0, 0, HealthKit.class);
if (zombie != null && (health == 20))
{
World world;
world = getWorld();
world.removeObject(zombie);
health = 20 + 20;
}
}
public void ZombieHit()
{
Actor zombie;
zombie = getOneObjectAtOffset(0, 0, Zombie.class);
if (zombie != null && (health == 60))
{
World world;
world = getWorld();
world.removeObject(zombie);
health = 60 - 20;
}
}
public void ZombieHit1()
{
Actor zombie;
zombie = getOneObjectAtOffset(0, 0, Zombie.class);
if (zombie != null && (health == 40))
{
World world;
world = getWorld();
world.removeObject(zombie);
health = 40 - 20;
}
}
public void ZombieHit2()
{
Actor zombie;
zombie = getOneObjectAtOffset(0, 0, Zombie.class);
if (zombie != null && (health == 20))
{
World world;
world = getWorld();
world.removeObject(zombie);
health = 20 - 20;
if (health == 0)
{
getWorld().removeObject(this);
Counter counter;
counter = (Counter)world.getObjects(Counter.class).get(0);
GreenfootImage image = new GreenfootImage("FINAL SCORE\n"+counter.getValue(), 84, java.awt.Color.green, null);
counter.setImage(image);
counter.setLocation(world.getWidth()/2, world.getHeight()/2);
Greenfoot.stop();
}
}
}
public void SurvivorZombieHit()
{
Actor zombie;
zombie = getOneObjectAtOffset(0, 0, SurvivorZombie.class);
if (zombie != null && (health == 60))
{
World world;
world = getWorld();
world.removeObject(zombie);
health = 60 - 20;
}
}
public void SurvivorZombieHit1()
{
Actor zombie;
zombie = getOneObjectAtOffset(0, 0, SurvivorZombie.class);
if (zombie != null && (health == 40))
{
World world;
world = getWorld();
world.removeObject(zombie);
health = 40 - 20;
}
}
public void SurvivorZombieHit2()
{
Actor zombie;
zombie = getOneObjectAtOffset(0, 0, SurvivorZombie.class);
if (zombie != null && (health == 20))
{
World world;
world = getWorld();
world.removeObject(zombie);
health = 20 - 20;
if (health == 0)
{
getWorld().removeObject(this);
Counter counter;
counter = (Counter)world.getObjects(Counter.class).get(0);
GreenfootImage image = new GreenfootImage("FINAL SCORE\n"+counter.getValue(), 84, java.awt.Color.green, null);
counter.setImage(image);
counter.setLocation(world.getWidth()/2, world.getHeight()/2);
Greenfoot.stop();
}
}
}
}
