protected override void InitControl(ISceneObject me)
        {
            if (!(me.CollisionShape is SquareCollisionShape))
            {
                throw new Exception("Collision shape must be Square");
            }

            cs = me.CollisionShape as SquareCollisionShape;
        }
示例#2
0
 public FloatingText(string text, Vector position, float time, FloatingTextType type, float fontSize, bool send)
 {
     Text                 = text;
     Position             = position;
     TotalTime            = time;
     RemainingTime        = time;
     Type                 = type;
     FontSize             = fontSize;
     Send                 = send;
     CS                   = new SquareCollisionShape();
     LastCollisionMovedUp = false;
     CollisionArea        = new Rect();
 }
示例#3
0
        public void ReadObject(NetIncomingMessage msg)
        {
            msg.ReadObjectStatPowerUp(this);

            SquareCollisionShape cs = new SquareCollisionShape();

            cs.Position    = Position;
            cs.Size        = Size;
            cs.Rotation    = Rotation;
            CollisionShape = cs;

            IList <IControl> controls = msg.ReadControls();

            foreach (Control c in controls)
            {
                AddControl(c);
            }
        }
示例#4
0
        /// <summary>
        /// prepocitava velikost kolizniho obdelniku floating textu tak, ze k nemu pricte poskytnuty kolizni obdelnik
        /// kolizni obdelnik udava oblast, ve ktere doslo ke kolizi a uz v ni neni opakovane zkouseno hledat volne misto
        /// </summary>
        /// <param name="squareCollisionShape"></param>
        private void UpdateCollisionArea(FloatingText ft, SquareCollisionShape cs)
        {
            // leva
            double x1 = ft.CollisionArea.Left;

            if (cs.Position.X < ft.CollisionArea.Left)
            {
                x1 = cs.Position.X - 1;
            }

            // prava
            double x2 = ft.CollisionArea.Right;

            if (cs.Position.X + cs.Size.Width > ft.CollisionArea.Right)
            {
                x2 = cs.Position.X + cs.Size.Width + 1;
            }

            // horni
            double y1 = ft.CollisionArea.Top;

            if (cs.Position.Y < ft.CollisionArea.Top)
            {
                y1 = cs.Position.Y - 1;
            }

            // dolni
            double y2 = ft.CollisionArea.Bottom;

            if (cs.Position.Y + cs.Size.Height > ft.CollisionArea.Bottom)
            {
                y2 = cs.Position.Y + cs.Size.Height + 1;
            }

            ft.CollisionArea = new Rect(x1, y1, x2 - x1, y2 - y1);

            if (CollisionShapeVisualization)
            {
                ShowCA(ft);
            }
        }
        public static StatPowerUp CreateStatPowerUp(ServerMgr mgr, DeviceType type)
        {
            Random randomGenerator = mgr.GetRandomGenerator();

            StatPowerUp s = new StatPowerUp(null, IdMgr.GetNewId(0));

            s.Size = new Size(20, 20);
            bool headingRight = randomGenerator.Next(10) > 5 ? true : false;

            s.Position  = GetPositionOnEdgeOfLowerOrbitArea(randomGenerator, headingRight, (int)s.Size.Width / 2);
            s.Direction = headingRight ? new Vector(1, 0) : new Vector(-1, 0);
            s.Rotation  = mgr.GetRandomGenerator().Next(360);

            s.PowerUpType = type;

            SquareCollisionShape cs = new SquareCollisionShape();

            cs.Position      = s.Position;
            cs.Size          = s.Size;
            cs.Rotation      = s.Rotation;
            s.CollisionShape = cs;

            NewtonianMovementControl nmc = new NewtonianMovementControl();

            nmc.Speed = mgr.GetRandomGenerator().Next(SharedDef.MIN_POWERUP_SPEED * 10, SharedDef.MAX_POWERUP_SPEED * 10) / 10.0f;
            s.AddControl(nmc);

            LinearRotationControl lrc = new LinearRotationControl();

            lrc.RotationSpeed = mgr.GetRandomGenerator().Next(SharedDef.MIN_ASTEROID_ROTATION_SPEED, SharedDef.MAX_ASTEROID_ROTATION_SPEED) / 10.0f;
            s.AddControl(lrc);

            s.AddControl(new StickySquareCollisionShapeControl());
            s.AddControl(new StatPowerUpCollisionReactionControl());

            return(s);
        }