Highlighted

How to make maze walls?

New Here ,
Jun 17, 2012

Copy link to clipboard

Copied

Hello,

First off I would like to clearify that i'm terrible at this and have no idea what im doing

Anyhow, i would like to make a maze game with accelerometer. I have managed to make a ball within a certain area with this code:

import flash.events.Event;

var accelX:Number;

var accelY:Number;

var fl_Accelerometer:Accelerometer = new Accelerometer();

fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);

function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void

{

          accelX = event.accelerationX;

          accelY = event.accelerationY;

}

ball.addEventListener(Event.ENTER_FRAME, moveBall);

function moveBall(evt:Event){

          ball.x -= accelX*30;

          ball.y += accelY*30;

 

          if(ball.x > (480-ball.width/2)){

                    ball.x = 480-ball.width/2;

          }

          if(ball.x < (0+ball.width/2)){

                    ball.x = 0+ball.width/2;

          }

          if(ball.y > (800-ball.width/2)){

             ball.y = 800-ball.width/2;

          }

          if(ball.y < (0+ball.width/2)){

                    ball.y = 0+ball.width/2;

          }

}

Now the problem is that i would like to make some walls within this maze, some restricted areas if i may, so it becomes an actually maze. Have tried and failed several times and have only managed to make a but not limit it. so it just cuts the screen in half etc.

TOPICS
ActionScript

Views

6.3K

Likes

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

How to make maze walls?

New Here ,
Jun 17, 2012

Copy link to clipboard

Copied

Hello,

First off I would like to clearify that i'm terrible at this and have no idea what im doing

Anyhow, i would like to make a maze game with accelerometer. I have managed to make a ball within a certain area with this code:

import flash.events.Event;

var accelX:Number;

var accelY:Number;

var fl_Accelerometer:Accelerometer = new Accelerometer();

fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);

function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void

{

          accelX = event.accelerationX;

          accelY = event.accelerationY;

}

ball.addEventListener(Event.ENTER_FRAME, moveBall);

function moveBall(evt:Event){

          ball.x -= accelX*30;

          ball.y += accelY*30;

 

          if(ball.x > (480-ball.width/2)){

                    ball.x = 480-ball.width/2;

          }

          if(ball.x < (0+ball.width/2)){

                    ball.x = 0+ball.width/2;

          }

          if(ball.y > (800-ball.width/2)){

             ball.y = 800-ball.width/2;

          }

          if(ball.y < (0+ball.width/2)){

                    ball.y = 0+ball.width/2;

          }

}

Now the problem is that i would like to make some walls within this maze, some restricted areas if i may, so it becomes an actually maze. Have tried and failed several times and have only managed to make a but not limit it. so it just cuts the screen in half etc.

TOPICS
ActionScript

Views

6.3K

Likes

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
Jun 17, 2012 0
Adobe Community Professional ,
Jun 17, 2012

Copy link to clipboard

Copied

if each wall is a rectangle, you can simplify your coding by creating a parent for the walls and adding rectangular movieclip walls to that parent. 

you could then loop through all the children of that parent checking a hitTestObject between your and the child walls.  if it's negative, store the ball x and y.  if positive, re-assign the ball x and y to the previously stored values.

Likes

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
Reply
Loading...
Jun 17, 2012 1
New Here ,
Jun 18, 2012

Copy link to clipboard

Copied

Tried to do as you said, but as i earlier declared. I'm terrible, so the follow-up question is: What's a parent and children etc? Il understand if you wont be bothered to help me, as it may seem useless


ty for the reply though

edit:
Would something like this be useful?

if(ball.hitTestObject(wall)){

                    ball.y = 50

As the ball is my moving character (movieclip) and the "wall" is also a movieclip but not moving ofc?

Likes

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
Reply
Loading...
Jun 18, 2012 0
Adobe Community Professional ,
Jun 18, 2012

Copy link to clipboard

Copied

create your maze.  convert each rectangle in the maze to a movieclip and assign an instance name (eg, m1,m2,...,m44).  don't convert any L-shaped, U-shaped or rotated L-shaped, U-shaped etc sections.  only rectangular blocks.

you can then use:

var prevX:int;

var prevY:int;

var i:int;

var mP:Sprite=new Sprite();

addChild(mP);

for(i=1;i<=44,i++){

mP.addChild(this["m"+i]);

}

function moveBall(evt:Event){

          ball.x -= accelX*30;

          ball.y += accelY*30;

 

          if(ball.x > (480-ball.width/2)){

                    ball.x = 480-ball.width/2;

          }

          if(ball.x < (0+ball.width/2)){

                    ball.x = 0+ball.width/2;

          }

          if(ball.y > (800-ball.width/2)){

             ball.y = 800-ball.width/2;

          }

          if(ball.y < (0+ball.width/2)){

                    ball.y = 0+ball.width/2;

          }

checkWallF();

}

function checkWallF():void{

for(i=0;i<mP.numChildren;i++){

if(ball.hitTestObject(mP.getChildAt(i))){

ball.x=prevX;

ball.y=prevY;

break;

}

prevX=ball.x;

prevY=ball.y

}

}

}

Likes

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
Reply
Loading...
Jun 18, 2012 0
New Here ,
Jun 19, 2012

Copy link to clipboard

Copied

Im very sorry mr kglad. But it seems like I have fallen of the waggon once again.I started all over, creating the walls within an own layer and converterted each one rectangular wall to a movieclip naming them m1 to m24.

But the actionscrip seems to get bugged as i try to publish. Or i get some error messages
Don't know if you ment me to use simply the last one you posted or combine them somehow.

Anyhow if I use the last one I get these errors:

Scene 1, Layer 'action', Frame 1, Line 71084: Syntax error: expecting semicolon before rightparen.
Scene 1, Layer 'action', Frame 1, Line 81084: Syntax error: expecting colon before dot.
Scene 1, Layer 'action', Frame 1, Line 91084: Syntax error: expecting identifier before rightbrace.
Scene 1, Layer 'action', Frame 1, Line 111084: Syntax error: expecting rightparen before function.

and if i try to fix them several other errors joins the party.

is it ment for me to swap something out from the code, amount of walls, wall names etc?
Again really, thanks for all the support. Wish I knew this a bit better, I am going to take some courses next year at school. Maybe i'll get it then.

Likes

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
Reply
Loading...
Jun 19, 2012 0
Adobe Community Professional ,
Jun 19, 2012

Copy link to clipboard

Copied

this line:

for(i=1;i<=44,i++){

should b:

for(i=1;i<=44;i++){

Likes

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
Reply
Loading...
Jun 19, 2012 0
New Here ,
Jun 21, 2012

Copy link to clipboard

Copied

Hmm yes,

Am I wrong or is there one to many}?

Either way I'm left with tons of errors. I think I'll put this project on ice for now.

One last thing, do you know of any tutorials or online classes, preferably free?

Thanks for your attempt though.

Likes

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
Reply
Loading...
Jun 21, 2012 0
Adobe Community Professional ,
Jun 21, 2012

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Jun 21, 2012 0
New Here ,
Jun 28, 2012

Copy link to clipboard

Copied

hmm alright, I must have screwed up somewhere. Anyhow il check up on it as i get home, my summerhouse dont have internett -.- bummer
thanks for your help though

Likes

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
Reply
Loading...
Jun 28, 2012 0
Adobe Community Professional ,
Jun 28, 2012

Copy link to clipboard

Copied

you're welcome.

Likes

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
Reply
Loading...
Jun 28, 2012 0
Explorer ,
Jun 30, 2012

Copy link to clipboard

Copied

Hi again, Kglad. I've downloaded this flash file with code for the maze (i too am keen to make a maze), but when i test the movie, the ball fails to move.

Am i missing something?

Likes

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
Reply
Loading...
Jun 30, 2012 0
Adobe Community Professional ,
Jun 30, 2012

Copy link to clipboard

Copied

are you testing on an iDevice?

Likes

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
Reply
Loading...
Jun 30, 2012 0
Explorer ,
Jul 01, 2012

Copy link to clipboard

Copied

not at all, am testing on a big pc. And, BTW, when i test the Flash file, an xml file is created. Is that supposed to happen?

Likes

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
Reply
Loading...
Jul 01, 2012 0
Adobe Community Professional ,
Jul 01, 2012

Copy link to clipboard

Copied

check the publish settings.  you're publishing for iOS, that's why flash is creating the xml.

also, that code uses the accelerometer to move the ball.

you need to change both to test ball movement in that file.

Likes

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
Reply
Loading...
Jul 01, 2012 0
Explorer ,
Jul 05, 2012

Copy link to clipboard

Copied

Hi. U are right, of course. I got that code and flash file from the above link, and it is set up for mobile devices. As i understand, Accelometer is for mobile devices, and while i changed the publish settings to use Flash as the Player (instead of Air for ios which was how the file was set up), i am wondering if it is possible to use this code as such, on a big PC, not mobile device.

And, i dont know how to change the accelemeter in hte publish settings....

thank you.

Likes

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
Reply
Loading...
Jul 05, 2012 0
Adobe Community Professional ,
Jul 05, 2012

Copy link to clipboard

Copied

yes, but instead of using the accelerometer, use something else (like a keyboardevent listener) to move the ball.

Likes

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
Reply
Loading...
Jul 05, 2012 0
New Here ,
Jul 06, 2012

Copy link to clipboard

Copied

Hey i got around to test your application now. It was set on android for Ios, but i simply swapped this in settings to air for android. Since that's what im working on , but when i tested the app only one wall appear to be working, the very left one, m1. I find this rather odd since i see no difference on any of the rectangels. Did you test your app, was it fully functioning?

Likes

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
Reply
Loading...
Jul 06, 2012 0
New Here ,
Nov 28, 2012

Copy link to clipboard

Copied

Hi Kglad

I have downloaded http://www.kglad.com/Files/forums/maze.fla

I'm having the same problem as Tixy where just one wall of the left of the maze.fla file has collision, the ball MC just passes through the other walls in the project, is there something I need to change with the checkwall function?

Rgeards

Sam

Likes

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
Reply
Loading...
Nov 28, 2012 0
New Here ,
Jan 09, 2020

Copy link to clipboard

Copied

why cant be downloaded

 

Likes

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
Reply
Loading...
Jan 09, 2020 0