0
votes

I am currently working on a flash game and am rather new to AS 3 or flash. Need some advice in how to implement one of the core elements of my game.

The idea is 2 player competitive snake style game, only the players do not try to kill each other, but try to reach their opponents spawnpoint.

1 of the key parts of the game would be a grid which is created over the stage where either player may use to "Create walls" by passing through points on the grid. I have no idea how to implement this. Currently I have the basics down where there are 2 players with a starting spot, and if either one reaches the other's starting zone, they score a point.

I need some advice in how to go about implementing this feature:

Each point in the grid will start off in a certain state, and when a player passes through that point, it will be "activated". Then the player may move through any adjacent points to the "activated" point, which will generate a wall between both active points, and thats how they will create mazes to protect their starting area.

Should I generate each point individually or create a grid with a simple function:

    //function to create grids on the map
    public function createGrid()
    {
        var rows:int = 6;
        var cols:int = 11;
        for (var py:int = 0; py < rows; py++) {
            for (var px:int = 0; px < cols; px++) {
                this.grid = new griDot(player1,player2, this);
                grid.x = 50 + grid.width + 100 * px +10;
                grid.y = 50 + grid.height +100 * py + 10;
                this.addChild(grid);
                }
        }
    }

and they are detected with this function(don't laugh i'm pretty noob):

    public function checkDotCollision(player)
    {

        if(player1.hitTestObject(grid) == true)
        {
            trace("player dot collision detected");
        }
        if(player2.hitTestObject(grid) == true)
        {
            trace("player dot collision detected");
        }
    }

currently only the left most bottom square of the grid is detecting the player. Any help / advice on how to implement this feature would be greatly appreciated.

1

1 Answers

0
votes

I'm not going to provide you with code, just with an idea.

In your Player class (if you don't have one, you can get away with the dynamic properties of a movieclip but it's not very clean), add a lastTouchedGriDot of type griDot.

In checkDotCollision, check for each tile. You can't do this at the moment; looks like you'll have to maintain a collection for griDots somewhere. So alter createGrid() to store the created objects in a collection of sorts. Then we can check for each tile. So do so. If you've found a hit, do the following:

  • If there is no last touched grid point, set the last touched grid point to the one you're touching now.
  • If the grid point that was last touched is the same as the one you're touching now, do nothing.
  • If the grid point that was last touched is different than the one you're touching now, check if it's adjacent. If so, build a wall. If not, set the last touched grid point to the one you're touching now.

This should provide you with a solid start. You'll have to add wall collisions and checking if there already IS a wall yourself.