Do you understand kind of what I want to do?
public void act() { fireBallHit(); if (getWorld() == null) return; // insert this line minionHit(); // etc.
((Platform)getWorld()).addPoints();
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import javax.swing.JOptionPane; /** * Write a description of class Alien here. * * @author (your name) * @version (a version number or a date) */ public class Alien extends Actor { private GreenfootImage run1 = new GreenfootImage("AlienRun1.png"); private GreenfootImage run2 = new GreenfootImage("AlienRun2.png"); private GreenfootImage run3 = new GreenfootImage("AlienRun3.png"); private GreenfootImage run4 = new GreenfootImage("AlienRun4.png"); private GreenfootImage run5 = new GreenfootImage("AlienRun5.png"); private GreenfootImage run6 = new GreenfootImage("AlienRun6.png"); private GreenfootImage run7 = new GreenfootImage("AlienRun7.png"); private GreenfootImage run8 = new GreenfootImage("AlienRun8.png"); private int frame = 1; private int score; private ScoreKeeper scoreKeeper; private double animationCounter = 1; /** * Act - do whatever the Alien wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { fireBallHit(); if (getWorld() == null) return; minionHit(); soldierHit(); if (Greenfoot.getRandomNumber(100) < 10) { move(-Greenfoot.getRandomNumber(50)); } if(animationCounter % 4 == 0) animateRun(); animationCounter++; } public void animateRun() { if(frame == 1) { setImage(run1); } else if(frame == 2) { setImage(run2); } else if(frame == 3) { setImage(run3); } else if(frame == 4) { setImage(run4); } else if(frame == 5) { setImage(run5); } else if(frame == 6) { setImage(run6); } else if(frame == 7) { setImage(run7); } else if(frame == 8) { setImage(run8); frame = 1; return; } frame++; } private boolean hasTakenAHit; public void fireBallHit() { Actor b = getOneIntersectingObject(FireBall.class); if(b != null) { getWorld().removeObject(b); if(hasTakenAHit) getWorld().removeObject(this); hasTakenAHit = true; ((Platform)getWorld()).addPoint(); } } public void minionHit() { Actor m = getOneIntersectingObject(Minion.class); if(m != null) { getWorld().removeObject(m); if(hasTakenAHit) getWorld().removeObject(this); hasTakenAHit = true; ((Platform)getWorld()).addPoint(); } } public void soldierHit() { Actor s = getOneIntersectingObject(Soldier.class); if(s != null) { JOptionPane.showMessageDialog(null, "Game Over!"); Greenfoot.stop(); } } }