Пример #1
0
        public void Initialize()
        {
            blaster        = new Blaster(this);
            this.maxHealth = 10;
            this.Health    = this.maxHealth;

            TimedActionManager.GetInstance().RegisterAction(
                () =>
            {
                if (last_time + MovementSpeed <= Time.time)
                {
                    // Holding key down
                    last_time = Time.time;
                    HandleGetKey();
                }
                else
                {
                    if (HandleGetKeyDown())
                    {
                        // Looks like we moved. Reset the clock!
                        last_time = Time.time;
                    }
                }
            }
                , this, MovementPollRate
                );
        }
Пример #2
0
 public void DoTimedAction()
 {
     if (Time.time >= LastTime + Timeout + TimedActionManager.GetLag())
     {
         Action();
         LastTime = Time.time;
     }
 }
Пример #3
0
        public void StopShooting()
        {
            if (action == null)
            {
                return;
            }

            TimedActionManager
            .GetInstance()
            .UnregisterAction(action, this);

            action = null;
        }
Пример #4
0
        // Start is called before the first frame update
        void Awake()
        {
            boardArray = new Tile[height, width];
            InitTiles();

            TimedActionManager.GetInstance().RegisterAction(
                () =>
            {
                TickAllTiles();
            },
                this,
                1f / TickRate
                );
        }
Пример #5
0
        public TileEntity(GameBoard gb, string name, int maxHealth, TileEntityType tileEntityType)
        {
            this.name             = name;
            this.maxHealth        = maxHealth;
            this.gameBoard        = gb;
            this.uid              = System.Guid.NewGuid().ToString();
            this.MyTileEntityType = tileEntityType;

            // Update health every .5 seconds
            TimedActionManager.GetInstance().RegisterAction(
                () =>
            {
                DoTick();
            }
                , this, .5f);
        }
Пример #6
0
        public void StartShooting(float interval)
        {
            if (action != null)
            {
                Debug.Log("[TurretEntity] Turret is already shooting");
                return;
            }

            action =
                TimedActionManager
                .GetInstance()
                .RegisterAction(
                    () =>
            {
                DoShoot();
            },
                    this,
                    interval
                    );
        }
Пример #7
0
 // Update is called once per frame
 void Update()
 {
     TimedActionManager.GetInstance().DoActions();
 }
Пример #8
0
        protected void StartAI()
        {
            directionWeights = new double[numDirections];
            AssignRandomProbability();

            TimedActionManager.GetInstance().RegisterAction(
                () =>
            {
                ProbabilityUpdatePolicy();

                string s = "";
                for (int i = 0; i < directionWeights.Length; ++i)
                {
                    s += directionWeights[i] + " ";
                }
                double upVal   = directionWeights[DIRS.UP] * 100000;
                double downVal = directionWeights[DIRS.DOWN] * 100000;
                double lVal    = directionWeights[DIRS.LEFT] * 100000;
                double rVal    = directionWeights[DIRS.RIGHT] * 100000;

                double lower = lVal + rVal;
                double upper = lower + downVal + upVal;

                int idx = 0;
                if ((int)upper <= 0 || random.Next(0, (int)upper) <= lower)
                {
                    lVal += rVal;
                    // move up/down
                    if ((int)lVal <= 0 || random.Next(0, (int)lVal) <= rVal)
                    {
                        idx = DIRS.RIGHT;
                    }
                    else
                    {
                        idx = DIRS.LEFT;
                    }
                }
                else
                {
                    downVal += upVal;
                    // move up/down
                    if (random.Next(0, (int)downVal) <= upVal)
                    {
                        idx = DIRS.UP;
                    }
                    else
                    {
                        idx = DIRS.DOWN;
                    }
                }

                switch (idx)
                {
                case DIRS.UP:
                    GameManager.Instance.MyGameBoard.DoMoveTileEntity(this, TileEntityConstants.DirectionVectors.UP, false);
                    break;

                case DIRS.DOWN:
                    GameManager.Instance.MyGameBoard.DoMoveTileEntity(this, TileEntityConstants.DirectionVectors.DOWN, false);
                    break;

                case DIRS.LEFT:
                    GameManager.Instance.MyGameBoard.DoMoveTileEntity(this, TileEntityConstants.DirectionVectors.LEFT, false);
                    break;

                case DIRS.RIGHT:
                    GameManager.Instance.MyGameBoard.DoMoveTileEntity(this, TileEntityConstants.DirectionVectors.RIGHT, false);
                    break;

                default:
                    break;
                }
            }, this, SPEED
                );
        }