Permalink
Browse files

Moved swpe object call to initApp and out of Input

Increased render height
  • Loading branch information...
1 parent 7da1207 commit 385ae931fb020ac76c31befd84f2fac41eb02ac3 @a727891 committed May 19, 2013
Showing with 22 additions and 85 deletions.
  1. +1 −1 src/Game.js
  2. +14 −65 src/Input.js
  3. +3 −2 src/Intro.js
  4. +4 −17 src/Render.js
View
@@ -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;
View
@@ -1,93 +1,42 @@
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;
this.RightFlag = false;
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,
View
@@ -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);
View
@@ -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) {

0 comments on commit 385ae93

Please sign in to comment.