var Game = { data : ['SCORE','COINS','WORLD','TIME','LIVES'], imgs : ['img/gk1.jpg','img/allbgs.png','img/move.gif','img/bullet.gif','img/flower.gif','img/gold.gif','img/macadam.gif','img/map-ask.gif','img/mushroom.gif','img/mushroomR.gif'], gk : { //关卡的数据 units : 32, //宽高 type : { //地图样式 0 : 'maptype-bare', 1 : 'maptype-land', 2 : 'maptype-stone', 3 : 'maptype-ask', 4 : 'maptype-pipeline1', 5 : 'maptype-pipeline2', 6 : 'maptype-pipeline3', 7 : 'maptype-pipeline4', 8 : 'maptype-rock', 9 : 'maptype-nothing', 10: 'maptype-blockhouse', 11: 'maptype-flagTop', 12: 'maptype-flagpole', 13: 'maptype-castleRock1', 14: 'maptype-castleRock2', 15: 'maptype-castleRock3', 16: 'maptype-castleRock4', 17: 'maptype-castleRock5', 18: 'maptype-castleRock6' }, flag : { style : 'flag', score : 2000 }, annexs : [ {}, { style : 'gold', score : 200 }, { style : 'largenMushroom', score : 1000, effect : 'bigStyle', iSpeedX : 4, iSpeedY : 8 }, { style : 'flower', score : 1000, effect : 'sendBulletStyle' }, { style : 'lifeMushroom', text : '1UP', effect : 'life', iSpeedX : 4, iSpeedY : 8 }, ], level_1 : { //第一关 style : 'map-list', personX : 80, personY : 384, obstacles : [ [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','3-1','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['3-1','0','0','0','2','3-2','2','3-1','2','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','4','5','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','6','7','0','0'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','4','5'], ['0','0','0','0','0','0','4','5','0','0','0','0','0','0','6','7'], ['0','0','0','0','0','0','6','7','0','0','0','0','0','0','6','7'], ['0','0','0','0','0','0','6','7','0','0','0','0','0','0','6','7'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','4','5','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','6','7','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','6','7','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','6','7','0','0','0','0','0'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0-4','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','2','3-2','2'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['1','1','1','1','1','0','0','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','0','0','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['2','2','2','2','2','2','2','2','0','0','0','2','2','2','3-1','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','2-1','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['1','1','1','1','1','1','0','0','0','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','0','0','0','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','3-2','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','2','2','0','0','0','0','3-1','0','0','3-1','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','2','2','2','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['3-1','0','0','0','0','0','2','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['2','3-1','3-1','2','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','2','2','0','0','0','0','0','0','8','0','0','8','0','0','0'], ['0','0','0','0','0','0','0','0','8','8','0','0','8','8','0','0'], ['0','0','0','0','0','0','0','8','8','8','0','0','8','8','8','0'], ['0','0','0','0','0','0','8','8','8','8','0','0','8','8','8','8'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','8','8','0','0','8','0','0','0','0'], ['0','0','0','0','0','0','8','8','8','0','0','8','8','0','0','0'], ['0','0','0','0','0','8','8','8','8','0','0','8','8','8','0','0'], ['0','0','0','0','8','8','8','8','8','0','0','8','8','8','8','0'], ['1','1','1','1','1','1','1','1','1','0','0','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','0','0','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','2','2','3-1','2','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','4','5','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','6','7','0','0','0','0','0','0','0','0','0','0','0'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','8','8','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','8','8','8','0','0'], ['0','0','0','0','0','0','0','0','0','0','8','8','8','8','0','0'], ['0','0','0','0','0','0','0','0','0','8','8','8','8','8','0','0'], ['0','0','0','0','0','0','0','0','8','8','8','8','8','8','0','0'], ['0','0','0','0','0','0','0','8','8','8','8','8','8','8','0','0'], ['0','0','0','4','5','0','8','8','8','8','8','8','8','8','0','0'], ['0','0','0','6','7','8','8','8','8','8','8','8','8','8','0','0'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ], [ ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','11','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','12','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','12','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','12','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','12','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','12','0','0','0','0','0','0','0','0'], ['0','0','0','0','0','0','0','12','0','0','0','0','13','13','13','0'], ['0','0','0','0','0','0','0','12','0','0','0','0','14','18','17','0'], ['0','0','0','0','0','0','0','12','0','0','0','13','15','15','15','13'], ['0','0','0','0','0','0','0','12','0','0','0','18','18','16','18','18'], ['0','0','0','0','0','0','0','8','0','0','0','18','18','10','18','18'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'], ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ] ], enemyPosition : [ { X : 640, Y : 384, type : 'mushroom' }, { X : 1376, Y : 384, type : 'mushroom' }, { X : 1664, Y : 384, type : 'mushroom' }, { X : 1700, Y : 384, type : 'mushroom' }, { X : 2560, Y : 128, type : 'mushroom' }, { X : 2608, Y : 128, type : 'mushroom' }, { X : 3040, Y : 384, type : 'mushroom' }, { X : 3088, Y : 384, type : 'mushroom' }, { X : 3616, Y : 384, type : 'mushroom' }, { X : 3664, Y : 384, type : 'mushroom' }, { X : 3936, Y : 384, type : 'mushroom' }, { X : 3984, Y : 384, type : 'mushroom' }, { X : 4064, Y : 384, type : 'mushroom' }, { X : 4112, Y : 384, type : 'mushroom' }, { X : 5504, Y : 384, type : 'mushroom' }, { X : 5552, Y : 384, type : 'mushroom' } ] }, times : 400 }, start : 72, mario : { //马里奥数据 id : 'person', style : 'base', bigStyle : 'big', sendBulletStyle : 'sendBullet', leftStyle : 'personL', rightStyle : 'personR', leftMoveStyle : 'personLM', rightMoveStyle : 'personRM', leftJumpStyle : 'personLU', rightJumpStyle : 'personRU', leftFStyle : 'personLF', rightFStyle : 'personRF', supportLStyle : 'supportL', supportRStyle : 'supportR', dieStyle : 'die', life : 3, marioSpeedX : 6, marioSpeedY : 8, jumpHigh : 128, acceleratedSpeedX : .2, bind : { left : 65, right : 68, jump : 75, sendBullet : 74 }, bullet : { style : 'bullet', speed : 8, explode : 'explode' } }, enemy : { //敌人数据 mushroom : { style : 'mushroom', reStyle : 'reverse', iSpeedX : -2, iSpeedY : 8, score : 100 } }, loading : function(){ var iNow = 0; var This = this; for(var i=0; i 0){ playerRect.iSpeedX -= this.mario.acceleratedSpeedX; if(playerRect.iSpeedX<0) playerRect.iSpeedX = 0; }else if(playerRect.iSpeedX < 0){ playerRect.iSpeedX += this.mario.acceleratedSpeedX; if(playerRect.iSpeedX>0) playerRect.iSpeedX = 0; } } if(playerRect.iSpeedX > this.mario.marioSpeedX || playerRect.iSpeedX < -this.mario.marioSpeedX){ playerRect.iSpeedX = playerRect.iSpeedX > 0 ? this.mario.marioSpeedX : -this.mario.marioSpeedX; } // 跳跃 速度 if(this.key[player.jump]){ if(!playerRect.isJump){ playerRect.isJump = true; playerRect.iSpeedY = -this.mario.marioSpeedY; }; }else{ playerRect.iSpeedY = this.mario.marioSpeedY; } if(playerRect.trampleEnemy){ playerRect.iSpeedY = - this.mario.marioSpeedY; } // 马里奥 左右移动 样式 if(playerRect.iSpeedX < 0){ removeClass(playerRect,this.mario.rightMoveStyle); addClass(playerRect,this.mario.leftMoveStyle); }else if(playerRect.iSpeedX > 0){ removeClass(playerRect,this.mario.leftMoveStyle); addClass(playerRect,this.mario.rightMoveStyle); }else{ removeClass(playerRect,this.mario.leftMoveStyle); removeClass(playerRect,this.mario.rightMoveStyle); } // 马里奥 跳跃 样式 removeClass(playerRect,this.mario.leftJumpStyle); removeClass(playerRect,this.mario.rightJumpStyle); if(playerRect.offsetTop != playerRect.iT){ if(playerRect.direction<0){ addClass(playerRect,this.mario.leftJumpStyle); }else{ addClass(playerRect,this.mario.rightJumpStyle); } playerRect.isJump = true; } if(playerRect.isJump){ if(playerRect.iSpeedX>0){ addClass(playerRect,this.mario.rightJumpStyle); }else if(playerRect.iSpeedX<0){ addClass(playerRect,this.mario.leftJumpStyle); } } L = playerRect.offsetLeft + playerRect.iSpeedX; T = playerRect.offsetTop + playerRect.iSpeedY; var n = parseInt(L/512); for(var i=n-2<0?0:n-2,l=n+2>this.mapType.length?this.mapType.length:n+2; i 0){ // 与物体碰撞 switch(this.pzDir(playerRect,spriteRect)){ case 'left': if(playerRect.iSpeedX > 0){ playerRect.iSpeedX = 0; L = this.getPos(spriteRect,this.gameMap).l - playerRect.offsetWidth; if(spriteRect.type == 12){ iWin = true; }; } break; case 'right': if(playerRect.iSpeedX < 0){ playerRect.iSpeedX = 0; L = this.getPos(spriteRect,this.gameMap).l + spriteRect.offsetWidth; } break; case 'top': if(playerRect.iSpeedY > 0){ playerRect.iT = T = this.getPos(spriteRect,this.gameMap).t - playerRect.offsetHeight; playerRect.isJump = false; } break; case 'bottomMid': if(playerRect.iSpeedY < 0){ playerRect.iSpeedY *= -1; T = this.getPos(spriteRect,this.gameMap).t + spriteRect.offsetHeight; this.topHeadMario(spriteRect,playerRect); } break; } }else if(spriteRect.type == 0){ if(this.pzDir(playerRect,spriteRect) == 'bottomMid' && spriteRect.annexs > 0){ if(playerRect.iSpeedY < 0){ playerRect.iSpeedY *= -1; T = this.getPos(spriteRect,this.gameMap).t + spriteRect.offsetHeight; this.topHeadMario(spriteRect,playerRect); } } } } } if(T>this.gameWrap.clientHeight){ this.player.isCloaking = false; this.delMario(); } if(T 0){ iLeft = 0; }else if(iLeft < (1 - this.lengthBg) * 512){ iLeft = (1 - this.lengthBg) * 512; } this.gameMap.style.left = iLeft + 'px'; this.iBgOldLeft = iLeft; }, waneMario : function(){ // 变小 var This = this; if(this.player.isSendBullet){ removeClass(this.player,this.mario.sendBulletStyle); this.player.isSendBullet = false; } removeClass(this.player,this.mario.bigStyle); this.player.isBig = false; this.player.isCloaking = true; this.cloaking(); setTimeout(function(){ This.player.isCloaking = false; },5000) }, cloaking : function(){ // 闪 var This = this; var timer = setInterval(function(){ if(!This.player.isCloaking) clearInterval(timer); addClass(This.player,'cloaking'); setTimeout(function(){ removeClass(This.player,'cloaking'); },100); },200) }, pauseFn : function(){ //停止 var This = this; this.pause = true; setTimeout(function(){ This.pause = false; },1000) }, changeStyle : function(sClass){ //变身 this.pauseFn(); var This = this; var T = this.player.offsetTop; var H = this.player.offsetHeight; var timer = setInterval(function(){ addClass(This.player,sClass); This.player.style.top = T + H - This.player.offsetHeight + 'px'; if(!This.pause) { clearInterval(timer); return; } setTimeout(function(){ removeClass(This.player,sClass); This.player.style.top = T + 'px' },100); },200) }, delMario : function(){ // 马里奥死亡 if(this.player.isCloaking) return; if(this.player.isBig){ if(this.player.isSendBullet){ removeClass(this.player,this.mario.sendBulletStyle); } removeClass(this.player,this.mario.bigStyle); } var T = this.player.offsetTop; var This = this; clearInterval(this.player.timer); clearInterval(this.timeTimer); for(var i=0; i 0 ? this.mario.rightFStyle : this.mario.leftFStyle; addClass(this.player,style); setTimeout(function(){ removeClass(This.player,style); },100) this.bulletNum ++; var oBullet = document.createElement('div'); oBullet.className = this.mario.bullet.style; this.gameMap.appendChild(oBullet); oBullet.style.left = (this.player.direction > 0 ? this.getPos(this.player,this.gameMap).l + this.player.offsetWidth : this.getPos(this.player,this.gameMap).l) - oBullet.offsetWidth + 'px'; oBullet.style.top = this.getPos(this.player,this.gameMap).t + (this.player.offsetHeight - oBullet.offsetHeight)/2 + 'px'; this.moveBullet(oBullet); }, moveBullet : function(obj){ // 子弹飞 var speedX = this.mario.bullet.speed * this.player.direction * 2; var speedY = this.mario.bullet.speed; var iT = 0; var This = this; clearInterval(obj.timer); obj.timer = setInterval(function(){ if(This.pause) return; var T = obj.offsetTop + speedY; var L = obj.offsetLeft + speedX; if(L<-This.gameMap.offsetLeft - obj.offsetWidth || L > -This.gameMap.offsetLeft + 512 ){ This.bulletNum --; clearInterval(obj.timer); This.gameMap.removeChild(obj); } if(speedY<0 && T < iT - 1.5 * This.gk.units){ speedY*=-1; T = iT - 1.5 * This.gk.units; } var n = parseInt(L/512); for(var i=n-2<0?0:n-2,l=n+2>This.mapType.length?This.mapType.length:n+2; i 0){ // 与物体碰撞 switch(This.pzDir(obj,spriteRect)){ case 'left': This.removeBullet(obj); break; case 'right': This.removeBullet(obj); break; case 'top': if(speedY>0){ speedY*=-1; iT = T = This.getPos(spriteRect,This.gameMap).t - obj.offsetHeight; } break; case 'bottom': break; } } } } for(var i=0; i 0 ? 1 : -1; This.removeBullet(obj); This.reverseEnemy(This.aEnemy[i],dir) } } obj.style.left = L + 'px'; obj.style.top = T + 'px'; },30); }, removeBullet : function(obj){ // 移除子弹 if(!obj.timer) return; this.bulletNum --; var This = this; clearInterval(obj.timer); obj.timer = null; obj.className = this.mario.bullet.explode; setTimeout(function(){ This.gameMap.removeChild(obj); },100) }, createAllEnemy : function(){ // 创建敌人容器 循环所有敌人的位置 this.enemyParent = document.createElement("div"); this.enemyParent.className = 'enemy'; for(var i=0; i iH){ clearInterval(obj.timer); } obj.style.top = T + 'px'; obj.style.left = L + 'px'; },30) }, createData : function(){ var oDiv = document.createElement('div'); oDiv.className = 'data_display'; var oUl = document.createElement('ul'); for(var i=0; i0' oUl.appendChild(oLi); } oDiv.appendChild(oUl); this.gameWrap.appendChild(oDiv); this.oDataDisplay = oDiv; this.aData = oDiv.getElementsByTagName('span'); this.score = this.aData[0]; this.coins = this.aData[1]; this.world = this.aData[2]; this.time = this.aData[3]; this.lives = this.aData[4]; }, scoreShow : function(obj){ // 所得分数 显示 var T = obj.offsetTop; var L = obj.offsetLeft + this.gameMap.offsetLeft; var oSpan = document.createElement("span"); var This = this; oSpan.className = 'score'; oSpan.style.top = T + 'px'; oSpan.style.left = L + 'px'; if( 'score' in obj){ oSpan.innerHTML = obj.score; this.score.innerHTML = parseInt(this.score.innerHTML) + obj.score; }else if( 'text' in obj){ oSpan.innerHTML = obj.text; } this.gameWrap.appendChild(oSpan); startMoveTime(oSpan,{top: T-2 * this.gk.units},function(){ This.gameWrap.removeChild(oSpan); }); }, objectMove : function(obj){ // 物体移动移动 包括 敌人移动和附属物移动 clearInterval(obj.timer) var iSpeedX = obj.iX; var iSpeedY = obj.iY; var This = this; var L,T; obj.timer = setInterval(function(){ if(!obj.isMove||This.pause){ return; };//进入可视区的时候移动 增加性能 L = obj.offsetLeft + iSpeedX; T = obj.offsetTop + iSpeedY; if(L + obj.offsetWidth<-This.gameMap.offsetLeft){ clearInterval(obj.timer); } var n = parseInt(L/512); for(var i=n-2<0?0:n-2,l=n+2>This.mapType.length?This.mapType.length:n+2; i 0){ // 与物体碰撞 switch(This.pzDir(obj,spriteRect)){ case 'left': if(iSpeedX > 0){ iSpeedX *= -1; } break; case 'right': if(iSpeedX < 0){ iSpeedX *= -1; } break; case 'top': if(iSpeedY > 0){ T = This.getPos(spriteRect,This.gameMap).t - obj.offsetHeight; } break; case 'bottom': break; } } } } if(obj.isEnemy){ if(!obj.die){ switch(This.pzDir(This.player,obj)){ // 做为敌人 与马里奥碰撞 case 'left': case 'right': case 'bottom': case 'bottomLeft': case 'bottomRight': if(This.player.isBig){ This.waneMario(); }else{ This.delMario(); } break; case 'top': This.player.trampleEnemy = true; This.player.iT = obj.offsetTop - This.player.offsetHeight; This.delOneEnemy(obj); break; } } }else{ // 做为附属物 与马里奥碰撞 if(This.pz(This.player,obj)){ clearInterval(obj.timer); This.scoreShow(obj); This.gameMap.removeChild(obj); if(obj.className == This.gk.annexs[2].style){ if(!This.player.isBig){ This.changeStyle(This.mario[obj.effect]); This.player.isBig = true; } }else if(obj.className == This.gk.annexs[3].style){ if(!This.player.isSendBullet){ This.changeStyle(This.mario[obj.effect]); if(!This.player.isBig){ This.player.isBig = true; }else{ This.player.isSendBullet = true; } } }else if(obj.className == This.gk.annexs[4].style){ This.lives.innerHTML = ++This.blood; } } } obj.style.left = L + 'px'; obj.style.top = T + 'px'; },30) }, showPoleScore : function(){ // 碰撞旗杆 展现相应分数 var T = this.getPos(this.player,this.gameMap).t; var L ; var iNow = this.flagpole.length - 1; var oSpan = document.createElement("span"); for(var i=0; i T){ iNow = i; break; }; }; T = this.getPos(this.flagpole[iNow],this.gameMap).t; L = this.getPos(this.flagpole[iNow],this.gameMap).l + this.flagpole[iNow].offsetWidth; oSpan.className = 'score'; oSpan.style.top = T + 'px'; oSpan.style.left = L + 'px'; oSpan.innerHTML = this.flagpole[iNow].score; this.score.innerHTML = parseInt(this.score.innerHTML) + this.flagpole[iNow].score; this.gameMap.appendChild(oSpan); startMoveTime(oSpan,{top: this.flagpole[0].offsetTop}); }, slidePole : function(obj,fn){ //滑竿 var flagBottom = this.flagpole[this.flagpole.length - 1]; var T = this.getPos(flagBottom,this.gameMap).t + flagBottom.offsetHeight - this.player.offsetHeight; if(T < obj.offsetTop ){ obj.style.top = T + 'px'; } startMoveTime(obj,{top:T},1000,fn); }, moveToHouse : function(){ // 移动到城堡 var T = this.getPos(this.blockhouse,this.gameMap).t + this.blockhouse.offsetHeight - this.player.offsetHeight; var L = this.getPos(this.blockhouse,this.gameMap).l; var This = this; this.player.style.top = T + 'px'; this.player.style.left = this.player.offsetLeft + 0.75 * this.gk.units + 'px'; removeClass(this.player,This.mario.supportLStyle); startMoveTime(this.player,{left:L},2000,function(){ This.player.style.display = 'none'; This.timeToScore(); }); }, timeToScore : function(){ //剩余时间转换成分数 var This = this; var timer = null; clearInterval(timer); timer = setInterval(function(){ This.time.innerHTML = parseInt(This.time.innerHTML) - 1; This.score.innerHTML = parseInt(This.score.innerHTML) + 50; if(parseInt(This.time.innerHTML) == 0) clearInterval(timer); },10) }, pz : function(obj1,obj2){ //碰撞检测 var L1 = this.getPos(obj1,this.gameMap).l; var R1 = L1 + obj1.offsetWidth; var T1 = this.getPos(obj1,this.gameMap).t; var B1 = T1 + obj1.offsetHeight; var L2 = this.getPos(obj2,this.gameMap).l; var R2 = L2 + obj2.offsetWidth; var T2 = this.getPos(obj2,this.gameMap).t; var B2 = T2 + obj2.offsetHeight; if( L1>R2 || R1B2 || B1 Math.abs(T1-T2)){ if(L1L2){ return 'right'; } }else if(Math.abs(L1-L2) < Math.abs(T1-T2)){ if(T1 this.getPos(obj2,this.gameMap).l && L1 - obj1.offsetWidth/2 < this.getPos(obj2,this.gameMap).l + obj2.offsetWidth){ return 'top'; } }else if(T1>T2){ if(L1 < this.getPos(obj2,this.gameMap).l){ return 'bottomLeft'; }else if(L1 > this.getPos(obj2,this.gameMap).l + obj2.offsetWidth){ return 'bottomRight'; }else{ return 'bottomMid'; } } } return false; }, getPos : function(obj,anc){ var aPos = {l: 0, t: 0}; while(obj && obj != anc){ aPos.l += obj.offsetLeft; aPos.t += obj.offsetTop; obj = obj.offsetParent; } return aPos; }, imgLoad : function(url, callback) { var img = new Image(); img.src = url; if (img.complete) { callback(img.width, img.height); } else { img.onload = function () { callback(img.width, img.height); img.onload = null; }; }; } }