public CubeSet(PhysicsController physicsController, TextureStore textureStore, Vector2 position, int playnum, PhysicsGame.Game1.RoundSpecific cr)
        {
            currentRound           = cr;
            this.textureStore      = textureStore;
            this.physicsController = physicsController;
            //sound = s;
            if (playnum == 1)
            {
                ID = PhysicsGameObject.PhysicsMapID.player1;
            }
            else
            {
                ID = PhysicsGameObject.PhysicsMapID.player2;
            }

            CubeNode rootNode = createNode(new CubeDescription(CubeType.PlainCube));

            rootNode.physicalObject.boxBody.Position = position;

            cubeLookUp                         = new Dictionary <Vector2, CubeNode>();
            rootNode.positionIndex             = new Vector2();
            cubeLookUp[rootNode.positionIndex] = rootNode;

            changeSelecetedNode(rootNode.positionIndex);

            rootNode.physicalObject.boxBody.Position = position;
        }
        public void replaceCubeNodeAndCleanOld(Vector2 replacePosition, CubeDescription cubeDescription)
        {
            cleanUpNodeAt(replacePosition);
            CubeNode toReplace = createNode(cubeDescription);

            cubeLookUp[replacePosition] = toReplace;
            if (selectedCube.Value == replacePosition)
            {
                getSelectedNode().deselect();
                toReplace.select();
            }
        }
        public bool addCubeNodeFromTo(Vector2 fromPosition, Vector2 targetPosition, CubeDescription cubeDescription)
        {
            CubeNode nodeToAdd = createNode(cubeDescription);

            if (!addCubeNodeAtPossible(targetPosition))
            {
                return(false); // already has a block in target position
            }
            else
            {
                nodeToAdd.positionIndex    = targetPosition;
                cubeLookUp[targetPosition] = nodeToAdd;

                if (cubeDescription.type == CubeType.ChainCube)
                {
                    ChainCube chain = (ChainCube)nodeToAdd;
                    ChainPhysicsGameObject chainPhys = (ChainPhysicsGameObject)chain.physicalObject;
                    for (int i = 0; i < 10; i++)
                    {
                        chainPhys.path.Add(new Vector2(
                                               fromPosition.X + (i * (targetPosition.X - fromPosition.X) / 10f),
                                               fromPosition.Y + (i * (targetPosition.Y - fromPosition.Y) / 10f)));
                    }
                    chainPhys.makeLink();
                }
                nodeToAdd.physicalObject.boxBody.Position =
                    getRootNode().physicalObject.boxBody.Position + getRealPosition(targetPosition, cubeSize);

                // joining up blocks (from fromPosition to targetPosition)
                //physicsController.registerPhysicsGameJoint(new PhysicsGameJoint(physicsController.physicsSimulator, this.cubeLookUp[fromPosition].physicalObject, nodeToAdd.physicalObject));

                foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                {
                    Vector2 neighbourIndex = adjacentIndex(targetPosition, dir);
                    if (cubeLookUp.ContainsKey(neighbourIndex)) // TODO check for duplicate joints
                    {
                        physicsController.registerPhysicsGameJoint(new PhysicsGameJoint(physicsController.physicsSimulator, cubeLookUp[neighbourIndex].physicalObject, nodeToAdd.physicalObject));
                    }
                }

                return(true);
            }
        }
 public bool addCubeNodePossible(Direction dir, CubeNode fromNode)
 {
     return(addCubeNodeAtPossible(adjacentIndex(fromNode.positionIndex, dir)));
 }
        public CubeNode createNode(CubeDescription cubeDescription)
        {
            CubeNode temp = CubeFactory.createCubeNode(textureStore, physicsController, cubeDescription, cubeSize, this);

            return(temp);
        }