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

2013/12/17

how to let my ship get a crate

12
13
14
15
16
17
18
danpost danpost

2014/1/6

#
Please show the error message (copy/paste in entirety).
virginia001 virginia001

2014/1/6

#
java.lang.NullPointerException at Kratten.act(Kratten.java:11) at greenfoot.core.Simulation.actActor(Simulation.java:568) at greenfoot.core.Simulation.runOneLoop(Simulation.java:526) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205) java.lang.NullPointerException at Kratten.act(Kratten.java:11) at greenfoot.core.Simulation.actActor(Simulation.java:568) at greenfoot.core.Simulation.runOneLoop(Simulation.java:526) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205) java.lang.NullPointerException at Kratten.act(Kratten.java:11) at greenfoot.core.Simulation.actActor(Simulation.java:568) at greenfoot.core.Simulation.runOneLoop(Simulation.java:526) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205)
danpost danpost

2014/1/6

#
Please comment out your act method of the Kratten class, compile the project and re-upload the scenario so that I may take a look as to what is causing the problem.
virginia001 virginia001

2014/1/6

#
doneee
danpost danpost

2014/1/6

#
You missed or removed the setting of the color in the 'Schipgroen' class as well as the 'Schiprood' class. Also you have something that appears to be something in the Schippaars' class, but it is not correct.
virginia001 virginia001

2014/1/6

#
thanks its working
danpost danpost

2014/1/6

#
In all of your Schip class movement methods ('moveLeft' etc.), put as the first line:
setImage(new GreenfootImage(image));
and in the 'moveRight' method add immediately after that line, this:
getImage().mirrorVertically();
Then remove all the 'act' methods from all subclasses of Schip. Also, in each of the constructors for all the subclasses of Schip, add the following as the first line:
super();
which should be followed by the setting of the String color.
virginia001 virginia001

2014/1/6

#
I've now almost done the loading crates part but the only thing that misses is the trucks riding a little bit forward and then dissapear (Also the same for the ships when no more of the same crate color that it must dissapear and makes another ship respawn at the upper right corner)
danpost danpost

2014/1/6

#
Let us clean up your code a little bit: - remove the Color class from the project - remove all code within the Lives class (leave the 'import' statement and the class declaration statement with its curly brackets). - do what I suggested in my last post Then we can work on the leaving of the trucks and ships, plus the spawning of new ships. Let me know when you are done with the above.
virginia001 virginia001

2014/1/6

#
danpost wrote...
In all of your Schip class movement methods ('moveLeft' etc.), put as the first line:
setImage(new GreenfootImage(image));
and in the 'moveRight' method add immediately after that line, this:
getImage().mirrorVertically();
Then remove all the 'act' methods from all subclasses of Schip. Also, in each of the constructors for all the subclasses of Schip, add the following as the first line:
super();
which should be followed by the setting of the String color.
You say that i need to remove all of my movement methods in my Schip subclasses but i need a different image for every ship and that code is in each subclass so how am I supposed to do that...
danpost danpost

2014/1/6

#
Adding the 'super' call (as per the final step above) will take care of that. It tells the 'Schip' class constructor to execute which saves the default image for that Schip object in a field to be used when moving.
virginia001 virginia001

2014/1/6

#
This is a subclass of my ship class but i get the error illegal start of expression before super();
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Schipgroen here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Schipgroen extends Schip
{
    super();
    
    public Schipgroen()  
    {  
        setColor("groen");  
    }       
}      
    
Super_Hippo Super_Hippo

2014/1/6

#
It has to be in the constructor. Like this I guess:
    public Schipgroen()  
    {  
        super();
        setColor("groen");  
    }       
virginia001 virginia001

2014/1/7

#
okay this problem is solved ... but I have another problem, when someones loses the game i have an sound effect and also another one for when somebody lost a life, but these two now are both playing at the same time when i lose a life or lose the game... this is my code:
public void removeLive()  
    {  
        int lives = getWorld().getObjects(Lives.class).size();  
        getWorld().removeObject((Actor)getWorld().getObjects(Lives.class).get(lives-1));
        Greenfoot.playSound("lose life.wav");
        if (lives == 1) Greenfoot.stop();
        Greenfoot.playSound("game over.wav");
    }  
Super_Hippo Super_Hippo

2014/1/7

#
If you do not use these curly brackets after the if condition, then only the action in the same line is affected by the condition. In your code, you remove the latest placed object of the class 'Lives' and play the sound "lose life.wav". If it was your last life, the execution will stop (line 6). Line 5 and 7 are not affected by the 'if', so both sounds are always played.
    public void removeLive()  
    {  
        int lives = getWorld().getObjects(Lives.class).size();  
        getWorld().removeObject((Actor)getWorld().getObjects(Lives.class).get(lives-1));
        
        if (lives != 1)
        {
            //Only does the following, if it was the not the last last life
            Greenfoot.playSound("lose life.wav");
        }
        else
        {
            //Only does the following, if it was the last life.
            Greenfoot.playSound("game over.wav");
            Greenfoot.stop();
        }
    } 
There are more replies on the next page.
12
13
14
15
16
17
18