Skip to content

Commit

Permalink
Moved swpe object call to initApp and out of Input
Browse files Browse the repository at this point in the history
Increased render height
  • Loading branch information
a727891 committed May 19, 2013
1 parent 7da1207 commit 385ae93
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/Game.js
Expand Up @@ -327,7 +327,6 @@ var Game = Class.extend({
break; break;
case this.deletingRow: case this.deletingRow:
if (this.FramesSinceLastAction >= this.DeleteRowFramesPerCell) { if (this.FramesSinceLastAction >= this.DeleteRowFramesPerCell) {
navigator.vibrate(15 * this.DeleteRowFramesPerCell);
//Still deleting the scored rows //Still deleting the scored rows
var i, j; var i, j;
if (this.deleteRowCnt < this.WellWidth) { if (this.deleteRowCnt < this.WellWidth) {
Expand Down Expand Up @@ -479,6 +478,7 @@ var Game = Class.extend({
if (checkRow) { if (checkRow) {
this.deleteRow.push(y); this.deleteRow.push(y);
TransitionToDelete = true; TransitionToDelete = true;

} }
} }
return TransitionToDelete; return TransitionToDelete;
Expand Down
79 changes: 14 additions & 65 deletions src/Input.js
@@ -1,93 +1,42 @@
var Input = Class.extend({ var Input = Class.extend({


init: function (APP) { init: function (APP,SWIPE) {
this.app = APP; this.app = APP;
this.swipe = SWIPE;
var self = this; var self = this;
this.RotateFlag = false; this.RotateFlag = false;
this.LeftFlag = false; this.LeftFlag = false;
this.RightFlag = false; this.RightFlag = false;
this.FallFlag = false; this.FallFlag = false;
this.InstaDropFlag = false; this.InstaDropFlag = false;


var el = document.getElementsByTagName("canvas")[0];
var swipe = new Swipe(); this.swipe.bindTouchToElement('AppCanvas');
swipe.bindTouchToElement('AppCanvas');
swipe.bindCallback('left',function(){ this.swipe.bindCallback('left',function(){
self.LeftFlag = true; self.LeftFlag = true;
}); });
swipe.bindCallback('right',function(){
this.swipe.bindCallback('right',function(){
self.RightFlag = true; self.RightFlag = true;
}); });
swipe.bindCallback('down',function(){
this.swipe.bindCallback('down',function(){
self.InstaDropFlag = true; self.InstaDropFlag = true;
}); });
swipe.bindCallback('tap',function(){
this.swipe.bindCallback('tap',function(){
self.RotateFlag = true; self.RotateFlag = true;
}); });
swipe.bindCallback('up',function(){
this.swipe.bindCallback('up',function(){
if (self.app.isStopped) { if (self.app.isStopped) {
self.app.start(); self.app.start();
} else { } else {
self.app.stop(); 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 () { readInput: function () {
var ret = { var ret = {
Rotate: this.RotateFlag, Rotate: this.RotateFlag,
Expand Down
5 changes: 3 additions & 2 deletions src/Intro.js
@@ -1,5 +1,5 @@
(function () { (function () {
var app, game, input, renderer; var app, game, input, renderer,swipe;
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.id = 'AppCanvas'; canvas.id = 'AppCanvas';
canvas.width = window.innerWidth; canvas.width = window.innerWidth;
Expand All @@ -12,7 +12,8 @@
//TODO: Create an intro animation, maybe an end game animation //TODO: Create an intro animation, maybe an end game animation
app = new App(); app = new App();
game = new Game(); game = new Game();
input = new Input(app); swipe = new Swipe();
input = new Input(app,swipe);
renderer = new Renderer(game, canvas); renderer = new Renderer(game, canvas);
app.setObjects(game, input, renderer); app.setObjects(game, input, renderer);
renderer.render(true); renderer.render(true);
Expand Down
21 changes: 4 additions & 17 deletions src/Render.js
Expand Up @@ -5,8 +5,8 @@ var Renderer = Class.extend({
this.context = this.canvas.getContext('2d'); this.context = this.canvas.getContext('2d');
this.context.font = '16px Arial'; this.context.font = '16px Arial';


this.TileWidth = Math.floor((window.innerWidth * .9) / (this.game.WellWidth + 5));//16; 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.TileHeight = Math.floor((window.innerHeight) / (this.game.WellHeight + 1));//16;
var min = Math.min(this.TileHeight, this.TileWidth); var min = Math.min(this.TileHeight, this.TileWidth);
this.TileHeight = min; this.TileHeight = min;
this.TileWidth = min; this.TileWidth = min;
Expand Down Expand Up @@ -38,7 +38,7 @@ var Renderer = Class.extend({
if (isStopped) { if (isStopped) {
self.drawWell(1); self.drawWell(1);
msg = "Game Paused."; msg = "Game Paused.";
msg2 = "Tap P/P to begin"; msg2 = "Swipe [UP] to begin";
self.printMessage(msg, msg2); self.printMessage(msg, msg2);
self.drawScore(self.game.points, self.game.level, self.game.linesCleared, self.game.linesUntilNextLevel); self.drawScore(self.game.points, self.game.level, self.game.linesCleared, self.game.linesUntilNextLevel);
} else { } else {
Expand All @@ -52,23 +52,10 @@ var Renderer = Class.extend({
} }
} else { } else {
msg = "Game Over."; msg = "Game Over.";
msg2 = "Tap P/P to play again"; msg2 = "Swipe [UP] to play again";
self.printMessage(msg, msg2); 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) { printMessage: function (msg, msg2) {
Expand Down

0 comments on commit 385ae93

Please sign in to comment.