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

2015/3/24

Colliding

1
2
3
4
aliozkan aliozkan

2015/3/26

#
Thank you Super_Hippo, but there is a problem. Everything works fine except for one thing. When enemy's number is smaller than ours, then when the collision occurs half of its points are not added to main character's points. Enemy is being removed but main character's points remains same.
aliozkan aliozkan

2015/3/26

#
Actually I realize that it is adding the points but it is not updating the image how can update the image of the value?
aliozkan aliozkan

2015/3/26

#
No need. I figured it out. Thanks for everything guys
Super_Hippo Super_Hippo

2015/3/26

#
//when randomValue changes
randomValueDisplay.update();
//in BasicActor
public void update()
{
    setImage(new GreenfootImage(""+randomValue, 14, null, null));
)
I think this should work.
danpost danpost

2015/3/26

#
Super_Hippo wrote...
//when randomValue changes
randomValueDisplay.update();
//in BasicActor
public void update()
{
    setImage(new GreenfootImage(""+randomValue, 14, null, null));
)
I think this should work.
It would be best to keep the BasicActor class clean of code and just use:
randomValueDisplay.setImae(new GreenfootImage(""+randomValue, 14, null, null));
However, on the other hand, you could junk it up with all different kinds of methods to do all kinds of different things provided you do not add an act method to it (but, that would not be very good programming).
aliozkan aliozkan

2015/3/29

#
Now I decided do a scoreboard to my game, however I can't make the final value of the main character appear on the scoreboard. Could you please help me how can I make that value appear on the scoreboard.
danpost danpost

2015/3/29

#
Create a basic actor, add it to the world and give it its image.
aliozkan aliozkan

2015/3/29

#
I have a basic actor in main character's class, do I need to create another one in scoreboard's class?
danpost danpost

2015/3/30

#
The basic actor class should be a subclass of Actor created by right-clicking on the Actor class icon and selecting 'New subclass...'.
aliozkan aliozkan

2015/3/30

#
By saying Actor you mean the general Actor class right? Isn't everything, except for the world class,already a subclass of the Actor class?
aliozkan aliozkan

2015/3/30

#
public static final float FONT_SIZE = 48.0f;
    public static final int WIDTH = 400;
    public static final int HEIGHT = 300;
    /**
     * Create a score board for the final result.
     */
    public ScoreBoard2(int score)
    {
        final int a = Airplane.getValue();
        makeImage("Game Over", "Score: ", a);
    }
    /**
     * Make the score board image.
     */
    private void makeImage(String title, String prefix, int score)
    {
        GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);
        
        image.setColor(new Color(255,255,255, 128));
        image.fillRect(0, 0, WIDTH, HEIGHT);
        image.setColor(new Color(0, 0, 0, 128));
        image.fillRect(5, 5, WIDTH-10, HEIGHT-10);
        Font font = image.getFont();
        font = font.deriveFont(FONT_SIZE);
        image.setFont(font);
        image.setColor(Color.WHITE);
        image.drawString(title, 60, 100);
        image.drawString(prefix + score, 60, 200);
        setImage(image);
    }
}
I am trying to insert the value but it says "non static method getValue() cannot be referenced from a static context" I don't know what to do
danpost danpost

2015/3/30

#
aliozkan wrote...
By saying Actor you mean the general Actor class right? Isn't everything, except for the world class,already a subclass of the Actor class?
I supplied the code for the BasicActor class on the first page of this discussion (my 4th post on the page). Look hard -- because it is a whopping 1 line long. As far as fixing the error, you need to show the code for you Airplane class.
Super_Hippo Super_Hippo

2015/3/30

#
If the int, which 'getValue' should return, is static, then you can simply make this method static: public static int getValue() { return ... } If it is not a static value, then you need a reference to the object instead of the class.
aliozkan aliozkan

2015/3/30

#
private int randomValue2 = this.getValue();
private Actor randomValueDisplay2 = new BasicActor();
protected void addedToWorld2(World world)
{
    GreenfootImage image2 = new GreenfootImage("Score: "+randomValue2, 35, null, null);
    GreenfootImage image3 = new GreenfootImage(WIDTH, HEIGHT);
    randomValueDisplay2.setImage(image2);
        image3.setColor(new Color(255,255,255, 128));
        image3.fillRect(0, 0, WIDTH, HEIGHT);
        image3.setColor(new Color(0, 0, 0, 128));
        image3.fillRect(5, 5, WIDTH-10, HEIGHT-10);
        Font font = image3.getFont();
        font = font.deriveFont(FONT_SIZE);
        image3.setFont(font);
        image3.setColor(Color.WHITE);
        
        
    world.addObject(randomValueDisplay2, 800, 400);
}
Ok I add this to my Airplane class. But I don't know how exactly make it appear when Airplane3 get destroyed.
if (ap3 != null)
    {
        final int a = ap3.getRandomValue();
                    getWorld().addObject(new Explosion(), getX(), getY());
        if (randomValue >= a)
        {
            randomValue += a / 2;
            ap3.remove();
            GreenfootImage image = new GreenfootImage(""+randomValue, 13, null, null);
            randomValueDisplay.setImage(image);
aliozkan aliozkan

2015/3/30

#
Super_hippo it is not a static value, how can reference to an object not to a class?
There are more replies on the next page.
1
2
3
4