Пример #1
0
        public void Insert(CollisionCircle circle)
        {
            if (_nodes[0] != null)
            {
                int index = GetIndex(circle);
                if (index != -1)
                {
                    _nodes[index].Insert(circle);
                    return;
                }
            }

            _collisiobobejcts.Add(circle);
            if (_collisiobobejcts.Count > MAX_OBJECTS && _layer < MAX_LAYERS)
            {
                if (_nodes[0] == null)
                {
                    Split();
                }
                for (int i = 0; i < _collisiobobejcts.Count;)
                {
                    int index = GetIndex(_collisiobobejcts[i]);
                    if (index != -1)
                    {
                        _nodes[index].Insert(new CollisionCircle(circle));
                    }
                    else
                    {
                        i++;
                    }
                }
            }
        }
Пример #2
0
 public CollisionCircle(CollisionCircle circle)
 {
     _center = circle.getCenter();
     _radius = circle.getRadius();
     _object = circle.getObject();
     _type   = circle.getType();
 }
Пример #3
0
 public RemotePlayer(string connectionID, int ID, PlayerActor player)
 {
     _connectionId    = connectionID;
     _playerShape     = player;
     _id              = ID;
     _collisionCircle = new CollisionCircle(_playerShape.pos, 30, this, CollisionCircle.ObjectType.PLAYER);
 }
Пример #4
0
 public RemotePlayer(string connectionID, int ID, string areaname, string name)
 {
     _connectionId = connectionID;
     _playerShape  = new PlayerActor(ID, new Vec2(0, 0), connectionID, name, 1);
     _playerShape.LastUpdatedBy = connectionID;
     this.areaname      = areaname;
     _recordedpositions = new Vec2[10];
     _collisionCircle   = new CollisionCircle(_playerShape.pos, 30, this, CollisionCircle.ObjectType.PLAYER);
     for (int i = 0; i < 10; i++)
     {
         RecordPosition(GetPosition());
     }
     hasmoved = false;
 }
Пример #5
0
        public List <CollisionCircle> Retrieve(List <CollisionCircle> ret, CollisionCircle circle)
        {
            //Check where the circle fits
            int index = GetIndex(circle);

            //if it actually fit somewhere and this has nodes
            if (index != -1 && _nodes[0] != null)
            {
                //recursively retrieve from correct node
                _nodes[index].Retrieve(ret, circle);
            }
            //retrieve this leaf's objects
            foreach (CollisionCircle c in _collisiobobejcts)
            {
                ret.Add(c);
            }
            return(ret);
        }
Пример #6
0
 public Npc(Item hat, int level, Vec2 position, bool hostile, double id, string areaname)
 {
     this.id             = id;
     rand                = MyRandom.rand;
     this.position       = position;
     this.targetposition = position;
     droplist            = new List <Item>();
     this.stats          = new Stats(hat, level);
     this.appearance     = hat.baseitem.appearance;
     droplist.Add(hat);
     this.level     = level;
     this.hostile   = hostile;
     this.speed     = 4;
     this.collision = new CollisionCircle(position, 50, this, CollisionCircle.ObjectType.NPC);
     state          = NPC_STATE.STOP;
     timer          = 0;
     stopfor        = 40;
     this.areaname  = areaname;
 }
Пример #7
0
        //Test where collisioncircle fits
        private int GetIndex(CollisionCircle circle)
        {
            //parent is -1 if circle cannot fit into the nodes it will belong to this leaf
            int index = -1;

            //test if the circle fits in the top quadrant of the rect
            bool top = (circle.getCenter().y + circle.getRadius() < _limits.getCenter().y + _limits.getHeight() / 2 && circle.getCenter().y - circle.getRadius() > _limits.getCenter().y);

            bool bottom = (circle.getCenter().y + circle.getRadius() < _limits.getCenter().y&& circle.getCenter().y - circle.getRadius() > _limits.getCenter().y - _limits.getHeight() / 2);

            //test if the circle fits completely in the left quadrant
            if (circle.getCenter().x + circle.getRadius() < _limits.getCenter().x&&
                circle.getCenter().x - circle.getRadius() > _limits.getCenter().x - _limits.getWidth() / 2)
            {
                if (top)
                {
                    index = 0;
                }
                else if (bottom)
                {
                    index = 2;
                }
            }
            //else test if it fits completely in the right quadrant
            else if (circle.getCenter().x + circle.getRadius() < _limits.getCenter().x + _limits.getWidth() / 2 &&
                     circle.getCenter().x - circle.getRadius() > _limits.getCenter().x)
            {
                if (top)
                {
                    index = 1;
                }
                else if (bottom)
                {
                    index = 3;
                }
            }

            //returns -1 if circle doesn't fit completely into any quadrant
            return(index);
        }