From 385ae931fb020ac76c31befd84f2fac41eb02ac3 Mon Sep 17 00:00:00 2001 From: Soeed Date: Sun, 19 May 2013 01:29:50 -0500 Subject: [PATCH] Moved swpe object call to initApp and out of Input Increased render height --- src/Game.js | 2 +- src/Input.js | 79 +++++++++------------------------------------------ src/Intro.js | 5 ++-- src/Render.js | 21 +++----------- 4 files changed, 22 insertions(+), 85 deletions(-) diff --git a/src/Game.js b/src/Game.js index 8ac202f..241ab1c 100644 --- a/src/Game.js +++ b/src/Game.js @@ -327,7 +327,6 @@ var Game = Class.extend({ break; case this.deletingRow: if (this.FramesSinceLastAction >= this.DeleteRowFramesPerCell) { - navigator.vibrate(15 * this.DeleteRowFramesPerCell); //Still deleting the scored rows var i, j; if (this.deleteRowCnt < this.WellWidth) { @@ -479,6 +478,7 @@ var Game = Class.extend({ if (checkRow) { this.deleteRow.push(y); TransitionToDelete = true; + } } return TransitionToDelete; diff --git a/src/Input.js b/src/Input.js index 3cdfcd7..7999291 100644 --- a/src/Input.js +++ b/src/Input.js @@ -1,7 +1,8 @@ var Input = Class.extend({ - init: function (APP) { + init: function (APP,SWIPE) { this.app = APP; + this.swipe = SWIPE; var self = this; this.RotateFlag = false; this.LeftFlag = false; @@ -9,85 +10,33 @@ var Input = Class.extend({ this.FallFlag = false; this.InstaDropFlag = false; - var el = document.getElementsByTagName("canvas")[0]; - var swipe = new Swipe(); - swipe.bindTouchToElement('AppCanvas'); - swipe.bindCallback('left',function(){ + + this.swipe.bindTouchToElement('AppCanvas'); + + this.swipe.bindCallback('left',function(){ self.LeftFlag = true; }); - swipe.bindCallback('right',function(){ + + this.swipe.bindCallback('right',function(){ self.RightFlag = true; }); - swipe.bindCallback('down',function(){ + + this.swipe.bindCallback('down',function(){ self.InstaDropFlag = true; }); - swipe.bindCallback('tap',function(){ + + this.swipe.bindCallback('tap',function(){ self.RotateFlag = true; }); - swipe.bindCallback('up',function(){ + + this.swipe.bindCallback('up',function(){ if (self.app.isStopped) { self.app.start(); } else { self.app.stop(); } }); -// this.attachImages(); - - }, - attachImages: function () { - var images = [ - {pic: 'DownHard.png', flag: 'InstaDrop'}, - {pic: 'Left.png', flag: 'Left'}, - {pic: 'Rotate.png', flag: 'Rotate'}, - {pic: 'Right.png', flag: 'Right'}, - {pic: 'Down.png', flag: 'Fall'}, - {pic: 'PP.png', flag: 'Pause'} - ], newImg, self = this, - canvas = document.getElementsByTagName("canvas")[0], - Canvas20H = canvas.height * .2, - Canvas20W = Math.floor(canvas.width / images.length), - imgsize = Math.min(Canvas20H, Canvas20W); - for (var i = 0; i < images.length; i++) { - newImg = document.createElement('img'); - newImg.src = images[i].pic; - newImg.id = images[i].flag; - newImg.style.position = 'absolute'; - newImg.style.left = (imgsize * i); - newImg.style.top = canvas.height - imgsize; - newImg.style.width = imgsize; - - newImg.addEventListener('touchstart', this.touchHandler.bind(this)); - document.body.appendChild(newImg); - } }, - touchHandler: function (event) { - var id = event.target.id; - switch (id) { - case 'Left': - this.LeftFlag = true; - break; - case 'Right': - this.RightFlag = true; - break; - case 'Rotate': - this.RotateFlag = true; - break; - case 'Fall': - this.FallFlag = true; - break; - case 'InstaDrop': - this.InstaDropFlag = true; - break; - case 'Pause': - if (this.app.isStopped) { - this.app.start(); - } else { - this.app.stop(); - } - break; - } - }, - readInput: function () { var ret = { Rotate: this.RotateFlag, diff --git a/src/Intro.js b/src/Intro.js index ab770be..4640f59 100644 --- a/src/Intro.js +++ b/src/Intro.js @@ -1,5 +1,5 @@ (function () { - var app, game, input, renderer; + var app, game, input, renderer,swipe; var canvas = document.createElement('canvas'); canvas.id = 'AppCanvas'; canvas.width = window.innerWidth; @@ -12,7 +12,8 @@ //TODO: Create an intro animation, maybe an end game animation app = new App(); game = new Game(); - input = new Input(app); + swipe = new Swipe(); + input = new Input(app,swipe); renderer = new Renderer(game, canvas); app.setObjects(game, input, renderer); renderer.render(true); diff --git a/src/Render.js b/src/Render.js index f6446ad..2a079ab 100644 --- a/src/Render.js +++ b/src/Render.js @@ -5,8 +5,8 @@ var Renderer = Class.extend({ this.context = this.canvas.getContext('2d'); this.context.font = '16px Arial'; - this.TileWidth = Math.floor((window.innerWidth * .9) / (this.game.WellWidth + 5));//16; - this.TileHeight = Math.floor((window.innerHeight * .8) / (this.game.WellHeight + 1));//16; + this.TileWidth = Math.floor((window.innerWidth *.9) / (this.game.WellWidth + 5));//16; + this.TileHeight = Math.floor((window.innerHeight) / (this.game.WellHeight + 1));//16; var min = Math.min(this.TileHeight, this.TileWidth); this.TileHeight = min; this.TileWidth = min; @@ -38,7 +38,7 @@ var Renderer = Class.extend({ if (isStopped) { self.drawWell(1); msg = "Game Paused."; - msg2 = "Tap P/P to begin"; + msg2 = "Swipe [UP] to begin"; self.printMessage(msg, msg2); self.drawScore(self.game.points, self.game.level, self.game.linesCleared, self.game.linesUntilNextLevel); } else { @@ -52,23 +52,10 @@ var Renderer = Class.extend({ } } else { msg = "Game Over."; - msg2 = "Tap P/P to play again"; + msg2 = "Swipe [UP] to play again"; self.printMessage(msg, msg2); } -//// this.context.fillStyle = 'white'; -//// this.context.fillRect(0,300,100,100); -// this.context.save(); -// this.context.fillStyle = 'red'; -// this.context.fillRect(0,this.canvas.height *.8,this.canvas.width/2,this.canvas.height *.2); -// this.context.fillStyle = 'green'; -// this.context.fillRect(this.canvas.width/2,this.canvas.height *.8,this.canvas.width/2,this.canvas.height *.2); -// this.context.fillStyle = 'yellow'; -// this.context.fillRect(this.canvas.width *.7,this.canvas.height *.5,this.canvas.width *.3,this.canvas.height *.3); -// -// -//// this.context.fillText('LEFT'); -// this.context.restore(); }, printMessage: function (msg, msg2) {