Ejemplo n.º 1
0
        public static bool TryToMove(StateSpaceComponents spaceComponents, DungeonTile[,] dungeonGrid, PositionComponent newPosition, Guid attemptingEntity)
        {
            bool canMove = true;
            foreach (Guid id in spaceComponents.Entities.Where(x => (x.ComponentFlags & ComponentMasks.Collidable) == ComponentMasks.Collidable).Select(x => x.Id))
            {
                if((int)spaceComponents.PositionComponents[id].Position.X == (int)newPosition.Position.X &&
                    (int)spaceComponents.PositionComponents[id].Position.Y == (int)newPosition.Position.Y &&
                    id != attemptingEntity)
                {
                    spaceComponents.CollisionComponents[attemptingEntity].CollidedObjects.Add(id);
                    spaceComponents.GlobalCollisionComponent.EntitiesThatCollided.Add(attemptingEntity);
                    if(spaceComponents.CollisionComponents[id].Solid && spaceComponents.CollisionComponents[attemptingEntity].Solid)
                    {
                        canMove = false;
                    }
                }
            }

            if(canMove)
            {
                spaceComponents.PositionComponents[attemptingEntity] = newPosition;
                if(dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].Type == TileType.TILE_TALLGRASS && 
                    (spaceComponents.Entities.Where(x => (x.Id == attemptingEntity)).First().ComponentFlags & ComponentMasks.Observer) != ComponentMasks.Observer)
                {
                    dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].Type = TileType.TILE_FLATTENEDGRASS;
                    dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].Symbol = Tiles.FlatGrassSymbol;
                    dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].SymbolColor = Tiles.FlatGrassSymbolColor;
                    dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].ChanceToIgnite = Tiles.FlatGrassIgniteChance;
                }
                if (dungeonGrid[(int)newPosition.Position.X, (int)newPosition.Position.Y].Type == TileType.TILE_FIRE &&
                    (spaceComponents.Entities.Where(x => (x.Id == attemptingEntity)).First().ComponentFlags & ComponentMasks.Observer) != ComponentMasks.Observer)
                {
                    spaceComponents.DelayedActions.Add(new Action(() =>
                    {
                        //Burn effect damage is hardcoded for now
                        StatusSystem.ApplyBurnEffect(spaceComponents, attemptingEntity, StatusEffects.Burning.Turns, StatusEffects.Burning.MinDamage, StatusEffects.Burning.MaxDamage);
                    }));
                }
            }

            return canMove;
        }
Ejemplo n.º 2
0
        private static PositionComponent AIRoam(Guid entity, PositionComponent position, DungeonTile[,] dungeonGrid, Vector2 dungeonDimensions, Random random)
        {
            List<Vector2> validSpots = new List<Vector2>();
            //Select a random traversible direction and move in that direction
            for(int i = (int)position.Position.X-1; i <= (int)position.Position.X+1; i++)
            {
                for(int j = (int)position.Position.Y-1; j <= (int)position.Position.Y+1; j++)
                {
                    if(i >=0 && j >= 0 && i < (int)dungeonDimensions.X && j < (int)dungeonDimensions.Y &&  dungeonGrid[i,j].Occupiable)
                    {
                        validSpots.Add(new Vector2(i, j));
                    }
                }
            }

            //Choose a new spot
            return new PositionComponent() { Position = validSpots[random.Next(0, validSpots.Count)] };

        }
Ejemplo n.º 3
0
 private static PositionComponent AIFlee(Guid entity, PositionComponent position, Vector2 dungeonDimensions, DijkstraMapTile[,] mapToPlayer, Random random)
 {
     int lowestGridTile = 1;
     List<Vector2> validSpots = new List<Vector2>();
     for (int i = (int)position.Position.X - 1; i <= (int)position.Position.X + 1; i++)
     {
         for (int j = (int)position.Position.Y - 1; j <= (int)position.Position.Y + 1; j++)
         {
             if (i >= 0 && j >= 0 && i < (int)dungeonDimensions.X && j < (int)dungeonDimensions.Y)
             {
                 if (mapToPlayer[i, j].Weight < DevConstants.Grid.WallWeight)
                 {
                     lowestGridTile = (mapToPlayer[i, j].Weight * -1 < lowestGridTile * -1) ? mapToPlayer[i, j].Weight : lowestGridTile;
                 }
             }
         }
     }
     for (int i = (int)position.Position.X - 1; i <= (int)position.Position.X + 1; i++)
     {
         for (int j = (int)position.Position.Y - 1; j <= (int)position.Position.Y + 1; j++)
         {
             if (i >= 0 && j >= 0 && i < (int)dungeonDimensions.X && j < (int)dungeonDimensions.Y && mapToPlayer[i, j].Weight == lowestGridTile)
             {
                 validSpots.Add(new Vector2(i, j));
             }
         }
     }
     return new PositionComponent() { Position = validSpots[random.Next(0, validSpots.Count)] };
 }
Ejemplo n.º 4
0
        private static void CreateObserver(StateSpaceComponents spaceComponents, PositionComponent position)
        {
            Guid id = spaceComponents.CreateEntity();
            spaceComponents.Entities.Where(x => x.Id == id).First().ComponentFlags = ComponentMasks.Observer;
            spaceComponents.PositionComponents[id] = position;
            spaceComponents.CollisionComponents[id] = new CollisionComponent() { Solid = false, CollidedObjects = new List<Guid>() };
            spaceComponents.InputMovementComponents[id] = new InputMovementComponent() { InitialWait = .3f, IsButtonDown = false, LastKeyPressed = Keys.None, TimeIntervalBetweenMovements = .1f, TimeSinceLastMovement = 0f, TotalTimeButtonDown = 0f };
            spaceComponents.DisplayComponents[id] = new DisplayComponent()
            {
                Color = Colors.Messages.Special,
                Rotation = 0f,
                Origin = Vector2.Zero,
                Scale = 1f,
                SpriteEffect = SpriteEffects.None,
                SpriteSource = new Rectangle(0 * DevConstants.Grid.CellSize, 0 * DevConstants.Grid.CellSize, DevConstants.Grid.CellSize, DevConstants.Grid.CellSize),
                AlwaysDraw = true,
                Opacity = .6f
            };

        }
Ejemplo n.º 5
0
        private static bool CalculateMovement(ref PositionComponent pos, int xChange, int yChange, ref InputMovementComponent movementComponent, GameTime gameTime, Keys keyPressed)
        {
            bool movement = false;
            if (movementComponent.IsButtonDown)
            {
                if(keyPressed == movementComponent.LastKeyPressed)
                {
                    movementComponent.TimeSinceLastMovement += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    movementComponent.TotalTimeButtonDown += (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                else
                {
                    movementComponent.IsButtonDown = false;
                    movementComponent.TotalTimeButtonDown = 0f;
                }
            }
            if (!movementComponent.IsButtonDown || (movementComponent.TimeIntervalBetweenMovements < movementComponent.TimeSinceLastMovement 
                && movementComponent.InitialWait < movementComponent.TotalTimeButtonDown))
            {
                movementComponent.IsButtonDown = true;
                movementComponent.LastKeyPressed = keyPressed;
                movementComponent.TimeSinceLastMovement = 0f;
                movement = true;
                pos.Position.X += xChange;
                pos.Position.Y += yChange;

            }


            return movement;
        }