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

2013/5/21

Score

1
2
3
4
Gzuzfrk Gzuzfrk

2013/5/21

#
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)    
import java.awt.Color;  
import java.awt.Graphics;  
  
/** 
 * Counter that displays a text and number. 
 *  
 * @author Michael Kolling 
 * @version 1.0.1 
 */  
public class Counter extends Actor  
{  
    private static final Color textColor = new Color(255, 180, 150);  
      
    private int value = 0;  
    private int target = 0;  
    private String text;  
    private int stringLength;  

    public Counter()  
    {  
        this("");  

    }  
  
    public Counter(String prefix)  
    {  
        text = prefix;  
        stringLength = (text.length() + 2) * 10;  
  
        setImage(new GreenfootImage(stringLength, 16));  
        GreenfootImage image = getImage();  
        image.setColor(textColor);  
  
        updateImage();  
    }  
      
    public void act() {  
        if(value < target) {  
            value++;  
            updateImage();  
        }  
        else if(value > target) {  
            value--;  
            updateImage();  
        }  
    }  
 
    public void add(int score)  
    {  
       target += score;  
    }  
  
    public int getValue()  
    {  
        return value;  
    }  
  
    /** 
     * Make the image 
     */  
    private void updateImage()  
    {  
        GreenfootImage image = getImage();  
        image.clear();  
        image.drawString(text + value, 1, 12);  
        
    }  
Ok so I have this old asteroid code for my code but I cant get it to show up? Is there something wrong with it?
danpost danpost

2013/5/21

#
Are you creating a Counter object and adding it to the world? and did you copy the image file for the counter into you images folder within the folder of this project?
Gzuzfrk Gzuzfrk

2013/5/21

#
I just want a little thing in the top that says Score: how many he has that's it lol
Gzuzfrk Gzuzfrk

2013/5/21

#
And make it to where every time he kills one alien he gets 100 points and every time he presses z he decreases by 50 because I have a little minion that comes running out to help kill
Gzuzfrk Gzuzfrk

2013/5/21

#
Sorry btw im like totally new and this is for my highschool programming class my teacher isn't to good at teaching
TheMissingKey TheMissingKey

2013/5/21

#
if you are using greenfoot, there is a class you can import called counter, when you open up greenfoot, go under the edit tab at the top, and choose import class, then select the counter and import it. All that's left is to add it to the world and then make it so that it checks a variable score or such. Let me know if you have any other questions
danpost danpost

2013/5/21

#
@TheMissingKey, if you had looked at the initial discussion post, you would have noticed that the counter class you are referring to is the one that is being used.
Gzuzfrk Gzuzfrk

2013/5/21

#
Ok heres my new scoreboard code but it keeps giving me a giant error I used one off a bee scenario in here
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.awt.Font;

public class ScoreKeeper extends Actor
{
    private GreenfootImage scoreBoard;
    private Color backgroundColor = new Color (108, 108, 108);
    private Color textColor = new Color (176,0,0);
    private Font textFont = new Font ("Arial", Font.BOLD, 28);
    
    public ScoreKeeper()
    {
        scoreBoard = new GreenfootImage(150, 40);
        scoreBoard.setFont (textFont);
        scoreBoard.setColor (backgroundColor);
        scoreBoard.fill();
        this.setImage(scoreBoard);
    }

    public void setScore (int score)
    {
        String s = "Score: " + score;
        // erase everything in score and start again
        scoreBoard.clear();
        scoreBoard.setColor (backgroundColor);
        scoreBoard.fill();
        scoreBoard.setColor (textColor);
        scoreBoard.drawString (s, 5, 32);
    }
}
That is in my score board thing. and then in my world I put it in but I cant seem to get it to where it will add it when I hit a character I also have this in my code in alien
private int score;
private ScoreKeeper scoreKeeper;

 private boolean hasTakenAHit;
  public void fireBallHit()
    {
        Actor b = getOneIntersectingObject(FireBall.class);
        if(b != null)
        {
            getWorld().removeObject(b);
            if(hasTakenAHit)
            getWorld().removeObject(this);
            hasTakenAHit = true;
            addPoint();
        }
    }
public void addPoint()
{
    score+= 100;
    scoreKeeper.setScore(score);
}
But its not working....
danpost danpost

2013/5/21

#
You need to follow your ScoreKeeper object, from its creation, to the point where you change its value here. Make sure that the one you are setting is indeed the one you see in the world. Or, are you missing a call to that method from the act method.
Gzuzfrk Gzuzfrk

2013/5/21

#
Is there any way I can send this to you so you can fix everything I have Cause now it just keeps pausing every time an alien dies
danpost danpost

2013/5/21

#
You can upload it on the site (including source) and as soon as I have it, I can let you know so you can delete it back off the site.
Gzuzfrk Gzuzfrk

2013/5/22

#
ok let me figure out how to do that lol
Gzuzfrk Gzuzfrk

2013/5/22

#
Its in there
danpost danpost

2013/5/22

#
Got it. You can open the scenario on the site, and just under the 'Open in Greenfoot' button, you will find the delete scenario clickable text.
Gzuzfrk Gzuzfrk

2013/5/22

#
Sorry about the disorganization Im trying to keep organized
There are more replies on the next page.
1
2
3
4