Skip to main content
purowag
Participating Frequently
April 13, 2017
Answered

How can I fix my walls in my maze game in Adobe Animate? Please help meee ;A;

  • April 13, 2017
  • 1 reply
  • 1070 views

This is the code that I've used. My issue is that, the character will stop in the near center of the screen without moving to the right, before touching the wall. the left and upper walls are fine, however. I need the character to have free movement other then wall colision. This is my final project for class and I'm ahead of scheduale because i want to laze around later.

My character is "mc_glo"

The wall is called "mc_wall1"

the collectables are "mc_scout1" and "mc_zombie1"

stage.addEventListener(KeyboardEvent.KEY_DOWN, checkkeysdown);

stage.addEventListener(KeyboardEvent.KEY_UP, checkkeysup);

var moveup:Boolean=false;

var movedown:Boolean=false;

var moveleft:Boolean=false;

var moveright:Boolean=false;

var speed:Number=10;

function checkkeysdown (mykey:KeyboardEvent) {

  if (mykey.keyCode==Keyboard.UP) {

  moveup=true;

  }

  if (mykey.keyCode==Keyboard.DOWN) {

  movedown=true;

  }

  if (mykey.keyCode==Keyboard.LEFT) {

  moveleft=true;

  }

  if (mykey.keyCode==Keyboard.RIGHT) {

  moveright=true;

  }

}

function checkkeysup(mykey:KeyboardEvent) {

  if (mykey.keyCode==Keyboard.UP) {

  moveup=false;

  }

  if (mykey.keyCode==Keyboard.DOWN) {

  movedown=false;

  }

  if (mykey.keyCode==Keyboard.LEFT) {

  moveleft=false;

  }

  if (mykey.keyCode==Keyboard.RIGHT) {

  moveright=false;

  }

}

stage.addEventListener(Event.ENTER_FRAME, gameloop);

function gameloop(evt:Event) {

  if (moveup==true) {

  if (!mc_wall1.hitTestPoint(mc_glo.x,mc_glo.y-10,true)) {

  mc_glo.y-=speed;

  }

  }

  if (movedown==true) {

  if (!mc_wall1.hitTestPoint(mc_glo.x,mc_glo.y+10,true)) {

  mc_glo.y+=speed;

  }

  }

  if (moveleft==true) {

  if (!mc_wall1.hitTestPoint(mc_glo.x,mc_glo.x-10,true)) {

  mc_glo.x-=speed;

  }

  }

  if (moveright==true) {

  if (!mc_wall1.hitTestPoint(mc_glo.x,mc_glo.x+10,true)) {

  mc_glo.x+=speed;

  }

  }

  pickUp();

}

function pickUp(){

  if (mc_glo.hitTestObject(mc_scout1)){

  mc_scout1.x=1000;

  }

  if (mc_glo.hitTestObject(mc_zombie1)){

  mc_zombie1.x=1000;

  }

}

[Moved from non-technical Lounge Forum to specific Program forum... Mod]

[Here is the list of all Adobe forums... https://forums.adobe.com/welcome]

    This topic has been closed for replies.
    Correct answer kglad

    you have typos in

      if (moveleft==true) {

      if (!mc_wall1.hitTestPoint(mc_glo.x,mc_glo.x-10,true)) {

      mc_glo.x-=speed;

      }

      }

      if (moveright==true) {

      if (!mc_wall1.hitTestPoint(mc_glo.x,mc_glo.x+10,true)) {

      mc_glo.x+=speed;

      }

      }

    that looks like it should be

      if (moveleft==true) {

      if (!mc_wall1.hitTestPoint(mc_glo.x-10,mc_glo.y,true)) {

      mc_glo.x-=speed;

      }

      }

      if (moveright==true) {

      if (!mc_wall1.hitTestPoint(mc_glo.x+10,mc_glo.y,true)) {

      mc_glo.x+=speed;

      }

      }

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    April 13, 2017

    you have typos in

      if (moveleft==true) {

      if (!mc_wall1.hitTestPoint(mc_glo.x,mc_glo.x-10,true)) {

      mc_glo.x-=speed;

      }

      }

      if (moveright==true) {

      if (!mc_wall1.hitTestPoint(mc_glo.x,mc_glo.x+10,true)) {

      mc_glo.x+=speed;

      }

      }

    that looks like it should be

      if (moveleft==true) {

      if (!mc_wall1.hitTestPoint(mc_glo.x-10,mc_glo.y,true)) {

      mc_glo.x-=speed;

      }

      }

      if (moveright==true) {

      if (!mc_wall1.hitTestPoint(mc_glo.x+10,mc_glo.y,true)) {

      mc_glo.x+=speed;

      }

      }

    purowag
    purowagAuthor
    Participating Frequently
    April 13, 2017

    YOU ARE A GOD-SENT!!

    THANK YOU! <3 <3 <3

    kglad
    Community Expert
    Community Expert
    April 13, 2017

    you're welcome.