Example #1
0
        public override void OnUpdate(GameEntity entity, EntityStateMachine fsm)
        {
            var movable  = entity.GetComponent <MovableEntity>();
            var movement = (fsm as EntityController).Movement;

            movement.y = 0;
            entity.GetComponent <AnimationController>().PlayAnimation(AnimatorController, movement.x);
            movable.Move(movement);
            if (movable.velocity.y < 0)
            {
                movable.GravityScale = 1.4f;
            }
            else
            {
                movable.GravityScale = 1;
            }
            if (movable.OnGround)
            {
                movable.GravityScale = 1f;
                fsm.ChangeState(IdleState);
            }
            if (ClimbState)
            {
                fsm.ChangeState(ClimbState);
            }
        }
Example #2
0
        public override IEnumerator Begin(GameEntity entity, EntityStateMachine fsm)
        {
            var trigger  = entity.GetComponent <EntityEffector>()?.GetEffect <Damage>()?.GetTrigger <ImpactData>();
            var blowUp   = entity.GetComponent <EntityEffector>()?.GetEffect <BlowUp>();
            var effector = entity.GetComponent <EntityEffector>();

            if (trigger != null)
            {
                if (blowUp != null)
                {
                    var locker = (fsm as EntityController).Lock(this);
                    // Debug.Log($"locked {(fsm as EntityController).Locker.Locked}");
                    entity.GetComponent <SkillController>().Abort();
                    var movable = entity.GetComponent <MovableEntity>();
                    var v       = (blowUp.Effect as BlowUp).Blow;
                    v.x *= MathUtility.SignInt(blowUp.GetTrigger <ImpactData>().Position.x - entity.transform.position.x);
                    entity.GetComponent <MovableEntity>().Frozen = true;
                    entity.GetComponent <MovableEntity>().SetVelocity(v);
                    entity.GetComponent <AnimationController>().PlayAnimation(BlowUpAction, trigger.Position.x - entity.transform.position.x);
                    yield return(null);

                    while (!movable.OnGround)
                    {
                        yield return(null);
                    }
                    movable.Frozen = false;
                    entity.GetComponent <Animator>().SetTrigger("end");
                    yield return(new WaitForSeconds(BlowUpSleepTime));

                    entity.GetComponent <EntityEffector>().RemoveEffect(blowUp.Effect);
                    (fsm as EntityController).UnLock(locker);
                    while (!fsm.ChangeState(MoveState) && !fsm.ChangeState(JumpState))
                    {
                        yield return(null);
                    }
                    // Debug.Log($"unlocked {(fsm as EntityController).Locker.Locked}");
                    yield break;
                }
                else
                {
                    var interrupt = effector.GetEffect <Interruption>();
                    if (interrupt != null && entity.GetComponent <SkillController>().Interrupt(Mathf.RoundToInt(interrupt.Strength)))
                    {
                        entity.GetComponent <AnimationController>().PlayAnimation(HitAction, trigger.Position.x - entity.transform.position.x);
                        while (!entity.GetComponent <AnimationController>().IsEnd())
                        {
                            yield return(null);

                            if (fsm.ChangeState(JumpState) || fsm.ChangeState(MoveState))
                            {
                                yield break;
                            }
                        }
                    }
                }
            }
            fsm.ChangeState(IdleState);
        }
Example #3
0
        public override void OnUpdate(GameEntity entity, EntityStateMachine fsm)
        {
            entity.GetComponent <MovableEntity>().EnableGravity = true;
            if (!entity.GetComponent <MovableEntity>().Climb((fsm as EntityController).ClimbSpeed))
            {
                fsm.ChangeState(AirState);
            }

            fsm.ChangeState(JumpState);
        }
Example #4
0
 public override void OnUpdate(GameEntity entity, EntityStateMachine fsm)
 {
     if (MoveState)
     {
         fsm.ChangeState(MoveState);
     }
     if (ClimbState)
     {
         fsm.ChangeState(ClimbState);
     }
 }
Example #5
0
 public override void OnUpdate(GameEntity entity, EntityStateMachine fsm)
 {
     if (entity.GetComponent <EntityEffector>().GetEffect <Stun>() == null)
     {
         fsm.ChangeState(IdleState);
     }
 }
Example #6
0
        public Entity CreateTile(float x, float y, int gid, Ground g)
        {
            var offsetX          = gid > 66 ? gid * cellSize.X - 2010 : gid * cellSize.X;
            var offsetY          = gid > 66 ? 30 : 0;
            var destroyedPos     = Vector2.Zero;
            var randForDestroyed = r.Next(3) * cellSize.X;

            if (g == Ground.Ground)
            {
                destroyedPos = new Vector2(510 + randForDestroyed, 0);
            }
            else if (g == Ground.Asphalt)
            {
                destroyedPos = new Vector2(1560 + randForDestroyed, 30);
            }
            else if (g == Ground.Sand)
            {
                destroyedPos = new Vector2(630 + randForDestroyed, 30);
            }

            var sprite = new Sprite(textureManager.Get(Images.Instance.TileSet), cellSize, Layers.Ground);
            var entity = CreateEntity();
            var fsm    = new EntityStateMachine(entity);

            fsm.CreateState(States.Alive)
            .Add <Display>().WithInstance(new Display(new Clip(sprite, new Vector2(offsetX, offsetY))));
            fsm.CreateState(States.Destroyed)
            .Add <Display>().WithInstance(new Display(new Clip(sprite, destroyedPos)));
            fsm.ChangeState(States.Alive);

            return(entity
                   .Add(new FSM(fsm))
                   .Add(new Position(x, y)));
        }
Example #7
0
        public Entity CreateTank(float x, float y, int level = 0)
        {
            var entity   = CreateEntity(EntityType.RedTank);
            var position = new Position(x, y, AntEnum.Parse <Direction>(r.Next(1, 5).ToString()));
            var myvars   = vars.LightTank[level];
            var view     = new TankView(myvars[5], 0, position.direction);

            var listFsm   = new Dictionary <string, EntityStateMachine>();
            var moveFSM   = new EntityStateMachine(entity);
            var aiFSM     = new EntityStateMachine(entity);
            var motionFSM = new EntityStateMachine(entity);

            moveFSM.CreateState(States.Stand).Add <Stand>().WithInstance(new Stand());
            moveFSM.CreateState(States.Turn).Add <Turn>().WithInstance(new Turn());
            moveFSM.CreateState(States.Walk).Add <Walk>().WithInstance(new Walk());
            moveFSM.ChangeState(States.Stand);

            aiFSM.CreateState(States.Idle).Add <Idle>().WithInstance(new Idle(7));
            aiFSM.CreateState(States.Pursuit).Add <Pursuit>().WithInstance(new Pursuit());
            aiFSM.CreateState(States.Attack).Add <Attack>().WithInstance(new Attack());
            aiFSM.ChangeState(States.Idle);

            var addSpeed = Mathf.FromPercent(0.5f, myvars[0]);

            motionFSM.CreateState(States.Fast).Add <Controls>()
            .WithInstance(new Controls(new Vector2(myvars[0] + addSpeed)));
            motionFSM.CreateState(States.Slow).Add <Controls>()
            .WithInstance(new Controls(new Vector2(myvars[0] - addSpeed)));
            motionFSM.CreateState(States.Normal).Add <Controls>()
            .WithInstance(new Controls(new Vector2(myvars[0])));
            motionFSM.ChangeState(States.Normal);

            listFsm.Add("MoveFSM", moveFSM);
            listFsm.Add("AiFSM", aiFSM);
            listFsm.Add("MotionFSM", motionFSM);

            entity
            .Add(position)
            .Add(view.GetView())
            .Add(new Health(myvars[2], myvars[4]))
            .Add(new Damage(100))
            .Add(new Tank())
            .Add(new FSM(listFsm))
            .Add(new AI(360, 210, new[] { EntityType.GreenTank }))
            .Add(new Gun(myvars[1], myvars[3]))
            .Add(new Collision(cellSize, 15))
            .Add(new Motion(Vector2.Zero, r.Next(CellType.Segment, 10000)))
            .Add(new ActionAfterDeath(() =>
            {
                gameField.ClearCell(position.prevCell);
                CreateEnemyExplosion(position.position);
                CreateQuake();
            }));

            CreateRedOverlay(entity);
            CreateGreenHealthBar(entity);

            return(entity);
        }
Example #8
0
 public override bool OnEnter(GameEntity entity, EntityState previousState, EntityStateMachine fsm)
 {
     if ((fsm as EntityController).Jumped && entity.GetComponent <MovableEntity>().Jump())
     {
         base.OnEnter(entity, previousState, fsm);
         fsm.ChangeState(AirState);
     }
     return(false);
 }
        public void AddESMComponent(NodeAddedEvent e, SingleNode <ServiceMessageComponent> node)
        {
            ServiceMessageESMComponent component = new ServiceMessageESMComponent();
            EntityStateMachine         esm       = component.Esm;

            esm.AddState <ServiceMessageStates.ServiceMessageHiddenState>();
            esm.AddState <ServiceMessageStates.ServiceMessageVisibleState>();
            node.Entity.AddComponent(component);
            esm.ChangeState <ServiceMessageStates.ServiceMessageHiddenState>();
        }
        private void SetupCameraRotationESM(Entity camera)
        {
            HangarCameraRotationStateComponent component = new HangarCameraRotationStateComponent();

            camera.AddComponent(component);
            EntityStateMachine esm = component.Esm;

            esm.AddState <HangarCameraRotationState.Enabled>();
            esm.AddState <HangarCameraRotationState.Disabled>();
            esm.ChangeState <HangarCameraRotationState.Disabled>();
        }
Example #11
0
        private void SetupCameraFlightESM(Entity camera)
        {
            HangarCameraFlightStateComponent component = new HangarCameraFlightStateComponent();

            camera.AddComponent(component);
            EntityStateMachine esm = component.Esm;

            esm.AddState <HangarCameraFlightState.EmptyState>();
            esm.AddState <HangarCameraFlightState.ArcFlightState>();
            esm.AddState <HangarCameraFlightState.LinearFlightState>();
            esm.ChangeState <HangarCameraFlightState.ArcFlightState>();
        }
Example #12
0
 public void InitESM(NodeAddedEvent e, [Combine] InteractivityPrerequisiteNode prerequisite, [JoinByScreen, Combine, Context] DependentInteractivityNode interactableElement)
 {
     if (!prerequisite.Entity.HasComponent <InteractivityPrerequisiteESMComponent>())
     {
         InteractivityPrerequisiteESMComponent component = new InteractivityPrerequisiteESMComponent();
         prerequisite.Entity.AddComponent(component);
         EntityStateMachine esm = component.Esm;
         esm.AddState <InteractivityPrerequisiteStates.AcceptableState>();
         esm.AddState <InteractivityPrerequisiteStates.NotAcceptableState>();
         esm.ChangeState <InteractivityPrerequisiteStates.NotAcceptableState>();
     }
 }
        private void SetupCameraViewESM(Entity camera)
        {
            HangarCameraViewStateComponent component = new HangarCameraViewStateComponent();

            camera.AddComponent(component);
            EntityStateMachine esm = component.Esm;

            esm.AddState <HangarCameraViewState.TankViewState>();
            esm.AddState <HangarCameraViewState.FlightToLocationState>();
            esm.AddState <HangarCameraViewState.LocationViewState>();
            esm.AddState <HangarCameraViewState.FlightToTankState>();
            esm.ChangeState <HangarCameraViewState.TankViewState>();
        }
Example #14
0
        public void InitESM(NodeAddedEvent e, SingleNode <InputFieldComponent> node)
        {
            ESMComponent component = new ESMComponent();

            node.Entity.AddComponent(component);
            EntityStateMachine esm = component.Esm;

            esm.AddState <InputFieldStates.NormalState>();
            esm.AddState <InputFieldStates.InvalidState>();
            esm.AddState <InputFieldStates.ValidState>();
            esm.AddState <InputFieldStates.AwaitState>();
            esm.ChangeState <InputFieldStates.NormalState>();
        }
Example #15
0
        public override void OnUpdate(GameEntity entity, EntityStateMachine fsm)
        {
            // Movement
            var movement = entity.GetComponent <EntityController>().Movement;

            movement.y = 0;
            entity.GetComponent <MovableEntity>().Move(movement);

            if (Mathf.Approximately(movement.x, 0))
            {
                fsm.ChangeState(IdleState);
            }
            else
            {
                entity.GetComponent <AnimationController>().PlayAnimation(AnimatorController, movement.x);
            }

            if (!entity.GetComponent <MovableEntity>().OnGround)
            {
                fsm.ChangeState(AirState);
            }

            if (JumpState)
            {
                fsm.ChangeState(JumpState);
            }

            if (ClimbState)
            {
                fsm.ChangeState(ClimbState);
            }

            if (SkillState)
            {
                fsm.ChangeState(SkillState);
            }
        }
Example #16
0
        /*
         * public override bool OnEnter(GameEntity entity, EntityState previousState, EntityStateMachine fsm)
         * {
         *  entity.GetComponent<EventBus>().AddEventListenerOnce("Hit", () =>
         *  {
         *      fsm.ChangeState(HitState);
         *  });
         *  entity.GetComponent<AnimationController>().ChangeAnimation(AnimatorController, (GameSystem.Instance.PlayerInControl.transform.position - entity.transform.position).x);
         *  return base.OnEnter(entity, previousState, fsm);
         * }*/

        public override void OnUpdate(GameEntity entity, EntityStateMachine fsm)
        {
            if (MoveState && fsm.ChangeState(MoveState))
            {
                return;
            }
            if (JumpState && fsm.ChangeState(JumpState))
            {
                return;
            }
            if (SkillState && fsm.ChangeState(SkillState))
            {
                return;
            }
            if (ClimbState && fsm.ChangeState(ClimbState))
            {
                return;
            }
            if (!entity.GetComponent <MovableEntity>().OnGround&& fsm.ChangeState(AirState))
            {
                return;
            }
            fsm.GetComponent <AnimationController>().PlayAnimation(AnimatorController, (fsm as EntityController).FaceDirection);
        }
Example #17
0
        public Entity CreateTower(float x, float y, int level = 0)
        {
            var entity   = CreateEntity(EntityType.RedTank);
            var listFsm  = new Dictionary <string, EntityStateMachine>();
            var moveFSM  = new EntityStateMachine(entity);
            var aiFSM    = new EntityStateMachine(entity);
            var position = new Position(x, y, AntEnum.Parse <Direction>(r.Next(1, 5).ToString()));
            var myvars   = vars.Tower[level];
            var view     = new TowerView(myvars[5], position.direction);

            moveFSM.CreateState(States.Stand).Add <Stand>().WithInstance(new Stand());
            moveFSM.CreateState(States.Turn).Add <Turn>().WithInstance(new Turn());
            moveFSM.ChangeState(States.Stand);

            aiFSM.CreateState(States.Idle).Add <Idle>().WithInstance(new Idle(10));
            aiFSM.CreateState(States.Attack).Add <Attack>().WithInstance(new Attack());
            aiFSM.ChangeState(States.Idle);

            listFsm.Add("MoveFSM", moveFSM);
            listFsm.Add("AiFSM", aiFSM);

            entity
            .Add(position)
            .Add(view.GetView())
            .Add(new Health(myvars[2], myvars[4]))
            .Add(new Damage(100))
            .Add(new Tank())
            .Add(new FSM(listFsm))
            .Add(new AI(210, 210, new[] { EntityType.GreenTank }))
            .Add(new Gun(myvars[1], myvars[3]))
            .Add(new Collision(cellSize, 15))
            .Add(new Motion(Vector2.Zero, r.Next(CellType.Segment, 10000)))
            .Add(new ActionAfterDeath(() =>
            {
                gameField.ClearCell(position.position.Divide(cellSize.X));
                CreateEnemyExplosion(position.position);
                CreateQuake();
            }));

            CreateRedOverlay(entity);
            CreateGreenHealthBar(entity);
            AddCellToMap(x, y, CellType.Tower);

            return(entity);
        }
        public void InitShaftShotAnimation(NodeAddedEvent evt, InitialShaftShotAnimationNode weapon)
        {
            Animator             animator    = weapon.animation.Animator;
            ShaftEnergyComponent shaftEnergy = weapon.shaftEnergy;
            Entity entity = weapon.Entity;

            weapon.shaftShotAnimation.Init(animator, weapon.weaponCooldown.CooldownIntervalSec, shaftEnergy.UnloadEnergyPerQuickShot, shaftEnergy.ReloadEnergyPerSec, shaftEnergy.PossibleUnloadEnergyPerAimingShot);
            weapon.shaftShotAnimationTrigger.Entity = entity;
            ShaftShotAnimationESMComponent component = new ShaftShotAnimationESMComponent();

            entity.AddComponent(component);
            EntityStateMachine esm = component.Esm;

            esm.AddState <ShaftShotAnimationStates.ShaftShotAnimationIdleState>();
            esm.AddState <ShaftShotAnimationStates.ShaftShotAnimationBounceState>();
            esm.AddState <ShaftShotAnimationStates.ShaftShotAnimationCooldownState>();
            esm.ChangeState <ShaftShotAnimationStates.ShaftShotAnimationIdleState>();
        }
 public void InitPlayButton(NodeAddedEvent e, SingleNode <MainScreenComponent> screen, Optional <ButtonNode> pb)
 {
     if (!pb.IsPresent())
     {
         Entity entity = base.CreateEntity("PlayButtonEntity");
         screen.component.playButton.GetComponent <EntityBehaviour>().BuildEntity(entity);
         ESMComponent component = new ESMComponent();
         entity.AddComponent(component);
         EntityStateMachine esm = component.Esm;
         esm.AddState <PlayButtonStates.NormalState>();
         esm.AddState <PlayButtonStates.SearchingState>();
         esm.AddState <PlayButtonStates.EnteringLobbyState>();
         esm.AddState <PlayButtonStates.MatchBeginTimerState>();
         esm.AddState <PlayButtonStates.NotEnoughtPlayersState>();
         esm.AddState <PlayButtonStates.MatchBeginningState>();
         esm.AddState <PlayButtonStates.CustomBattleState>();
         esm.AddState <PlayButtonStates.StartCustomBattleState>();
         esm.AddState <PlayButtonStates.ReturnToBattleState>();
         esm.AddState <PlayButtonStates.EnergyShareScreenState>();
         esm.ChangeState <PlayButtonStates.NormalState>();
     }
 }
Example #20
0
        public override IEnumerator Begin(GameEntity entity, EntityStateMachine fsm)
        {
            yield return(entity.GetComponent <SkillController>().WaitSkill());

            fsm.ChangeState(IdleState);
        }
Example #21
0
        public Entity CreatePlayer(float x, float y)
        {
            var entity   = CreateEntity(EntityType.GreenTank);
            var position = new Position(x, y, Direction.Left);
            var view     = new TankView(32, 36, position.direction);

            var listFsm   = new Dictionary <string, EntityStateMachine>();
            var moveFSM   = new EntityStateMachine(entity);
            var motionFSM = new EntityStateMachine(entity);

            moveFSM.CreateState(States.Stand).Add <Stand>().WithInstance(new Stand());
            moveFSM.CreateState(States.Turn).Add <Turn>().WithInstance(new Turn());
            moveFSM.CreateState(States.Walk).Add <Walk>().WithInstance(new Walk());
            moveFSM.ChangeState(States.Stand);

            var speed    = 1.5f;
            var addSpeed = Mathf.FromPercent(0.5f, speed);

            motionFSM.CreateState(States.Fast).Add <Controls>()
            .WithInstance(new Controls(
                              Config.Instance.MoveUp,
                              Config.Instance.MoveDown,
                              Config.Instance.MoveLeft,
                              Config.Instance.MoveRight,
                              new Vector2(speed + addSpeed)));

            motionFSM.CreateState(States.Slow).Add <Controls>()
            .WithInstance(new Controls(
                              Config.Instance.MoveUp,
                              Config.Instance.MoveDown,
                              Config.Instance.MoveLeft,
                              Config.Instance.MoveRight,
                              new Vector2(speed - addSpeed)));

            motionFSM.CreateState(States.Normal).Add <Controls>()
            .WithInstance(new Controls(
                              Config.Instance.MoveUp,
                              Config.Instance.MoveDown,
                              Config.Instance.MoveLeft,
                              Config.Instance.MoveRight,
                              new Vector2(speed)));
            motionFSM.ChangeState(States.Normal);

            listFsm.Add("MoveFSM", moveFSM);
            listFsm.Add("MotionFSM", motionFSM);

            entity
            .Add(position)
            .Add(view.GetView())
            .Add(new Health(100, 0))
            .Add(new Damage(100))
            .Add(new Player())
            .Add(new FSM(listFsm))
            .Add(new Gun(5, 500))
            .Add(new GunControls(Config.Instance.GunTrigger))
            .Add(new Motion(Vector2.Zero, r.Next(CellType.Segment, 10000)))
            .Add(new Collision(cellSize, 15))
            .Add(new ActionAfterDeath(() =>
            {
                gameField.ClearCell(position.prevCell);
                CreateEnemyExplosion(position.position);
                CreateQuake();
            }));

            CreateGreenOverlay(entity);
            CreateGreenHealthBar(entity);

            return(entity);
        }