# How to make maze walls?

Jun 17, 2012 Jun 17, 2012

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();

function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void

{

accelX = event.accelerationX;

accelY = event.accelerationY;

}

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.4K

Likes

Report

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

Adobe Community Professional , Jun 21, 2012 Jun 21, 2012

Likes

18 Replies 18
Jun 17, 2012 Jun 17, 2012

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

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 18, 2012 Jun 18, 2012

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

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

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 18, 2012 Jun 18, 2012

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();

for(i=1;i<=44,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

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 19, 2012 Jun 19, 2012

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 7 1084: Syntax error: expecting semicolon before rightparen. Scene 1, Layer 'action', Frame 1, Line 8 1084: Syntax error: expecting colon before dot. Scene 1, Layer 'action', Frame 1, Line 9 1084: Syntax error: expecting identifier before rightbrace. Scene 1, Layer 'action', Frame 1, Line 11 1084: 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

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 19, 2012 Jun 19, 2012

Copied

this line:

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

should b:

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

Likes

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 21, 2012 Jun 21, 2012

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?

Likes

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 21, 2012 Jun 21, 2012

Copied

Likes

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 28, 2012 Jun 28, 2012

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

Likes

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 28, 2012 Jun 28, 2012

Copied

you're welcome.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jun 30, 2012 Jun 30, 2012

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

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 30, 2012 Jun 30, 2012

Copied

are you testing on an iDevice?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jul 01, 2012 Jul 01, 2012

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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 01, 2012 Jul 01, 2012

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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jul 05, 2012 Jul 05, 2012

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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 05, 2012 Jul 05, 2012

Copied

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 06, 2012 Jul 06, 2012

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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 28, 2012 Nov 28, 2012

Copied

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

Report

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

Copied

LATEST