Exemple #1
0
 public static void GOTO_STATE2(AiComponent aicomponent, InputComponent input)
 {
     Debug.Log("GOTO_2");
     clearInputState(aicomponent, input);
     aicomponent.Dir        = 0;
     aicomponent.finishMove = false;
     aicomponent.timeCount  = 0;
     if (aicomponent.MoveState == 0)
     {
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd / 5;
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 2;
     }
     else if (aicomponent.MoveState == 1)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 4;
     }
     else if (aicomponent.MoveState == 3)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 8;
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd / 5;
     }
     else if (aicomponent.MoveState == 5)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 2;
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd / 5;
     }
     aicomponent.MoveState         = 2;
     aicomponent.StateChangeCount += 1;
     if (aicomponent.StateChangeCount > 4)
     {
         aicomponent.StateChangeCount = 0;
         GOTO_STATE3(aicomponent, input);
     }
 }
Exemple #2
0
    /*
     * MoveState=0 根据玩家方向选择横向或者纵向持续来回移动并不断扫射 5s 接状态2
     *           1 四方向原地射击 接状态1
     *           2 玩家靠近时变换到战场的四个点其中之一,四方向射击一次
     *           3 玩家坐标越过中线时,对称跳跃到玩家另一侧
     *           4 暴走状态 射速以及移速加快 接状态1或2
     *           5 开始搜寻状态 玩家最后一次miss的方位
     *           6 目标丢失,停顿
     *           状态12重复四次没有状态2时接状态2
     *           血量到1/5时接状态4
     */
    public static void Boss1Shoot(AiComponent aicomponent, InputComponent input)
    {
        aicomponent.MoveState       = aicomponent.bodyworkAIcomponent.MoveState;
        aicomponent.timeCountShoot += Time.deltaTime;


        switch (aicomponent.MoveState)
        {
        case 1:
            skill_MoveShoot(aicomponent, input);
            break;

        case 2:
            skill_Attack(aicomponent, input);
            break;

        case 3:
            skill_QuickMove(aicomponent, input);
            break;

        case 4:
            //暴走状态
            break;

        case 5:
            //搜寻状态
            break;

        default:
            break;
        }
    }
Exemple #3
0
 public static void GOTO_STATE3(AiComponent aicomponent, InputComponent input)
 {
     Debug.Log("GOTO_3");
     clearInputState(aicomponent, input);
     aicomponent.Dir        = 0;
     aicomponent.finishMove = false;
     aicomponent.timeCount  = 0;
     if (aicomponent.MoveState == 0)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 4;
     }
     else if (aicomponent.MoveState == 1)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 2;
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd * 5;
     }
     else if (aicomponent.MoveState == 2)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 8;
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd * 5;
     }
     else if (aicomponent.MoveState == 5)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 4;
     }
     aicomponent.MoveState = 3;
 }
Exemple #4
0
 public static void GOTO_STATE4(AiComponent aicomponent, InputComponent input)
 {
     Debug.Log("GOTO_4");
     clearInputState(aicomponent, input);
     aicomponent.MoveState  = 4;
     aicomponent.Dir        = 0;
     aicomponent.finishMove = false;
     aicomponent.timeCount  = 0;
 }
Exemple #5
0
    /*
     * MoveState=1 根据玩家方向选择横向或者纵向持续来回移动并不断扫射 5s 接状态2
     *           2 追击
     *           3 长距离移动,横冲直撞
     *           4 暴走状态 射速以及移速加快 接状态1或2
     *           5 开始搜寻状态 玩家最后一次miss的方位
     *
     *           血量到1/5时接状态4
     */
    //boss1
    public static void Boss1Move(AiComponent aicomponent, InputComponent input)
    {
        updateCollider(aicomponent);
        if (aicomponent.MoveState != 5)
        {
            getEnemyDir(aicomponent, input);
        }
        if (aicomponent.Dir != aicomponent.lastDir && aicomponent.Dir != 0)//玩家方向发生变化,记录方向
        {
            aicomponent.lastDir = aicomponent.EnemyDir;
        }

        /*if(aicomponent.entity)  //血量
         * {
         *  GOTO_STATE4(aicomponent, input);
         * }
         */
        switch (aicomponent.MoveState)
        {
        case 0:
            GOTO_STATE1(aicomponent, input);
            break;

        case 1:
            //中移速,高射速
            aicomponent.timeCount += Time.deltaTime;
            skill_MoveShoot(aicomponent, input);
            break;

        case 2:
            //低移速,高射速
            aicomponent.timeCount += Time.deltaTime;
            skill_Attack(aicomponent, input);
            break;

        case 3:
            //高移速,低射速
            aicomponent.timeCount += Time.deltaTime;
            skill_QuickMove(aicomponent, input);
            break;

        case 4:
            //暴走状态,视距翻倍,移速翻倍,射击cd减半
            aicomponent.stadia = aicomponent.stadia * 2;
            aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 2;
            aicomponent.shootCD = aicomponent.shootCD / 2;
            GOTO_STATE2(aicomponent, input);
            break;

        case 5:
            //搜索状态
            skill_FindEnemy(aicomponent, input);
            break;
        }
    }
Exemple #6
0
 public static void updateCollider(AiComponent aicomponent) //更新视野内的collider对象
 {
     if (aicomponent.AttackableObject == null)              //无攻击目标,获取攻击对象
     {
         Debug.Log("开始获取对象");
         aicomponent.collider = Physics2D.OverlapBoxAll(aicomponent.entity.gameobjectComponent.transform.position, aicomponent.stadia, 0);
         List <GameObject> attackObject = new List <GameObject> {
         };
         float mindistance = 99999;
         if (aicomponent.collider[0] != null) //collider非空
         {
             foreach (Collider2D co in aicomponent.collider)
             {
                 //collider对象拥有identity组件和tankcomponent组件,且camp与自己不同,列入可攻击列表
                 if (co.GetComponent <EntityHolder>().entity.identity.enable == true &&
                     co.GetComponent <EntityHolder>().entity.tankComponent.enable == true &&
                     co.GetComponent <EntityHolder>().entity.identity.camp != aicomponent.entity.identity.camp
                     )
                 {
                     attackObject.Add(co.gameObject);
                 }
             }
         }
         if (attackObject.Count == 0)   //范围内没有可攻击对象
         {
             aicomponent.AttackableObject = null;
         }
         else  //确定攻击目标,选择距离最近的锁定
         {
             Debug.Log("视野内的可攻击对象数目为:" + attackObject.Count);
             foreach (GameObject obj in attackObject)
             {
                 if (mindistance > Vector2.Distance(aicomponent.entity.gameobjectComponent.transform.position, obj.transform.position))
                 {
                     mindistance = Vector2.Distance(aicomponent.entity.gameobjectComponent.transform.position, obj.transform.position);
                     aicomponent.AttackableObject = obj;
                 }
             }
             Debug.Log("锁定对象,开始攻击");
             //aicomponent.MoveState = Random.Range(1, 3);
         }
     }
     else  //有攻击目标,锁定攻击对象,离开视野时刷新
     {
         if (Mathf.Abs(aicomponent.entity.gameobjectComponent.transform.position.x
                       - aicomponent.AttackableObject.transform.position.x) > aicomponent.stadia.x ||
             Mathf.Abs(aicomponent.entity.gameobjectComponent.transform.position.y
                       - aicomponent.AttackableObject.transform.position.y) > aicomponent.stadia.y) //离开视野范围,清空攻击目标
         {
             Debug.Log("对象miss");
             aicomponent.AttackableObject = null;
         }
     }
 }
Exemple #7
0
    public static void skill_Attack(AiComponent aicomponent, InputComponent input) //追击
    {
        if (aicomponent.Dir == 0)
        {
            aicomponent.Dir = aicomponent.EnemyDir;
        }
        if (aicomponent.finishMove)
        {
            if (aicomponent.Dir != aicomponent.EnemyDir)
            {
                aicomponent.Dir = aicomponent.EnemyDir;
                if (aicomponent.lastMoveAction != "")
                {
                    InputSystem.ReleaseAction(input, aicomponent.lastMoveAction);
                    aicomponent.lastMoveAction = "";
                }
                if (aicomponent.timeCount >= 3)
                {
                    GOTO_STATE1(aicomponent, input);
                }
                aicomponent.finishMove = false;
            }
        }
        else
        {
            aicomponent.finishMove = true;
            switch (aicomponent.Dir)
            {
            case 1:
                InputSystem.PressAction(input, "move_up");
                aicomponent.lastMoveAction = "move_up";
                break;

            case 2:
                InputSystem.PressAction(input, "move_right");
                aicomponent.lastMoveAction = "move_right";
                break;

            case 3:
                InputSystem.PressAction(input, "move_down");
                aicomponent.lastMoveAction = "move_down";
                break;

            case 4:
                InputSystem.PressAction(input, "move_left");
                aicomponent.lastMoveAction = "move_left";
                break;

            default:
                break;
            }
        }
    }
Exemple #8
0
 private static void FindNextWaypoint(AiComponent aiC)
 {
     if (aiC.Waypoint.Id + 1 == AiSystem.Waypoints.Count)
     {
         aiC.SetState(new IdleState());
         Debug.WriteLine("Changing State to Idle");
     }
     else
     {
         aiC.Waypoint = AiSystem.Waypoints[aiC.Waypoint.Id + 1];
         Debug.WriteLine("Changing Waypoint to " + (aiC.Waypoint.Id + 1) + " / " + AiSystem.Waypoints.Count);
     }
 }
 // Start is called before the first frame update
 void Start()
 {
     GameObject[] NPCsGO = GameObject.FindGameObjectsWithTag("AI");
     foreach (GameObject Element in NPCsGO)
     {
         AiComponent Comp = Element.GetComponent <AiComponent>();
         if (Comp)
         {
             NPC.Add(Comp);
         }
     }
     closestNPC = NPC[0];
 }
Exemple #10
0
 public static void FindNextWaypoint(AiComponent aiC)
 {
     if (aiC.Waypoint.Id + 1 == AiSystem.Waypoints.Count)
     {
         //State change from within state as discussed here:
         //https://sourcemaking.com/design_patterns/state
         aiC.SetState(new IdleState());
         Debug.WriteLine("Changing State to Idle");
     }
     else
     {
         aiC.Waypoint = AiSystem.Waypoints[aiC.Waypoint.Id + 1];
         Debug.WriteLine("Changing Waypoint to " + (aiC.Waypoint.Id + 1) + " / " + AiSystem.Waypoints.Count);
     }
 }
Exemple #11
0
    public void Update(Identity identity, AiComponent aicompont, InputComponent input)
    {
        if (aicompont == null || aicompont.enable == false)
        {
            return;
        }

        if (identity.isAIControl == true)
        {
            foreach (AI ai in aicompont.ais)
            {
                ai.Update();
            }
        }
    }
Exemple #12
0
    //扫射
    public static void skill_MoveShoot(AiComponent aicomponent, InputComponent input)
    {
        if (aicomponent.finishShoot)
        {
            aicomponent.timeCountShoot += Time.deltaTime;
            if (aicomponent.timeCountShoot >= aicomponent.shootCD)
            {
                aicomponent.timeCountShoot = 0;
                aicomponent.finishShoot    = false;
                if (aicomponent.lastShootAction != "")
                {
                    InputSystem.ReleaseAction(input, aicomponent.lastShootAction);
                    aicomponent.lastShootAction = "";
                }
            }
        }
        else
        {
            aicomponent.Dir         = aicomponent.bodyworkAIcomponent.Dir;
            aicomponent.finishShoot = true;
            switch (aicomponent.Dir)
            {
            case 1:
                InputSystem.PressAction(input, "rnf_up");
                aicomponent.lastShootAction = "rnf_up";
                break;

            case 2:
                InputSystem.PressAction(input, "rnf_right");
                aicomponent.lastShootAction = "rnf_right";
                break;

            case 3:
                InputSystem.PressAction(input, "rnf_down");
                aicomponent.lastShootAction = "rnf_down";
                break;

            case 4:
                InputSystem.PressAction(input, "rnf_left");
                aicomponent.lastShootAction = "rnf_left";
                break;

            default:
                break;
            }
        }
    }
Exemple #13
0
        private void InitAi(ECSEngine engine)
        {
            _sm.RegisterSystem("Game", new AiSystem());

            var entity = EntityFactory.Instance.NewEntityWithTag("AiKart");
            var modelC = new ModelComponent(engine.LoadContent <Model>("Chopper"), true, false, false)
            {
                staticModel = false
            };

            ModelRenderSystem.AddMeshTransform(ref modelC, 1, Matrix.CreateRotationY(0.2f));
            ModelRenderSystem.AddMeshTransform(ref modelC, 3, Matrix.CreateRotationY(0.5f));
            ComponentManager.Instance.AddComponentToEntity(entity, modelC);

            //Create waypoints and add the AIComponent.
            var waypoints = CreateWaypoints();

            AiSystem.Waypoints = waypoints;
            var aiC = new AiComponent(waypoints[0], new CountdownState());

            ComponentManager.Instance.AddComponentToEntity(entity, aiC);

            ComponentManager.Instance.AddComponentToEntity(entity, new Collision3Dcomponent());

            var aiKartTransform = new TransformComponent {
                Position = new Vector3(0.0f, 5.0f, 0.0f)
            };

            aiKartTransform.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, AiSystem.GetRotation(aiKartTransform.Position, aiC.Waypoint.TargetPosition));
            aiKartTransform.Scale    = new Vector3(2.5f, 2.5f, 2.5f);
            ComponentManager.Instance.AddComponentToEntity(entity, aiKartTransform);

            SceneManager.Instance.AddEntityToSceneOnLayer("Game", 3, entity);
            ComponentManager.Instance.AddComponentToEntity(entity, new PhysicsComponent()
            {
                Mass  = 5f,
                Force = new Vector3(15f, 250f, 0)
            });
            ComponentManager.Instance.AddComponentToEntity(entity, new GravityComponent());
            //ComponentManager.Instance.AddComponentToEntity(entity, new FrictionComponent());
            //ComponentManager.Instance.AddComponentToEntity(entity, new DragComponent());
            ComponentManager.Instance.AddComponentToEntity(entity, new KartComponent());
            ComponentManager.Instance.AddComponentToEntity(entity, new PlayerComponent());
            ComponentManager.Instance.AddComponentToEntity(entity, new LapComponent());
        }
Exemple #14
0
    public static void clearInputState(AiComponent aicomponent, InputComponent input)
    {
        if (aicomponent.lastMoveAction != "")
        {
            InputSystem.ReleaseAction(input, aicomponent.lastMoveAction);
            aicomponent.lastMoveAction = "";
        }

        if (aicomponent.entity.tankComponent.gunEntity.aiComponent.lastShootAction != "")
        {
            InputSystem.ReleaseAction(aicomponent.entity.tankComponent.gunEntity.inputComponent, aicomponent.entity.tankComponent.gunEntity.aiComponent.lastShootAction);
            aicomponent.entity.tankComponent.gunEntity.aiComponent.lastShootAction = "";
        }
        if (aicomponent.entity.tankComponent.gunEntity.aiComponent.lastShootAction1 != "")
        {
            InputSystem.ReleaseAction(aicomponent.entity.tankComponent.gunEntity.inputComponent, aicomponent.entity.tankComponent.gunEntity.aiComponent.lastShootAction1);
            aicomponent.entity.tankComponent.gunEntity.aiComponent.lastShootAction1 = "";
        }
    }
Exemple #15
0
    public void Update(Identity identity, AiComponent aicompont, InputComponent input)
    {
        if (aicompont == null || aicompont.enable == false)
        {
            return;
        }

        if (identity.isAIControl == true)
        {
            if (identity.tag == "tank")
            {
                MoveAI.moveAI(aicompont, input);
            }
            else if (identity.tag == "gun")
            {
                ShootAI.shootAI(aicompont, input);
            }
        }
    }
Exemple #16
0
    public static void moveAI(AiComponent aicomponent, InputComponent input)
    {
        switch (aicomponent.AIId)
        {
        case 0:
            EnemyMove(aicomponent, input);
            break;

        case 1:
            Boss1Move(aicomponent, input);
            break;

        case 2:
            Boss2Move(aicomponent, input);
            break;

        default:
            break;
        }
    }
Exemple #17
0
    public static void GOTO_STATE5(AiComponent aicomponent, InputComponent input)
    {
        Debug.Log("GOTO_5");
        clearInputState(aicomponent, input);
        aicomponent.Dir = 0;

        if (aicomponent.MoveState == 1)
        {
            aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 2;
            aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd * 5;
        }
        else if (aicomponent.MoveState == 2)
        {
            aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 2;
            aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd * 5;
        }
        else if (aicomponent.MoveState == 3)
        {
            aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 4;
        }
        aicomponent.MoveState  = 5;
        aicomponent.finishMove = false;
    }
Exemple #18
0
        //Constructors
        public TankObject(Coordinate spawnPosition, TankColor type) : base()
        {
            camera         = Camera.Instance;
            this.color     = type;
            model          = new TankModel(this.color);
            Position       = spawnPosition;
            maxHP          = 100;
            currentHP      = maxHP;
            speed          = 0;
            acceleration   = 0;
            turningAngle   = 0;
            directionBody  = 3 * Math.PI / 2;
            cannonTarget   = Position; //So that cannon is facing forward
            cannonTarget.x = (model.AllSprites["TankBody"].SubRect.w) * Math.Cos(directionBody) + Position.x;
            cannonTarget.y = (model.AllSprites["TankBody"].SubRect.w) * Math.Sin(directionBody) + Position.y;
            UpdateCannonDirection();
            model.UpdateModel(this, directionBody, directionCannon);
            cannonBulletPrototype = new BulletObject(this, this.GetBarrelEndPosition(), this.DirectionCannon);
            cannonBulletSpawner   = new WeaponProjectileSpawner(cannonBulletPrototype);
            //initialize Timers only after setting spawners and their prototypes!
            InitializeTimers();

            tankPhysics = new TankPhysicsComponent(this);

            if (color == TankColor.PLAYER)
            {
                aiComponent    = new DefaultAiComponent();
                currentFaction = Faction.PLAYER;
            }
            else
            {
                aiComponent = new TankAiComponent();
                //Use only for debugging, it neuters Tanks AI
                //aiComponent = new DefaultAiComponent();
                currentFaction = Faction.AI;
            }
        }
        //Create AI Player
        public static Entity NewAiPlayer(String model, Vector3 transformPos, Texture2D texture)
        {
            Entity             player             = EntityFactory.NewEntity(GameEntityFactory.AI_PLAYER);
            TransformComponent transformComponent = new TransformComponent(player, transformPos);
            ModelComponent     modelComponent     = new ModelComponent(player, AssetManager.Instance.GetContent <Model>(model));
            VelocityComponent  velocityComponent  = new VelocityComponent(player);
            CollisionComponent collisionComponent = new CollisionComponent(player, new BoxVolume(EntityFactory.CreateBoundingBox(modelComponent.Model)));
            PlayerComponent    playerComponent    = new PlayerComponent(player);
            FrictionComponent  frictionComponent  = new FrictionComponent(player);
            TextureComponent   textureComponent   = new TextureComponent(player, texture);
            GravityComponent   gravityComponent   = new GravityComponent(player);
            AiComponent        aiComponent        = new AiComponent(player);
            LightComponent     lightComponent     = new LightComponent(player, new Vector3(0, 7, -5), Color.White.ToVector4(), 10f, Color.Blue.ToVector4(), 0.2f, Color.White.ToVector4(), 1000f);
            EffectComponent    effectComponent    = new EffectComponent(player, AssetManager.Instance.GetContent <Effect>("Shading"));



            ComponentManager.Instance.AddComponentToEntity(player, modelComponent);
            ComponentManager.Instance.AddComponentToEntity(player, transformComponent);
            ComponentManager.Instance.AddComponentToEntity(player, velocityComponent);
            ComponentManager.Instance.AddComponentToEntity(player, collisionComponent, typeof(CollisionComponent));
            ComponentManager.Instance.AddComponentToEntity(player, playerComponent);
            ComponentManager.Instance.AddComponentToEntity(player, frictionComponent);
            ComponentManager.Instance.AddComponentToEntity(player, textureComponent);
            ComponentManager.Instance.AddComponentToEntity(player, gravityComponent);
            ComponentManager.Instance.AddComponentToEntity(player, aiComponent);
            ComponentManager.Instance.AddComponentToEntity(player, effectComponent);
            ComponentManager.Instance.AddComponentToEntity(player, lightComponent);

            //TransformHelper.SetInitialModelPos(modelComponent, transformComponent);
            //TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent);

            TransformHelper.SetInitialModelPos(modelComponent, transformComponent);
            TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent);

            return(player);
        }
Exemple #20
0
    public static void shootAI(AiComponent aicomponent, InputComponent input)
    {
        aicomponent.bodyworkAIcomponent = aicomponent.entity.identity.master.aiComponent;
        aicomponent.EnemyDir            = aicomponent.bodyworkAIcomponent.EnemyDir;
        aicomponent.AIId    = aicomponent.bodyworkAIcomponent.AIId;
        aicomponent.shootCD = aicomponent.entity.gunComponent.shootCd;
        switch (aicomponent.AIId)
        {
        case 0:
            EnemyShoot(aicomponent, input);
            break;

        case 1:
            Boss1Shoot(aicomponent, input);
            break;

        case 2:
            Boss2Shoot(aicomponent, input);
            break;

        default:
            break;
        }
    }
        private AiComponent getNearest(AiComponentController controller, List <AiComponent> agents)
        {
            AiComponent near = null;

            foreach (AiComponent agent in agents)
            {
                if (agent.getController().tag == "CAT")
                {
                    if (near == null)
                    {
                        near = agent;
                    }
                    else
                    {
                        if (Vector3.Distance(controller.transform.position, agent.getController().transform.position)
                            <= Vector3.Distance(controller.transform.position, near.getController().transform.position))
                        {
                            near = agent;
                        }
                    }
                }
            }
            return(near);
        }
Exemple #22
0
 public Unit(HealthComponent health, AttackComponent attack, MovementComponent movement, TargetComponent target, AiComponent ai,
             StatsComponent stats)
 {
     this.health   = health;
     this.attack   = attack;
     this.movement = movement;
     this.target   = target;
     this.ai       = ai;
     this.stats    = stats;
 }
    // Update is called once per frame
    void Update()
    {
        closestNPC = null;
        foreach (AiComponent npc in NPC)
        {
            if (npc.IsDead)
            {
                continue;
            }
            if (!closestNPC || Vector3.Distance(npc.transform.position, transform.position) < Vector3.Distance(closestNPC.transform.position, transform.position))
            {
                closestNPC = npc;
            }
        }

        bool IsAtKillingDistance = closestNPC && Vector3.Distance(closestNPC.transform.position, transform.position) < killDistance && !IsTriggering("AI");

        float IsMoving = 0.0f;

        if (Input.GetKey(KeyCode.RightArrow))
        {
            IsMoving = 1.0f;
        }
        else if (Input.GetKey(KeyCode.LeftArrow))
        {
            IsMoving = -1.0f;
        }

        // ContextualUI
        if (IsTriggering("Corpse"))
        {
            ContextualUI.IsEnabled = true;
            image.sprite           = reviveSprite;
        }
        else if (IsAtKillingDistance)
        {
            ContextualUI.IsEnabled = true;
            image.sprite           = killingSprite;
        }
        else
        {
            // Default Behavior
            ContextualUI.IsEnabled = IsTriggering("ContextualUI");
            image.sprite           = hidingSprite;
        }

        // Actions
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Inventory.NextItem();
        }

        if (Input.GetKeyDown(KeyCode.Return))
        {
            if (IsTriggering("Corpse"))
            {
                GetComponent <ReviveComponent>().Revive();
            }
            else if (IsAtKillingDistance && closestNPC)
            {
                // Kill Someone
                CharacterAnimator.SetTrigger("Kill");

                Animator NPCAnimator = closestNPC.GetComponentInChildren <Animator>();
                if (NPCAnimator)
                {
                    NPCAnimator.SetTrigger("Kill");
                }

                AiComponent Component = closestNPC.GetComponent <AiComponent>();
                if (Component)
                {
                    Component.Kill();
                }

                // Update HUD
                ScreenUIComponent.HUD.SoulGauge.DecreaseSoulsCount();
            }
            else if (IsTriggering("ContextualUI"))
            {
                ToggleHide();
            }
            else
            {
                Inventory.ToggleCurrentItem(CharacterAnimator);
                IsSpottable = !Inventory.IsWearing;
            }
        }

        Move(IsMoving);
    }
Exemple #24
0
    //追击,正前方三方向散射子弹
    public static void skill_Attack(AiComponent aicomponent, InputComponent input)
    {
        if (aicomponent.finishShoot)
        {
            aicomponent.timeCountShoot += Time.deltaTime;
            if (aicomponent.timeCountShoot >= aicomponent.shootCD)
            {
                aicomponent.timeCountShoot = 0;
                aicomponent.finishShoot    = false;

                if (aicomponent.lastShootAction != "")
                {
                    InputSystem.ReleaseAction(input, aicomponent.lastShootAction);
                    aicomponent.lastShootAction = "";
                }
                if (aicomponent.lastShootAction1 != "")
                {
                    InputSystem.ReleaseAction(input, aicomponent.lastShootAction1);
                    aicomponent.lastShootAction1 = "";
                }
                aicomponent.ShootStateCount += 1;
                if (aicomponent.ShootStateCount >= 3)
                {
                    aicomponent.ShootStateCount = 0;
                }
            }
        }
        else
        {
            switch (aicomponent.EnemyDir)
            {
            case 1:
                if (aicomponent.ShootStateCount == 0)
                {
                    InputSystem.PressAction(input, "rnf_left");
                    InputSystem.PressAction(input, "rnf_up");
                    aicomponent.lastShootAction  = "rnf_left";
                    aicomponent.lastShootAction1 = "rnf_up";
                }
                else if (aicomponent.ShootStateCount == 1)
                {
                    InputSystem.PressAction(input, "rnf_up");
                    aicomponent.lastShootAction = "rnf_up";
                }
                else if (aicomponent.ShootStateCount == 2)
                {
                    InputSystem.PressAction(input, "rnf_up");
                    InputSystem.PressAction(input, "rnf_right");
                    aicomponent.lastShootAction  = "rnf_up";
                    aicomponent.lastShootAction1 = "rnf_right";
                }
                aicomponent.finishShoot = true;
                break;

            case 2:
                if (aicomponent.ShootStateCount == 0)
                {
                    InputSystem.PressAction(input, "rnf_up");
                    InputSystem.PressAction(input, "rnf_right");
                    aicomponent.lastShootAction  = "rnf_up";
                    aicomponent.lastShootAction1 = "rnf_right";
                }
                else if (aicomponent.ShootStateCount == 1)
                {
                    InputSystem.PressAction(input, "rnf_right");
                    aicomponent.lastShootAction = "rnf_right";
                }
                else if (aicomponent.ShootStateCount == 2)
                {
                    InputSystem.PressAction(input, "rnf_right");
                    InputSystem.PressAction(input, "rnf_down");
                    aicomponent.lastShootAction  = "rnf_right";
                    aicomponent.lastShootAction1 = "rnf_down";
                }

                aicomponent.finishShoot = true;
                break;

            case 3:
                if (aicomponent.ShootStateCount == 0)
                {
                    InputSystem.PressAction(input, "rnf_down");
                    InputSystem.PressAction(input, "rnf_right");
                    aicomponent.lastShootAction  = "rnf_down";
                    aicomponent.lastShootAction1 = "rnf_right";
                }
                else if (aicomponent.ShootStateCount == 1)
                {
                    InputSystem.PressAction(input, "rnf_down");
                    aicomponent.lastShootAction = "rnf_down";
                }
                else if (aicomponent.ShootStateCount == 2)
                {
                    InputSystem.PressAction(input, "rnf_down");
                    InputSystem.PressAction(input, "rnf_left");
                    aicomponent.lastShootAction  = "rnf_down";
                    aicomponent.lastShootAction1 = "rnf_left";
                }

                aicomponent.finishShoot = true;
                break;

            case 4:
                if (aicomponent.ShootStateCount == 0)
                {
                    InputSystem.PressAction(input, "rnf_down");
                    InputSystem.PressAction(input, "rnf_left");
                    aicomponent.lastShootAction  = "rnf_down";
                    aicomponent.lastShootAction1 = "rnf_left";
                }
                else if (aicomponent.ShootStateCount == 1)
                {
                    InputSystem.PressAction(input, "rnf_left");
                    aicomponent.lastShootAction = "rnf_left";
                }
                else if (aicomponent.ShootStateCount == 2)
                {
                    InputSystem.PressAction(input, "rnf_left");
                    InputSystem.PressAction(input, "rnf_up");
                    aicomponent.lastShootAction  = "rnf_left";
                    aicomponent.lastShootAction1 = "rnf_up";
                }


                aicomponent.finishShoot = true;
                break;

            default:
                break;
            }
        }
    }
Exemple #25
0
 public static void Boss2Shoot(AiComponent aicomponent, InputComponent input)
 {
 }
Exemple #26
0
        protected Point ExecuteState(GameTime gameTime, Point matrixPosition, Vector3 position, VelocityComponent aiVelocity, GravityComponent gravity, AiComponent aiComponent)
        {
            //Get the block at the AI's current position
            var currentBlock = GetBlock(matrixPosition);

            // Debug
            //WriteWorld(worldMatrix);

            // Get the "real" values of the next block (destination) and the players "real" position
            // to make the move to the next block:
            //int row = 0;

            //if (matrixPosition.Y < worldMatrix.GetLength(1) - 1)
            //    row = matrixPosition.Y + 1;
            //else
            //    row = matrixPosition.Y;

            //var decision = ChooseBlock(worldMatrix, row);
            //var destinationBlock = GetBlock(decision);

            int row = 0;

            if (matrixPosition.Y < worldMatrix.GetLength(1) - 1)
            {
                row = matrixPosition.Y + 1;
            }
            else
            {
                row = matrixPosition.Y;
            }

            if (targetBlockTile.Y <= matrixPosition.Y)
            {
                targetBlockTile = ChooseBlock(worldMatrix, row);
                targetBlockPos  = GetBlock(targetBlockTile);
            }

            // Execute the move to the next block
            ExecuteMove(gameTime, currentBlock, targetBlockPos, position, aiVelocity, gravity, aiComponent);

            // We look to see if the player is in the same block in the "real" world as
            // in the matrix. if he is, we "wait" until the move is completed and return the same
            // position, or we make the move.
            // TODO: Need to fix
            if (currentBlock.Z + 50 <= position.Z)
            {
                return(targetBlockTile);
            }
            else
            {
                return(matrixPosition);
            }
        }
Exemple #27
0
 public void Update(GameTime gameTime, ref Point matrixPosition, Vector3 Position, VelocityComponent aiVelocity, GravityComponent gravity, AiComponent aiComponent)
 {
     worldMatrix       = GameService.Instance.GameWorld;
     worldEntityMatrix = GameService.Instance.EntityGameWorld;
     matrixPosition    = ExecuteState(gameTime, matrixPosition, Position, aiVelocity, gravity, aiComponent);
 }
Exemple #28
0
 public void AddAi(AiComponent aiComponent, AI ai)
 {
     aiComponent.ais.Add(ai);
     ai.world = this.world;
 }
Exemple #29
0
 protected void ExecuteMove(GameTime gameTime, Vector3 currentBlock, Vector3 nextBlock, Vector3 position, VelocityComponent velocity, GravityComponent gravity, AiComponent aiComponent)
 {
     PlayerActions.AcceleratePlayerForwards(gameTime, velocity);
     if (aiComponent.CurrentState == State.Winning)
     {
         if (Random.Next(0, 11) == 1) //20% chance to make random move
         {
             Console.WriteLine("RandomMove ");
             if (Random.Next(0, 2) == 1) //50% chance to go left or right
             {
                 PlayerActions.AcceleratePlayerLeftwards(gameTime, velocity);
                 if (!gravity.HasJumped)
                 {
                     PlayerActions.PlayerJump(gameTime, velocity, null);
                     gravity.HasJumped = true;
                 }
             }
             PlayerActions.AcceleratePlayerRightwards(gameTime, velocity);
             if (!gravity.HasJumped)
             {
                 PlayerActions.PlayerJump(gameTime, velocity, null);
                 gravity.HasJumped = true;
             }
             return;
         }
     }
     Console.WriteLine("Regular move");
     if (currentBlock.X < nextBlock.X) //if the block that AI wants to go to is "lower" X value AKA left of the current we need to jump left
     {
         PlayerActions.AcceleratePlayerLeftwards(gameTime, velocity);
         if (!gravity.HasJumped)
         {
             PlayerActions.PlayerJump(gameTime, velocity, null);
             gravity.HasJumped = true;
         }
     }
     if (currentBlock.X > nextBlock.X) //if the block that AI wants to go to is "higher" X value AKA right of the current we need to jump right
     {
         PlayerActions.AcceleratePlayerRightwards(gameTime, velocity);
         if (!gravity.HasJumped)
         {
             PlayerActions.PlayerJump(gameTime, velocity, null);
             gravity.HasJumped = true;
         }
     }
     if (currentBlock.X == nextBlock.X)
     {
         PlayerActions.AcceleratePlayerForwards(gameTime, velocity);
         if (!gravity.HasJumped)
         {
             PlayerActions.PlayerJump(gameTime, velocity, null);
             gravity.HasJumped = true;
         }
     }
 }
Exemple #30
0
 private void OnEnable()
 {
     this.ai = target as AiComponent;
 }