Ejemplo n.º 1
0
        public virtual void UpdateLogic(Time timeElapsed)
        {
            if (this.levelNode != null)
            {
                this.levelNode.UpdateLogic(this, timeElapsed);

                if (this.levelNode.NodeState == NodeState.NOT_ACTIVE)
                {
                    this.levelNode.VisitEnd(this);

                    if (this.levelNode.NextNode == null)
                    {
                        this.levelNode = null;
                    }
                    else
                    {
                        this.levelNode = this.levelNode.NextNode as LevelNode;
                        this.levelNode.VisitStart(this);
                    }
                }
            }

            foreach (ALayer layer in this.layers)
            {
                layer.UpdateLogic(this, timeElapsed);
            }
        }
    private void InsertLevel()
    {
        selectedObject = Selection.activeGameObject;
        var selectedNodeIndex = selectedObject.transform.GetSiblingIndex();

        GameObject insertedLevelObject = new GameObject("Level Node " + levelNodeRoot.childCount, typeof(LevelNode));

        insertedLevelObject.transform.SetParent(levelNodeRoot, false);

        LevelNode levelNode = insertedLevelObject.GetComponent <LevelNode>();

        if (levelNodeRoot.childCount > 1)
        {
            levelNode.previousLevel           = levelNodeRoot.GetChild(selectedNodeIndex).gameObject.GetComponent <LevelNode>();
            levelNode.nextLevel               = levelNode.previousLevel.nextLevel;
            levelNode.previousLevel.nextLevel = levelNode;
            levelNode.nextLevel.previousLevel = levelNode;

            levelNode.transform.position = (levelNode.nextLevel.transform.position + levelNode.previousLevel.transform.position) / 2;
            levelNode.transform.forward  = levelNode.previousLevel.transform.forward;
        }

        insertedLevelObject.transform.SetSiblingIndex(selectedNodeIndex + 1);

        ResetNames(1);
    }
    private void InsertAnchor()
    {
        selectedObject = Selection.activeGameObject;
        var selectedNodeIndex = selectedObject.transform.GetSiblingIndex();

        GameObject levelAnchorObject = new GameObject("Anchor Node " + anchorNodeRoot.childCount, typeof(LevelNode));

        levelAnchorObject.transform.SetParent(anchorNodeRoot, false);

        LevelNode levelAnchor = levelAnchorObject.GetComponent <LevelNode>();

        if (anchorNodeRoot.childCount >= 1)
        {
            levelAnchor.previousLevel           = levelNodeRoot.GetChild(selectedNodeIndex).gameObject.GetComponent <LevelNode>();
            levelAnchor.nextLevel               = levelAnchor.previousLevel.nextLevel;
            levelAnchor.previousLevel.nextLevel = levelAnchor;
            levelAnchor.nextLevel.previousLevel = levelAnchor;

            levelAnchor.transform.position = (levelAnchor.nextLevel.transform.position + levelAnchor.previousLevel.transform.position) / 2;
            levelAnchor.transform.forward  = levelAnchor.previousLevel.transform.forward;
        }

        levelAnchorObject.transform.SetSiblingIndex(selectedNodeIndex + 1);

        ResetNames(3);
    }
Ejemplo n.º 4
0
    private void GenerateNodes(LevelMapSO _levelFlowSO)
    {
        //Start Data
        foreach (StartNodeData _data in _levelFlowSO.startNodeDatas)
        {
            StartNode _startNode = graphView.CreateStartNode(_data.position);
            _startNode.NodeGuid  = _data.guid;
            _startNode.startName = _data.startName;
            _startNode.portSet   = _data.portSet;
            _startNode.LoadValueIntoField();

            graphView.AddElement(_startNode);
        }
        //Level Node
        foreach (LevelNodeData _data in _levelFlowSO.levelNodeDatas)
        {
            LevelNode _lvNode = graphView.CreateLevelNode(_data.position);
            _lvNode.NodeGuid = _data.guid;
            //_lvNode.scene = _data.scene;
            //_lvNode.scenePath = _data.scenePath;
            _lvNode.scenAssetGuid = _data.sceneAssestGuid;
            _lvNode.asyncType     = _data.asyncType;
            _lvNode.loadType      = _data.loadType;
            _lvNode.portSets      = _data.portSets;
            _lvNode.scenePath     = _data.scenePath;
            Debug.Log("1. GenerateNodes  port count" + _data.portSets.Count);
            _lvNode.LoadValueIntoField();

            graphView.AddElement(_lvNode);
        }
    }
Ejemplo n.º 5
0
        void CheckTouch()
        {
            Touch touch = Input.GetTouch(0);

            RaycastHit hit;
            Ray        ray = camera.ScreenPointToRay(touch.position);

            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log("Touch Hit " + hit.collider.gameObject.name);
                currentSelected = hit.collider.gameObject.GetComponent <LevelNode>();

                if (currentSelected != null)
                {
                    //set the previous cube as not selected
                    if (previousSelectedNode != null)
                    {
                        previousSelectedNode.isSelected = false;
                    }

                    //set the current cube as selected
                    currentSelected.isSelected = true;

                    //assgn the currently selected cube as the previous cube, for the next round
                    previousSelectedNode = currentSelected;
                }
            }
        }
Ejemplo n.º 6
0
    /// <summary>
    /// Returns whether or not the given path could continue in the given direction.
    /// </summary>
    /// <param name="path">The path to check.</param>
    /// <param name="dir">The direction to check.</param>
    /// <returns>True if the path could continue in that direction; false otherwise.</returns>
    private bool IsDirectionPossibleForPathContinuation(LevelPath path, Direction dir)
    {
        // Verify that the path has a tail node
        LevelNode tailNode = path.TailNode;

        if (tailNode == null)
        {
            throw new ArgumentException("Cannot operate on given path; path has no nodes.");
        }

        // Get the new coordinates
        Tuple <int, int> newCoordinates = GetNewCoordinatesInDirection(tailNode.WorldRow, tailNode.WorldColumn, dir);
        int newRow = newCoordinates.First;
        int newCol = newCoordinates.Second;

        // If the coordinates are outside the world, we can't continue here
        if (!AreCoordinatesInsideWorld(path.ParentWorld, newRow, newCol))
        {
            return(false);
        }

        // If there is a non tail node at these coordinates, we can't continue here
        LevelNode nodeAtCoordinates = path.ParentWorld.ChildNodes[newRow, newCol];

        if (nodeAtCoordinates != null && !nodeAtCoordinates.IsTailNodeOfPath())
        {
            return(false);
        }

        return(true);
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Continues the given path from the given node in the given direction.
    /// </summary>
    /// <param name="path">The path to continue.</param>
    /// <param name="previousNode">The previous node that connects to the new node or join. Typically, this will be the given path's tail node.</param>
    /// <param name="directionToContinue">The direction to continue the path in from the previous node.</param>
    /// <exception cref="InvalidOperationException">Thrown if the new node's coordinates would be outside the world.</exception>
    /// <returns>True if the path can continue after this step; false otherwise.</returns>
    private bool ProcessPathContinuation(LevelPath path, LevelNode previousNode, Direction directionToContinue)
    {
        Tuple <int, int> newNodeCoords = GetNewCoordinatesInDirection(previousNode, directionToContinue);
        bool             pathContinuesNextIteration = false;

        // Verify that the new coordinates are inside the world
        if (!AreCoordinatesInsideWorld(previousNode.ParentWorld, newNodeCoords.First, newNodeCoords.Second))
        {
            throw new InvalidOperationException(string.Format(
                                                    "Cannot add new node at the given direction from the given node. New node would have coordinates ({0}, {1}), which are outside the world.", newNodeCoords.First, newNodeCoords.Second));
        }

        // If there's no node at these coordinates, create a new node
        LevelNode nodeAtCoordinates = path.ParentWorld.ChildNodes[newNodeCoords.First, newNodeCoords.Second];

        if (nodeAtCoordinates == null)
        {
            nodeAtCoordinates = new LevelNode(path, newNodeCoords.First, newNodeCoords.Second);

            // Since we added a new node (and didn't join paths), this path continues
            pathContinuesNextIteration = true;
        }

        // Join the nodes
        previousNode.UpdateOpenSideStatus(directionToContinue, true);
        nodeAtCoordinates.UpdateOpenSideStatus(GetOppositeDirection(directionToContinue), true);

        return(pathContinuesNextIteration);
    }
Ejemplo n.º 8
0
        protected override void DoUpdate(SAMTime gameTime, InputState istate)
        {
            var sel = ((GDWorldHUD)HUD).SelectedNode;

            tabTimer += gameTime.ElapsedSeconds;
            tab       = (int)(tabTimer / TAB_SWITCHTIME) % 3;

            if (sel != null && progressDisplay < 1)
            {
                tabTimer = 0;
                tab      = 0;
                FloatMath.ProgressInc(ref progressDisplay, gameTime.ElapsedSeconds * SPEED_BLEND);
                node = sel;
            }
            else if (sel == null && progressDisplay > 0)
            {
                FloatMath.ProgressDec(ref progressDisplay, gameTime.ElapsedSeconds * SPEED_BLEND);
            }
            else if (sel != null && node != null && sel != node)
            {
                node = sel;
            }

            IsVisible = FloatMath.IsNotZero(progressDisplay);
        }
Ejemplo n.º 9
0
    public Vector3 Load(LevelNode levelNode, int levelId, int stageId, Vector3 startpos)
    {
        stageEntity = LevelResManager.Instance.GetStage(levelId, levelNode.type);
        //stageEntity.gameObject.transform.position = levelNode.GetPosition (LevelManager.width,LevelManager.heigh);
        Vector3 local = startpos;

        local.x = local.x + stageEntity.getXSize() * 0.5f;
        local.y = local.y + stageEntity.getYSize() * 0.5f;
        stageEntity.gameObject.transform.position = local;
        if (levelNode.type == eNodeType.Start)
        {
            stageEntity.gameObject.name = "start";
        }
        if (levelNode.type == eNodeType.End)
        {
            stageEntity.gameObject.name = "end";
        }
        if (levelNode.type == eNodeType.Boss)
        {
            stageEntity.gameObject.name = "boss";
        }
        if (levelNode.type == eNodeType.Normal)
        {
            stageEntity.gameObject.name = "normal";
        }
        stageEntity.InitDoorState(levelNode, stageId);
        stageEntity.OpenAllEnableDoor();

        startpos.x = startpos.x + stageEntity.getXSize();

        return(startpos);
    }
Ejemplo n.º 10
0
        private void Init()
        {
            // create level nodes
            levelNodes = new List <LevelNode>();
            for (int i = 0; i < levelCount; i++)
            {
                var node = new LevelNode();

                int worldIndex = i / levelPerWorld;
                int index      = i % levelPerWorld;
                node.Name = string.Format("{0}-{1}", (char)('A' + worldIndex), index);

                node.StarNumber    = (i % 3) + 1;
                node.SelectCommand = new DelegateCommand(() => SelectLevel(node));

                levelNodes.Add(node);
            }

            // create boss level nodes
            bossLevelNodes = new List <BossLevelNode>();
            for (int i = 0; i < bossLevelCount; i++)
            {
                var node = new BossLevelNode();

                node.Name = string.Format("Boss {0}", (char)('A' + i));
                node.RequiredStarNumber = 10 * (i + 1);
                node.SelectCommand      = new DelegateCommand(() => SelectBossLevel(node));

                bossLevelNodes.Add(node);
            }
        }
Ejemplo n.º 11
0
    public void CancelRoadSign()
    {
        LevelNode node = levelNode.GetComponent <LevelNode>();

        node.notOpen.SetActive(true);
        node.roadSign.SetActive(false);
        node.levelSprite.enabled = false;
    }
Ejemplo n.º 12
0
 //Methods
 //---------------------------------------------
 public LevelNodeController()
 {
     Previous         = null;
     _step            = null;
     _length          = 0;
     _levelNode       = World.Instance.Level.CreateLevelNode <DefaultNode>(this);
     OnLengthChanged += _levelNode.OnPreviousNodeChangedLength;
 }
Ejemplo n.º 13
0
    //----------------//
    // Updating Nodes //
    //----------------//

    /// <summary>
    /// Adds a node to this path and the parent world at the given location.
    /// </summary>
    /// <param name="node">The node to add.</param>
    /// <param name="row">The row to place the node in.</param>
    /// <param name="col">The column to place the node in.</param>
    public void AddNode(LevelNode node, int row, int col)
    {
        if (!ChildNodes.Contains(node))
        {
            ParentWorld.AddNode(node, row, col);
            ChildNodes.Add(node);
        }
    }
Ejemplo n.º 14
0
 /// <summary>
 /// Removes the given node from this world.
 /// </summary>
 /// <param name="node">The node to remove.</param>
 public void RemoveNode(LevelNode node)
 {
     if (ChildNodes.Contains(node))
     {
         ParentWorld.RemoveNode(node);
         ChildNodes.Remove(node);
     }
 }
 public void SetLevel(LevelNode target)
 {
     if (nodes[target.reference] != null)
     {
         currentLevel = target.reference;
         currentNode  = target.id;
     }
 }
Ejemplo n.º 16
0
    //---------------//
    // Build Helpers //
    //---------------//

    /// <summary>
    /// Continues building the world given the current active paths in it.
    /// </summary>
    /// <param name="world">The world to continue building.</param>
    /// <param name="currentActivePaths">The current active paths in the world.</param>
    /// <returns>The world after all active paths have completed.</returns>
    private LevelWorld BuildWorldFromExistingPaths(LevelWorld world, List <LevelPath> currentActivePaths)
    {
        while (currentActivePaths.Count > 0)
        {
            List <LevelPath> nextIterationActivePaths = new List <LevelPath>();
            foreach (var path in currentActivePaths)
            {
                // Verify that the path has at least one node already
                LevelNode tailNode = path.TailNode;
                Debug.Assert(tailNode != null);

                // Get the possible directions to move
                List <Direction> possibleDirections = GetPossibleDirectionsForPathContinuation(path);

                // Check to see if we're out of possible directions
                if (possibleDirections.Count == 0)
                {
                    // Note that we don't add this current path to the next iteration's paths; this path is done
                    continue;
                }

                // Continue the path in a random direction
                Direction dirToContinueIn        = GetRandomDirection(possibleDirections);
                bool      addPathToNextIteration = ProcessPathContinuation(path, tailNode, dirToContinueIn);
                if (addPathToNextIteration)
                {
                    nextIterationActivePaths.Add(path);
                }

                // Check for a split
                float splitCheck = UnityEngine.Random.Range(0.0f, 1.0f);
                if (splitCheck < splitChance)
                {
                    possibleDirections.Remove(dirToContinueIn);

                    // Check if there are any directions to continue in
                    if (possibleDirections.Count != 0)
                    {
                        // Get the direction for the new node
                        Direction dirToSplitIn = GetRandomDirection(possibleDirections);

                        // Create the new path and add a node to it
                        LevelPath splitPath = new LevelPath(world);
                        addPathToNextIteration = ProcessPathContinuation(splitPath, tailNode, dirToSplitIn);
                        if (addPathToNextIteration)
                        {
                            nextIterationActivePaths.Add(splitPath);
                        }
                    }
                }
            }

            // Update the current paths for the next iteration
            currentActivePaths = nextIterationActivePaths;
        }

        return(world);
    }
Ejemplo n.º 17
0
    //----------------//
    // Updating Nodes //
    //----------------//

    /// <summary>
    /// Adds a node to this path and the parent world at the given location.
    /// </summary>
    /// <param name="node">The node to add.</param>
    /// <param name="row">The row to place the node in.</param>
    /// <param name="col">The column to place the node in.</param>
    public void AddNode(LevelNode node, int row, int col)
    {
        if (!ChildNodes.Contains(node))
        {
            ParentWorld.AddNode(node, row, col);
            ChildNodes.Add(node);
        }
        
    }
Ejemplo n.º 18
0
    static void NodeAnchorCallback()
    {
        LevelNode selectedNode = Selection.activeGameObject.GetComponent <LevelNode>();

        isAnchor = !isAnchor;

        /*            if(isAnchor) selectedNode.isAnchorNode = true;
         *          else selectedNode.isAnchorNode = false;*/
    }
Ejemplo n.º 19
0
 public void InitDoorState(LevelNode node, int stageId)
 {
     leftDoor.mStageId  = stageId;
     rightDoor.mStageId = stageId;
     leftDoor.SetDoorState(node.left);
     rightDoor.SetDoorState(node.right);
     type         = node.type;
     this.stageId = stageId;
 }
Ejemplo n.º 20
0
            public void Add(LevelNode url, uint level)
            {
                if (!Levels.ContainsKey(level)) // if it does not contain the key, create it
                {
                    Levels = Levels.Add(level, ImmutableList <LevelNode> .Empty);
                }

                Levels = Levels.SetItem(level, Levels[level].Add(url));
            }
Ejemplo n.º 21
0
    public void OnNodeDeselected()
    {
        selectedLevel = null;

        // update details pane
        if (DetailsPane != null)
        {
            DetailsPane.SetBool("IsLevelSelected", false);
        }
    }
Ejemplo n.º 22
0
        private void nextLevel()
        {
            //Good animation
            Animation("AnimationSuccess");

            this.s.playCorrectVoice(); // When the kid answer is correct
            currentLevel = currentLevel.next;
            changeLetter();
            restart();
        }
Ejemplo n.º 23
0
    void SetLevelNode(LevelNode node)
    {
        Vector3 target = node.transform.position;

        target.y += yOffset;
        playerAnim.transform.position = target;
        playerMoving = false;
        playerAnim.SetBool("isMoving", false);

        panelText.text = node.name;
        node.SetCurrentNodeSprite(true);
    }
Ejemplo n.º 24
0
    //----------------//
    // Updating Nodes //
    //----------------//

    /// <summary>
    /// Adds a node to this world at the given location. Will throw an exception if this location is not empty.
    /// </summary>
    /// <param name="node">The node to add.</param>
    /// <param name="row">The row to place the node in.</param>
    /// <param name="col">The column to place the node in.</param>
    /// <exception cref="InvalidOperationException">Thrown if the given location is not empty.</exception>
    public void AddNode(LevelNode node, int row, int col)
    {
        // Make sure this location is empty
        if (ChildNodes[row, col] != null)
        {
            throw new InvalidOperationException(string.Format(
                                                    "Cannot add node to location ({0}, {1}); location already has a node.", row, col));
        }

        // If we got here, we're good to proceed and add the node
        ChildNodes[row, col] = node;
    }
Ejemplo n.º 25
0
        public TheGame(bool isRightHand)
        {
            this.isRightHand = isRightHand;

            s = new Sounds.Sounds();

            InitializeComponent();

            //Init GameFlow
            currentLevel = GameFlow.createGameFlow();

            Loaded += delegate
            {
                if (currentLevel.getLetter().ToString().Length > 1)
                {
                    getScreenSize(currentLevel.getLetter());
                }
            };

            this.speechEngine = SpeechRecognition.init();
            this.speechEngine.SpeechRecognized += this.SpeechRecognized;


            _sensor = KinectSensor.GetDefault();

            if (_sensor != null)
            {
                _sensor.Open();

                _width  = _sensor.ColorFrameSource.FrameDescription.Width;
                _height = _sensor.ColorFrameSource.FrameDescription.Height;

                _colorReader = _sensor.ColorFrameSource.OpenReader();
                _colorReader.FrameArrived += ColorReader_FrameArrived;

                _bodyReader = _sensor.BodyFrameSource.OpenReader();
                _bodyReader.FrameArrived += BodyReader_FrameArrived;

                _pixels = new byte[_width * _height * 4];
                _bitmap = new WriteableBitmap(_width, _height, 96.0, 96.0, PixelFormats.Bgra32, null);

                _bodies = new Body[_sensor.BodyFrameSource.BodyCount];

                camera.Source = _bitmap;

                changeLetter();
            }

            polylines = new List <Polyline>();
            addNewPolyline();
            isSecondClick = false;
        }
Ejemplo n.º 26
0
        public void SelectNode(LevelNode n)
        {
            SelectedNode = n;
            InfoDisplay.ResetCycle();

            foreach (var node in GDOwner.GetEntities <LevelNode>())
            {
                var s = node.StateSum;
                if (node != n && (s == BistateProgress.Open || s == BistateProgress.Opening || s == BistateProgress.Undefined))
                {
                    node.CloseNode();
                }
            }
        }
Ejemplo n.º 27
0
    void MovePlayerToNode(LevelNode node)
    {
        Vector3 target = node.transform.position;

        target.y += yOffset;
        if (Vector3.Distance(playerAnim.transform.position, target) > 0.1f)
        {
            playerAnim.transform.position = Vector3.MoveTowards(playerAnim.transform.position, target, moveSpeed * Time.deltaTime);
        }
        else
        {
            SetLevelNode(node);
        }
    }
Ejemplo n.º 28
0
    public LevelEdge(LevelNode A, LevelNode B)
    {
        start = A;
        end   = B;

        if (start.xIndex == end.xIndex)
        {
            edgeType = eEdgeType.Vetical;
        }
        else
        {
            edgeType = eEdgeType.Horizon;
        }
        pos = GetPosition(LevelManager.h1, LevelManager.h2);
    }
Ejemplo n.º 29
0
        public OfficeWorld()
        {
            this.objectsById = new Dictionary <string, AObject>();

            this.layers = new List <ALayer>();

            // Level creation
            TutoLevelNode tutoLevelNode  = new TutoLevelNode();
            LevelNode     firstLevelNode = this.CreateGame("Levels", 5);

            // Level links
            tutoLevelNode.NextNode = firstLevelNode;

            this.levelNode = tutoLevelNode;
        }
Ejemplo n.º 30
0
        public LevelNodeController(LevelNodeController previous, Scenario.IScenarioStep step)
        {
            Previous = previous;
            _step    = step;
            _length  = step.DefaultLength;

            //instantiate the corresponding LevelNode for the step by calling Level's templated method via reflection
            Type type = ScenarioStepToLevelNodeTypeDictionary[step.GetType()];

            Debug.Assert(type.IsSubclassOf(typeof(LevelNode)));
            // ReSharper disable once PossibleNullReferenceException
            var genericMethod = typeof(View.Level.Level).GetMethod("CreateLevelNode").MakeGenericMethod(type);

            _levelNode       = (LevelNode)genericMethod.Invoke(World.Instance.Level, new object[] { this });
            OnLengthChanged += _levelNode.OnPreviousNodeChangedLength;
        }
Ejemplo n.º 31
0
    /// <summary>
    /// Removes the given node from this world. Will throw an exception if the node's store coordinates do not match its actual coordinates.
    /// </summary>
    /// <param name="node">The node to remove.</param>
    /// <exception cref="InvalidOperationException">Thrown if the given node's location is occupied by a different node.</exception>
    public void RemoveNode(LevelNode node)
    {
        // Check to make sure this node is registered at the correct location
        if (ChildNodes[node.WorldRow, node.WorldColumn] == node)
        {
            // If it is, remove it
            ChildNodes[node.WorldRow, node.WorldColumn] = null;
        }

        // If it's not, throw an exception
        else
        {
            throw new InvalidOperationException(string.Format(
                                                    "Cannot remove node from location({0}, {1}); this location is occupied by a different node.", node.WorldRow, node.WorldColumn));
        }
    }
Ejemplo n.º 32
0
    //-------------//
    // Constructor //
    //-------------//

    /// <summary>
    /// Instantiates a new level world with the given dimensions.
    /// </summary>
    /// <param name="rows">The number of rows in the world.</param>
    /// <param name="cols">The number of columns in the world.</param>
    public LevelWorld(int rows, int cols)
    {
        ChildPaths = new List<LevelPath>();
        ChildNodes = new LevelNode[rows, cols];
    }
Ejemplo n.º 33
0
        /// <summary>
        /// Draw the level tiles
        /// </summary>
        /// <param name="level"></param>
        public void DrawLevel(LevelNode level)
        {
            // Bind sprite batcher
            m_spriteBatch.Begin( );

            // Draw background "brick"
            Vector2 backgroundSize = new Vector2(((float)m_graphicsDevice.Viewport.Width * 0.55f), ((float)m_graphicsDevice.Viewport.Height * 0.55f));
            Vector2 backgroundPos = new Vector2(((float)m_graphicsDevice.Viewport.Width / 2) - (backgroundSize.X / 2), ((float)m_graphicsDevice.Viewport.Height / 2) - (backgroundSize.Y / 2) - 50.0f);
            Rectangle rc = new Rectangle((int)(((float)m_graphicsDevice.Viewport.Width * (float)level.x) + backgroundPos.X), (int)backgroundPos.Y, (int)backgroundSize.X, (int)backgroundSize.Y);
            m_spriteBatch.Draw(m_levelBackground, rc, Color.White);

            // Calculate a new camera scale to fit the level to as much as possible of the background brick
            // minus the border level height as reference
            float newCameraScaleX = ((float)backgroundSize.X + BORDER_SIZE) / ((float)(((float)level.level.Width + 1) * m_tileWidth * m_camera.Scale.X));
            float newCameraScaleY = ((float)backgroundSize.Y + BORDER_SIZE) / ((float)(((float)level.level.Height + 1) * m_tileHeight * m_camera.Scale.Y));
            float smallestScale = newCameraScaleX < newCameraScaleY ? newCameraScaleX : newCameraScaleY;
            smallestScale = smallestScale > 1 ? 1 : smallestScale;
            m_camera.SetScale(smallestScale, smallestScale);

            // Translate camera to center on the level
            float cameraX = (m_graphicsDevice.Viewport.Width / 2) - ((level.level.Width * m_tileWidth * m_camera.Scale.X) / 2);
            float cameraY = (m_graphicsDevice.Viewport.Height / 2) - ((level.level.Height * m_tileHeight * m_camera.Scale.Y) / 2);
            m_camera.Translate(cameraX + ((float)m_graphicsDevice.Viewport.Width * (float)level.x), cameraY - 50.0f);

            // Draw statical tiles
            List<Tile> staticTiles = level.level.StaticTiles;
            foreach (Tile tile in staticTiles)
            {
                DrawTile(level.level, tile);
            }

            // Draw moveable tiles
            List<Tile> moveableTiles = level.level.MoveableTiles;
            foreach (Tile tile in moveableTiles)
            {
                DrawTile(level.level, tile);
            }

            // Unbind the sprite batcher
            m_spriteBatch.End();

            // Reset camera scale
            m_camera.SetScale(1, 1);
        }
Ejemplo n.º 34
0
    /// <summary>
    /// Builds a new world with the class's parameters and returns the start node of the world.
    /// </summary>
    /// <exception cref="InvalidOperationException">Thrown if world dimensions, start coordinates, or split chance is invalid.</exception>
    /// <returns>The start node in the new world.</returns>
    public LevelNode BuildNewWorld()
    {
        // Verify world dimensions
        if (rowsInWorld < 1 || colsInWorld < 1)
        {
            throw new InvalidOperationException(
                string.Format("Invalid world dimensions ({0}, {1}). Dimensions must be >= 1.", rowsInWorld, colsInWorld));
        }

        // Verify split chance
        if (splitChance < 0 || splitChance > 1)
        {
            throw new InvalidOperationException(
                string.Format("Invalid split chance {0}. Split chance must be >= 0 and <= 1.", splitChance));
        }

        // Create the world
        LevelWorld world = new LevelWorld(rowsInWorld, colsInWorld);

        // Verify start coordinates
        if (!AreCoordinatesInsideWorld(world, startRow, startCol))
        {
            throw new InvalidOperationException(
                string.Format("Invalid start coordinates ({0}, {1}) for world with dimensions ({0}, {1}). Coordinates must be located inside world.", startRow, startCol, rowsInWorld, colsInWorld));
        }

        // Add the first path and start node
        LevelPath firstPath = new LevelPath(world);
        LevelNode startNode = new LevelNode(firstPath, startRow, startCol);

        // Get the directions for the next two nodes
        List<Direction> possibleDirections = GetPossibleDirectionsForPathContinuation(firstPath);
        Debug.Assert(possibleDirections.Count >= 2); // Since the world is square and there are no other nodes, there should always be at least 2 possible directions

        Direction dirOfFirstPath = GetRandomDirection(possibleDirections);
        possibleDirections.Remove(dirOfFirstPath);
        Direction dirOfSecondPath = GetRandomDirection(possibleDirections);

        // Add the nodes to the world
        AddNodeToWorld(startNode, firstPath, dirOfFirstPath);
        LevelPath secondPath = new LevelPath(world);
        AddNodeToWorld(startNode, secondPath, dirOfSecondPath);

        // Begin adding paths
        List<LevelPath> currentActivePaths = new List<LevelPath>()
        {
            firstPath,
            secondPath
        };

        while (currentActivePaths.Count > 0)
        {
            List<LevelPath> nextIterationActivePaths = new List<LevelPath>();
            foreach (var path in currentActivePaths)
            {
                // Verify that the path has at least one node already
                Debug.Assert(path.TailNode != null);
                
                // Get the possible directions to move
                possibleDirections = GetPossibleDirectionsForPathContinuation(path);

                // Check to see if we're out of possible directions
                if (possibleDirections.Count == 0)
                {
                    // Note that we don't add this current path to the next iteration's paths; this path is done
                    continue;
                }

                // Get the direction for the new node
                Direction dirToContinueIn = GetRandomDirection(possibleDirections);

                // Check if this is a join or if we're adding a new node
                Tuple<int, int> newCoordinates = GetNewCoordinatesInDirection(path.TailNode, dirToContinueIn);
                LevelNode nodeAtCoordinates = world.ChildNodes[newCoordinates.First, newCoordinates.Second];

                // If there's no node at these coordinates, add the node
                if (nodeAtCoordinates == null)
                {
                    AddNodeToWorld(path.TailNode, path, dirToContinueIn);

                    // This path continues next iteration
                    nextIterationActivePaths.Add(path);
                }

                // Otherwise, process a path join
                else
                {
                    JoinNodes(path.TailNode, nodeAtCoordinates);

                    // Note that we don't add this current path to the next iteration's paths; this path is done
                    continue;
                }

                // Check for a split
                float splitCheck = UnityEngine.Random.Range(0.0f, 1.0f);
                if (splitCheck < splitChance)
                {
                    possibleDirections.Remove(dirToContinueIn);
                    
                    // Check if there are any directions to continue in
                    if (possibleDirections.Count == 0)
                    {
                        // Get the direction for the new node
                        Direction dirToSplitIn = GetRandomDirection(possibleDirections);

                        // TODO: Implement. Perhaps refactor lines 103 to 125
                    }
                }
            }

            // Update the current paths for the next iteration
            currentActivePaths = nextIterationActivePaths;
        }
        

        return startNode;
    }
Ejemplo n.º 35
0
    //----------------//
    // Updating Nodes //
    //----------------//

    /// <summary>
    /// Adds a node to this world at the given location. Will throw an exception if this location is not empty.
    /// </summary>
    /// <param name="node">The node to add.</param>
    /// <param name="row">The row to place the node in.</param>
    /// <param name="col">The column to place the node in.</param>
    /// <exception cref="InvalidOperationException">Thrown if the given location is not empty.</exception>
    public void AddNode(LevelNode node, int row, int col)
    {
        // Make sure this location is empty
        if (ChildNodes[row, col] != null)
        {
            throw new InvalidOperationException(string.Format(
                "Cannot add node to location ({0}, {1}); location already has a node.", row, col));
        }

        // If we got here, we're good to proceed and add the node
        ChildNodes[row, col] = node;
    }
Ejemplo n.º 36
0
 /// <summary>
 /// Removes the given node from this world.
 /// </summary>
 /// <param name="node">The node to remove.</param>
 public void RemoveNode(LevelNode node)
 {
     if (ChildNodes.Contains(node))
     {
         ParentWorld.RemoveNode(node);
         ChildNodes.Remove(node);
     }
 }
Ejemplo n.º 37
0
 public virtual void UseLadder(float dir, LevelNode ladder)
 {
     // Note should be something here to check if on ladder but just for testing now
     Vector3 p = _transform.position;
     p.x = ladder.Centre.x;
     _transform.position = p;
     _moveVector = new Vector2(0, dir * _walkSpeed);
 }
Ejemplo n.º 38
0
 public Neighbour GetNeighbour(LevelNode neighbourNode)
 {
     for (int i = 0; i < _neighbours.Length; ++i)
     {
         if (_neighbours[i].node == neighbourNode) return _neighbours[i];
     }
     return new Neighbour();
 }
Ejemplo n.º 39
0
    /// <summary>
    /// Removes the given node from this world. Will throw an exception if the node's store coordinates do not match its actual coordinates.
    /// </summary>
    /// <param name="node">The node to remove.</param>
    /// <exception cref="InvalidOperationException">Thrown if the given node's location is occupied by a different node.</exception>
    public void RemoveNode(LevelNode node)
    {
        // Check to make sure this node is registered at the correct location
        if (ChildNodes[node.WorldRow, node.WorldColumn] == node)
        {
            // If it is, remove it
            ChildNodes[node.WorldRow, node.WorldColumn] = null;
        }

        // If it's not, throw an exception
        else
        {
            throw new InvalidOperationException(string.Format(
                "Cannot remove node from location({0}, {1}); this location is occupied by a different node.", node.WorldRow, node.WorldColumn));
        }
    }
Ejemplo n.º 40
0
 void Update()
 {
     if (Input.GetAxisRaw("Mouse ScrollWheel") > 0) {
         zoomLimited(1f / zoomSpeed);
     }
     if (Input.GetAxisRaw("Mouse ScrollWheel") < 0) {
         zoomLimited(zoomSpeed);
     }
     if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2)) {
         draggingWorldPoint = camera.ScreenToWorldPoint(Input.mousePosition);
     }
     if (Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButton(2)) {
         var mouseWorldPoint = camera.ScreenToWorldPoint(Input.mousePosition);
         move(draggingWorldPoint - mouseWorldPoint);
     }
     if (Input.GetMouseButtonDown(0)) {
         if (hovered != null) {
             if (hovered.level.Unlocked() || Cheats.on) {
                 GameManager.instance.Play(hovered.level);
             }
         }
     }
     move(new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * keyboardSpeed * currentZoom);
     var oldHovered = hovered;
     this.hovered = null;
     Physics.Raycast(camera.ScreenToWorldPoint(Input.mousePosition), Vector3.forward, out hit);
     if (hit.collider != null) {
         var hoveredNode = hit.collider.GetComponent<LevelNode>();
         if (hoveredNode != null) {
             this.hovered = hoveredNode;
         }
     }
     if (oldHovered != hovered) {
         levelNameSubstitution.Recalculate();
         levelStatusSubstitution.Recalculate();
         DynamicTextManager.instance.Invalidate();
     }
 }
Ejemplo n.º 41
0
    /// <summary>
    /// Adds a new node to the world given the previous node, the direction to the new node, and parent path.
    /// </summary>
    /// <param name="previousNode">The node that connects to the new node; often the previous node in the path.</param>
    /// <param name="parentPathOfNewNode">The parent path of the new node.</param>
    /// <param name="directionToNewNode">The direction from the previous node to the new node.</param>
    /// <exception cref="InvalidOperationException">Thrown if the new node's coordinates would be outside the world or if there is already a node at these coordinates.</exception>
    /// <returns>The newly created node.</returns>
    private LevelNode AddNodeToWorld(LevelNode previousNode, LevelPath parentPathOfNewNode, Direction directionToNewNode)
    {
        Tuple<int, int> newNodeCoords = GetNewCoordinatesInDirection(previousNode, directionToNewNode);

        // Verify that the new coordinates are inside the world
        if (!AreCoordinatesInsideWorld(previousNode.ParentWorld, newNodeCoords.First, newNodeCoords.Second))
        {
            throw new InvalidOperationException(string.Format(
                "Cannot add new node at the given direction from the given node. New node would have coordinates ({0}, {1}), which are outside the world.", newNodeCoords.First, newNodeCoords.Second));
        }

        // Verify that there is no node at these coordinates already
        if (parentPathOfNewNode.ParentWorld.ChildNodes[newNodeCoords.First, newNodeCoords.Second] != null)
        {
            throw new InvalidOperationException(string.Format(
                "Cannot add new node at location ({0}, {1}); location already has a node.", newNodeCoords.First, newNodeCoords.Second));
        }

        // Create the new node
        LevelNode newNode = new LevelNode(parentPathOfNewNode, newNodeCoords.First, newNodeCoords.Second);

        // Update the open side statuses
        previousNode.UpdateOpenSideStatus(directionToNewNode, true);
        newNode.UpdateOpenSideStatus(GetOppositeDirection(directionToNewNode), true);

        return newNode;
    }
Ejemplo n.º 42
0
    /// <summary>
    /// Joins the two given nodes. Nodes must be adjacent.
    /// </summary>
    /// <param name="firstNode">The first node to join.</param>
    /// <param name="secondNode">The second node to join.</param>
    /// <exception cref="InvalidOperationException">Thrown if the two nodes are not adjacent.</exception>
    private void JoinNodes(LevelNode firstNode, LevelNode secondNode)
    {
        Direction dirToSecondNode = GetDirectionToCoordinates(firstNode.WorldRow, firstNode.WorldColumn, secondNode.WorldRow, secondNode.WorldColumn);

        // Verify that we found a direction
        if (dirToSecondNode == Direction.NONE)
        {
            throw new InvalidOperationException(string.Format(
                "Cannot join nodes at locations ({0}, {1}) and ({2}, {3}); nodes are not adjacent.", firstNode.WorldRow, firstNode.WorldColumn, secondNode.WorldRow, secondNode.WorldColumn));
        }

        firstNode.UpdateOpenSideStatus(dirToSecondNode, true);
        secondNode.UpdateOpenSideStatus(GetOppositeDirection(dirToSecondNode), true);
    }
Ejemplo n.º 43
0
 /// <summary>
 /// Gets the new coordinates for the given node after moving one unit in the given direction.
 /// </summary>
 /// <param name="node">The node whose coordinates to use.</param>
 /// <param name="dir">The direction to move in.</param>
 /// <returns>The new coordinates.</returns>
 private Tuple<int, int> GetNewCoordinatesInDirection(LevelNode node, Direction dir)
 {
     return GetNewCoordinatesInDirection(node.WorldRow, node.WorldColumn, dir);
 }
Ejemplo n.º 44
0
 public Node(int value, int levelCount)
 {
     Value = value;
     LevelCount = levelCount;
     LevelNodes = new LevelNode[levelCount];
 }