Exemplo n.º 1
0
        public override async ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken)
        {
            Scene clientScene = aiComponent.DomainScene();

            Unit myUnit = Client.UnitHelper.GetMyUnitFromClientScene(clientScene);

            if (myUnit == null)
            {
                return;
            }

            Log.Debug("开始巡逻");

            while (true)
            {
                XunLuoPathComponent xunLuoPathComponent = myUnit.GetComponent <XunLuoPathComponent>();
                Vector3             nextTarget          = xunLuoPathComponent.GetCurrent();
                int ret = await myUnit.MoveToAsync(nextTarget, cancellationToken);

                if (ret != 0)
                {
                    return;
                }
                xunLuoPathComponent.MoveNext();
            }
        }
Exemplo n.º 2
0
    public void LOCAL_SetPlayerNumber(int id)
    {
        Color c = playerMaterials [id - 1].color;

        playercolor = c;
        playerID    = id;
        myStats     = new Scorecard(id);
        XBox        = new Xbox360Controller(id);
        if (nametag == null)
        {
            nametag = transform.FindChild("Nametag").GetComponent <TextMesh> ();
            //change player to dif color
            //body
            //transform.GetChild (0).GetChild (0).GetComponent<SpriteRenderer> ().material = playerMaterials[id - 1];
            //5
            for (int i = 0; i < 5; ++i)
            {
                //transform.GetChild (0).GetChild (0).GetChild (i).GetComponent<SpriteRenderer> ().material = playerMaterials[id - 1];
                if (i != 4)
                {
                    //transform.GetChild (0).GetChild (0).GetChild (i).GetChild(0).GetComponent<SpriteRenderer> ().material = playerMaterials[id - 1];
                    //transform.GetChild (0).GetChild (0).GetChild (i).GetChild(0).GetChild(0).GetComponent<SpriteRenderer> ().material = playerMaterials[id - 1];
                }
            }
            //nametag.color = c;
            nametag.text = "P" + id.ToString();

            AI = GetComponent <AIComponent>();
            if (AI != null)
            {
                nametag.text = "CP" + id.ToString();
            }
        }
    }
Exemplo n.º 3
0
    public override Collider[] GetObjects(AIComponent boid)
    {
        currentPos = boid.position;

        int numberOfColliders = Physics.OverlapSphereNonAlloc(boid.position, range, colliders, layerMask);

        for (int i = 0; i < colliders.Length; i++)
        {
            // Remove boid from array
            if (i < numberOfColliders)
            {
                if (colliders[i].transform == boid.transform)
                {
                    colliders[i] = null;
                }
            }
            // Reset the rest of the slots
            else
            {
                colliders[i] = null;
            }
        }

        return(colliders);
    }
Exemplo n.º 4
0
    public GameObject player;                                    // The player object


    /// <summary>
    /// Constructor for <see cref="BTContext"/>
    /// </summary>
    /// <param name="navAgent">The <see cref="NavMeshAgent"/> on the agent</param>
    /// <param name="owner">The <see cref="AIComponent"/> script attached to the agent</param>
    /// <param name="ownerTransform">The owner's <see cref="Transform"/></param>
    /// <param name="target">The target of the agent</param>
    public BTContext(NavMeshAgent navAgent, AIComponent owner, Transform ownerTransform, GameObject target)
    {
        agent        = navAgent;
        contextOwner = owner;
        transform    = ownerTransform;
        player       = target;
    }
Exemplo n.º 5
0
    public override void Execute(List <BasicEntity> entities)
    {
        for (int i = 0; i < entities.Count; i++)
        {
            BasicEntity       e            = entities [i];
            DeadComponent     dead         = e.GetComponent <DeadComponent> ();
            PropertyComponent propertyComp = (PropertyComponent)e.GetSpecicalComponent(ComponentType.Property);

            if (dead.hp <= 0)
            {
                if (propertyComp.m_characterType == PropertyComponent.CharacterType.Heretic ||
                    propertyComp.m_characterType == PropertyComponent.CharacterType.Deepone)
                {
                    AIComponent aiComp = (AIComponent)e.GetSpecicalComponent(ComponentType.AI);
                    //todo
                    //aiComp.m_enemy.Dead ();
                }
                //播放死亡动画
                RemoveDead(dead);
                dead.m_entity.RemoveAllComponent();
                continue;
            }
            if (dead.san == 0)
            {
            }
        }
    }
Exemplo n.º 6
0
    public override Vector3 DoBehavior(AIComponent boid)
    {
        AIComponent[] neighbors = GetNeighbors(boid);

        if (neighbors.Length < neighborMinLimit)
        {
            return(Vector3.zero);
        }

        Vector3 force = Vector3.zero;

        Vector3[] directions = new Vector3[neighbors.Length];

        for (int i = 0; i < neighbors.Length; i++)
        {
            directions[i] = neighbors[i].velocity;
        }

        Vector3 averageDirection = GetAverageVector(boid, directions);

        if (averageDirection != Vector3.zero)
        {
            force = averageDirection;
        }

        return(force.normalized);
    }
Exemplo n.º 7
0
        public override async ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken)
        {
            Scene clientScene = aiComponent.DomainScene();

            Unit myUnit = Client.UnitHelper.GetMyUnitFromClientScene(clientScene);

            if (myUnit == null)
            {
                return;
            }

            // 停在当前位置
            clientScene.GetComponent <SessionComponent>().Session.Send(new C2M_Stop());

            Log.Debug("开始攻击");

            for (int i = 0; i < 100000; ++i)
            {
                Log.Debug($"攻击: {i}次");

                // 因为协程可能被中断,任何协程都要传入cancellationToken,判断如果是中断则要返回
                bool timeRet = await TimerComponent.Instance.WaitAsync(1000, cancellationToken);

                if (!timeRet)
                {
                    return;
                }
            }
        }
Exemplo n.º 8
0
 public void Remove(AIComponent component)
 {
     foreach (var c in FindAllComponents(component))
     {
         AssetDatabase.RemoveObjectFromAsset(c);
     }
 }
Exemplo n.º 9
0
    public override Vector3 DoBehavior(AIComponent boid)
    {
        Vector3 force = Vector3.zero;

        Collider[] obstacles = GetObstacles(boid);

        Vector3[] positions = new Vector3[obstacles.Length];

        for (int i = 0; i < obstacles.Length; i++)
        {
            if (obstacles[i])
            {
                positions[i] = boid.position - obstacles[i].transform.position;
            }
        }

        Vector3 averagePosition = GetAverageVector(positions);

        if (averagePosition != Vector3.zero)
        {
            force = averagePosition;
        }

        Debug.DrawRay(boid.transform.position, force.normalized, Color.red);

        return(force.normalized);
    }
Exemplo n.º 10
0
 protected override void ExitAction()
 {
     if (AIComponent == null)
     {
         AIComponent = GetComponent <BaseAIComponent>() as BaseAIComponent;
     }
     AIComponent.UpdateState(true, finishedState);
 }
Exemplo n.º 11
0
    private GameEntity targetedEntity = null;               // Entity that has been targeted for combat


    public Enemy(
        string name,
        List <EnemyComponent> components,
        AIComponent intel)
    {
        this.name       = name;
        enemyComponents = components;
        intelComponent  = intel;
    }
Exemplo n.º 12
0
 public Boid(AIComponent enemy, int id, Transform transform, Rigidbody rigidbody, Vector3 position, Vector3 velocity)
 {
     this.data      = enemy;
     this.id        = id;
     this.transform = transform;
     this.rigidbody = rigidbody;
     this.position  = position;
     this.velocity  = velocity;
 }
Exemplo n.º 13
0
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (BasicEntity e in entities)
        {
            AIComponent aiInfo = e.GetComponent <AIComponent>();
            if (aiInfo == null)
            {
                continue;
            }
            if (aiInfo.m_enemyState == EnemyState.Action)
            {
                //Debug.Log (StateStaticComponent.m_currentEntity + " aciont is going");
                AbilityManager abilityManager = new AbilityManager();
                abilityManager.RemoveTemppraryComponent(e);
                aiInfo.m_enemyState = EnemyState.Select;
            }
            //只有在系统结束工作之后才会重新开始执行
            if (aiInfo.m_enemyState == EnemyState.Wait)
            {
                StateComponent state = (StateComponent)e.GetSpecicalComponent(ComponentType.State);
                //增加输入组件
                AbilityManager abilityManager = new AbilityManager();
                //根据能力表新建新的组件
                abilityManager.AddTemporaryComponent(e);
                if (state.m_actionPoint > 0)
                {
                    //切换状态
                    aiInfo.m_enemyState = EnemyState.Select;
                    aiInfo.m_enemy.Execute();
                }
                else
                {
                    if (aiInfo.m_coldTime < aiInfo.m_actionInterval)
                    {
                        aiInfo.m_coldTime += Time.deltaTime;
                    }
                    else
                    {
                        aiInfo.m_coldTime   = 0;
                        state.m_actionPoint = e.GetComponent <PropertyComponent>().AP;
                        aiInfo.m_enemyState = EnemyState.Select;
                        aiInfo.m_enemy.Execute();
                    }
                }
            }

            //if (turnNumber - StateStaticComponent.m_EturnNumber != 0)
            //{
            //    turnNumber++;
            //    if (StateStaticComponent.m_EcurrentEntity == e)
            //    {
            //        AIComponent aiComponent = (AIComponent)e.GetSpecicalComponent(ComponentType.AI);
            //        aiComponent.m_enemy.Execute();
            //    }
            //}
        }
    }
Exemplo n.º 14
0
    public virtual void Start()
    {
        invicible = true;

        explosionPrefabGo = Resources.Load("Explosion") as GameObject;
        if (isPlayer) mainCharacter = this;
        moveComponent = GetComponent<MoveComponent>();
        fireComponent = GetComponent<FireComponent>();
        aiComponent = GetComponent<AIComponent>();
    }
 public void Start()
 {
     numEntities = 10;
     for (int i = 0; i < numEntities; i++)
     {
         aiComponents[i]      = new AIComponent();
         physicsComponents[i] = new PhysicsComponent();
         renderComponents[i]  = new RenderComponent();
     }
 }
Exemplo n.º 16
0
        public override int Check(AIComponent aiComponent, AIConfig aiConfig)
        {
            long sec = TimeHelper.ClientNow() / 1000 % 15;

            if (sec >= 10)
            {
                return(0);
            }
            return(1);
        }
Exemplo n.º 17
0
    Vector3 GetAverageVector(AIComponent enemy, Vector3[] positions)
    {
        Vector3 sum = Vector3.zero;

        // Get the sum of all the positions
        for (int i = 0; i < positions.Length; i++)
        {
            sum += positions[i];
        }
        return(sum / positions.Length);
    }
Exemplo n.º 18
0
 private void OnTriggerExit(Collider col)
 {
     if (col.gameObject.TryGetComponent(out playerControl player))
     {
         foreach (var AIComponent in enemyAIManagers)
         {
             Debug.Log("Disabling behavior");
             AIComponent.DisableBehavior();
         }
     }
 }
Exemplo n.º 19
0
 private void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.TryGetComponent(out playerControl player))
     {
         SetLock(true);
         foreach (var AIComponent in enemyAIManagers)
         {
             AIComponent.EnableBehavior();
         }
     }
 }
Exemplo n.º 20
0
    // Use this for initialization
    void Start()
    {
        sprintSlider = GameObject.Find("P" + playerID + "SprintSlider");
        sprintSlider.GetComponent <Slider> ().value = sprintSlider.GetComponent <Slider> ().maxValue;

        bombImage = GameObject.Find("Canvas").transform.FindChild("P" + playerID + "UI").FindChild("P" + playerID + "BombImage").gameObject;
        bombImage.GetComponent <Image> ().color = Color.white;
        bombImage.SetActive(false);

        Diagnostics.DrawDebugOn = true;
        myBody   = GetComponent <Rigidbody2D> ();
        animator = this.transform.GetChild(0).GetComponent <Animator> ();
        if (nametag == null)
        {
            nametag       = transform.FindChild("Nametag").GetComponent <TextMesh> ();
            nametag.color = transform.GetChild(0).GetChild(0).GetComponent <SpriteRenderer> ().material.color;
            nametag.text  = playerName;
        }
        footTransform   = transform.FindChild("FootPosition");
        nametagScale    = new Vector3(nametag.transform.localScale.x, nametag.transform.localScale.y, nametag.transform.localScale.z);
        nametagMinScale = new Vector3(-nametag.transform.localScale.x, nametag.transform.localScale.y, nametag.transform.localScale.z);
        abs             = this.transform.GetComponentInChildren <AbilityStatus> ();
        absScale        = new Vector3(abs.transform.localScale.x, abs.transform.localScale.y, abs.transform.localScale.z);
        absMinScale     = new Vector3(-abs.transform.localScale.x, abs.transform.localScale.y, abs.transform.localScale.z);
        scale           = new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z);
        minScale        = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
        sprintParticle  = Resources.Load <GameObject> ("DustParticle");
        sprintBar       = this.transform.FindChild("SprintStatus").GetComponent <SpriteRenderer> ();
        sprintBar.color = playercolor;
        sprintScale     = new Vector3(sprintBar.transform.localScale.x, sprintBar.transform.localScale.y, sprintBar.transform.localScale.z);
        sprintMinScale  = new Vector3(-sprintBar.transform.localScale.x, sprintBar.transform.localScale.y, sprintBar.transform.localScale.z);

        //raycasting setup
        Transform raycast = transform.FindChild("Raycasts");

        raycastObjects = new Transform[raycast.childCount];
        for (int i = 0; i < raycast.childCount; ++i)
        {
            raycastObjects[i] = raycast.GetChild(i);
        }

        if (GlobalProperties.IS_NETWORKED)
        {
            //tell camera we have joined
            GameObject.FindObjectOfType <GameCamera> ().MyPlayerHasJoined();
        }
        //this will be null forever if you are player controller player instead of AI
        AI = GetComponent <AIComponent> ();

        if (XBox == null)
        {
            LOCAL_SetPlayerNumber(playerID);
        }
    }
Exemplo n.º 21
0
    public override Vector3 DoBehavior(AIComponent boid)
    {
        Vector3 force  = Vector3.zero;
        Bounds  bounds = new Bounds(center, area);

        if (!bounds.Contains(boid.transform.position))
        {
            force = bounds.ClosestPoint(boid.position) - boid.position;
        }

        return(force.normalized);
    }
Exemplo n.º 22
0
 // Start is called before the first frame update
 void Start()
 {
     box = GetComponent <Collider>();
     // If isLocked has been set to true in the inspector
     if (isLocked)
     {
         SetLock(true);
         foreach (var AIComponent in enemyAIManagers)
         {
             AIComponent.EnableBehavior();
         }
     }
 }
Exemplo n.º 23
0
    public virtual void Start()
    {
        invicible = true;

        explosionPrefabGo = Resources.Load("Explosion") as GameObject;
        if (isPlayer)
        {
            mainCharacter = this;
        }
        moveComponent = GetComponent <MoveComponent>();
        fireComponent = GetComponent <FireComponent>();
        aiComponent   = GetComponent <AIComponent>();
    }
Exemplo n.º 24
0
        /// <summary>
        /// onSceneCreated this function is called whenever the current gamestate is changed. This function should contain logic that
        /// needs to be processed before the state is shown for the player. This could be enteties that's not able to be created pre-runtime.
        /// </summary>
        public void onSceneCreated()
        {
            SpriteFont            font1  = Game.Instance.GetContent <SpriteFont>("Fonts/Menufont");
            DrawableTextComponent winner = new DrawableTextComponent("Winner:", Color.Black, font1);
            PositionComponent     pos    = new PositionComponent(new Vector2(Game.Instance.GraphicsDevice.Viewport.Width * 0.5f - ((float)font1.MeasureString("Winner:").X * 0.5f), 0));

            kbc = new KeyBoardComponent();
            int WinnerId = ComponentManager.Instance.CreateID();

            kbc.keyBoardActions.Add(ActionsEnum.Up, Keys.Enter);
            ComponentManager.Instance.AddComponentToEntity(WinnerId, winner);
            ComponentManager.Instance.AddComponentToEntity(WinnerId, kbc);
            ComponentManager.Instance.AddComponentToEntity(WinnerId, pos);
            entitiesInState.Add(WinnerId);

            HealthSystem hs = (HealthSystem)SystemManager.Instance.RetrieveSystem <IUpdate>("HealthSystem");
            int          id = hs.deathList.First();

            hs.deathList.Clear();
            AIComponent ai = new AIComponent();

            ComponentManager.Instance.AddComponentToEntity(id, ai);
            PlayerComponent player = ComponentManager.Instance.GetEntityComponent <PlayerComponent>(id);

            entitiesInState.Add(id);
            SpriteFont            font2         = Game.Instance.GetContent <SpriteFont>("Fonts/Menufont");
            DrawableTextComponent winningPlayer = new DrawableTextComponent(player.playerName, Color.Black, font2);
            PositionComponent     pos2          = new PositionComponent(new Vector2(Game.Instance.GraphicsDevice.Viewport.Width * 0.5f - ((float)font2.MeasureString(player.playerName).X * 0.5f), 50));
            int textId2 = ComponentManager.Instance.CreateID();

            ComponentManager.Instance.AddComponentToEntity(textId2, winningPlayer);
            ComponentManager.Instance.AddComponentToEntity(textId2, pos2);
            entitiesInState.Add(textId2);

            SpriteFont            font3 = Game.Instance.GetContent <SpriteFont>("Fonts/Menufont");
            DrawableTextComponent text  = new DrawableTextComponent("Press enter to return to Main menu", Color.Black, font3);
            PositionComponent     poss  = new PositionComponent(new Vector2(Game.Instance.GraphicsDevice.Viewport.Width * 0.5f - ((float)font3.MeasureString("Press enter to return to Main menu").X * 0.5f), Game.Instance.GraphicsDevice.Viewport.Height - 100));
            int textId = ComponentManager.Instance.CreateID();

            ComponentManager.Instance.AddComponentToEntity(textId, text);
            ComponentManager.Instance.AddComponentToEntity(textId, poss);
            entitiesInState.Add(textId);

            int se = ComponentManager.Instance.CreateID();

            ComponentManager.Instance.AddComponentToEntity(se, new SoundEffectComponent("winner"));
            entitiesInState.Add(se);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="position"></param>
        /// <param name="pixlePer"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public int CreateAIPlayer(Direction dir, Vector2 position, bool pixlePer, string name, Color colour)
        {
            SpriteEffects flip;

            if (dir == Direction.Left)
            {
                flip = SpriteEffects.FlipHorizontally;
            }
            else
            {
                flip = SpriteEffects.None;
            }

            DirectionComponent          dc   = new DirectionComponent(dir);
            DrawableComponent           comp = new DrawableComponent(Game.Instance.GetContent <Texture2D>("Pic/Helmutsh"), flip);
            PositionComponent           pos  = new PositionComponent(position);
            VelocityComponent           vel  = new VelocityComponent(new Vector2(200F, 0), 50F);
            JumpComponent               jump = new JumpComponent(300F, 50F);
            CollisionRectangleComponent CRC  = new CollisionRectangleComponent(new Rectangle((int)pos.position.X, (int)pos.position.Y, comp.texture.Width, comp.texture.Height));
            CollisionComponent          CC   = new CollisionComponent(pixlePer);
            DrawableTextComponent       dtc  = new DrawableTextComponent(name, Color.Yellow, Game.Instance.GetContent <SpriteFont>("Fonts/NewTestFont"));
            HUDComponent       hudc          = new HUDComponent(Game.Instance.GetContent <Texture2D>("Pic/PowerUp"), new Vector2(pos.position.X, pos.position.Y));
            HUDComponent       hudc2         = new HUDComponent(Game.Instance.GetContent <Texture2D>("Pic/PowerUp"), Vector2.One);
            HealthComponent    hc            = new HealthComponent(3, false);
            AnimationComponent ani           = new AnimationComponent(75, 75, comp.texture.Width, comp.texture.Height, 0.2);
            AIComponent        ai            = new AIComponent();
            PlayerComponent    play          = new PlayerComponent(name);

            comp.colour = colour;

            int id = ComponentManager.Instance.CreateID();

            ComponentManager.Instance.AddComponentToEntity(id, vel);
            ComponentManager.Instance.AddComponentToEntity(id, comp);
            ComponentManager.Instance.AddComponentToEntity(id, pos);
            ComponentManager.Instance.AddComponentToEntity(id, CRC);
            ComponentManager.Instance.AddComponentToEntity(id, CC);
            ComponentManager.Instance.AddComponentToEntity(id, dtc);
            ComponentManager.Instance.AddComponentToEntity(id, hudc);
            ComponentManager.Instance.AddComponentToEntity(id, hc);
            ComponentManager.Instance.AddComponentToEntity(id, ani);
            ComponentManager.Instance.AddComponentToEntity(id, dc);
            ComponentManager.Instance.AddComponentToEntity(id, jump);
            ComponentManager.Instance.AddComponentToEntity(id, play);
            ComponentManager.Instance.AddComponentToEntity(id, ai);
            return(id);
        }
Exemplo n.º 26
0
    public void Patrol(BasicEntity entity)
    {
        //寻找一个坐标进行来回移动
        AIComponent    ai    = entity.GetComponent <AIComponent> ();
        StateComponent state = entity.GetComponent <StateComponent> ();

        List <Vector3> path      = ai.m_patrolPoint;
        Vector3        entityPos = entity.GetComponent <BlockInfoComponent> ().m_logicPosition;

        if (path [0] == entityPos)
        {
            Vector3 t = path [0];
            path.Remove(t);
            path.Add(t);
        }
        AiToInput.Move(entity, path [0]);
    }
Exemplo n.º 27
0
 protected override void ExitAction()
 {
     nextState = GameManagerScript.Instance.Random.Next(1, 3);
     if (transform.position.x - EvaMovement.Instance.transform.position.x > 0)
     {
         transform.rotation = new Quaternion(0f, 0f, 0f, 0f);
     }
     else
     {
         transform.rotation = new Quaternion(0f, 180f, 0f, 0f);
     }
     if (AIComponent == null)
     {
         AIComponent = GetComponent <BaseAIComponent>() as BaseAIComponent;
     }
     AIComponent.UpdateState(true, finishedState);
 }
Exemplo n.º 28
0
    public override Vector3 DoBehavior(AIComponent boid)
    {
        Vector3 force = Vector3.zero;

        if (boid.velocity == Vector3.zero)
        {
            force += RandomVector;
        }
        else
        {
            float   angleOffset = 45;
            Vector3 offset      = Quaternion.Euler(0, RandomFloat * angleOffset, 0) * boid.velocity;

            force = boid.velocity + offset;
        }

        return(force.normalized);
    }
Exemplo n.º 29
0
    public T[] GetObjects <T>(AIComponent boid)
    {
        Collider[] gos = GetObjects(boid);
        List <T>   filteredGameObjects = new List <T>();

        for (int i = 0; i < gos.Length; i++)
        {
            if (gos[i])
            {
                T component = gos[i].GetComponent <T>();

                if (component != null)
                {
                    filteredGameObjects.Add(component);
                }
            }
        }
        return(filteredGameObjects.ToArray());
    }
Exemplo n.º 30
0
    public override void init_agent(Pos position, GameAgentStats stats, string name = null)
    {
        map_manager = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapManager>();
        grid_pos    = position;

        animator = GetComponent <CharacterAnimator>();

        this.stats    = stats;
        _attack       = stats.attack;
        maxHealth     = stats.maxHealth;
        currentHealth = maxHealth;
        range         = stats.range;
        _speed        = stats.speed;
        if (name == null)
        {
            this.nickname = CharacterRaceOptions.getString(stats.characterRace) + " " + CharacterClassOptions.getWeaponDescriptor(stats.playerCharacterClass.weapon);
        }
        else
        {
            this.nickname = name;
        }

        weapon = stats.playerCharacterClass.weapon;

        speed       = 10;
        move_budget = 10;

        level         = stats.level;
        viewableState = stats.currentState;

        animator     = GetComponent <CharacterAnimator>();
        classDefiner = GetComponent <CharacterClassDefiner>();
        animator.init();
        classDefiner.init(stats.characterRace, stats.characterClassOption, stats.playerCharacterClass.weapon);

        source = GetComponent <AudioSource>();

        // AI init
        team = 1;
        AI   = new AIComponent(this);       // AI component that decides the actions for this enemy to take
        TurnManager.instance.addToRoster(this);
        SetCurrentAction(0);
    }
Exemplo n.º 31
0
    public override Collider[] GetObjects(AIComponent boid)
    {
        colliders[0] = null;
        Vector3 dir = direction;

        if (relativeTo == RelativeTo.self)
        {
            dir = boid.transform.TransformDirection(dir);
        }

        Ray        ray = new Ray(boid.position, direction);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, range, layerMask))
        {
            colliders[0] = hit.collider;
        }

        return(colliders);
    }
Exemplo n.º 32
0
        public static void UpdateEnemyPosition(Guid enemyId, AIComponent enemyAIComponent, PlayingState playingState, LevelCollisionDetection levelCollisionDetection)
        {
            #region set our variables
            var CurrentPosition = playingState.PositionComponents[enemyId];
            var AABBComponent = playingState.AABBComponents[enemyId];
            var Acceleration = playingState.AccelerationComponents[enemyId];
            var AdjustedActive = new Vector2(enemyAIComponent.ActivePath.First.Value.TilePosition.X, enemyAIComponent.ActivePath.First.Value.TilePosition.Y);
            #endregion

            //update enemy position
            #region move right
            if (CurrentPosition.Position.X < AdjustedActive.X)
            {
                if ((CurrentPosition.Position.X + (int)Acceleration.xAcceleration) > AdjustedActive.X)
                {
                    CurrentPosition.Position.X = (int)AdjustedActive.X;

                    //update our bounded box to new position
                    AABBComponent.BoundedBox.X = (int)CurrentPosition.Position.X - (AABBComponent.BoundedBox.Width / 2);
                    AABBComponent.BoundedBox = levelCollisionDetection.CheckWallCollision(AABBComponent.BoundedBox, Direction.Right);
                }
                else
                {
                    CurrentPosition.Position.X += (int)Acceleration.xAcceleration;

                    //update our bounded box to new position
                    AABBComponent.BoundedBox.X = (int)CurrentPosition.Position.X - (AABBComponent.BoundedBox.Width / 2);
                    AABBComponent.BoundedBox = levelCollisionDetection.CheckWallCollision(AABBComponent.BoundedBox, Direction.Right);
                }
                //this.Position = mapCollisionDetection.CheckWallCollision(this.Position, this.Width, this.Height, Direction.Right);
            }
            #endregion

            #region move left
            else if (CurrentPosition.Position.X > AdjustedActive.X)
            {
                if ((CurrentPosition.Position.X - Acceleration.xAcceleration) < AdjustedActive.X)
                {
                    CurrentPosition.Position.X = (int)AdjustedActive.X;

                    //update our bounded box to new position
                    AABBComponent.BoundedBox.X = (int)CurrentPosition.Position.X - (AABBComponent.BoundedBox.Width / 2);
                    AABBComponent.BoundedBox = levelCollisionDetection.CheckWallCollision(AABBComponent.BoundedBox, Direction.Left);
                }
                else
                {
                    CurrentPosition.Position.X -= (int)Acceleration.xAcceleration;

                    //update our bounded box to new position
                    AABBComponent.BoundedBox.X = (int)CurrentPosition.Position.X - (AABBComponent.BoundedBox.Width / 2);
                    AABBComponent.BoundedBox = levelCollisionDetection.CheckWallCollision(AABBComponent.BoundedBox, Direction.Left);
                }
                //this.Position = mapCollisionDetection.CheckWallCollision(this.Position, this.Width, this.Height, Direction.Left);
            }
            #endregion

            #region move up
            if (CurrentPosition.Position.Y > AdjustedActive.Y)
            {
                if (CurrentPosition.Position.Y - (int)Acceleration.yAcceleration < AdjustedActive.Y)
                {
                    CurrentPosition.Position.Y = (int)AdjustedActive.Y;

                    //update our bounded box to new position
                    AABBComponent.BoundedBox.Y = (int)CurrentPosition.Position.Y - (AABBComponent.BoundedBox.Height / 2);
                    AABBComponent.BoundedBox = levelCollisionDetection.CheckWallCollision(AABBComponent.BoundedBox, Direction.Up);
                }
                else
                {
                    CurrentPosition.Position.Y -= (int)Acceleration.yAcceleration;

                    //update our bounded box to new position
                    AABBComponent.BoundedBox.Y = (int)CurrentPosition.Position.Y - (AABBComponent.BoundedBox.Height / 2);
                    AABBComponent.BoundedBox = levelCollisionDetection.CheckWallCollision(AABBComponent.BoundedBox, Direction.Up);
                }
                //this.Position = mapCollisionDetection.CheckWallCollision(this.Position, this.Width, this.Height, Direction.Up);
            }
            #endregion

            #region move down
            else if (CurrentPosition.Position.Y < AdjustedActive.Y)
            {
                if (CurrentPosition.Position.Y + (int)Acceleration.yAcceleration > AdjustedActive.Y)
                {
                    CurrentPosition.Position.Y = (int)AdjustedActive.Y;

                    //update our bounded box to new position
                    AABBComponent.BoundedBox.Y = (int)CurrentPosition.Position.Y - (AABBComponent.BoundedBox.Height / 2);
                    AABBComponent.BoundedBox = levelCollisionDetection.CheckWallCollision(AABBComponent.BoundedBox, Direction.Down);
                }
                else
                {
                    CurrentPosition.Position.Y += (int)Acceleration.yAcceleration;

                    //update our bounded box to new position
                    AABBComponent.BoundedBox.Y = (int)CurrentPosition.Position.Y - (AABBComponent.BoundedBox.Height / 2);
                    AABBComponent.BoundedBox = levelCollisionDetection.CheckWallCollision(AABBComponent.BoundedBox, Direction.Down);
                }
                //this.Position = mapCollisionDetection.CheckWallCollision(this.Position, this.Width, this.Height, Direction.Down);
            }
            #endregion

            //update our position based on our new bounded box after collision
            #region save component changes
            CurrentPosition.Position = new Vector2(AABBComponent.BoundedBox.X + (AABBComponent.BoundedBox.Width / 2), AABBComponent.BoundedBox.Y + (AABBComponent.BoundedBox.Height / 2));

            playingState.PositionComponents[enemyId] = CurrentPosition;

            playingState.AIComponents[enemyId] = enemyAIComponent;
            playingState.AABBComponents[enemyId] = AABBComponent;
            #endregion
        }