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

Walls in flash

New Here ,
Jan 14, 2013 Jan 14, 2013

Copy link to clipboard

Copied

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

Views

2.2K

Translate

Translate

Report

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

...

Votes

Translate

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

Copy link to clipboard

Copied

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

stage.addEventListener(KeyboardEvent,myResponse);

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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;

          }

}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

thats what i have

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

ok i see

solved the problem

thanks

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

you're welcome.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

i have them and now it works

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

thanks

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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;

}

}

}

 

 

 

 

 

 

 

Votes

Translate

Translate

Report

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