private void CreateHaystack(float x, float y)
        {
            ObstacleEntity haystack = new ObstacleEntity(ObstacleType.Haystack, x, y);

            haystack.FloorY       = Floor.Y;
            haystack.ImageLoaded += Entity_ImageLoaded;

            obstacleEntities.Add(haystack);
        }
示例#2
0
 public void Despawner(ResourceType t, ObstacleEntity obs)
 {
     if (null == obs)
     {
         return;
     }
     TSCData.Instance.ObstacleDic.Remove(obs.Index);
     PoolMgr.Instance.Despawner(t, obs.Cache);
 }
示例#3
0
    void InistantObstacle(Obstacle obstacle)
    {
        float      PosX = obstacle.PosX;
        float      PosY = obstacle.PosY;
        GameObject go   = Spawner((int)obstacle.ObsType, new Vector3(obstacle.PosX, obstacle.Poshh, obstacle.PosY), ResourceType.RESOURCE_OBSTACLE, GameMgr.Instance.ObstacleRoot);
        Transform  temp = go.transform;

        temp.localScale    = new Vector3(obstacle.Width, obstacle.Hh, obstacle.Height);
        temp.localRotation = Quaternion.Euler(0, obstacle.Rotate, 0);

        ObstacleEntity entity = Util.AddComponent <ObstacleEntity>(go);

        entity.Index    = obstacle.Id;
        entity.Width    = obstacle.Width;
        entity.Height   = obstacle.Height;
        entity.Obs_type = obstacle.ObsType;
        TSCData.Instance.ObstacleDic[entity.Index] = entity;
    }
示例#4
0
文件: NetEntity.cs 项目: k3498gg/TSC
    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        if (!IsAlive)
        {
            return;
        }

        Transform temp = hit.transform;

        if (temp.CompareTag(AppConst.TAG_OBSTACLE))
        {
            ObstacleEntity entity = temp.GetComponent <ObstacleEntity>();
            if (null != entity)
            {
                Vector3 dir = CacheModel.forward;
                switch (entity.Obs_type)
                {
                case ObstType.ObsType_TA:
                    UpdateDir(Vector3.zero - CacheModel.position);
                    break;

                case ObstType.ObsType_TB:
                case ObstType.ObsType_TC:
                    UpdateDir(CacheModel.position - temp.position);
                    break;
                }
            }
            EndCurrentStateToOtherState(StateID.Walk);
        }
        else if (temp.CompareTag(AppConst.TAG_NETENTITY))
        {
            NetEntity entity = temp.GetComponent <NetEntity>();
            if (null != entity)
            {
                if (!entity.IsAlive)
                {
                    return;
                }

                Vector3 dir = CacheModel.position - temp.position;
                UpdateDir(dir);

                if (Util.CanKillBody(entity.Occupation, Occupation))
                {
                    entity.EndCurrentStateToOtherState(StateID.Walk);

                    if (IsProtect())
                    {
                        if (entity.IsUsingSkill())
                        {
                            HitDir = CacheModel.TransformVector(entity.CacheModel.position - CacheModel.position);
                            EndCurrentStateToOtherState(StateID.CrashPlayer);
                        }
                        else
                        {
                            EndCurrentStateToOtherState(StateID.Walk);
                        }
                    }
                    else
                    {
                        BeKilled();
                        entity.KillBody();
                        EndCurrentStateToOtherState(StateID.Dead);
                    }
                }
                else if (Util.CanKillBody(Occupation, entity.Occupation))
                {
                    EndCurrentStateToOtherState(StateID.Walk);

                    if (entity.IsProtect())
                    {
                        if (IsUsingSkill())
                        {
                            entity.HitDir = entity.CacheModel.TransformVector(CacheModel.position - entity.CacheModel.position);
                            entity.EndCurrentStateToOtherState(StateID.CrashPlayer);
                        }
                        else
                        {
                            entity.EndCurrentStateToOtherState(StateID.Walk);
                        }
                    }
                    else
                    {
                        entity.BeKilled();
                        KillBody();
                        entity.EndCurrentStateToOtherState(StateID.Dead);
                    }
                }
                else
                {
                    if (entity.IsUsingSkill())
                    {
                        HitDir = entity.CacheModel.TransformVector(entity.CacheModel.position - CacheModel.position);
                        EndCurrentStateToOtherState(StateID.CrashPlayer);
                    }
                    else
                    {
                        EndCurrentStateToOtherState(StateID.Walk);
                    }

                    if (IsUsingSkill())
                    {
                        entity.HitDir = entity.CacheModel.TransformVector(CacheModel.position - entity.CacheModel.position);
                        entity.EndCurrentStateToOtherState(StateID.CrashPlayer);
                    }
                    else
                    {
                        entity.EndCurrentStateToOtherState(StateID.Walk);
                    }
                }
            }
        }
        else if (temp.CompareTag(AppConst.TAG_PLAYER))
        {
            //Vector3 dir = CacheModel.position - temp.position;
            //UpdateDir(dir);
            if (!GameMgr.Instance.MainEntity.IsAlive)
            {
                return;
            }

            if (Util.CanKillBody(GameMgr.Instance.MainEntity.Occupation, Occupation))
            {
                GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.Idle);

                if (IsProtect())
                {
                    if (GameMgr.Instance.MainEntity.IsUsingSkill())
                    {
                        HitDir = CacheModel.position - GameMgr.Instance.MainEntity.CacheModel.position;
                        EndCurrentStateToOtherState(StateID.CrashPlayer);
                    }
                    else
                    {
                        EndCurrentStateToOtherState(StateID.Walk);
                    }
                }
                else
                {
                    BeKilled();
                    GameMgr.Instance.MainEntity.KillBody();
                    EndCurrentStateToOtherState(StateID.Dead);
                }
            }
            else if (Util.CanKillBody(Occupation, GameMgr.Instance.MainEntity.Occupation))
            {
                EndCurrentStateToOtherState(StateID.Walk);

                if (GameMgr.Instance.MainEntity.IsProtect())
                {
                    if (IsUsingSkill())
                    {
                        GameMgr.Instance.MainEntity.HitDir = GameMgr.Instance.MainEntity.CacheModel.position - CacheModel.position;
                        GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.CrashPlayer);
                    }
                    else
                    {
                        if (GameMgr.Instance.MainEntity.IsForceDrag)
                        {
                            GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.Walk);
                        }
                        else
                        {
                            GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.Idle);
                        }
                        //GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.Idle);
                    }
                }
                else
                {
                    GameMgr.Instance.MainEntity.BeKilled();
                    KillBody();
                    GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.Dead);
                }
            }
            else
            {
                if (GameMgr.Instance.MainEntity.IsUsingSkill())
                {
                    HitDir = (CacheModel.position - GameMgr.Instance.MainEntity.CacheModel.position);
                    EndCurrentStateToOtherState(StateID.CrashPlayer);
                }
                else
                {
                    if (IsUsingSkill())
                    {
                        GameMgr.Instance.MainEntity.HitDir = GameMgr.Instance.MainEntity.CacheModel.position - CacheModel.position;
                        GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.CrashPlayer);
                    }
                    else
                    {
                        if (GameMgr.Instance.MainEntity.IsForceDrag)
                        {
                            GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.Walk);
                        }
                        else
                        {
                            GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.Idle);
                        }
                        //GameMgr.Instance.MainEntity.EndCurrentStateToOtherState(RoleStateID.Idle);
                    }
                    //EndCurrentStateToOtherState(StateID.Walk);
                }
            }
        }
    }
        private void CreateChest(float x, float y)
        {
            ObstacleEntity chest = new ObstacleEntity(ObstacleType.Chest, x, y);

            obstacleEntities.Add(chest);
        }
        private void CreateEnhancedChest(float x, float y)
        {
            ObstacleEntity chest = new ObstacleEntity(ObstacleType.EnhancedChest, x: x, y: y);

            obstacleEntities.Add(chest);
        }
示例#7
0
 public ObstacleRenderer(Game game, ObstacleEntity owner)
     : base(game, owner)
 {
 }
示例#8
0
 public ObstacleLogical(Game game, ObstacleEntity owner)
     : base(game, owner)
 {
 }
示例#9
0
        public override Vector2D Calculate()
        {
            double dBoxLength = this.minDectionBoxLength + (this.ME.Pos.Speed() / this.ME.MaxSpeed) * this.minDectionBoxLength;

            List <ObstacleEntity> inRangeObstacles = this.getObstaclesInRange();

            ObstacleEntity ClosestIntersectionObstacle = null;
            Vector2D       LocalPosOfClosestObstacle   = null;
            Vector2D       localPos = new Vector2D();

            double DistToClosestIP = Double.MaxValue;

            foreach (ObstacleEntity Obstacle in this.Obstacles)
            {
                // Get the distance, and angle between your own vehicle and obstacle;
                localPos = this.ME.Pos.Clone().Sub(Obstacle.Pos);

                // if the position is behind, we can ignore the value.
                if (localPos.X >= 0)
                {
                    // if the distance from the x axis to the object's position is less
                    // than its radius + half of the width of the detection box.
                    // then there is a potential intersection
                    double ExpendedRadius = (Obstacle.Scale * 2) + this.ME.Scale * 2;

                    if (Math.Abs(localPos.Y) < ExpendedRadius)
                    {
                        // Now to do a line/circle intersection test. the center of the circle is represented by (cX, cY).
                        // The intersection points are given by the formula x = cX +/-sqrt(r^2-cY^2) for y=0.
                        // We only need to look at the smallest positive value of x because
                        // That will be the closest point of intersection.
                        double cX = localPos.X;
                        double cY = localPos.Y;

                        // We only need to calculate the sqrt part of the above equation once.
                        double SqrtPart = Math.Sqrt(ExpendedRadius * ExpendedRadius - cY * cY);

                        double ip = cX - SqrtPart;

                        if (ip <= 0)
                        {
                            ip = cX + SqrtPart;
                        }

                        // test to see if this is the closest so far. if it is, keep a
                        // record of the obstacle and it local coordinates.
                        if (ip < DistToClosestIP)
                        {
                            DistToClosestIP = ip;

                            ClosestIntersectionObstacle = Obstacle;

                            LocalPosOfClosestObstacle = localPos;
                        }
                    }
                }
            }

            // if we have found an intersecting obstacle, calculate a steering force away from it
            Vector2D SteeringForce = null;

            if (ClosestIntersectionObstacle != null)
            {
                SteeringForce = new Vector2D();
                // The closer the agent is to an object, the stronger the steering force should be.
                double Multiplier = 1.0 + (dBoxLength - LocalPosOfClosestObstacle.X) / dBoxLength;

                // calculate the lateral force
                SteeringForce.Y = (ClosestIntersectionObstacle.Scale * 2 - LocalPosOfClosestObstacle.Y) * Multiplier;

                // apply a braking force proportional to the obstacle's distance from the vehicle.
                const double BrakingWeight = 0.2;

                SteeringForce.X = (ClosestIntersectionObstacle.Scale * 2) - LocalPosOfClosestObstacle.X * BrakingWeight;
            }

            // Finally, convert the steering vector from local to world space.
            return(SteeringForce);
        }