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

2016/9/27

Yet Another Score Counter!

TheBluePhoenix TheBluePhoenix

2016/9/27

#
Hi, this is my first time posting but I have had experience with Greenfoot... Until now xD Okay, I have no code, to show, for this but I hope I can describe it well enough. In my program, there is a bee, that you control, that goes around collecting green orbs and at the very end, there will be a gold orb that appears. The player collects the gold orb to end the game. My question is, can I make a point system so that the gold orb appears under certain conditions. Like if the player collects enough orbs? If I were to put it in basic Pseudocode; orbsCollected = 0 when Bee detects Orb: remove Orb orbsCollected= orbsCollected +1 when orbsCollected = 5: Add goldOrb Sorry for simplicity but hopefully you understand me. The stuff I can't do is in bold. I can remove the orb but I can't find a way of making the point system and adding the golden orb. Thank you!
Super_Hippo Super_Hippo

2016/9/27

#
Add a variable to track the number of collectedOrbs just as you tried in your pseudo code:
private int orbsCollected = 0; //create the variable

//in act-method or called from that
if (isTouching(GreenOrb.class)
{
    removeTouching(Orb.class);
    orbsCollected++; //same as the line you gave above
    if (orbsCollected == 5)
    {
        getWorld().addObject(new GoldOrb(), 100, 100); //change the 100, 100 to your needs
    }
}
If the Orb is just one class, it could like this:
//Orb class

private int color = 0; //0=green, 1=gold

public Orb(int c)
{
    color = c;
    //set image based on the color -- maybe you create them manually, then you only have to change the color
    if (color == 0) setImage("GreenOrb.png");
    else setImage("GoldOrb.png");
}

public int getColor()
{
    return color;
}
//Bee class
[code]private int orbsCollected = 0; //create the variable

//in act-method or called from that
Orb orb = (Orb) getOneIntersectingObject(Orb.class);
if (orb != null)
{
    if (orb.getColor() == 1) //gold orb
    {
        //win the game
    }
    else //green orb
    {
        orbsCollected++;
        if (orbsCollected == 5)
        {
            getWorld().addObject(new Orb(1), 100, 100);
        }
        getWorld().removeObject(orb);
    }
}
//when adding a green orb
addObject(new Orb(0), 100, 100);
TheBluePhoenix TheBluePhoenix

2016/9/29

#
@Super_Hippo Oh my god! Thank you so much! Love the Greenfoot community, so easy to ask for help and not be criticised for "Being a NOOB." Thanks so much.
You need to login to post a reply.