A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Breakout - A little starting trouble

  1. #1
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167

    Breakout - A little starting trouble

    Hey everyone

    Im in the game making part of Flash as it is a great way to learn alot of different methods of doing things as well as learning new Actionscript , and also because you have something impressive to show once your done


    Well a little while ago I came across a tutorial here on Flashkit that showed me how to make the basic engine for the Classic Breakout game, though the author of the tutorial's english wasnt all that great, I was still able to piece it together


    Now Im running into a problem (I have attached the .fla)


    1) I have three walls which are each a seperate movieclip (left, top, right) and each has the code in it that checks for a hittest with the ball

    2) I have a unseen Movieclip (the black ball on the outside left of the stage) that controls the direction of the ball
    Basically in this movieclip 'moving', there are four different frames each with its own movieclip

    3) Each of these 4 seperate movieclips contains the code
    tellTarget (_root._root.ball) {
    _x -= 10;
    _y -= 10;
    }
    Except the + and - are arranged differently depending on which direction the ball will be moving


    To help you I will tell you which frame inside the movieclip 'moving' moves the ball in which direction

    Frame 1 = Up-Left
    Frame 2 = Down-Left
    Frame 3 = Up-Right
    Frame 4 = Down-Right



    Now I tried going about this by having a variable 'direction' inside the 'moving' movieclip that begins at one since the ball starts in the Up-Left moving direction

    Everytime it hits the wall or the paddle, it checks to see what value this direction variable can be (1,2,3 or 4). Depending on which it is, it'll go to the different frames in the moving movieclip


    When I run the program it works (try) except for when it goes Down-Right and hits the right wall, for some reason it will just go right through it


    Anyways, sorry for the length thread and hopefully it will make sense. If not, perhaps you can make sense of my .fla

    Thanks everyone, hopefully you can help
    Last edited by Osteel; 05-01-2009 at 02:39 AM.

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    the code in your LEFT wall is:
    Code:
    	if (this.hitTest(_root.ball)) {
    		if (_root.moving.direction == 1) {
    			_root.moving.gotoAndPlay(3);
    			_root.moving.direction = 3;
    		}
    	} else if (_root.moving.direction == 2) {
    		_root.moving.gotoAndPlay(4);
    		_root.moving.direction = 4;
    	}
    while it should be:
    Code:
    	if (this.hitTest(_root.ball)) {
    		if (_root.moving.direction == 1) {
    			_root.moving.gotoAndPlay(3);
    			_root.moving.direction = 3;
    		} else if (_root.moving.direction == 2) {
    			_root.moving.gotoAndPlay(4);
    			_root.moving.direction = 4;
    		}
    	}
    Basically else statement has been written for wrong if statement so whenever direction was changed to 2 this code changed it straight back to 4.

    If I may say so, this is not good way to go with breakout game. Not only is the code spread all over the place, but it does not allow you to change the movement at all to any other angle then 45 degrees.

  3. #3
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Haha *embarrased*

    Thanks tony, I also though about the whole angle thing and I dont know how I would go about changing it

    The way it is now wont really work in the end since it will ALWAYS do the same thing no matter how hard you try, where as with angles it would be whole different story

    Anyways, thanks again ... I guess that tutorial I found really wasnt a good one haha

  4. #4

  5. #5
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Hey

    mbenney, thanks so much for the link, Ive checked it out and it appears to be exactly what I want

    I suppose the best way to learn is to reverse engineering something your attempting to make, so you know how to go about doing it next time around

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center