From zero to Bombuzal – step 2

It’s time to create the field of the first level.

Creating the level

Merging the ideas of Andre Marianiello and Chris, I was able to create the 2d level in this way:

and this is the result:

Aligning the level to the stage

“Everything” is working, but I don’t want the level to start at the upper left corner… I want the level to be centered in the stage.

So I have to calculate level’s height and width and move the movieclip in the center of the stage.

Now the level is aligned to the stage

Panning the level

I think advanced levels will be greater than this 4×4 array, so I have to allow the player to pan the level with mouse. I want the level to pan when the mouse gets closer to stage edges.

And this is the first error… panning in this way means your level will pan even when your mouse is outside the stage. Probably you will need to reload the page to see the level in this movieclip

Also, I don’t want the movieclip to leave the stage if it entirely fits in it.

That’s where you can help me and have your name in the credits: make the level pan only when the mouse is inside the stage and don’t let the level leave the stage if it entirely fits in it.

I would like you all to read AS3 Bombuzal tile test post in the forum by LivesInABox where you can find a very good AS3 script to generate both 2D and isometric levels.

It would be interesting to create Bombuzal both in AS2 and in AS3.

The winner of this post is LivesInABox for his wonderful AS3 work.

I remember that winners will have their names in the credits of this remake, and should the game be sponsored (but I think it will be quite hard because it’s an open source game) I will share the income with winners.

Download the source code and fix that scrolling!

  • Thanks alot man…oh and FIRST POST

  • Hi,
    i can’t see any content in your movieclips :-/

  • Emanuele Feronato

    Thank you mariusz… fixed

  • Looks great so far – thx for sharing your knowledge ;-)

  • use something like :

    if the mouse_x is between 0 and 550 and the mouse_y is between 0 and 400 only then pan the screen.

  • Emanuele Feronato

    this won’t work… when the mouse leaves the stage, if its last position was (499,123), _xmouse and _ymouse will keep their values and the screen will continue panning

  • i beleave there was a way to check wether the game had “keyboard control”. so you could only pan it when the game has that control…

  • or else, keep the panning, but only pan it as long as one of the tiles is inside the screen. so if all the tiles have an _x then 550 then it stops panning.

  • an _x bigger then *

  • I don’t think I need to send you a new .fla, just replace the code with what I’ve done. I put it up here:

    http://souled.newgrounds.com/news/post/85482

    I’ve fixed the panning and the other problem, however it does now have a button across the entire stage, so it would look better with a custom mouse. :/

  • Oh, and here’s an example:

    http://www.ngup.net/view?file=668

    Hope that’s what you need! :)

  • cool souled how did you do it ?

  • gas

    Using “tollerance”?

    [code]

    // panning level
    level.onEnterFrame = function() {
    tolerance = 10;
    dontmove = false;
    if ((_root._xmouse>Stage.width-tolerance) or (_root._ymouse>Stage.height-tolerance) or (_root._xmouse<tolerance) or (_root._ymouse<tolerance)) {
    dontmove = true;
    }
    if (!dontmove) {
    // pan right
    if (_root._xmouseStage.width-pan_dist) {
    level._x -= pan_speed;
    }
    // pan down
    if (_root._ymouseStage.height-pan_dist) {
    level._y -= pan_speed;
    }
    }
    };

    [/code]

    I think it’s better than having an overall button that can cause problem with other buttons… ;) :)

  • Logic. :)

  • Rick

    would it be easier to name the tile and bomb movies with x and y in the movie’s name ex: “tile_”+y+”_”+x, and “bomb_”+y+”_”+x, instead of using “tile”+level.getNextHighestDepth(), ?

    (someone else made this suggestion to me and I found it usefull)

  • Xodus

    well, why do you have to make the mouse pan all the time? why don’t you only make the mouse pan when the space button is pressed? so if you want to move your mouse off the stage, you wouldn’t hold down space, and no one would pan unless they needed to, so it solves the 2nd problem too.

  • Pingback: From zero to Bombuzal - step 3 : Emanuele Feronato - italian geek and PROgrammer()

  • Andre Marianiello

    buffer = 25;//max distance the edge of the level can get away from edge of the stage
    if(level._width>Stage.width and level._height>Stage.height){
    level.onEnterFrame = function() {
    // pan right
    if (_root._xmouseStage.width-pan_dist) {
    level._x -= pan_speed;
    }
    // pan down
    if (_root._ymouseStage.height-pan_dist) {
    level._y -= pan_speed;
    }
    if(level._x>Stage.width-buffer-level._width/2){
    level._x=Stage.width-buffer-level._width/2
    }
    if(level._xStage.height-buffer-level._height/2){
    level._y=Stage.height-buffer-level._height/2
    }
    if(level._y<Stage.height+buffer+level._height/2){
    level._y=Stage.height+buffer+level._height/2
    }
    };
    }