Пример #1
0
 private void SetConsoleSymbolForCell(RLNET.RLConsole console, RogueSharp.Cell cell)
 {
     // if not explored don't draw
     if (!cell.IsExplored)
     {
         return;
     }
     // if cell in FOV draw with lighter colour
     if (IsInFov(cell.X, cell.Y))
     {
         if (cell.IsWalkable)
         {
             console.Set(cell.X, cell.Y, Colours.FloorFov, Colours.FloorBackgroundFov, '.');
         }
         else
         {
             console.Set(cell.X, cell.Y, Colours.WallFov, Colours.WallBackgroundFov, '#');
         }
     }
     else
     {
         if (cell.IsWalkable)
         {
             console.Set(cell.X, cell.Y, Colours.Floor, Colours.FloorBackground, '.');
         }
         else
         {
             console.Set(cell.X, cell.Y, Colours.Wall, Colours.WallBackground, '#');
         }
     }
 }
        public void MoveToCenterOfGivenCell(RogueSharp.Cell NextCell, Level level, GraphicsDevice graphicsDevice)
        {
            int PosX = NextCell.X * level.cellSize + level.cellSize / 2;
            int PosY = NextCell.Y * level.cellSize + level.cellSize / 2;

            if (Math.Abs(Center.Y - PosY) > Speed)
            {
                if (Center.Y - PosY > Speed)
                {
                    Move(Directions.Top, level, graphicsDevice);
                }
                if (Center.Y - PosY < Speed)
                {
                    Move(Directions.Bottom, level, graphicsDevice);
                }
            }

            if (Math.Abs(Center.X - PosX) > Speed)
            {
                if (Center.X - PosX > Speed)
                {
                    Move(Directions.Left, level, graphicsDevice);
                }
                if (Center.X - PosX < Speed)
                {
                    Move(Directions.Right, level, graphicsDevice);
                }
            }
        }
Пример #3
0
        private Vector2 CenteredPosition(RogueSharp.Cell cell, bool clampToMap = false)
        {
            var _cameraPosition = new Vector2(cell.X * Statics.SpriteWidth, cell.Y * Statics.SpriteHeight);
            var _cameraCenteredOnTilePosition = new Vector2(_cameraPosition.X + Statics.SpriteWidth / 2, _cameraPosition.Y + Statics.SpriteHeight / 2);

            return(clampToMap ? MapClampedPosition(_cameraCenteredOnTilePosition) : _cameraCenteredOnTilePosition);
        }
Пример #4
0
 public void SetAnimation(string attackName, string animationName, int cellX, int cellY)
 {
     RogueSharp.Cell cell = currentLevel.map.GetCell(cellX, cellY);
     if (cell.IsWalkable)
     {
         currentLevel.attackAnimations.Add(new AttackAnimation(levelManager.Content, attackName, animationName, cellX, cellY, currentLevel.cellSize));
     }
 }
        public static bool checkCollisionInGivenCell(RogueSharp.Cell futureNextCell, Level level, GraphicsDevice graphicsDevice)
        {
            if (level.grid.GetCellCost(new Position(futureNextCell.X, futureNextCell.Y)) > 1.0f)
            {
                return(true);
            }

            return(false);
        }
Пример #6
0
        public List <MapCell> FindPath(Point source, Point destination, IMap map, Func <ICell, ICell, bool> IsValidStep)
        {
            var rogueSharpSource      = new RogueSharp.Cell(source.X, source.Y, true, true);
            var rogueSharpDestination = new RogueSharp.Cell(destination.X, destination.Y, true, true);
            var rogueSharpMap         = map.ToRogueSharpMap();

            var path = implementation.FindPath(rogueSharpSource, rogueSharpDestination, rogueSharpMap, WrapIsValidStep(IsValidStep));

            return(path.Select(c => new MapCell(new Point(c.X, c.Y), CellType.Maze, true, true)).ToList());
        }
        public bool isCenterOfGivenCell(RogueSharp.Cell NextCell, Level level, GraphicsDevice graphicsDevice)
        {
            int PosX = NextCell.X * level.cellSize + level.cellSize / 2;
            int PosY = NextCell.Y * level.cellSize + level.cellSize / 2;

            if (Math.Abs(Center.Y - PosY) <= Speed && Math.Abs(Center.X - PosX) <= Speed)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public static RogueSharp.Cell getCellFromDirection(RogueSharp.Cell currentCell, Character.Directions currentDirection, Level level)
        {
            if (currentDirection == Character.Directions.Top)
            {
                return(level.map.GetCell(currentCell.X, currentCell.Y - 1));
            }

            if (currentDirection == Character.Directions.Bottom)
            {
                return(level.map.GetCell(currentCell.X, currentCell.Y + 1));
            }

            if (currentDirection == Character.Directions.Left)
            {
                return(level.map.GetCell(currentCell.X - 1, currentCell.Y));
            }

            if (currentDirection == Character.Directions.Right)
            {
                return(level.map.GetCell(currentCell.X + 1, currentCell.Y));
            }

            if (currentDirection == Character.Directions.TopLeft)
            {
                return(level.map.GetCell(currentCell.X - 1, currentCell.Y - 1));
            }

            if (currentDirection == Character.Directions.TopRight)
            {
                return(level.map.GetCell(currentCell.X + 1, currentCell.Y - 1));
            }

            if (currentDirection == Character.Directions.BottomLeft)
            {
                return(level.map.GetCell(currentCell.X - 1, currentCell.Y + 1));
            }

            if (currentDirection == Character.Directions.BottomRight)
            {
                return(level.map.GetCell(currentCell.X + 1, currentCell.Y + 1));
            }

            return(null);
        }
Пример #9
0
        public void Move(RogueSharp.Cell cell)
        {
            Point mv = new Point(0, 0);

            if (cell.X > Position.X)
            {
                mv += new Point(1, 0);
            }
            if (cell.X < Position.X)
            {
                mv += new Point(-1, 0);
            }
            if (cell.Y < Position.Y)
            {
                mv += new Point(0, -1);
            }
            if (cell.Y > Position.Y)
            {
                mv += new Point(0, 1);
            }

            Move(mv);
        }
        public static List <Character.Directions> checkIfOneOfDoubleDirectionsIsOk(RogueSharp.Cell currentCell, Character.Directions currentDirection, Level level, GraphicsDevice graphicsDevice)
        {
            List <Character.Directions> dirList = new List <Character.Directions>(2);

            if (currentDirection == Character.Directions.TopLeft)
            {
                Character.Directions top  = Character.Directions.Top;
                Character.Directions left = Character.Directions.Left;

                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, top, level), level, graphicsDevice))
                {
                    dirList.Add(top);
                }
                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, left, level), level, graphicsDevice))
                {
                    dirList.Add(left);
                }

                return(dirList);
            }

            if (currentDirection == Character.Directions.TopRight)
            {
                Character.Directions top   = Character.Directions.Top;
                Character.Directions right = Character.Directions.Right;

                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, top, level), level, graphicsDevice))
                {
                    dirList.Add(top);
                }
                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, right, level), level, graphicsDevice))
                {
                    dirList.Add(right);
                }

                return(dirList);
            }

            if (currentDirection == Character.Directions.BottomLeft)
            {
                Character.Directions bottom = Character.Directions.Bottom;
                Character.Directions left   = Character.Directions.Left;

                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, bottom, level), level, graphicsDevice))
                {
                    dirList.Add(bottom);
                }
                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, left, level), level, graphicsDevice))
                {
                    dirList.Add(left);
                }

                return(dirList);
            }

            if (currentDirection == Character.Directions.BottomRight)
            {
                Character.Directions bottom = Character.Directions.Bottom;
                Character.Directions right  = Character.Directions.Right;

                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, bottom, level), level, graphicsDevice))
                {
                    dirList.Add(bottom);
                }
                if (!checkCollisionInGivenCell(getCellFromDirection(currentCell, right, level), level, graphicsDevice))
                {
                    dirList.Add(right);
                }

                return(dirList);
            }
            return(dirList);
        }
Пример #11
0
 public void SetIsWalkable(int x, int y, bool isWalkable)
 {
     RogueSharp.Cell cell = (RogueSharp.Cell)GetCell(x, y);
     SetCellProperties(cell.X, cell.Y, cell.IsTransparent, isWalkable, cell.IsExplored);
 }
        public override void Update(GameTime gameTime, Level level, GraphicsDevice graphicsDevice)
        {
            CellX = (int)Math.Floor(Center.X / level.cellSize);
            CellY = (int)Math.Floor(Center.Y / level.cellSize);
            if (CellX > 0 && CellX < level.map.Width && CellY > 0 && CellY < level.map.Height)
            {
                CurrentCell = level.map.GetCell(CellX, CellY);
            }
            if (CurrentHealth > 0)
            {
                if (calculateExpForNextLevel(Level + 1) < Experience)
                {
                    Global.SoundManager.playerLevelUP.Play();
                    calculateStatistics();
                    CurrentResource = Resource;
                    CurrentHealth   = Health;
                    Global.Gui.nextLevel(Level);
                    Level++;
                }
            }

            if (!isRangerInvisible)
            {
                level.map.ComputeFov(CellX, CellY, 15, true);
                isInvisShaderOn = false;
            }
            else
            {
                level.map.ComputeFov(0, 0, 1, false);
                isInvisShaderOn  = true;
                CurrentResource -= invisDecay;
                invisDecay      += 0.02f;
                if (CurrentResource < 0)
                {
                    Global.Gui.WriteToConsole("You are no longer invisible");
                    CurrentResource   = 0;
                    isRangerInvisible = false;
                    isInvisShaderOn   = false;
                    invisDecay        = 0.3f;
                }
            }

            actionTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (isBerserkerRageOn)
            {
                berserkerTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (berserkerTimer > howLongShouldBerserkerWork)
                {
                    timeBetweenActions  = normalTimeBetweenActions;
                    isBerserkerRageOn   = false;
                    isBerserkerShaderOn = false;
                    Global.Gui.WriteToConsole("You are no longer in Berserker Rage");
                    berserkerTimer = 0;
                }
            }


            HandleHitState(gameTime);
            HandleHealthState(gameTime);

            ManageResource();

            if (currentHealthState != HealthState.Freeze)
            {
                if (currentActionState == ActionState.Standing)
                {
                    if (ChangeDirection(level))
                    {
                        return;
                    }
                    else
                    {
                        currentDirection = GetDirection();
                    }

                    if (currentDirection != (int)Directions.None)
                    {
                        RogueSharp.Cell futureNextCell = Collision.getCellFromDirection(CurrentCell, currentDirection, level);
                        if (CellX > 0 && CellX < level.map.Width && CellY > 0 && CellY < level.map.Height)
                        {
                            if (!Collision.checkCollisionInGivenCell(futureNextCell, level, graphicsDevice))
                            {
                                NextCell           = futureNextCell;
                                currentActionState = ActionState.Moving;
                                level.grid.SetCellCost(new Position(CurrentCell.X, CurrentCell.Y), 1.0f);
                                level.grid.SetCellCost(new Position(NextCell.X, NextCell.Y), 5.0f);
                            }
                            else
                            {
                                //there is a collision in current direction
                                //we check if it is one of joined directions (top-left top-right bottom-left bottom-right)
                                //we try separate direction (for top-left we should try top, then left)

                                List <Character.Directions> dirList = Collision.checkIfOneOfDoubleDirectionsIsOk(CurrentCell, currentDirection, level, graphicsDevice);
                                if (dirList.Count > 0)
                                {
                                    foreach (Character.Directions newdir in dirList)
                                    {
                                        RogueSharp.Cell futureNextCell2 = Collision.getCellFromDirection(CurrentCell, newdir, level);
                                        if (CellX > 0 && CellX < level.map.Width && CellY > 0 && CellY < level.map.Height)
                                        {
                                            if (!Collision.checkCollisionInGivenCell(futureNextCell2, level, graphicsDevice))
                                            {
                                                NextCell           = futureNextCell2;
                                                currentActionState = ActionState.Moving;
                                                level.grid.SetCellCost(new Position(CurrentCell.X, CurrentCell.Y), 1.0f);
                                                level.grid.SetCellCost(new Position(NextCell.X, NextCell.Y), 5.0f);
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    Global.Gui.WriteToConsole("Cant go there");
                                }
                            }
                        }
                        else
                        {
                            Global.Gui.WriteToConsole("Cant go there");
                        }
                    }
                }
                else //Moving
                {
                    if (isCenterOfGivenCell(NextCell, level, graphicsDevice))
                    {
                        currentActionState = ActionState.Standing;
                    }
                    else
                    {
                        MoveToCenterOfGivenCell(NextCell, level, graphicsDevice);
                        Global.Camera.CenterOn(Center);
                    }
                }

                BasicAttack(level);
                SecondaryAttack(level);
                PositionTargetedAttackFromItem(level);
                Abillity1(level);
                Abillity2(level);
                Abillity3(level);

                CoreAbility(level);

                ToggleStatsAllocationMenu();
                ToggleStats();
                ExamineSelectedItem();
                DropItem(level, SelectedItem);
                TakeItem(level, graphicsDevice);
                SwapItem(level, SelectedItem, graphicsDevice);
                SelectItem();
                UseItem(SelectedItem);

                SetAnimations();
                _animationManager.Update(gameTime);
                Position += Velocity;
                Velocity  = Vector2.Zero;
            }
            UpdateItems(gameTime);
        }
Пример #13
0
        private List <RogueSharp.Cell> GetCellsInFrontOfCharacter(Character attaker, int cellX, int cellY, int distance)
        {
            List <RogueSharp.Cell> cells = new List <RogueSharp.Cell>(distance);

            RogueSharp.Cell nextCell = null;
            int             nextX, nextY;

            if (attaker.currentFaceDirection == Character.FaceDirections.Up)
            {
                for (int dist = 1; dist <= distance; dist++)
                {
                    nextX = cellX;
                    nextY = cellY - dist;

                    if (nextX < 0 || nextX >= currentLevel.map.Width || nextY < 0 || nextY >= currentLevel.map.Height)
                    {
                        break;
                    }
                    else
                    {
                        nextCell = currentLevel.map.GetCell(nextX, nextY);
                        if (!nextCell.IsWalkable)
                        {
                            break;
                        }
                        cells.Add(nextCell);
                    }
                }
            }
            else if (attaker.currentFaceDirection == Character.FaceDirections.Down)
            {
                for (int dist = 1; dist < distance; dist++)
                {
                    nextX = cellX;
                    nextY = cellY + dist;

                    if (nextX < 0 || nextX >= currentLevel.map.Width || nextY < 0 || nextY >= currentLevel.map.Height)
                    {
                        break;
                    }
                    else
                    {
                        nextCell = currentLevel.map.GetCell(nextX, nextY);
                        if (!nextCell.IsWalkable)
                        {
                            break;
                        }
                        cells.Add(nextCell);
                    }
                }
            }
            else if (attaker.currentFaceDirection == Character.FaceDirections.Left)
            {
                for (int dist = 1; dist < distance; dist++)
                {
                    nextX = cellX - dist;
                    nextY = cellY;

                    if (nextX < 0 || nextX >= currentLevel.map.Width || nextY < 0 || nextY >= currentLevel.map.Height)
                    {
                        break;
                    }
                    else
                    {
                        nextCell = currentLevel.map.GetCell(nextX, nextY);
                        if (!nextCell.IsWalkable)
                        {
                            break;
                        }
                        cells.Add(nextCell);
                    }
                }
            }
            else
            {
                for (int dist = 1; dist < distance; dist++)
                {
                    nextX = cellX + dist;
                    nextY = cellY;

                    if (nextX < 0 || nextX >= currentLevel.map.Width || nextY < 0 || nextY >= currentLevel.map.Height)
                    {
                        break;
                    }
                    else
                    {
                        nextCell = currentLevel.map.GetCell(nextX, nextY);
                        if (!nextCell.IsWalkable)
                        {
                            break;
                        }
                        cells.Add(nextCell);
                    }
                }
            }

            return(cells);
        }
Пример #14
0
 public void CenterOn(RogueSharp.Cell cell)
 {
     Position = CenteredPosition(cell, true);
 }