This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gzuzfrk
Gzuzfrk wrote ...

2013/5/21

Score

1
2
3
4
Gzuzfrk Gzuzfrk

2013/5/22

#
Do you understand kind of what I want to do?
danpost danpost

2013/5/22

#
Ok, first thing: in your Alien class act method, start it like this:
public void act()
{
    fireBallHit();
    if (getWorld() == null) return; // insert this line
    minionHit();
    // etc.
If the 'fireBallHit' method removes the actor from the world, the getOneIntersectingObject method in the minionHit method will produce this error 'IllegalStateException ...actor not in world...'.
Gzuzfrk Gzuzfrk

2013/5/22

#
Oh ok
Gzuzfrk Gzuzfrk

2013/5/22

#
Have you found out why my score wont add anything?
danpost danpost

2013/5/22

#
I believe I am close to solving it. Just give me a couple.
Gzuzfrk Gzuzfrk

2013/5/22

#
Alright thanks :)
danpost danpost

2013/5/22

#
Alright. You have a reference and a method for the ScoreKeeper object and 'addPoints' method in both the Platform world class AND the Alien actor class. Remove them from the Alien class. Then, I could not find anywhere any calls to any 'addPoints' method (that would explain its value staying at zero).
Gzuzfrk Gzuzfrk

2013/5/22

#
I did all of that and then refrenced it in the getintersection in the alien class
Gzuzfrk Gzuzfrk

2013/5/22

#
but it cant find the code in the alien class
danpost danpost

2013/5/22

#
You need to execute the addPoints method in the Platform world from an actor class with:
((Platform)getWorld()).addPoints();
Gzuzfrk Gzuzfrk

2013/5/22

#
ok it worked but now its giving me a terminal window saying at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.NullPointerException at Alien.minionHit(Alien.java:117) at Alien.act(Alien.java:34) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.NullPointerException at Alien.minionHit(Alien.java:118) at Alien.act(Alien.java:34) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203)
danpost danpost

2013/5/22

#
Produce the error again. Then look at the number at the end of the second line of the error message (the location of this line is not always the second). That number is the line number in the class code that the error occurred. Inform me as to the content of that line (should be in the minionHit method of the Alien class).
Gzuzfrk Gzuzfrk

2013/5/22

#
java.lang.NullPointerException at Alien.fireBallHit(Alien.java:103) at Alien.act(Alien.java:31) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.NullPointerException at Alien.minionHit(Alien.java:118) at Alien.act(Alien.java:34) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) that's the thing that pops up and this is my code
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();
}
}
}
Gzuzfrk Gzuzfrk

2013/5/22

#
java.lang.NullPointerException at Alien.fireBallHit(Alien.java:103) at Alien.act(Alien.java:31) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.NullPointerException at Alien.minionHit(Alien.java:118) at Alien.act(Alien.java:34) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.NullPointerException at Alien.fireBallHit(Alien.java:104) at Alien.act(Alien.java:31) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) that is what it says when I shoot
danpost danpost

2013/5/22

#
Move the calls to 'addPoint' to before the 'removeObject(this)' statement before them.
There are more replies on the next page.
1
2
3
4