I AM ERNIE NEEDING OF THE ASSISTANCE DAN POST HELP ERNIE IN DANGER
public class Counter extends Actor { private static final Color transparent = new Color(0,0,0,0); private GreenfootImage background; private int health; private int target; /** * Create a new counter, initialised to 0. */ public Counter() { background = getImage(); // get image from class health = 100; target = 0; updateImage(); } /** * Animate the display to count up (or down) to the current target health. */ public void act() { if (health < target) { health++; updateImage(); } else if (health > target) { health--; updateImage(); } } /** * Add a new score to the current counter health. */ public void add(int score) { target += score; } /** * Return the current counter health. */ public int gethealth() { return health; } /** * Set a new counter health. */ public void sethealth(int newhealth) { target = newhealth; health = newhealth; updateImage(); } /** * Update the image on screen to show the current health. */ private void updateImage() { GreenfootImage image = new GreenfootImage(background); GreenfootImage text = new GreenfootImage("" + health, 40, Color.RED, transparent); image.drawImage(text, (image.getWidth()-text.getWidth())/2, (image.getHeight()-text.getHeight())/2); setImage(image); } }
public class Movers extends Actor { /** * Test if we are close to one of the edges of the world. Return true is we are. */ public boolean atWorldEdge() { if(getX() < 10 || getX() > getWorld().getWidth() - 10) return true; if(getY() < 10 || getY() > getWorld().getHeight() - 10) return true; else return false; } /** * Return true if we can see an object of class 'clss' right where we are. * False if there is no such object here. */ public boolean canSee(Class clss) { Actor actor = getOneObjectAtOffset(0, 0, clss); return actor != null; } /** * Try to eat an object of class 'clss'. This is only successful if there * is such an object where we currently are. Otherwise this method does * nothing. */ public void eat(Class clss) { Actor actor = getOneObjectAtOffset(0, 0, clss); if(actor != null) { getWorld().removeObject(actor); } } public void deadChampion() { if (this.getWorld().getClass() == PlayArea.class) { PlayArea world = getWorldOfType(PlayArea.class); if(world.getHealth()<=0) { getWorld().removeObject(this); Greenfoot.setWorld(new GameOver()); } } } public void deadChampion2() { if (this.getWorld().getClass() == BossBattle.class) { BossBattle world = getWorldOfType(BossBattle.class); if(world.getHealth()<=0) { getWorld().removeObject(this); Greenfoot.setWorld(new GameOver()); } } } public void removeHealth() { if (this.getWorld().getClass() == PlayArea.class) { if(this.isTouching(Monsters.class)) { PlayArea world = getWorldOfType(PlayArea.class); world.removeHealth();//removes players health } } } public void removeHealth2() { if (this.getWorld().getClass() == BossBattle.class) { if(this.canSee(Monsters.class)) { BossBattle world = getWorldOfType(BossBattle.class); world.removeHealth2();//removes players health } } } }
public class Champion extends People { public int health = 100; int x; int y; int firecount; public void act() { checkKeys(); firecount++; if(firecount > 5) if(Greenfoot.isKeyDown("space")) { getWorld().addObject(new Bullet(getRotation()), getX(), getY()); firecount = 4; } removeHealth(); deadChampion(); removeHealth2(); deadChampion2(); } /** * Check whether the control keys are being pressed, and turn * if they are. */ public void checkKeys() { //these events make this program an event driven application. if ( Greenfoot.isKeyDown("up") )//trigger function { move(8);//event handler } if ( Greenfoot.isKeyDown("down") )//trigger function { move(-5);//event handler } if ( Greenfoot.isKeyDown("left") )//trigger function { turn(-5);//event handler } if ( Greenfoot.isKeyDown("right") )//trigger function { turn(5);//event handler } } }
public class BossMan extends Monsters { public int speed = 1; public int health = 2000; public int spawnAmount = 1; /** * Act - do whatever the Klorb wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(2); followChampion(); loseHealth(); die(); } public void followChampion() { if (getWorld().getObjects(Champion.class).isEmpty()) return; // skips following if the turtle is not in world Actor champion = (Actor)getWorld().getObjects(Champion.class).get(0); // gets reference to turtle turnTowards(champion.getX(), champion.getY()); // turn toward turtle } public void loseHealth() { if(canSee(Bullet.class)) { health = health - 5; } } public void die() { if (health == 0) { getWorld().removeObject(this); Greenfoot.setWorld(new WinScreen()); } } }