Skip to content

Commit 09b4854

Browse files
committed
Kind of dirty and underhanded scoreboard.
Will look into refinements later.
1 parent e120931 commit 09b4854

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

pacman.js

1.71 KB
Binary file not shown.

src/display.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Game.Display = function (width, height, tileWidth, tileHeight, sheet) {
1212
this._context.canvas.width = this.width * this.tileWidth;
1313
this._context.canvas.height = this.height * this.tileHeight;
1414
this.clear();
15+
this._context.textAlign="center";
1516
};
1617

1718
Game.Display.prototype.getContainer = function () {
@@ -23,6 +24,16 @@ Game.Display.prototype.drawTile = function (x, y, tile, frame, clear) {
2324
this._context.drawImage(this.sheet, (frame * this.tileWidth), (tile * this.tileHeight), this.tileWidth, this.tileHeight, (x * this.tileWidth), (y * this.tileHeight), this.tileWidth, this.tileHeight);
2425
};
2526

27+
Game.Display.prototype.drawText = function(x, y, size, text) {
28+
this._context.font = this.tileWidth*size+"px Verdana";
29+
this._context.fillStyle = '#000000';
30+
var width = Math.ceil((this._context.measureText(text).width)/this.tileWidth);
31+
//alert(width);
32+
this.drawBlock(x-(width/2), y-size, width, 1, "#000000");
33+
this._context.fillStyle = '#FFFFFF';
34+
this._context.fillText(text, this.tileWidth*x, this.tileHeight*y);
35+
}
36+
2637
Game.Display.prototype.drawBlock = function (x, y, w, h, color) {
2738
this._context.fillStyle = color;
2839
this._context.fillRect((x * this.tileWidth), (y * this.tileHeight), (w * this.tileWidth), (h * this.tileHeight));

src/levels/level01.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Game.Level01 = {
66
map.defineObject("inky", new Game.Map.Ghost(3));
77
map.defineObject("clyde", new Game.Map.Ghost(4));
88
map.defineObject("food", Game.Map.Food );
9-
9+
map.scoreBoard(21,13,1);
1010
Game.Level01.buildMaze(map, this.Walls);
1111

1212
},
@@ -45,12 +45,12 @@ Game.Level01 = {
4545
'W*W*WW*WW*************************WW*W_WW_W*WW*************************WW*WW*W*W',
4646
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
4747
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
48-
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
49-
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
50-
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
51-
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W****W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
52-
'W*W*WW*__*WWWWWWWWWWWWWWWWWWWWWWW*WW*WWWWWW*WW*WWWWWWWWWWWWWWWWWWWWWWW*__*WW*W*W',
53-
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW********WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
48+
'W*W*WW*WW*WW___________________WW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
49+
'W*W*WW*WW*WW___________________WW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
50+
'W*W*WW*WW*WW___________________WW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
51+
'W*W*WW*WW*WW___________________WW*WW*W****W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
52+
'W*W*WW*__*WW___________________WW*WW*WWWWWW*WW*WWWWWWWWWWWWWWWWWWWWWWW*__*WW*W*W',
53+
'W*W*WW*WW*WW___________________WW*WW********WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
5454
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WWWW_WW_WWWW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
5555
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WWWW_WW_WWWW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
5656
'W*W*WW*WW**************************************************************WW*WW*W*W',

src/map.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Game.Map.prototype.clear = function() {
1818
this._foodCount = 0;
1919
}
2020

21+
Game.Map.prototype.scoreBoard = function (x, y, size) {
22+
this._scoreX = x;
23+
this._scoreY = y;
24+
this._scoreSize = size;
25+
}
26+
2127
/**
2228
* Add object definition
2329
*/
@@ -161,6 +167,10 @@ Game.Map.prototype.draw = function() {
161167
this._display.drawTile( curr.getX(), curr.getY(), curr.getTile(), curr.getFrame(), true );
162168
};
163169
if (this._player) {this._display.drawTile( this._player.getX(), this._player.getY(), this._player.getTile(), this._player.getFrame(), true );};
170+
if (this._scoreSize) {
171+
this._display.drawText(this._scoreX, this._scoreY, this._scoreSize, "Score:");
172+
this._display.drawText(this._scoreX, this._scoreY+this._scoreSize, this._scoreSize, this._player.getScore());
173+
};
164174
}
165175

166176
Game.Map.prototype.canMoveTo = function(nx, ny, type) {

src/map_objects/player.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Game.Player.prototype.act = function() {
2626
Game.Player.prototype.killedBy = function(killer) {
2727
//this._game.lock();
2828
this.killed = true;
29-
alert("Killed by "+killer);
29+
alert("Killed by "+killer+"\nScore achieved: "+this._score);
3030
};
3131

3232
Game.Player.prototype.nom = function ( food ) {

0 commit comments

Comments
 (0)