示例#1
0
        public void Spawn()
        {
            if (GameStateService.CurEnemyCount >= GameStateService.MaxEnemyCount)
            {
                return;
            }

            GameStateService.CurEnemyCount++;
            GameStateService.CreateEntity <Enemy>(Info.prefabId, Info.spawnPoint);
        }
 public GameStateService()
 {
     Instance = this;
 }
示例#3
0
        public override void DoUpdate(LFloat deltaTime)
        {
            if (!entity.rigidbody.isOnFloor)
            {
                return;
            }

            //find target
            var    allPlayer = GameStateService.GetPlayers();
            var    minDist   = LFloat.MaxValue;
            Entity minTarget = null;

            foreach (var player in allPlayer)
            {
                if (player.isDead)
                {
                    continue;
                }
                var dist = (player.transform.pos - transform.pos).sqrMagnitude;
                if (dist < minDist)
                {
                    minTarget = player;
                    minDist   = dist;
                }
            }

            target   = minTarget;
            targetId = target?.EntityId ?? -1;

            if (minTarget == null)
            {
                return;
            }
            if (minDist > stopDistSqr)
            {
                // turn to target
                var targetPos  = minTarget.transform.pos;
                var currentPos = transform.pos;
                var turnVal    = entity.turnSpd * deltaTime;
                var targetDeg  = CTransform2D.TurnToward(targetPos, currentPos, transform.deg, turnVal,
                                                         out var isFinishedTurn);
                transform.deg = targetDeg;
                //move to target
                var distToTarget = (targetPos - currentPos).magnitude;
                var movingStep   = entity.moveSpd * deltaTime;
                if (movingStep > distToTarget)
                {
                    movingStep = distToTarget;
                }

                var toTarget = (targetPos - currentPos).normalized;
                transform.pos = transform.pos + toTarget * movingStep;
            }
            else
            {
                //atk target
                atkTimer -= deltaTime;
                if (atkTimer <= 0)
                {
                    atkTimer = atkInterval;
                    //Atk
                    target.TakeDamage(entity.damage, target.transform.Pos3);
                }
            }
        }
示例#4
0
 protected virtual void OnDead()
 {
     EntityView?.OnDead();
     PhysicSystem.Instance.RemoveCollider(this);
     GameStateService.DestroyEntity(this);
 }
示例#5
0
 public override void BindEntity(BaseEntity e)
 {
     base.BindEntity(e);
     target = GameStateService.GetEntity(targetId) as Entity;
 }