Пример #1
0
        public bool SetPosition(Vec2 newpos)
        {
            bool ret = true;

            ret = _playerShape.MoveTo(newpos);
            RecordPosition(_playerShape.pos);
            _collisionCircle.setPosition(GetPosition());
            return(ret);
        }
Пример #2
0
        public bool Update()
        {
            if (Vec2.Approximately(position, targetposition))
            {
                if (rand.NextDouble() <= 0.5)
                {
                    targetposition = GetRandPosFromArea(new Vec2(10, 10), new Vec2(2600, 330));

                    return(true);
                }
                else
                {
                    state   = NPC_STATE.STOP;
                    stopfor = (rand.NextDouble() + 1.0) * 30;
                }
            }
            else
            {
                switch (state)
                {
                case NPC_STATE.STOP:
                    timer++;
                    if (timer >= stopfor)
                    {
                        state   = NPC_STATE.MOVE;
                        timer   = 0;
                        stopfor = 0;
                    }
                    break;

                case NPC_STATE.MOVE:
                    Vec2 diff = targetposition - position;
                    diff      = Vec2.Normalize(diff);
                    diff     *= speed;
                    position += diff;
                    collision.setPosition(position);
                    break;

                case NPC_STATE.BATTLE:
                    break;
                }
            }
            return(false);
        }