17 Replies Latest reply: Nov 28, 2012 9:46 AM by B_Sam RSS

    How to make maze walls?

    Tixzy

      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.

        • 1. Re: How to make maze walls?
          kglad MVP

          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.

          • 2. Re: How to make maze walls?
            Tixzy Community Member

            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?

            • 3. Re: How to make maze walls?
              kglad MVP

              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

              }

              }

              }

              • 4. Re: How to make maze walls?
                Tixzy Community Member

                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.

                • 5. Re: How to make maze walls?
                  kglad MVP

                  this line:

                   

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

                   

                  should b:

                   

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

                  • 6. Re: How to make maze walls?
                    Tixzy Community Member

                    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.

                    • 8. Re: How to make maze walls?
                      Tixzy Community Member

                      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

                      • 9. Re: How to make maze walls?
                        kglad MVP

                        you're welcome.

                        • 10. Re: How to make maze walls?
                          screeen Community Member

                          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?

                          • 11. Re: How to make maze walls?
                            kglad MVP

                            are you testing on an iDevice?

                            • 12. Re: How to make maze walls?
                              screeen Community Member

                              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?

                              • 13. Re: How to make maze walls?
                                kglad MVP

                                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.

                                • 14. Re: How to make maze walls?
                                  screeen Community Member

                                  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.

                                  • 15. Re: How to make maze walls?
                                    kglad MVP

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

                                    • 16. Re: How to make maze walls?
                                      Tixzy Community Member

                                      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?

                                      • 17. Re: How to make maze walls?
                                        B_Sam

                                        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