From 09b48543799656618d428af023a79c5eb9e413d1 Mon Sep 17 00:00:00 2001 From: LynxyssCZ Date: Wed, 18 Jun 2014 11:24:33 +0200 Subject: [PATCH] Kind of dirty and underhanded scoreboard. Will look into refinements later. --- pacman.js | Bin 41282 -> 43036 bytes src/display.js | 11 +++++++++++ src/levels/level01.js | 14 +++++++------- src/map.js | 10 ++++++++++ src/map_objects/player.js | 2 +- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/pacman.js b/pacman.js index eb0492daa79970a3c9e21f158a6dd6cf86118ec2..c89d1a1ba9413b58d192517d3c6dcdebb63ff595 100644 GIT binary patch delta 1088 zcmc&zO>0v@6uoK4*YKJqVv@!*OA5kk0KAS9-O{1tv?FO+V)w9zN5vUALESq^IB39WnC=)3s-(i1%4MIAkHl1J4f|!B zJ_BbJY!9){qu+vE-%S|d)e*2l3Y)CK%oFga;C~8Sjf@C!Q|U%RabWsvaZ0n>9+Go3 zNP--cMpMD2C#$1+H`ye6`1Q1%=W|lFNvXfjfVl+TwgRbMZu-8De<6(-LLZ6o!E4lS zF;;yZe&ZN+pNN(BZL&E5g^z7fO9JY~`Fk^{?b*+t*p=2 z%hr(>vitdWOE~5_vNa87u$W3*cpKnfEr})P2>-kxw67xzGOu43yc-lc$Tr)4M-I+} zc<-Fx#%0OYE)a!(w0xF1J!4~4>aGGEjG;w@W_tlnqIC9O1^>-sE>TkF<1a&ABQ$;f znD-9#c@*dj6|NTe=7v+-ymH^miJ}xcp#+LW!J}jlNQSb;7^j@}t(cX@%5;jxI}0!W zaC(z2Z=$otZA>qdLY_dgl%0qQGh#Ff diff --git a/src/display.js b/src/display.js index 1f17385..42e7e92 100644 --- a/src/display.js +++ b/src/display.js @@ -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 () { @@ -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)); diff --git a/src/levels/level01.js b/src/levels/level01.js index 99bd394..5bce7ac 100644 --- a/src/levels/level01.js +++ b/src/levels/level01.js @@ -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); }, @@ -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', diff --git a/src/map.js b/src/map.js index f3c7042..d0f3cab 100644 --- a/src/map.js +++ b/src/map.js @@ -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 */ @@ -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) { diff --git a/src/map_objects/player.js b/src/map_objects/player.js index 4d5e1c0..64ce586 100644 --- a/src/map_objects/player.js +++ b/src/map_objects/player.js @@ -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 ) {