@davmac - Thanks, but the console's copy button did not work at the time that I posted this thread.
@danpost - I am going to try that method soon. I'll post my results back here on this thread. Thank you.
-TheGoldenBucket
import greenfoot.*;
/**
* Write a description of class Skeleton here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Skeleton extends Actor
{
private int health;
private int directionY;
private int directionX;
private skelly skellyWorld;
private PlayerChar player;
protected void addedToWorld(World world)
{
skellyWorld = (skelly) world;
player = skellyWorld.getPlayer();
}
/**
* Act - do whatever the Skeleton wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
directionCheck();
move();
healthCheck();
attack();
deadCheck();
}
public void directionCheck()
{
if (player.getX() > getX())
{
directionX = (1);
}
if (player.getX() < this.getX())
{
directionX = (2);
}
if (player.getY() > this.getY())
{
directionY = (1);
}
if (player.getY() < this.getY())
{
directionY = (2);
}
}
public void move()
{
if (directionX == (1))
{
setLocation (1,0);
}
if (directionX == (2))
{
setLocation (-1,0);
}
if (directionY == (1))
{
setLocation (0,1);
}
if (directionY == (2))
{
setLocation (0,-1);
}
}
public void healthCheck()
{
if (health == (0))
{
health = (3);
}
//Insert collision code here.
}
public void attack()
{
if (health == (4))//collision code with player
{
Main_World.playerHealth--;
}
}
public void deadCheck()
{
if (health == (4))//collision code with sword
{
health--;
}
if (health == (4))//collision code with arrow
{
health--;
}
if (health == (1))
{
skellyWorld.removeObject(this);
}
}
}
if (player.getWorld() == null) return;
import greenfoot.*;
/**
* Write a description of class Skeleton here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Skeleton extends Actor
{
private int health;
private int directionY;
private int directionX;
private skelly skellyWorld;
private PlayerChar player;
protected void addedToWorld(World world)
{
skellyWorld = (skelly) world;
player = skellyWorld.getPlayer();
}
/**
* Act - do whatever the Skeleton wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
directionCheck();
move();
healthCheck();
attack();
deadCheck();
}
public void directionCheck()
{
if (player.getWorld() == null) return;
if (player.getX() > getX())
{
directionX = (1);
}
if (player.getX() < this.getX())
{
directionX = (2);
}
if (player.getY() > this.getY())
{
directionY = (1);
}
if (player.getY() < this.getY())
{
directionY = (2);
}
}
public void move()
{
if (directionX == (1))
{
setLocation (this.getX()+1,this.getY());
}
if (directionX == (2))
{
setLocation (this.getX()-1,this.getY());
}
if (directionY == (1))
{
setLocation (this.getX(),this.getY()+1);
}
if (directionY == (2))
{
setLocation (this.getX(),this.getY()-1);
}
}
public void healthCheck()
{
if (health == (0))
{
health = (3);
}
//Insert collision code here.
}
public void attack()
{
if (health == (4))//collision code with player
{
}
}
public void deadCheck()
{
if (health == (4))//collision code with sword
{
health--;
}
if (health == (4))//collision code with arrow
{
health--;
}
if (health == (1))
{
skellyWorld.removeObject(this);
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class PlayerChar here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class PlayerChar extends Actor
{
//Variables
public static int age;
/**
* Act - do whatever the PlayerChar wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
movement();
meleeAttack();
rangedAttack();
staminaRegen();
hurtCheck();
healthCheck();
}
public void movement()
{
GreenfootImage charImage = null;
if (Greenfoot.isKeyDown("a"))
{
int x = getX();
int y = getY();
int ny = getX()-2;
setLocation(ny,y);
if (getOneIntersectingObject(null) != null)
{
setLocation(getX()+2, getY());
}
charImage = new GreenfootImage("IMG_1193.PNG");
Main_World.playerTurn = (1);
}
if (Greenfoot.isKeyDown("d"))
{
int x = getX();
int y = getY();
int ny = getX()+2;
setLocation(ny,y) ;
if (getOneIntersectingObject(null) != null)
{
setLocation(getX()-2, getY());
}
charImage = new GreenfootImage("IMG_1192.PNG");
Main_World.playerTurn = (2);
}
if (Greenfoot.isKeyDown("w"))
{
int x = getX();
int y = getY();
int ny = getY()-2;
setLocation(x,ny) ;
if (getOneIntersectingObject(null) != null)
{
setLocation(getX(), getY()+2);
}
charImage = new GreenfootImage("IMG_1191.PNG");
Main_World.playerTurn = (3);
}
if (Greenfoot.isKeyDown("s"))
{
int x = getX();
int y = getY();
int ny = getY()+2;
setLocation(x,ny) ;
if (getOneIntersectingObject(null) != null)
{
setLocation(getX(), getY()-2);
}
charImage = new GreenfootImage("IMG_1190.PNG");
Main_World.playerTurn = (4);
}
if (charImage != null) setImage(charImage);
}
public void meleeAttack()
{
if (Greenfoot.isKeyDown("i"))
{
Melee attack = new Melee();
if (Main_World.playerTurn == (1))
{
getWorld().addObject(attack, getX()-25, getY());
}
if (Main_World.playerTurn == (2))
{
getWorld().addObject(attack, getX()+25, getY());
}
if (Main_World.playerTurn == (3))
{
getWorld().addObject(attack, getX(), getY()-25);
}
if (Main_World.playerTurn == (4))
{
getWorld().addObject(attack, getX(), getY()+25);
}
}
}
public void rangedAttack()
{
if (Greenfoot.isKeyDown("o") && Main_World.playerStamina > -1 && getWorld().getObjects(Ranged.class).isEmpty())
{
getWorld().addObject(new Ranged(), getX(), getY());
Main_World.playerStamina--;
}
}
public void staminaRegen()
{
age++;
if (age > 20 && Main_World.playerStamina < (3))
{
age = (0);
Main_World.playerStamina++;
}
}
public void hurtCheck()
{
Actor slimeu = getOneObjectAtOffset(0, 0, SlimeballUp.class);
Actor slimed = getOneObjectAtOffset(0, 0, SlimeballDown.class);
Actor slimel = getOneObjectAtOffset(0, 0, SlimeballLeft.class);
Actor slimer = getOneObjectAtOffset(0, 0, SlimeballRight.class);
if (slimeu != null)
{
Main_World.playerHealth--;
getWorld().removeObject(slimeu);
}
if (slimed != null)
{
Main_World.playerHealth--;
getWorld().removeObject(slimed);
}
if (slimel != null)
{
Main_World.playerHealth--;
getWorld().removeObject(slimel);
}
if (slimer != null)
{
Main_World.playerHealth--;
getWorld().removeObject(slimer);
}
}
public void healthCheck()
{
if (Main_World.playerHealth == (0))
{
getWorld().removeObject(this);
}
}
}