1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 1. Name of module
module scoreboard;

// 2. Import asteroids to get a hold of the level number variable 
import asteroids;

// 3. Import our truetype font, point and color to pass to font draw struct, window to place font, scenegraph for the scenegraph functionality
// we also have our scoreboard object defined as a global 
import arc.font;
import arc.math.point;
import arc.draw.color;
import arc.window; 
import arc.scenegraph.all; 
import std.string;

Scoreboard scoreBoard;

// 4. Scoreboard class will hold our scoreboard
class Scoreboard : CompositeNode
{
public:

    // 5. This function will load our font and initialize our score
    this()
    {
        Font font = new Font("astbin/font.ttf", 20);
        transform = new Transform;        
        transform.translation = Point(arc.window.getWidth-font.getWidth(cast(char[])"Score: 99999"), 10);
        text = new Text(font, Color(0,255,0, 150));
        transform.addChild(text);
        super(transform);
        
        reset();
    }

    //6. add something to our score
    void addScore(int argAdd)
    {
        score += argAdd; 
        updateText();
    }     

    //7. reset the score to zero
    void reset()
    {
        score = 0;
        updateText();
    }
    
    ///8. get the score
    int getScore() { return score; }
    
private:
    //9. update text of scoreboard 
    void updateText()
    {
        text.text = "Score: " ~ .toString(score) ~ "\nLevel: " ~ .toString(asteroids.level);
    }

    //10. transform and font nodes and score
    Transform transform;
    Text text;
    int score; 
}