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

2012/2/4

Making an HP bar

1
2
programmar programmar

2012/2/11

#
Okay, I don't really understand what you mean by that, but I managed to create a totally new bar and a new game over screen. There are still some errors though. Here is my background:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class bg1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class bg1 extends World
{
    /**
     * Constructor for objects of class bg1.
     * 
     */
     public Bar bar = new Bar("Pikachu", "Health Points", 100,100);  
     public Bar2 bar2 = new Bar2("Charmander", "Health Points", 100, 100);
     
    public bg1()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        addObject(bar, 250,40);
        addObject(bar, 400, 40);

        prepare();
    }
    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        Ground ground = new Ground();
        addObject(ground, 293, 393);
        Platform platform = new Platform();
        addObject(platform, 291, 193);
        Platform platform2 = new Platform();
        addObject(platform2, 107, 290);
        Platform platform3 = new Platform();
        addObject(platform3, 495, 283);
        Pikachu pikachu = new Pikachu();
        addObject(pikachu, 303, 105);
        Pikachu pikachu2 = new Pikachu();
        addObject(pikachu2, 295, 123);
        pikachu2.setLocation(179, 143);
        removeObject(pikachu2);
        pikachu.setLocation(88, 210);
        Charmander charmander = new Charmander();
        addObject(charmander, 517, 198);
        
    }
    GreenfootSound music = new GreenfootSound("19 Hyrule Field Main Theme.mp3");  
    public void started()  
    {  
        music.playLoop();  
    }  
    public void act()
    {
        if (bar.getValue() == 0)
        {
            showGameOverCharWins();
            Greenfoot.stop();
            return;
        }
        if (bar.getValue() == 0)
        {
            showGameoverPikaWins();
            Greenfoot.stop();
            return;
        }
    private void showGameOverCharWins()
    {
        addObject(new GameOverCharWins(), getWidth() / 2, getHeight() / 2);
    }
    private void showGameOverPikaWins()
    {
        addObject(new GameOverPikaWins(), getWidth() / 2, getHeight () / 2);
    }
    public void stopped()  
     {  
        music.stop();  
    } 
}
}
It says "illegal art of expression" and highlights "private void showGameOverCharWins()" What should I do to fix this?
kiarocks kiarocks

2012/2/11

#
You need another bracket at the end of the act method
danpost danpost

2012/2/11

#
Also, line 23 needs to add 'bar2' not 'bar'. But the call is still 'new Bar', not 'new Bar2' (you do not need multiple classes for different bar objects; you can create multiple bars with the same class and still name them seperately).
danpost danpost

2012/2/11

#
The second part of my last post was in reference to line 16, where you have 'public Bar2 bar2 = new Bar2("Charmander", "Health Points", 100, 100);'. Remove the Bar2 class, if you did create one, and change this line to 'public Bar bar2 = new Bar("Charmander", "Health Points", 100, 100);'. Also, when checking for game over, you are checking the same bar both times -- change the 'bar' in line 65 to 'bar2'. Lines 41 and 48 should be moved and inserted around lines 15 and 16 with the word 'public' in front of them. You will, I am sure, be happy to have a reference to them here. Minor corrections that can be made are (I believe that 'Save the world' did this): 1) Lines 43 through 46 are basically junk, in there entirety, they do nothing. 2) Line 47 can be removed AFTER replacing the 303 and 105 in line 42 with the 88 and 210 in 47.
programmar programmar

2012/2/11

#
It works now, and I can now say I have a real 2p game! Thank you so much danpost.
danpost danpost

2012/2/11

#
Do not forget to vote on the Progress bar/Health bar class scenario (I need the votes).
danpost danpost

2012/2/11

#
I am so glad it works. If you encounter other problems just post up.
You need to login to post a reply.
1
2