diff --git a/graphics/numbers.png b/graphics/numbers.png new file mode 100644 index 0000000..53a3f86 Binary files /dev/null and b/graphics/numbers.png differ diff --git a/sketch.js b/sketch.js index 7cc2a01..286e549 100644 --- a/sketch.js +++ b/sketch.js @@ -13,18 +13,24 @@ var pipeBodySprite; var pipePeakSprite; var bgImg; var bgX = 0; +var numbers; +var numberw; +var numberh; function preload() { pipeBodySprite = loadImage("./graphics/pipe_body.png"); pipePeakSprite = loadImage("./graphics/pipe_body.png"); birdSprite = loadImage("graphics/train.png"); bgImg = loadImage("graphics/background.png"); + numbers = loadImage("graphics/numbers.png"); } function setup() { createCanvas(600, 600); bird = new Bird(); pipes.push(new Pipe()); + numberw = numbers.width/10; + numberh = numbers.height; } function draw() { @@ -71,6 +77,7 @@ function draw() { } showScores(); + showNumber(score,width/2,10); } function showScores() { @@ -79,6 +86,15 @@ function showScores() { text("record: " + maxScore, 1, 64); } +function showNumber(n,x,y){ + var nString = n.toString(); + var finalX = x-((numberw*nString.length)/2); + for (let i = 0; i < nString.length; i++){ + let offset = int(nString.charAt(i))*numberw; + image(numbers,finalX+(i*numberw),y,numberw,numberh,offset,0,numberw,numberh); + } +} + function gameover() { console.log("HIT"); textSize(64);