mercredi 22 mars 2017

Platform game. Jump to next level in next frame

I create a platform game with 20 levels for android devices. Every level has different walking platforms and new enemies with differents properties. I have the first frame with 20 buttons , The first button go to first level(frame 2) the second button go to second level(frame 3) and goes on until the final level in frame 21. I write all of my code in frame 2(level 1) player movement , enemies properties , coins , life etc. When the player die or the player complete the stage i go to frame 1 and im ready to click to level 2 button , go to second stage in frame 3. So , what part of my code i must transfer to second level ?

Here is part of my code in second frame. (i show only one enemy(medouza) and the controls that i move the player because is a large code)

 stop();
    l_btn.addEventListener(TouchEvent.TOUCH_BEGIN,lbtisdown);
    l_btn.addEventListener(TouchEvent.TOUCH_END,lbtisup);
    r_btn.addEventListener(TouchEvent.TOUCH_BEGIN,rbtisdown);
    r_btn.addEventListener(TouchEvent.TOUCH_END,rbtisup);
    j_btn.addEventListener(TouchEvent.TOUCH_BEGIN,jbtisdown);
    k_btn.addEventListener(TouchEvent.TOUCH_BEGIN,kbtisdown);
    stop_btns.addEventListener(TouchEvent.TOUCH_END,allup);
    stop1_btn.addEventListener(TouchEvent.TOUCH_END,jkup);
    fire_btn.addEventListener(TouchEvent.TOUCH_BEGIN,fbtisdown);
function lbtisdown(e:TouchEvent)
{
  ldown = true;
}
function lbtisup(e:TouchEvent)
{
  ldown = false;
}
function rbtisdown(e:TouchEvent)
{
  rdown = true;
}
function rbtisup(e:TouchEvent)
{
  rdown = false;
}
function kbtisdown(e:TouchEvent)
{
  kdown = true;
}
function jbtisdown(e:TouchEvent)
{
  if (! jdown && onground && ! dizbl)
  {
  runJump();
  }
  jdown = true;
}
function fbtisdown(e:TouchEvent)
{
  fdown = true;
}
var movers = new Array(bg.ground.platkat0,bg.ground.plator0,bg.ground.platkat1,bg.ground.plator1,bg.ground .plator2,bg.ground.plator3);
var movedirs = new Array(0,1,0,1,1,1);
var movelimits = new Array([-57.5,60],[1853,2021],[-57.5,243],[1935,2072],[2548,2877],[2982,3073]);
var medouzaArr = new Array();
function addMedouza(med)
{
  medouzaArr.push(med);
  med.medouza.gotoAndStop(1);
  med.xvel = 0;
  med.yvel = 0;
  med.hitpoints = 20;
  med.startAttack = 0;
  med.fireAttack = 3;
  med.sp = Math.random() * .7 + .7;
  med.dir = Math.floor(Math.random() * 2);
  med.locksp = med.sp;
}
this.addEventListener(Event.ENTER_FRAME,FramesEvents);
function FramesEvents(e:Event)
{
  completeStage();
  moveplatforms();
  moveMedouza();
  phys();
  controls();
  windowcamera();
}
function moveMedouza()
{
  for (var k1=0; k1<medouzaArr.length; k1++)
  {
  var m = medouzaArr[k1];
  m.x +=  m.xvel;
  m.xvel *=  .3;
  m.y +=  m.yvel;
  m.yvel +=  GRA;
  if (m.x > savvito.x)
  {
  m.scaleX = -1;
  }
  if (m.x < savvito.x)
  {
  m.scaleX = 1;
  }
  if (m.startAttack > 4)
  {
  m.fireAttack = 1 + Math.floor(Math.random() * 2);
  m.startAttack = 0;
  }
  if (m.fireAttack == 0)
  {
  m.medouza.gotoAndStop(1);
  }
  if (m.fireAttack == 1)
  {
  m.medouza.gotoAndStop(2);
  }
  if (m.fireAttack == 2)
  {
  m.medouza.gotoAndStop(3);
  }
  if (m.medouza.currentFrame == 1 && m.medouza.medouza_iddle.currentFrame == m.medouza.medouza_iddle.totalFrames)
  {
  m.startAttack +=  1;
  }
  if (m.medouza.currentFrame == 2 && m.medouza.medouza_jump.currentFrame == m.medouza.medouza_jump.totalFrames)
  {
  m.fireAttack = 0;
  var e = bg.addChild(new enemy1());
  e.x = m.x;
  e.y = m.y;
  }
  if (m.medouza.currentFrame == 3 && m.medouza.medouza_attack.currentFrame == m.medouza.medouza_attack.totalFrames)
  {
  m.fireAttack = 0;
  }
  if (m.medouza.currentFrame == 3 && m.medouza.medouza_attack.currentFrame == 12)
  {
  var s = bg.addChild(new parentsmos());
  smoshArr.push(s);
  s.x = m.x;
  s.y = m.y;
  if (m.scaleX == 1)
  {
  s.scaleX = 1;
  }
  if (m.scaleX == -1)
  {
  s.scaleX = -1;
  }
  }
  if (savvito.hitTestObject(m.med_hit) && ! savvito.hit && ! die)
  {
  herohitpoints++;
  savvito.hit = true;
  savvito.hitcv = 0;
  if (savvito.x < m.x)
  {
  xvel = -8;
  }
  else
  {
  xvel = +8;
  }
  yvel = -6;
  }
  if (savvito.hero.currentFrame == 4 && savvito.hero.attack.hitTestObject(m.med_box) && savvito.hero.attack.currentFrame == 6)
  {
  m.hitpoints -=  15 + KnifeDamage;
  enemieslifebar.enemiesgreenlife.gotoAndStop(m.hitpoints);
  if (m.scaleX == 1)
  {
  m.x = 700;
  }
  if (m.scaleX == -1)
  {
  m.x = 100;
  }
  }
  upPushMedouza(m);
  if (m.hitpoints <= 0)
  {
  addBonusCoins();
  bg.stageClear.x = m.x;
  bg.stageClear.y = m.y + 7;
  medouzaArr.splice(k1,1);
  bg.removeChild(m);
  return;
  }
  }
}
function completeStage()
{
  if (savvito.hitTestObject(bg.stageClear)&&numKey >= 5)
  {
  j_btn.removeEventListener(TouchEvent.TOUCH_BEGIN,jbtisdown);
  stageDone.gotoAndStop(2);
  kdown = false;
  ldown = false;
  rdown = false;
  jdown = false;
  dizbl = false;
  for (var rk1=0; rk1<medouzaArr.length; rk1++)
  {
  var rm = medouzaArr[rk1];
  medouzaArr.splice(rk1,1);
  bg.removeChild(rm);
  return;
  }
  if (medouzaArr.length == 0)
  {
  goto2();
  }
  fl_CountDownTimerInstance.removeEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler);
  fl_CountDownTimerInstance.stop();
  fl_Countstart.removeEventListener(TimerEvent.TIMER, fl_CountDownstart);
  }
}
function goto2()
{
  medouzaArr.length = 0;
  movers.length = 0;
  movedirs.length = 0;
  movelimits.length = 0;
  fl_TimerInstancew.start();
  if (fl_SecondsElapsedw > 5 && herohitpoints <= 29)
  {
  channel1.stop();
  this.addEventListener(Event.ENTER_FRAME,empty1);
  fl_TimerInstancew.removeEventListener(TimerEvent.TIMER, fl_TimerHandlerw);
  fl_TimerInstancew.stop();
  }
  if (fl_SecondsElapsedw == 3 && herohitpoints < 29)
  {
  savecoins.data.banksavecoins = coinscount + buycoins;
  savecoins.flush();
  }
}
function empty1(e:Event)
{
  this.removeEventListener(Event.ENTER_FRAME,FramesEvents);
  gotoAndStop(2);
}

Aucun commentaire:

Enregistrer un commentaire