コード例 #1
0
        public void Update(EntityTeam team, EntityReport report)
        {
            //_report = report;

            if (team.TeamMembers.Length == 0) return;

            var entity = team.TeamMembers[0];

            var cm = Atlas.GetManager<CameraManager>();
            Vector2 v = Vector2.Zero;
            var keys = Atlas.Input;

            v += (keys.IsKeyDown(Keys.Up) ? 1 : 0) * cm.Up
                + (keys.IsKeyDown(Keys.Down) ? -1 : 0) * cm.Up
                + (keys.IsKeyDown(Keys.Right) ? 1 : 0) * cm.Right
                + (keys.IsKeyDown(Keys.Left) ? -1 : 0) * cm.Right;

            entity.TryMove(v);
            entity.TryCrouching(keys.IsKeyDown(Keys.LeftControl));

            foreach (var t in keys.GetTouchCollection())
            {
                v = cm.GetWorldPosition(t.Position, Vector2.One) - entity.Position;
            }

            entity.TryFace((float)Math.Atan2(v.Y, v.X));
        }
コード例 #2
0
ファイル: FactSheet.cs プロジェクト: Racura/IntelligentRobots
        public void UpdateFactSheet(EntityReport report)
        {
            List<EntityStruct> list = new List<EntityStruct>();

            foreach (var sight in report.SightList)
            {
                for (int i = 0; i < sight.Value.Length; ++i )
                    CompareEntities(sight.Value[i], report.TimeStamp);
            }
        }
コード例 #3
0
        public void exploreTile(Entity entity, EntityReport report)
        {
            float ratioX = report.Trunk.Width / WORLD_SPLITS;
            float ratioY = report.Trunk.Height / WORLD_SPLITS;

            int exploredX = (int)(entity.Position.X / ratioX);
            int exploredY = (int)(entity.Position.Y / ratioY);

            if (exploredInfo[exploredX][exploredY] == 0)
            {
                exploredInfo[exploredX][exploredY] = 1;
                yCount[exploredX]--;
            }
        }
コード例 #4
0
 public void Update(EntityTeam team, EntityReport report)
 {
 }
コード例 #5
0
        public override void Update(string arg)
        {
            base.Update(arg);
            _trunk.Update();

            if (Atlas.Input.IsKeyJustReleased(Keys.Enter))
            {
                try {
                    var json = _trunk.ToJson();
                    GridJson.ToFile("map.json", json);
                } catch { }
            }

            var teams = Atlas.GetManager<EntityManager>().Teams;

            List<Entity> entityList = new List<Entity>();

            foreach (var t in teams)
            {
                foreach (var e in t.Value.TeamMembers)
                {
                    MapCollide(e);

                    entityList.Add(e);
                }
            }

            var state = Atlas.GetStateController<Component.StateController>();

            if (state.State == Component.StateController.GameState.Combat)
            {
                foreach (var t in teams)
                {
                    EntityReport report = new EntityReport(_trunk, state.TimePassed);

                    if (t.Value.Delegate == null) continue;

                    foreach (var e1 in t.Value.TeamMembers)
                    {
                        List<EntityStruct> _list = new List<EntityStruct>();

                        Vector2 facingPos = new Vector2((float)Math.Cos(e1.Angle + e1.FOV * 0.5), (float)Math.Sin(e1.Angle + e1.FOV * 0.5));
                        Vector2 facingNeg = new Vector2((float)Math.Cos(e1.Angle - e1.FOV * 0.5), (float)Math.Sin(e1.Angle - e1.FOV * 0.5));

                        foreach (var e2 in entityList)
                        {
                            if (e1 == e2) continue;

                            var n = Vector2.Normalize(e2.Position - e1.Position);

                            for (int i = 0; i < 5; i++)
                            {
                                Vector2 testNormal = new Vector2(
                                    e2.Position.X + n.Y * e2.Radius * ((i - 2f) / 2),
                                    e2.Position.Y - n.X * e2.Radius * ((i - 2f) / 2));

                                if (e1.FOV < Math.PI * 2
                                    && ((e1.FOV < Math.PI
                                        && (facingPos.X * (testNormal.Y - e1.Position.Y) - facingPos.Y * (testNormal.X - e1.Position.X) > 0
                                            || facingNeg.X * (testNormal.Y - e1.Position.Y) - facingNeg.Y * (testNormal.X - e1.Position.X) < 0))
                                    || (facingPos.X * (testNormal.Y - e1.Position.Y) - facingPos.Y * (testNormal.X - e1.Position.X) > 0
                                            && facingNeg.X * (testNormal.Y - e1.Position.Y) - facingNeg.Y * (testNormal.X - e1.Position.X) < 0)))
                                    continue;

                                if (Trunk.Raytrace(e1.Position, testNormal, (e1.Crouching || e2.Crouching) ? 1 : 2))
                                {
                                    _list.Add(e2.GetStruct());
                                    break;
                                }
                            }
                        }
                        report.SightList.Add(e1, _list.ToArray());
                    }

                    t.Value.Delegate.Update(t.Value, report);
                }
            }

            Atlas.GetManager<AtlasEngine.BasicManagers.CameraManager>().LookAt(1,
                new Vector2(Trunk.Width * 0.5f, Trunk.Height * 0.5f),
                Math.Max(Trunk.Width, Trunk.Height) * 0.55f, 1, 1);
        }
コード例 #6
0
        public void Update(EntityReport report)
        {
            Vector2? destination;
            if (parentDelegate.winPoint.HasValue)
            {
                destination = parentDelegate.winPoint;
            }
            else
            {
                destination = getWinPosition(entity, report);
                if (destination.HasValue)
                {
                    parentDelegate.sendWinPoint(destination.Value);
                }
            }
            //entity.TryCrouching((report.SightList.Count > 0));
            parentDelegate.exploreTile(entity, report);

            scan(entity, report);
            //If we've found the win position, run for it!
            if (destination.HasValue && !panic)
            {
                pathToSpecificPoint(entity, report, destination.Value);
                panic = true;
                panicTimer = 5f;
            }

            if (_vectorList == null || _vectorList.Count < 2)
            {
                if (report.Trunk.TryFindPath(entity.Position, new Vector2(report.Trunk.Width * Atlas.Rand, report.Trunk.Height * Atlas.Rand), entity.Radius, out _vectorList))
                {
                    _version = report.Trunk.Version;
                }
            }
            else if (_version != report.Trunk.Version)
            {
                if (!pathToSamePoint(entity, report))
                {
                    pathToRandomPoint(entity, report);
                }
            }

            if (_vectorList != null && _vectorList.Count > 1)
            {
                _direction = _vectorList[1] - entity.Position;
                entity.TryMove(_direction);

                if (hitPoint(entity.Position, _vectorList[1], entity.Radius)) // fixed the idle problem
                {
                    _pastVectorList.AddFirst(_vectorList[0]);
                    _vectorList.RemoveAt(0);
                    if (_pastVectorList.Count > 30)
                    {
                        _pastVectorList.RemoveLast();
                    }
                }
            }
            else
            {
                entity.TryMove(Vector2.Zero);

            }

            if (hiding)
            {
                hidingTimer -= Atlas.Elapsed;
                if (hidingTimer < 0)
                {
                    hiding = false;
                    entity.TryCrouching(false);
                }
                else
                {
                    entity.TryCrouching(true);
                }

            }

            //Spin around to look for the win point and threats
            if (!panic)
            {
                timer += Atlas.Elapsed;
                if (timer > 2f)
                {
                    float angle = entity.Angle + 2;
                    entity.TryFace(angle);
                }
                else
                {
                    entity.TryFace(getFloatAngle(_direction));
                }
                if (timer > 3.0f)
                {
                    timer = 0;

                }
            }
            else
            {
                entity.TryFace(getFloatAngle(_direction));
                panicTimer -= Atlas.Elapsed;
                if (panicTimer <= 0)
                {
                    panic = false;

                }
            }
        }
コード例 #7
0
        private void scan(Entity entity, EntityReport report)
        {
            if (report.SightList.ContainsKey(entity)) //fixed null
            {
                foreach (var s in report.SightList[entity])
                {
                    if (s.type == typeof(VictoryComputerEntity))
                    {
                        //Found the win Computer
                        parentDelegate.sendWinPoint(s.position);
                    }

                    else if (s.type == typeof(SeekerEntity))
                    {
                        //Found a seeker
                        parentDelegate.sendSeekerThreat(s.position);

                    }

                    else if (s.type == typeof(HunterEntity))
                    {
                        //Found a hunter RUN AWAY
                        parentDelegate.sendHunterThreat(s.position);

                        if (hiding)
                        {
                            runFrom(s.position, report);
                        }
                        else
                        {
                            hideFrom(s.position, report);
                        }
                    }
                }
            }
        }
コード例 #8
0
 private void runFrom(Vector2 vector2, EntityReport report)
 {
     hidingTimer = 0f;
     //hiding = false;
     panic = true;
     panicTimer = 3f;
 }
コード例 #9
0
 private void pathToSpecificPoint(Entity entity, EntityReport report, Vector2 pos)
 {
     if (report.Trunk.TryFindPath(entity.Position, pos, entity.Radius, out _vectorList))
     {
         _version = report.Trunk.Version;
     }
 }
コード例 #10
0
 private bool pathToSamePoint(Entity entity, EntityReport report)
 {
     if (report.Trunk.TryFindPath(entity.Position, _vectorList[_vectorList.Count - 1], entity.Radius, out _vectorList))
     {
         _version = report.Trunk.Version;
         return true;
     }
     return false;
 }
コード例 #11
0
 private void pathToRandomPoint(Entity entity, EntityReport report)
 {
     Vector2 point = parentDelegate.whereShouldIGo(entity);
     if (point.X == -1 && point.Y == -1)
     {
         if (_vectorList == null || _vectorList.Count < 2)
         {
             if (report.Trunk.TryFindPath(entity.Position, new Vector2(report.Trunk.Width * Atlas.Rand, report.Trunk.Height * Atlas.Rand), entity.Radius, out _vectorList))
             {
                 _version = report.Trunk.Version;
             }
         }
     }
     else
     {
         pathToSpecificPoint(entity, report, parentDelegate.whereShouldIGo(entity));
     }
 }
コード例 #12
0
 //Try and hide from a point
 private void hideFrom(Vector2 vector2, EntityReport report)
 {
     if (panic)
     {
         return;
     }
     hiding = true;
     hidingTimer = 3f;
     _vectorList.Clear();
     _vectorList.AddRange(_pastVectorList);
 }
コード例 #13
0
        private Vector2? getWinPosition(Entity entity, EntityReport report)
        {
            //var e = report.SightList[entity][0].type == typeof(VictoryComputerEntity);

            if (report.SightList.ContainsKey(entity)) //fixed null
            {
                foreach (var s in report.SightList[entity])
                {
                    if (s.type == typeof(VictoryComputerEntity))
                    {

                        return s.position;
                    }
                }
            }
            return null;
        }
コード例 #14
0
        public void Update(EntityTeam team, EntityReport report)
        {
            Team = team;
            Report = report;

            FactSheet.UpdateFactSheet(report);

            foreach (var s in _subs)
            {
                s.Update();
            }
        }
コード例 #15
0
        public void Update(EntityTeam entityTeam, EntityReport report)
        {
            ratioX = report.Trunk.Width / WORLD_SPLITS;
            ratioY = report.Trunk.Height / WORLD_SPLITS;

            entityTeam.Color = Color.PeachPuff;
            if (entityTeam.TeamMembers.Length == 0) return;

            foreach (AlekEntitySubDelegate a in subDelegates)
            {
                a.Update(report);
            }
        }