Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Walls in flash

New Here ,
Jan 14, 2013 Jan 14, 2013

how do you make walls in flash for pacman?

why doesnt the code work?

var walls:Array = [walls1_mc];

for (var i:uint= 0; i<walls.length; i++)

{

          trace("wall x " + walls.x +" y " +walls.y);

}

function myResponse(evt:KeyboardEvent):void

{

          var i:uint = 0;

          if (evt.keyCode == Keyboard.RIGHT)

          {

                    for (i= 0; i<walls.length; i++)

                    {

                              if (walls.hitTestPoint(pacman_mc.x+24,pacman_mc.y))

                              {

                                        trace("OH!");

                              }

                    }

                    pacman_mc.x +=  5;

                    if (pacman_mc.x >= 550)

                    {

                              pacman_mc.x = 0;

                    }

          }

}

TOPICS
ActionScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 15, 2013 Jan 15, 2013

then your next problem is your logic is faulty.  each of those for-loops should be changed from:

       for (i= 0; i<walls.length; i++)

                              {

                                        if (walls.hitTestPoint(pacman_mc.x + 40,pacman_mc.y))

                                        {

                                                  return;

                                        }

                                        pacman_mc.x +=  5;

                              }

to:

       for

...
Translate
Community Expert ,
Jan 14, 2013 Jan 14, 2013

there's nothing calling myResponse().   you should also have something like:

stage.addEventListener(KeyboardEvent,myResponse);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 15, 2013 Jan 15, 2013

sorry this is my full code

var walls:Array = [walls1_mc];

for (var i:uint= 0; i<walls.length; i++)

{

          trace("wall x " + walls.x +" y " +walls.y);

}

stage.addEventListener(KeyboardEvent.KEY_DOWN,pacMove);

function pacMove(evt:KeyboardEvent):void

{

          var i:uint = 0;

          switch (evt.keyCode)

          {

                    case Keyboard.RIGHT :

                              pacman_mc.rotation = 0;

                              for (i= 0; i<walls.length; i++)

                              {

                                        if (walls.hitTestPoint(pacman_mc.x + 40,pacman_mc.y))

                                        {

                                                  return;

                                        }

                                        pacman_mc.x +=  5;

                              }

                              break;

                    case Keyboard.LEFT :

                              pacman_mc.rotation = 180;

                              for (i= 0; i<walls.length; i++)

                              {

                                        if (walls.hitTestPoint(pacman_mc.x - 40,pacman_mc.y))

                                        {

                                                  return;

                                        }

                                        pacman_mc.x -=  5;

                              }

                              break;

                    case Keyboard.UP :

                              pacman_mc.rotation = -90;

                              for (i= 0; i<walls.length; i++)

                              {

                                        if (walls.hitTestPoint(pacman_mc.x,pacman_mc.y - 4))

                                        {

                                                  return;

                                        }

                                        pacman_mc.y -=  5;

                              }

                              break;

                    case Keyboard.DOWN :

                              pacman_mc.rotation = 90;

                              for (i= 0; i<walls.length; i++)

                              {

                                        if (walls.hitTestPoint(pacman_mc.x,pacman_mc.y + 5))

                                        {

                                                  return;

                                        }

                                        pacman_mc.y +=  5;

                              }

                              break;

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 15, 2013 Jan 15, 2013

Enable debugging in Flash (Publishing Options/Extended/Allow Debugging). What does the Output window say?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2013 Jan 15, 2013

then your next problem is your logic is faulty.  each of those for-loops should be changed from:

       for (i= 0; i<walls.length; i++)

                              {

                                        if (walls.hitTestPoint(pacman_mc.x + 40,pacman_mc.y))

                                        {

                                                  return;

                                        }

                                        pacman_mc.x +=  5;

                              }

to:

       for (i= 0; i<walls.length; i++)

                              {

                                        if (walls.hitTestPoint(pacman_mc.x + 40,pacman_mc.y))

                                        {

                                                  return;

                                        }

}

                                        pacman_mc.x +=  5;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 20, 2013 Jan 20, 2013

thats what i have

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2013 Jan 20, 2013

no, you don't and that's why your code won't work for more than one wall unless you change to the code i suggested.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 20, 2013 Jan 20, 2013

ok i see

solved the problem

thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2013 Jan 20, 2013

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 15, 2013 Jan 15, 2013

Code works fine for me. So you probably named the instances on your stage not correct.

Is there a Wall-MovieClip with name "walls1_mc" on your stage?

Is there a pacman-Movieclip with name "pacman_mc" on your stage?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 20, 2013 Jan 20, 2013

i have them and now it works

now my question is how i can make more than just the one wall?

thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 20, 2013 Jan 20, 2013

Depending on what you intend to achieve (learing Actionscript or gettig a running game)

It could be a first start to look at a pac-man game thats done in as3 and works, and analyze the code.

Here is one.

If you instead want to learn AS3 from the Basics, a Pac-Man game is not the right place to start imo.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 09, 2020 Jan 09, 2020
LATEST

this is my code. why poop go through the walls?

 

import flash.events.KeyboardEvent;

stop();


wall.enabled=false;

var upPressed:Boolean = false;

var downPressed:Boolean = false;

var leftPressed:Boolean = false;

var rightPressed:Boolean = false;

poop.addEventListener(Event.ENTER_FRAME, fl_ClickToGoToWebPage);

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_3);

stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_3);

//stage.addEventListener(Event.ENTER_FRAME, everyFrame);

function fl_ClickToGoToWebPage(event:Event)

{

if (upPressed)

{

poop.y -= 5;

}

if (downPressed)

{

poop.y += 5;

}

if (leftPressed)

{

poop.x -= 5;

}

if (rightPressed)

{

poop.x += 5;

}

}

function fl_SetKeyPressed_3(event:KeyboardEvent):void

{

switch (event.keyCode)

{

case Keyboard.UP:

{

upPressed = true;

break;

}

case Keyboard.DOWN:

{

downPressed = true;

break;

}

case Keyboard.LEFT:

{

leftPressed = true;

break;

}

case Keyboard.RIGHT:

{

rightPressed = true;

break;

}

}

}

function fl_UnsetKeyPressed_3(event:KeyboardEvent):void

{

switch (event.keyCode)

{

case Keyboard.UP:

{

upPressed = false;

break;

}

case Keyboard.DOWN:

{

downPressed = false;

break;

}

case Keyboard.LEFT:

{

leftPressed = false;

break;

}

case Keyboard.RIGHT:

{

rightPressed = false;

break;

}

}

}

function everyFrame(event:Event):void {

var mazehit:Boolean = false;

if (upPressed) {

//for(var i:int = 0; i < speed; i++) {

if(poop.hitTestObject(wall)) {

poop.x += 5;

mazehit = true;

//break;

}

}

if (downPressed) {

//for(var i:int = 0; i < speed; i++) {

if(poop.hitTestObject(wall)) {

poop.x += 5;

mazehit = true;

//break;

}

}

if (leftPressed) {

//for(var i:int = 0; i < speed; i++) {

if(poop.hitTestObject(wall)) {

poop.x += 5;

mazehit = true;

//break;

}

}

if (rightPressed) {

//for(var i:int = 0; i < speed; i++) {

if(poop.hitTestObject(wall)) {

poop.x += 5;

mazehit = true;

//break;

}

}

}

 

 

 

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines