Пример #1
0
        private void solidCollide(CActor collider)
        {
            //Calculate How much to move to get out of collision moving towards last collisionless point
            CHitBox otherbox = collider.hitBox;

            //Calculate how far in we went
            float distx = (collider.position.X + otherbox.center.X) - (position.X + hitBox.center.X);

            distx = (float)Math.Sqrt(distx * distx);
            float disty = (position.Y + hitBox.center.Y) - (collider.position.Y + otherbox.center.Y);

            disty = (float)Math.Sqrt(disty * disty);

            float lenx = hitBox.halfWidth + otherbox.halfWidth;
            float leny = hitBox.halfHeight + otherbox.halfHeight;

            int px = 1;
            int py = 1;

            if (collider.position.X + otherbox.center.X < position.X + hitBox.center.X)
            {
                px = -1;
            }
            if (collider.position.Y + otherbox.center.Y < position.Y + hitBox.center.Y)
            {
                py = -1;
            }

            float penx = px * (distx - lenx);
            float peny = py * (disty - leny);
            //Resolve closest to previous position
            float diffx = (position.X + penx) - _oldPosition.X;

            diffx *= diffx;
            float diffy = (position.Y + peny) - _oldPosition.Y;

            diffy *= diffy;

            if (diffx < diffy)
            {
                _position.X += penx; //TODO: dont make a new vector every time
            }
            else if (diffx > diffy)
            {
                _position.Y += peny; //Same here
            }
            else
            {
                position = new Vector2(position.X + penx, position.Y + peny); //Corner cases
            }
        }
Пример #2
0
 public CDoor() :
     base()
 {
     _hitBox = new CHitBox(this, 0, 0, 16, 16);
 }
Пример #3
0
        private void dropHitbox(Vector2 position, MouseEventArgs args)
        {
            if (_hitboxTopLeft.X == -1 && _hitboxTopLeft.Y == -1)
            {
                if (args.Button == MouseButtons.Right)
                {
                    mpvMapView.deleteHitbox(position, mapHScroll.Value, mapVScroll.Value);
                }
                else
                {
                    position.X    += mapHScroll.Value;
                    position.Y    += mapVScroll.Value;
                    _hitboxTopLeft = position;
                }
            }
            else
            {
                position.X += mapHScroll.Value;
                position.Y += mapVScroll.Value;
                if (args.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    _hitboxTopLeft = new Vector2(-1, -1);
                    return;
                }
                string hbParams = "";
                King_of_Thieves.Actors.Collision.CSolidTile box = new Actors.Collision.CSolidTile((int)_hitboxTopLeft.X, (int)_hitboxTopLeft.Y, (int)(position.X - _hitboxTopLeft.X), (int)(position.Y - _hitboxTopLeft.Y));
                _hitBoxCounter += 1;


                hbParams = (int)(position.X - _hitboxTopLeft.X) + ":" + (int)(position.Y - _hitboxTopLeft.Y);
                string[] hbParamsArr = hbParams.Split(':');
                mpvMapView.dropActor("King_of_Thieves.Actors.Collision.CSolidTile", "hitbox" + CHitBox.produceRandomName(), _hitboxTopLeft, cmbLayers.SelectedIndex, hbParamsArr);
                _hitboxTopLeft = new Vector2(-1, -1);
            }
        }