class ScoreDisplayer { private int totalScore; private Vector scores; private PFont font; private color fontColorPos, fontColorNeg; private int fontSize; ScoreDisplayer(String fName, color fcp, color fcn, int fSize) { fontSize = fSize; fontColorPos = fcp; fontColorNeg = fcn; font = createFont(fName, fSize); totalScore = 0; scores = new Vector(10, 5); } int total() { return totalScore; } void reset() { scores.clear(); totalScore = 0; } void addScore(int amt, float x, float y) { totalScore += amt; scores.add(new Score(amt, x, y)); } void display() { fill(255, 0, 0); textFont(arial); textSize(24); textAlign(LEFT); text("Total Score: " + totalScore, 800, 30); textFont(font); textSize(16); textAlign(CENTER); for (int i = 0; i < scores.size(); i++) { Score tmp = (Score)scores.get(i); tmp.update(); tmp.render(); if ( tmp.isDone() ) scores.remove(i--); } } class Score { private float x, y, dx, dy, sc; private int amt, age; Score(int _amt, float _x, float _y) { amt = _amt; x = _x; y = _y; age = 0; dx = random(-1, 1); dy = random(-1, 1); sc = 1; } boolean isDone() { return age > 85; } void update() { x += dx*2; y += dy*2; sc *= 1.03f; age++; } void render() { if ( amt > 0 ) fill(red(fontColorPos), green(fontColorPos), blue(fontColorPos), 255 - (age*3)); else fill(red(fontColorNeg), green(fontColorNeg), blue(fontColorNeg), 255 - (age*3)); textSize(fontSize*sc); text(amt, x, y+10); } } }