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

2015/10/1

Need help with wombat game

bjshorty bjshorty

2015/10/1

#
I created a game in which two wombats eat leaves. I need to keep track of how many leaves each wombat ate. Any help?
Super_Hippo Super_Hippo

2015/10/1

#
Create a counter in the wombat class:
private int leavesEaten = 0;
When it eats a leaf, add one to the counter:
leavesEaten++;
GamemodeGod GamemodeGod

2015/10/2

#
I got another problem when I was typing that long long ago but nothing happens when I eat all my food, not even one point. Can someone help me? (a different game)
bjshorty bjshorty

2015/10/2

#
Yea, I have that already, but I cant display my score over the specific wombat. Can you help?
bjshorty bjshorty

2015/10/2

#
public void score(){ Actor label = getOneObjectAtOffset(0,0, Label.class); GreenfootImage img = new GreenfootImage (100, 30); img.drawString(String.valueOf(leavesEaten), 2, 20); setImage(img); } When the wombat eats a leaf, it turns to a number and it continues to move. I need the counter to stay on top of the wombat image. Not replace it.
danpost danpost

2015/10/2

#
bjshorty wrote...
When the wombat eats a leaf, it turns to a number and it continues to move. I need the counter to stay on top of the wombat image. Not replace it.
A reference variable for a Label object is created and assigned a value in the first line. However, nothing is done with this label within the method. If you do not want to replace the image of the wombat, then do not use 'this.setImage' (equivalent to 'setImage'). If it is the label you wish to set the image to, then use 'label.setImage'.
bjshorty bjshorty

2015/10/2

#
danpost wrote...
bjshorty wrote...
When the wombat eats a leaf, it turns to a number and it continues to move. I need the counter to stay on top of the wombat image. Not replace it.
A reference variable for a Label object is created and assigned a value in the first line. However, nothing is done with this label within the method. If you do not want to replace the image of the wombat, then do not use 'this.setImage' (equivalent to 'setImage'). If it is the label you wish to set the image to, then use 'label.setImage'.
For some reason, adding 'label.setImage' causes my game to stop. Nothing changes and no count is displayed.
danpost danpost

2015/10/2

#
bjshorty wrote...
For some reason, adding 'label.setImage' causes my game to stop. Nothing changes and no count is displayed.
What do you mean by stop? are you getting an error message? if so, what is it? which line is it stopping at? What is the new updated code you are using?
You need to login to post a reply.