Skip to content

Commit

Permalink
Kind of dirty and underhanded scoreboard.
Browse files Browse the repository at this point in the history
Will look into refinements later.
  • Loading branch information
LynxyssCZ committed Jun 18, 2014
1 parent e120931 commit 09b4854
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
Binary file modified pacman.js
Binary file not shown.
11 changes: 11 additions & 0 deletions src/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Game.Display = function (width, height, tileWidth, tileHeight, sheet) {
this._context.canvas.width = this.width * this.tileWidth;
this._context.canvas.height = this.height * this.tileHeight;
this.clear();
this._context.textAlign="center";
};

Game.Display.prototype.getContainer = function () {
Expand All @@ -23,6 +24,16 @@ Game.Display.prototype.drawTile = function (x, y, tile, frame, clear) {
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);
};

Game.Display.prototype.drawText = function(x, y, size, text) {
this._context.font = this.tileWidth*size+"px Verdana";
this._context.fillStyle = '#000000';
var width = Math.ceil((this._context.measureText(text).width)/this.tileWidth);
//alert(width);
this.drawBlock(x-(width/2), y-size, width, 1, "#000000");
this._context.fillStyle = '#FFFFFF';
this._context.fillText(text, this.tileWidth*x, this.tileHeight*y);
}

Game.Display.prototype.drawBlock = function (x, y, w, h, color) {
this._context.fillStyle = color;
this._context.fillRect((x * this.tileWidth), (y * this.tileHeight), (w * this.tileWidth), (h * this.tileHeight));
Expand Down
14 changes: 7 additions & 7 deletions src/levels/level01.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Game.Level01 = {
map.defineObject("inky", new Game.Map.Ghost(3));
map.defineObject("clyde", new Game.Map.Ghost(4));
map.defineObject("food", Game.Map.Food );

map.scoreBoard(21,13,1);
Game.Level01.buildMaze(map, this.Walls);

},
Expand Down Expand Up @@ -45,12 +45,12 @@ Game.Level01 = {
'W*W*WW*WW*************************WW*W_WW_W*WW*************************WW*WW*W*W',
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*W****W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*__*WWWWWWWWWWWWWWWWWWWWWWW*WW*WWWWWW*WW*WWWWWWWWWWWWWWWWWWWWWWW*__*WW*W*W',
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW********WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WW___________________WW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WW___________________WW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WW___________________WW*WW*W_WW_W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WW___________________WW*WW*W****W*WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*__*WW___________________WW*WW*WWWWWW*WW*WWWWWWWWWWWWWWWWWWWWWWW*__*WW*W*W',
'W*W*WW*WW*WW___________________WW*WW********WW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WWWW_WW_WWWW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW*WWWWWWWWWWWWWWWWWWWWWWW*WWWW_WW_WWWW*WWWWWWWWWWWWWWWWWWWWWWW*WW*WW*W*W',
'W*W*WW*WW**************************************************************WW*WW*W*W',
Expand Down
10 changes: 10 additions & 0 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Game.Map.prototype.clear = function() {
this._foodCount = 0;
}

Game.Map.prototype.scoreBoard = function (x, y, size) {
this._scoreX = x;
this._scoreY = y;
this._scoreSize = size;
}

/**
* Add object definition
*/
Expand Down Expand Up @@ -161,6 +167,10 @@ Game.Map.prototype.draw = function() {
this._display.drawTile( curr.getX(), curr.getY(), curr.getTile(), curr.getFrame(), true );
};
if (this._player) {this._display.drawTile( this._player.getX(), this._player.getY(), this._player.getTile(), this._player.getFrame(), true );};
if (this._scoreSize) {
this._display.drawText(this._scoreX, this._scoreY, this._scoreSize, "Score:");
this._display.drawText(this._scoreX, this._scoreY+this._scoreSize, this._scoreSize, this._player.getScore());
};
}

Game.Map.prototype.canMoveTo = function(nx, ny, type) {
Expand Down
2 changes: 1 addition & 1 deletion src/map_objects/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Game.Player.prototype.act = function() {
Game.Player.prototype.killedBy = function(killer) {
//this._game.lock();
this.killed = true;
alert("Killed by "+killer);
alert("Killed by "+killer+"\nScore achieved: "+this._score);
};

Game.Player.prototype.nom = function ( food ) {
Expand Down

0 comments on commit 09b4854

Please sign in to comment.