/* Made by Nambiar - Game Dolphin Feel free to use and learn from */ Block = function(game,x,y,type,color,scale){ this.centerX = x; this.centerY = y; this.blocktype = type; this.blockcolor = color; this.game = game; this.squares = new Array(); this.scale = scale; this.setupsquares(); }; var md = (width * this.scale ) / 2; Block.prototype = { setupsquares : function(){ this.squares.length = 0; switch(this.blocktype){ case 'o' : this.squares[0] = this.game.add.sprite(this.centerX-md,this.centerY-md,'blocks',this.blockcolor); this.squares[1] = this.game.add.sprite(this.centerX-md,this.centerY+md,'blocks',this.blockcolor); this.squares[2] = this.game.add.sprite(this.centerX+md,this.centerY+md,'blocks',this.blockcolor); this.squares[3] = this.game.add.sprite(this.centerX+md,this.centerY-md,'blocks',this.blockcolor); break; case 't' : this.squares[0] = this.game.add.sprite(this.centerX+md,this.centerY-md,'blocks',this.blockcolor); this.squares[1] = this.game.add.sprite(this.centerX+md,this.centerY+md,'blocks',this.blockcolor); this.squares[2] = this.game.add.sprite(this.centerX-md,this.centerY+md,'blocks',this.blockcolor); this.squares[3] = this.game.add.sprite(this.centerX+md*3,this.centerY+md,'blocks',this.blockcolor); break; case 'l' : this.squares[0] = this.game.add.sprite(this.centerX-md,this.centerY-md,'blocks',this.blockcolor); this.squares[1] = this.game.add.sprite(this.centerX-md,this.centerY+md,'blocks',this.blockcolor); this.squares[2] = this.game.add.sprite(this.centerX-md,this.centerY+md*3,'blocks',this.blockcolor); this.squares[3] = this.game.add.sprite(this.centerX+md,this.centerY+md*3,'blocks',this.blockcolor); break; case 'j' : this.squares[0] = this.game.add.sprite(this.centerX+md,this.centerY-md,'blocks',this.blockcolor); this.squares[1] = this.game.add.sprite(this.centerX+md,this.centerY+md,'blocks',this.blockcolor); this.squares[2] = this.game.add.sprite(this.centerX+md,this.centerY+md*3,'blocks',this.blockcolor); this.squares[3] = this.game.add.sprite(this.centerX-md,this.centerY+md*3,'blocks',this.blockcolor); break; case 'i' : this.squares[0] = this.game.add.sprite(this.centerX+md,this.centerY-md*3,'blocks',this.blockcolor); this.squares[1] = this.game.add.sprite(this.centerX+md,this.centerY-md,'blocks',this.blockcolor); this.squares[2] = this.game.add.sprite(this.centerX+md,this.centerY+md,'blocks',this.blockcolor); this.squares[3] = this.game.add.sprite(this.centerX+md,this.centerY+md*3,'blocks',this.blockcolor); break; case 's' : this.squares[0] = this.game.add.sprite(this.centerX+md*3,this.centerY-md,'blocks',this.blockcolor); this.squares[1] = this.game.add.sprite(this.centerX+md,this.centerY-md,'blocks',this.blockcolor); this.squares[2] = this.game.add.sprite(this.centerX+md,this.centerY+md,'blocks',this.blockcolor); this.squares[3] = this.game.add.sprite(this.centerX-md,this.centerY+md,'blocks',this.blockcolor); break; case 'z' : this.squares[0] = this.game.add.sprite(this.centerX-md,this.centerY-md,'blocks',this.blockcolor); this.squares[1] = this.game.add.sprite(this.centerX+md,this.centerY-md,'blocks',this.blockcolor); this.squares[2] = this.game.add.sprite(this.centerX+md,this.centerY+md,'blocks',this.blockcolor); this.squares[3] = this.game.add.sprite(this.centerX+md*3,this.centerY+md,'blocks',this.blockcolor); break; } for(var i=0;ithis.game.world.bounds.width) return true; } break; case 'down' : for(var i=0;i<4;i++){ if(this.squares[i].y+2*md>this.game.world.height) return true; } break; default : return false; } }else{ switch(dir){ case 'left' : for(var i=0;i<4;i++){ for(var j=0;joldsquares[j].x&&this.squares[i].x-3*mdthis.game.world.bounds.width||(this.squares[i].xoldsquares[j].x&&this.squares[i].y==oldsquares[j].y)) return true; } } break; case 'down' : for(var i=0;i<4;i++){ for(var j=0;jthis.game.world.bounds.height||(this.squares[i].y+3*md>oldsquares[j].y&&this.squares[i].x==oldsquares[j].x)) return true; } } break; default : return false; } } }, rotatecollide : function(oldsquares){ var arr = this.getrotated(); var len = oldsquares.length; for(var i=0;i<4;i++){ if ( (arr[i*2] < this.game.world.bounds.x) || (arr[i*2] > this.game.world.bounds.width) ) return true; if(arr[i*2+1]>this.game.world.bounds.height) return true; for(var j=0;j