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

2017/2/10

i need help urgent

fgryh123 fgryh123

2017/2/10

#
hi i really need help with my game... someone please help me so im trying to create a game for my project, the concept is like Diner Dash ( hence the name Garden Dash ). Basically how the game works is the farmer has to provide the needs of the plants found in the game. there are 3 icons in the side of the screen, a water, sunlight and fertilizer icon. how do i randomly get an image to pop up like at the side of each plant so that the farmer knows what it needs so that when the farmer touches the icon it makes a sound and then an image pops up above him and when he brings it to the plant the image disappears?
Nosson1459 Nosson1459

2017/2/10

#
the way it sounds is that you don't want that to be random, you might want to have a timer in each plant that when its done it needs water, sunlight, or fertilizer.lke this
private int water=50;
public void act()
{
    water--;
    if (water==0)
    {
        //do something that tells the player this plant 
        //needs water
    }
}
but if you want to make it random you could use
int water=Greenfoot.getRandomNumber(//put a number here that decides how random it will be i.e. 100 would be very infrequent 3 would be alot more common and so on);
if(water==//any number less than the number you put in before)
{
    //do something that tells the player this plant needs water
}
fgryh123 fgryh123

2017/2/12

#
How do i tell the player that this plant needs water, sunlight or fertilizer? is there a way i could but like an image beside the plant like this? https://gyazo.com/6831d835698ddb8204f784e91a9c965a
Super_Hippo Super_Hippo

2017/2/12

#
Should the image interact with anything or should it just be like a notification which disappears again when the plant got it?
Nosson1459 Nosson1459

2017/2/12

#
Make your icons be an actor that when they're clicked does what you want it to do.
fgryh123 fgryh123

2017/2/12

#
It should be like what SUper_Hippo said, just a notification which disappears when the plant got it
Nosson1459 Nosson1459

2017/2/13

#
fgryh123 wrote...
It should be like what SUper_Hippo said, just a notification which disappears when the plant got it
Hippo didn't say it's anything, he's asking YOU what you want the scenario to be.
Super_Hippo wrote...
Should the image interact with anything or should it just be like a notification which disappears again when the plant got it?
I answered your question from what I understood it was. I said that you should have an actor be the notification and do 'if (Greenfoot.mouseClicked(this))' in your notification actor and in this if put in the code for what you want to happen. When the plant got what? (or should it just be like a notification which disappears again when the plant got it)
Super_Hippo Super_Hippo

2017/2/13

#
@Nosson: Yes, my post was a question but still, his last post explained what he wants to do. @fgryh: You could put this in the Plant class. Make sure you have a waterNeeded method or some other way to check if the notification should appear.
private Actor waterNotification = new Actor() {};

//in constructor:
waterNotification.setImage("waterNotification.png");

//in act
if (waterNotification.getWorld() != null) //if the notification is shown
{
    if (!waterNeeded) //if the notification should not be shown
    {
        getWorld().removeObject(waterNotification); //remove the notification from the world
    }
}
else if (waterNeeded) //if the notification is not in the world, but should be shown
{
    getWorld().addObject(waterNotification, getX(), getY()-50); //add the notification to the world above the plant
}
You need to login to post a reply.