/// <summary>
 /// Default constructor for an un-positioned gridspace
 /// </summary>
 /// <param name="parentGrid">Grid of which to be a technical, but undrawn and inaccessible, member.</param>
 public GridSpace(Grid parentGrid)
 {
     currentActor = null;
     isOccupied = false;
     moveCost = 1;
     parent = parentGrid;
     walls = new Wall[3];
 }
 public void putActor(Actor toPut)
 {
     if (!isOccupied)
     {
         isOccupied = true;
         currentActor = toPut;
     }
 }
 /// <summary>
 /// Creates a grid space that considers itself at position (posX, posY) in the parent grid.
 /// </summary>
 /// <param name="spaceTypeSelector">Chooses the texture for this space. Does not affect the properties of it otherwise.</param>
 /// <param name="posX">Horizontal position in the grid</param>
 /// <param name="posY">Vertical position in the grid</param>
 /// <param name="elevation"></param>
 /// <param name="Parent"></param>
 public SimpleGridSpace(int spaceTypeSelector, int posX, int posY, int elevation, SimpleGrid Parent)
 {
     holder = EnvironmentTextureHolder.Holder;
     currentActor = null;
     isOccupied = false;
     moveCost = 1;
     parent = Parent;
     gridPos = new Vector2(posX, posY);
     spaceSprite = holder.MainHexagonSprites[spaceTypeSelector].copySprite();
     spaceType = spaceTypeSelector;
     walls = new Wall[3];
     for (int i = 0; i < 3; ++i)
     {
         walls[i] = new Wall();
     }
     this.elevation = elevation;
 }
Beispiel #4
0
        public void onClick(Vector2 screenPosition)
        {
            GridSpace tempGS = spaceAtScreenpos(Controls.MousePosition);
            Person temp = (Person)tempGS.CurrentActor;

            switch (gridState)
            {
                case GridState.noSelection:
                    if (temp != null)
                    {
                        selectedPerson = temp;
                        foreach (GridSpace space in spaceArray)
                        {
                            space.AvailableFlag = false;
                        }
                        availableSpaces = getAvailableMoveSpaces(selectedPerson.BaseMoveSpeed, tempGS.GridPosition, true, false);
                        foreach (Vector2 v in availableSpaces)
                        {
                            spaceArray[(int)v.X, (int)v.Y].AvailableFlag = true;
                        }
                        changeState(GridState.selectedMotionAvailable);
                    }
                    break;

                case GridState.castAnimating:
                    break;

                case GridState.selectedCastAvailable:
                    break;

                case GridState.selectedMotionAvailable:
                    foreach (GridSpace space in spaceArray)
                    {
                        space.AvailableFlag = false;
                    }
                    currentPath = Dijkstra(selectedPerson.GridPosition, tempGS.GridPosition, true, false);
                    int movesDone = 0;
                    if (currentPath.Count > 0)
                    {
                        LinkedListNode<Vector2> current = currentPath.First;
                        while (movesDone < selectedPerson.BaseMoveSpeed && current.Next != null)
                        {
                            movesDone += movementCosts[(int)current.Value.X, (int)current.Value.Y, (int)current.Next.Value.X, (int)current.Next.Value.Y];
                            current = current.Next;
                        }
                        while (current.Next != null)
                        {
                            currentPath.Remove(current.Next);
                        }
                        animationFinalGoal = spaceArray[(int)currentPath.Last.Value.X, (int)currentPath.Last.Value.Y];
                        animationCurrentGoal = currentPath.First.Value;
                        animatingActorScreenPos = selectedPerson.ScreenPosition;
                        currentPath.RemoveFirst();
                        if ((int)animationCurrentGoal.X % 2 == 1)
                        {
                            animationCurrentGoal.Y += 0.5f;
                        }
                        animationCurrentGoal.X *= 3 * ConstantHolder.HexagonGrid_HexSizeX / 4;
                        animationCurrentGoal.Y *= ConstantHolder.HexagonGrid_HexSizeY;
                        animationCurrentGoal -= originScreenPos;
                        animationCurrentGoal += new Vector2(ConstantHolder.HexagonGrid_HexSizeX / 3, ConstantHolder.HexagonGrid_HexSizeY);
                        animatingActor = selectedPerson;
                        spaceArray[(int)selectedPerson.GridPosition.X, (int)selectedPerson.GridPosition.Y].removeActor();
                        selectedPerson = null;
                        changeState(GridState.selectedMoving);
                    }
                    break;

                case GridState.selectedMoving:
                    break;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Main update function, based on pre-updated Control static class.
        /// </summary>
        public void updateGrid()
        {
            if (Controls.ButtonsLastDown[(int)Controls.ButtonNames.leftMouse])
            {
                if (Controls.ButtonsDown[(int)Controls.ButtonNames.leftMouse])
                {
                    moveGrid(Controls.MousePosition - Controls.MouseLastPosition);
                }
                else
                {
                    onClick(Controls.MousePosition);
                    
                }
            }
            foreach (GridSpace space in spaceArray)
            {
                space.Update();
            }
            switch (gridState)
            {
                case GridState.castAnimating:
                    break;

                case GridState.noSelection:
                    break;

                case GridState.selectedCastAvailable:
                    break;

                case GridState.selectedMotionAvailable:
                    break;

                case GridState.selectedMoving:
                    if (Vector2.Distance(animationCurrentGoal, animatingActorScreenPos) < 3)
                    {
                        animatingActorScreenPos = animationCurrentGoal;
                        if (currentPath.Count > 0)
                        {
                            animationCurrentGoal = currentPath.First.Value;
                            currentPath.RemoveFirst();
                            if ((int)animationCurrentGoal.X % 2 == 1)
                            {
                                animationCurrentGoal.Y += 0.5f;
                            }
                            animationCurrentGoal.X *= 3 * ConstantHolder.HexagonGrid_HexSizeX / 4;
                            animationCurrentGoal.Y *= ConstantHolder.HexagonGrid_HexSizeY;
                            animationCurrentGoal -= originScreenPos;
                            animationCurrentGoal += new Vector2(ConstantHolder.HexagonGrid_HexSizeX / 3, ConstantHolder.HexagonGrid_HexSizeY);
                        }
                        else
                        {
                            changeState(GridState.noSelection);
                            animationFinalGoal.tryPutActor(animatingActor);
                            animatingActor = null;
                            break;
                        }
                    }
                    Vector2 movement = Vector2.Normalize(animationCurrentGoal - animatingActorScreenPos);
                    movement *= 3;
                    animatingActorScreenPos += movement;
                    break;

            }
        }
 /// <summary>
 /// Get rid of the actor in this space.
 /// </summary>
 /// <returns>The removed actor</returns>
 public Actor removeActor()
 {
     Actor toReturn = currentActor;
     isOccupied = false;
     currentActor = null;
     return toReturn;
 }
 /// <summary>
 /// Attempts to put an actor in this space.
 /// </summary>
 /// <param name="newOccupant">Actor to be placed</param>
 /// <returns>True if the space was empty and now has the new occupant, false if it was already occupied.</returns>
 public bool tryPutActor(Actor newOccupant)
 {
     if (!isOccupied)
     {
         currentActor = newOccupant;
         currentActor.setParent(parent);
         currentActor.setPosition(gridPos);
     }
     else
         return false;
     isOccupied = true;
     return true;
 }