Hey you guys.
I was wondering how do i use a health code in another actor Add Exp in my main one.
For source here are the two actors
Main Actor (Protag)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Font;
import java.awt.Color;
import java.util.List;
/**
* Write a description of class Protag here.
*
* @author (your name)
* @version (V1 - No working Exp System)
*/
public class Protag extends Actor
{
private Wolf Wolf;
private int WolfHP = 0;
public int ExpCount_;
public int Lvl;
public int HP;
private GreenfootImage image1;
private GreenfootImage image2;
private GreenfootImage image3;
private int animationcount = 0;
int FireDelay = 10;
int soundPlay = 0;
int InvFrames = 30;
public Protag()
{
super();
ExpCount_ = 0;
image1 = new GreenfootImage("Hero2.png");
image2 = new GreenfootImage("Hero3.png");
image3 = new GreenfootImage("Hero.png");
setImage(image3);
}
/**
* Act - do whatever the Protag wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
keyboard();
animaion();
checkFire();
LevelUp();
getWolfHP();
Health();
}
public void keyboard()
{
int y = getY();
int x = getX();
if (Greenfoot.isKeyDown("d"))
{
setLocation(x+4,y);
animationcount ++;
setRotation(0);
}
if (Greenfoot.isKeyDown("a"))
{
setLocation(x-4,y);
animationcount ++;
setRotation(180);
}
if (Greenfoot.isKeyDown("s"))
{
setLocation(x,y+4);
animationcount ++;
setRotation(90);
}
if (Greenfoot.isKeyDown("w"))
{
setLocation(x,y-4);
animationcount ++;
setRotation(270);
}
}
public void animaion()
{
if(animationcount >= 20)
{
setImage("Hero2.png");
}
if(animationcount >= 40)
{
setImage("Hero3.png");
animationcount = 0;
}
}
public void checkFire()
{
if(Greenfoot.isKeyDown("x")){
ExpCount_ ++;
}
if(Greenfoot.isKeyDown("space"))
{
FireDelay ++;
}
if(FireDelay >= 35)
{
getWorld().addObject(new Sword(getRotation()), getX(), getY());
FireDelay = 0;
}
}
public void Health()
{
Actor a = getOneIntersectingObject(Wolf.class);
if(a!= null)
{
InvFrames--;
}
if(InvFrames <= 0)
{
HP = HP - 4;
InvFrames = 30;
}
}
public int getExpCount()
{
return ExpCount_;
}
public int getLvl()
{
return Lvl;
}
public int getHP()
{
return HP;
}
public void LevelUp()
{
if(ExpCount_ >= 0)
{
Lvl = 1;
}
if(ExpCount_ >= 100){
Lvl = 2;
}
if(ExpCount_ >= 200){
Lvl = 3;
}
if(ExpCount_ >= 300){
Lvl = 4;
}
if(ExpCount_ >= 400){
Lvl = 5;
}
if(ExpCount_ >= 500){
Lvl = 6;
}
}
public void level()
{
if(Lvl == 2 && ExpCount_ == 100)
{
HP = 20;
}
if(Lvl == 3 && ExpCount_ == 200)
{
HP = 30;
}
if(Lvl == 4 && ExpCount_ == 300)
{
HP = 40;
}
if(Lvl == 5 && ExpCount_ == 400)
{
HP = 50;
}
if(Lvl == 6 && ExpCount_ == 500)
{
HP = 60;
}
}
public int getWolfHP()
{
int WolfHP = ((getWolf()).getWorld().getObjects(Wolf.class).get(0)).getWolf;
/*if(WolfHP <= 0)
{
XP = XP + 100;
}*/
}
}
Wolf
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class Wolf here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Wolf extends Actor
{
public int Wolf = 4;
int InvFrames = 3;
int spawn = 0;
public void act()
{
Dmg();
move(2);
}
public void Dmg()
{
Actor Sword = getOneIntersectingObject(Sword.class);
if(Sword!= null){
InvFrames --;
}
if (InvFrames <= 0){
Wolf = Wolf - Greenfoot.getRandomNumber(2)-4;
InvFrames = 3;
}
if(Wolf <= 0){
getWorld().removeObject(this);
}
}
public int getWolf()
{
return Wolf;
}
}
Oh also have 3 working counters in Protag and the world
Thanks any help would be appreciated this is giving me a headache.