Пример #1
0
        public void CreateEnemySpawns(TmxList<TmxObject> enemySpawns, PlayingState playingState)
        {
            LevelCollisionDetection levelCollisionDetection = new LevelCollisionDetection(TileMap, TileMap.TileSize);
            foreach (TmxObject enemypawn in enemySpawns)
            {
                Guid id = playingState.CreateEntity();
                playingState.Entities.Where(x => x.ID == id).First().ComponentFlags = ComponentMasks.Enemy;                

                playingState.DirectionComponents[id] = new DirectionComponent() { Direction = (float)(enemypawn.Rotation * (Math.PI / 180)) };
                playingState.DisplayComponents[id] = new DisplayComponent() { Source = new Rectangle(343, 470, TileMap.TileSize, TileMap.TileSize) };
                playingState.HealthComponents[id] = new HealthComponent() { Health = 15 };
                playingState.PositionComponents[id] = new PositionComponent() { Position = new Vector2((float)enemypawn.X + (TileMap.TileSize / 2), (float)enemypawn.Y + (TileMap.TileSize / 2)) };
                playingState.VelocityComponents[id] = new VelocityComponent() { xVelocity = 0f, yVelocity = 0f, xTerminalVelocity = 3f, yTerminalVelocity = 3f };
                playingState.AccelerationComponents[id] = new AccelerationComponent() { xAcceleration = 3f, yAcceleration = 3f };
                playingState.DamageComponents[id] = new DamageComponent()
                {
                    AttackRange = 1 * TileMap.TileSize,
                    Damage = 5
                };

                //our origin is going to offset our bounded box
                playingState.AABBComponents[id] = new AABBComponent() { BoundedBox = new Rectangle((int)enemypawn.X, (int)enemypawn.Y, TileMap.TileSize, TileMap.TileSize) };

                //parse patrol paths
                string patrolPaths = enemypawn.Properties["PatrolPath"];
                List<Vector2> PatrolVectors = new List<Vector2>();
                if (!string.IsNullOrWhiteSpace(patrolPaths))
                {
                    string[] newPaths = patrolPaths.Split('|'); 
                    
                    for (int i = 0; i < newPaths.Length; i++)
                    {
                        newPaths[i] = newPaths[i].Replace("(", "");
                        newPaths[i] = newPaths[i].Replace(")", "");
                        int x = Int32.Parse(newPaths[i].Split(',')[0]);
                        int y = Int32.Parse(newPaths[i].Split(',')[1]);

                        //center our points too
                        x = (x * TileMap.TileSize) + (TileMap.TileSize / 2);
                        y = (y * TileMap.TileSize) + (TileMap.TileSize / 2);

                        PatrolVectors.Add(new Vector2(x, y));
                    }
                }

                playingState.AIComponents[id] = new AIComponent()
                {
                    ActiveState = new Stack<AIState>(),
                    LineOfSight = 6 * TileMap.TileSize,
                    PatrolPath = PatrolVectors,
                    ActivePath = new LinkedList<Tile>(),
                    Astar = TileMap.aStar,
                    AITree = AIPawnSystem.CreatePawnTree(id, playingState, levelCollisionDetection, TileMap.TileSize, TileMap.TileSize)
                };
                playingState.AIComponents[id].ActiveState.Push(AIState.STILL);
                playingState.LabelComponents[id] = new LabelComponent() { Label = "", Position = new Vector2((float)enemypawn.X, (float)(enemypawn.Y - 5)) };
            }
        }
Пример #2
0
        public void CreateBoundingRects(TmxList<TmxObject> rectangles, PlayingState playingState)
        {
            foreach (TmxObject rectangle in rectangles)
            {
                Guid id = playingState.CreateEntity();
                playingState.Entities.Where(l => l.ID == id).First().ComponentFlags = ComponentMasks.LevelObjects;
                Vector2 position = new Vector2((float)rectangle.X, (float)rectangle.Y);
                Rectangle boundedBox = new Rectangle((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height);

                playingState.DirectionComponents[id] = new DirectionComponent() { Direction = 0f };
                playingState.DisplayComponents[id] = new DisplayComponent() { Source = new Rectangle(342, 108, TileMap.TileSize, TileMap.TileSize) };
                playingState.PositionComponents[id] = new PositionComponent() { Position = position };
                playingState.AABBComponents[id] = new AABBComponent() { BoundedBox = boundedBox };
                playingState.MapObjectComponents[id] = new MapObjectComponent() { Type = MapObjectType.Wall };
            }
        }
Пример #3
0
        public void CreatePlayerSpawn(TmxList<TmxObject> playerSpawns, PlayingState playingState)
        {
            foreach (TmxObject playerspawn in playerSpawns)
            {
                Guid id = playingState.CreateEntity();
                playingState.Entities.Where(x => x.ID == id).First().ComponentFlags = ComponentMasks.Player;

                playingState.DirectionComponents[id] = new DirectionComponent() { Direction = 0f };
                playingState.DisplayComponents[id] = new DisplayComponent() { Source = new Rectangle(451, 470, TileMap.TileSize, TileMap.TileSize) };
                playingState.HealthComponents[id] = new HealthComponent() { Health = 100 };
                playingState.PositionComponents[id] = new PositionComponent() { Position = new Vector2((float)playerspawn.X, (float)playerspawn.Y) };
                playingState.VelocityComponents[id] = new VelocityComponent() { xVelocity = 0f, yVelocity = 0f, xTerminalVelocity = 6f, yTerminalVelocity = 6f };
                playingState.AccelerationComponents[id] = new AccelerationComponent() { xAcceleration = 6f, yAcceleration = 6f };

                //our origin is going to offset our bounded box
                playingState.AABBComponents[id] = new AABBComponent(){ BoundedBox = new Rectangle((int)playerspawn.X - (TileMap.TileSize / 2), (int)playerspawn.Y - (TileMap.TileSize / 2), TileMap.TileSize, TileMap.TileSize)};
            }
        }