window.JellyTruck.state.level16 = { preload: function(){ this.game.world.removeAll(); //background this.bg; this.light; this.scene; this.ground_art; this.map = this.game.add.tilemap("level_16_map"); this.phyBody = this.game.add.tilemap("map"); //camera this.jellyCamera = {cx:0,cy:0,focx:-1,focy:-1,mode:0,zoom:1,width:640,height:640,levelZoom:1,scale:0.8}; //player and flag this.player; this.flag; //objects this.statBody; this.scorePoint; this.failPoint; this.jellyObj; //Level win and fail this.win; this.restart; this.level_Fail = null; //score this.timeTrail; this.second; this.score; this.bonus; this.score_txt; this.spotLight; this.contact_count; this.truck_status; //Level Specific Objects this.enemy_truck; this.enemy_move; this.downArrows = []; this.lastWatchCall; }, create: function() { //score,bonus and win this.win = false; this.restart=false; this.second = 1000; this.score=0; this.bonus=0; this.timeTrail=0; this.contact_count=0; this.truck_status=0; this.enemy_move=false; //level data this.game.mobLevel = "Level 16"; this.game.levelNumber = "level16"; this.game.nextlevelNumber = "level17"; jt.current_level = 16; //init Game music and sound this.game.sound.stopAll(); if(jt.sfx) jt.sfx.playMusic("evenbg"); //setup sky background this.bg = new GameBg(this.game); //setup level scene this.scene = jt.setupScene(this.game,this.map,"scene_16",this.map.objects["Ground"][0].x-5,this.map.objects["Ground"][0].y-280,this.jellyCamera.width,this.jellyCamera.height,1000); this.jellyObj = jt.setupJellyObj(this.game,this.map,this.phyBody); this.game.world.setChildIndex(this.scene.art, 6); // setup static object this.statBody = jt.setupStaticObject(this.game,this.map,1000); //setup Score this.setupScore(); //setup Flag this.setupFlag(); //setup player this.player = jt.createTruck(this.game,this.scene.truck_x,this.scene.truck_y,this.scene.truck_type,this.phyBody); this.enemy_truck = this.createEnemy(this.game,567,663,this.phyBody); //setup Fail this.setupFail(); //setup game menu if(jt.game_menu !=null) jt.game_menu.killMenu(); jt.game_menu = new GameMenu(this.game); jt.game_menu.enable(); //setup keyboard jt.initInput(this.game); // if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)){ // jt.gameController(this.game); // } var transform = [{x:4725, y:750, r:0}, {x:4920, y:1428, r:90}, {x:1347,y:1381, r:0}, {x:1148, y:2092, r:-90}]; for(var i = 0; i < transform.length; i++){ this.downArrows[i] = this.game.add.sprite(transform[i].x, transform[i].y, "downArrow"); this.anim = this.downArrows[i].animations.add('down'); this.downArrows[i].animations.play('down', 30, true); this.downArrows[i].rotation = Phaser.Math.degToRad(transform[i].r); } this.levelEnds = [4949, 1150, 5110]; }, // Level Pause and Resume onGamePause:function() { }, onGameResume:function(){ }, //Level Update and Render updateCamera: function () { this._plx = this.player.truck.getSprite().x; this._ply = this.player.truck.getSprite().y; var offset = this.findCurrentLevel(this.enemy_truck)%2!=0?-200:70; this._vlc = Math.abs(this.player.truck.getBox().data.m_linearVelocity.x); this.jellyCamera = jt.updateCamera(this.game, this.jellyCamera, this._plx+offset, this._ply, this._vlc, this.win, this.restart, jt.pause); }, update: function(){ this.updateCamera(); if(jt.sfx) jt.sfx.loopMusic("evenbg"); if(!this.win && !this.restart && !jt.pause) { this.timeTrail++; if(this.timeTrail%10==0){ this.second--; } this.keyEvent(); this.truckSound(); this.enemyUpdate(); if(this.lastWatchCall + 1 < this.game.time.totalElapsedSeconds()){ this.lastWatchCall = this.game.time.totalElapsedSeconds(); } } else if(this.win) { if(this.flag.joint) this.game.physics.box2d.world.DestroyJoint(this.flag.joint); } else if(this.restart) { this.game.physics.box2d.world.DestroyJoint(this.player.joint1); this.game.physics.box2d.world.DestroyJoint(this.player.joint2); } if(this.restart && this.level_Fail && this.level_Fail.space.isDown) this.level_Fail.restartBtnClicked(); }, render:function(){ if(this.jellyObj) { for(var i=0;i10) { jt.sfx.stopSound("truck_idle"); jt.sfx.stopSound("truck_slow"); jt.sfx.playTruckSound("truck_speed"); } else { jt.sfx.stopSound("truck_speed"); if(jt.truck_move>30) jt.sfx.playTruckSound("truck_slow"); if(jt.truck_move==0) { jt.sfx.stopSound("truck_speed"); jt.sfx.stopSound("truck_slow"); jt.sfx.playTruckSound("truck_idle"); } } this._x1 = this.player.truck.getBody(0).x; this._y1 = this.player.truck.getBody(0).y; this._x2 = this.player.truck.getBody(6).x; this._y2 = this.player.truck.getBody(6).y; if((this._y2-this._y1)<-20 && !jt.pause && !this.restart && !this.win) if(jt.sfx) { jt.sfx.truck_speed.volume = 0.7; jt.sfx.playTruckSound("truck_wob"); } else jt.sfx.truck_speed.volume = 1; }, //Score and Bonus setupScore:function() { this.scorePoint = jt.setupScoreObject(this.game,this.map); for(var i=0;i 10){ this.enemy_truck.back.velocity.x /= 1.12; this.enemy_truck.front.velocity.x /= 1.12; } } var truckLevel = this.findCurrentLevel(this.player); var enemyLevel = this.findCurrentLevel(this.enemy_truck); var target = truckLevel == enemyLevel ? this.player.truck.getBox().x:this.levelEnds[enemyLevel-1]; if(this.enemy_truck.truck.getBox().x < target)// Level 1, or 3 { this.enemy_truck.jointback.SetMotorSpeed(speed); this.enemy_truck.jointback.SetMaxMotorTorque(360); this.enemy_truck.jointback.EnableMotor(true); this.enemy_truck.jointfront.SetMotorSpeed(speed); this.enemy_truck.jointfront.SetMaxMotorTorque(120); this.enemy_truck.jointfront.EnableMotor(true); } else // Level 2 { this.enemy_truck.jointback.SetMotorSpeed(-1*speed); this.enemy_truck.jointback.SetMaxMotorTorque(360); this.enemy_truck.jointback.EnableMotor(true); this.enemy_truck.jointfront.SetMotorSpeed(-1*speed); this.enemy_truck.jointfront.SetMaxMotorTorque(120); this.enemy_truck.jointfront.EnableMotor(true); } var angle = this.enemy_truck.truck.getBox().angle; if ((angle > 50 && angle < 180) || (angle < -50 && angle > -180)){ this.game.physics.box2d.getBody(this.enemy_truck.truck.getBox()).ApplyTorque(-180 * angle); } if(enemyLevel == 1 && this.enemy_truck.truck.getBox().x > 4950){ this.enemy_truck.back.velocity.x = 0; this.enemy_truck.front.velocity.x = 0; } else if(enemyLevel == 2 && this.enemy_truck.truck.getBox().x < 1200){ this.enemy_truck.back.velocity.x = 0; this.enemy_truck.front.velocity.x = 0; } } }, findCurrentLevel: function (obj) { var y = obj.truck.getBox().y; if (y < 1005) return 1; if (y < 1650) return 2; return 3; }, moveBy: function (x, y) { var pieces = this.enemy_truck.truck.getBodies(); for (var i = 0; i < pieces.length; i++) { pieces[i].getBody().x += x; pieces[i].getBody().y += y; } this.enemy_truck.front.x += x; this.enemy_truck.front.y += y; this.enemy_truck.back.x += x; this.enemy_truck.back.y += y; }, moveTo: function(x, y) { var dx = x - this.enemy_truck.truck.getBox().x; var dy = y - this.enemy_truck.truck.getBox().y; this.moveBy(dx, dy); }, };