-1

There is a too long, didn't read version down below.

So I've been making a little game in which the player has to click on a grid of bricks that matches the color of the needed brick in the upper right hand corner of the screen. After they click on the needed color, the bricks explode and the bricks of the same color next to them explode as well creating combos. That leaves holes in the grid so I have to somehow reset the grid itself without resetting the gamestate itself. I've got something working right now which is this:

private function ResetNow():Void
{                  

    if (Restter == 1) Restter = 0;

    //if this block is up here, same results
    /*
    wantedBricks.kill();
    wantedBrik._changeColor = FlxMath.rand(0, 2);
    bricks.autoReviveMembers = true;
    bricks.revive();           
    */ 
    Restter = 0;

    //Removes stray detectors so the neverending combo bug won't occur
    for (stray in dets.members) stray.kill();      

    if (Restter == 0)
    {  

        wantedBricks.kill();
        wantedBrik._changeColor = FlxMath.rand(0, 2);
        bricks.autoReviveMembers = true;
        bricks.revive();           

        wantedBricks.autoReviveMembers = true;
        wantedBricks.revive();         

        for (zgem in bricks.members) zgem.EQUITYCHECK = FlxMath.rand(0, 2);


    }      

    //add(bricks);     

    Restter = 1;

}

So, again, I have a grid of blocks set up at create, that is group bricks. And I have a sprite in the upper right corner which is wantedBrik. What happens during gameplay, is the player clicks on the bricks that matches the wanted bricks to clear them out of the grid. When there are no more wantedBricks(a group), it is supposed to reset the grid, and change the color of the wantedBrik. I also have it somewhere else in the code that if a member of the big grid's EQUITYCHECK(basic object hacked in value) is equal to the wantedBrik, add it to the wantedBricks(which, is why I'm checking for no more of them). So, what happens?

Well, if the color of the wantedBrik doesn't change, everything's fine and resets like normal. the wantedBricks group acurately counts the bricks that actually match the wantedBrik's color. And when it does change, for some reason, gameplay is normal. BUT, wantedBricks not only thinks that the old color is still needed, but it also thinks the new color is still needed too. So when the player clicks the new needed color bricks, they do explode, but because wantedBrik thinks the old color is still wanted, it doesn't hit null and the grid won't reset.

What can I do to make sure that wantedBricks behaves correctly after a color change?

TL;DR version: I need to get a Haxe array to forget or lose old numbers. How can I do this?

Gama11
  • 31,714
  • 9
  • 78
  • 100
xhunterko
  • 49
  • 7

1 Answers1

2

The "Pirate Pig" sample may be useful to you. Since it is a puzzle game, there may be some similar problems that were solved there. You can find it using openfl create or nme create depending on which you are currently using.

You can create a simple array like this:

var myArray = [];

You can also type arrays, like this:

var numbers = new Array<Float>();

Then you can use push(), concat() and other array methods.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Joshua Granick
  • 1,017
  • 6
  • 6