Пример #1
0
 public LPath(Vec2 v0,Vec2 v1)
 {
     N = 2;
     PATH = new Vec2[2];
     PATH[0] = v0;
     PATH[1] = v1;
 }
Пример #2
0
 public static int FastDistance(Vec2 v1, Vec2 v2)
 {
     r = Mathf.Abs(v1.R - v2.R);
     c = Mathf.Abs(v1.C - v2.C);
     if (r > c) return r;
     return c;
 }
Пример #3
0
 public Lazer(Vec2 pos, Vec2 p2)
 {
     Health = new Health(0.2);
     Position = pos;
     this.p2 = p2;
     Velocity = Direction * Speed;
 }
Пример #4
0
 public Vertex(Vec3 position, Vec3 normal, Vec2 texCoord, Vec3 tangent)
 {
     this.position = position;
     this.normal = normal;
     this.texCoord = texCoord;
     this.tangent = tangent;
 }
 protected override void Deserialize(BinaryReader reader)
 {
     base.Deserialize(reader);
     _beginModelPoint = Vec2.Deserialize(reader);
     _endModelPoint = Vec2.Deserialize(reader);
     _z = Vec2.Deserialize(reader);
 }
Пример #6
0
 public override void MouseMove(Vec2 pos)
 {
     base.MouseMove(pos);
     pos = new Camera(10).FromWH(pos, App.Width, App.Height);
     foreach (var b in buttons)
         b.Selected = b.Inside(pos);
 }
Пример #7
0
 public override void MouseDown(MouseButton button, Vec2 pos)
 {
     base.MouseDown(button, pos);
     foreach (var b in buttons)
         if (b.Selected)
             b.Action.Apply();
 }
Пример #8
0
 public Bullet(Vec2 pos, Vec2 p2)
 {
     Health = new Health(0.5);
     Position = pos;
     this.p2 = p2;
     Velocity = Direction * Speed;
 }
Пример #9
0
 public ProxyTile(ITileServer server, Vec2 point)
 {
     this.loaded = false;
     this.point = point;
     this.server = server;
     this.tile = new Tile (point, 0);
 }
Пример #10
0
 /**
    * Initialize the bodies, anchors, axis, and reference angle using the world anchor and world
    * axis.
    */
 public void initialize(Body bA, Body bB, Vec2 anchor)
 {
     bodyA = bA;
     bodyB = bB;
     bA.getLocalPointToOut(anchor, ref localAnchorA);
     bB.getLocalPointToOut(anchor, ref localAnchorB);
 }
Пример #11
0
        protected override void OnRenderUI( GuiRenderer renderer )
        {
            base.OnRenderUI( renderer );

            Vec2 size = new Vec2( 232, 335 );
            //size *= 1.0f + Time * .015f;
            size /= new Vec2( 768.0f * renderer.AspectRatio, 768.0f );

            Rect rectangle = new Rect( -size / 2, size / 2 ) + new Vec2( .3f, .5f );

            float alpha = 0;

            if( Time > 1 && Time <= 2 )
                alpha = Time - 1;
            else if( Time > 2 && Time <= lifeTime - 2 - 2 )
                alpha = 1;
            else if( Time >= lifeTime - 2 - 2 && Time < lifeTime - 1 )
                alpha = 1 - ( Time - ( lifeTime - 2 - 2 ) ) / 3;

            if( alpha != 0 )
            {
                renderer.AddQuad( rectangle, new Rect( 0, 0, 1, 1 ), productTexture,
                    new ColorValue( 1, 1, 1, alpha ) );
            }
        }
Пример #12
0
 public void addGenerator(Vec2 center, int tag)
 {
     Generator g = m_generatorBuffer[m_generatorCount++];
     g.center.x = center.x;
     g.center.y = center.y;
     g.tag = tag;
 }
Пример #13
0
 public void Shoot(Vec2 pos)
 {
     if (RemainingReloadTime > 0)
         return;
     RemainingReloadTime = ReloadTime;
     DoShoot(pos);
 }
Пример #14
0
        public override void initTest(bool argDeserialized)
        {
            input.transformA = new Transform();
            input.transformB = new Transform();
            {
                m_transformA = new Transform();
                m_transformA.setIdentity();
                m_transformA.p.set(0.0f, -0.2f);
                m_polygonA = new PolygonShape();
                m_polygonA.setAsBox(10.0f, 0.2f);
            }

            {
                m_positionB = new Vec2();
                m_positionB.set(12.017401f, 0.13678508f);
                m_angleB = -0.0109265f;

                m_transformB = new Transform();
                m_transformB.set(m_positionB, m_angleB);

                m_polygonB = new PolygonShape();
                m_polygonB.setAsBox(2.0f, 0.1f);
            }
            for (int i = 0; i < v.Length; i++)
            {
                v[i] = new Vec2();
            }
        }
Пример #15
0
 public WeldJointDef()
     : base(JointType.WELD)
 {
     localAnchorA = new Vec2();
     localAnchorB = new Vec2();
     referenceAngle = 0.0f;
 }
Пример #16
0
        public Vec2 Move(Human LeMe, IEnumerable<Human> NearestNeighbours)
        {
            if ((LeMe.Node - LeMe.Position).Length() > 100.0f)
            {
                LeMe.Node = this.GetNewTarget(LeMe);

                if (LeMe.HumanType == HumanType.Agent)
                {
                    LeMe.MovementBehaviour = new AgentMovementBehaviour();
                }
                else
                {
                    LeMe.MovementBehaviour = new UsualMovementBehaviour();
                }
            }

            this.velocity = LeMe.Node - LeMe.Position;
            this.velocity.Mul(-1.0f);

            this.velocity.Mul(1.0f / this.velocity.Length());

            this.velocity.Mul(this.speed);

            foreach (var human in NearestNeighbours.Where(Human => Human.Position != LeMe.Position && !(Human.HumanType != HumanType.Agent && LeMe.HumanType == HumanType.Victim)))
            {
                this.distance = human.Position - LeMe.Position;

                var num = this.distance.Length();

                distance.Mul(1.0f / distance.Length());

                distance.Mul(1.7f);

                if (!(num <= 15.0f))
                {
                    continue;
                }

                num = 15.0f - num;

                num /= 15.0f;

                this.distance.Mul(num * -1f);

                this.distance.Mul(3.5f);

                this.velocity += this.distance;

                this.distance = human.Position - LeMe.Position;
            }

            this.velocity.Mul(1.0f / this.velocity.Length());

            this.velocity.Mul(this.speed);

            LeMe.Position = LeMe.Position + this.velocity;

            return LeMe.Position;
        }
Пример #17
0
        public UsualMovementBehaviour()
        {
            velocity = new Vec2(0, 0);

            distance = new Vec2(0, 0);

            speed = 2.0f;
        }
        public AgentMovementBehaviour()
        {
            velocity = new Vec2(0, 0);

            distance = new Vec2(0, 0);

            speed = 2.4f;
        }
Пример #19
0
		public TeamMetaInfo(Vec2 spawnTile, Vec2 baseTile, Vec2 baseTowerTile, Vec2 botTowerTile, Vec2 topTowerTile)
		{
			SpawnTileIds = spawnTile;
			BaseTileIds = baseTile;
			BaseTowerTileIds = baseTowerTile;
			BottomTowerTileIds = botTowerTile;
			TopTowerTileIds = topTowerTile;
		}
Пример #20
0
 public FrictionJointDef()
     : base(JointType.FRICTION)
 {
     localAnchorA = new Vec2();
     localAnchorB = new Vec2();
     maxForce = 0f;
     maxTorque = 0f;
 }
Пример #21
0
        public EvadeMovementBehaviour()
        {
            velocity = new Vec2(0, 0);

            distance = new Vec2(0, 0);

            speed = 3.0f;
        }
Пример #22
0
        protected override void OnUpdateParameters( CompositorParameters parameters )
        {
            base.OnUpdateParameters( parameters );

            RadialBlurCompositorParameters p = (RadialBlurCompositorParameters)parameters;
            Center = p.Center;
            BlurFactor = p.BlurFactor;
        }
Пример #23
0
        public Arrow(Vec2 pStartPoint, Vec2 pVector, float pScale, uint pColor = 0xffffffff, uint pLineWidth = 1)
        {
            _startPoint = pStartPoint;
            _vector = pVector;
            Scale = pScale;

            Color = pColor;
            LineWidth = pLineWidth;
        }
        void Awake()
        {
            PlayerID = __playerID;
            Pos = Vec2.FromVector3(transform.position);
            Size = new Vec2(__sizeX, __sizeY);

            KRFacade.Add(this);
            Offer("OnBirth");
        }
Пример #25
0
 public LPath(Vec2 v0, Vec2 v1, Vec2 v2)
 {
     N = 3;
     PATH = new Vec2[N];
     PATH[0] = v0;
     PATH[1] = v1;
     PATH[2] = v2;
     Trim();
 }
Пример #26
0
 public void Swap(Vec2 v0, Vec2 v1)
 {
     int index0 = MAP[v0.R][v0.C];
     int index1 = MAP[v1.R][v1.C];
     MAP[v0.R][v0.C] = index1;
     MAP[v1.R][v1.C] = index0;
     SwapSpriteOfGameObject (v0, v1);
     //ItemManager.I.Swap(v0, v1);
 }
Пример #27
0
 public override void Update(double dt)
 {
     base.Update(dt);
     Rotation += RotSpeed * dt;
     var p = World.Current.player.Position - new Vec2(dist, dist);
     Position = new Vec2(
         p.X + GMath.Mod(Position.X - p.X, 2 * dist),
         p.Y + GMath.Mod(Position.Y - p.Y, 2 * dist));
 }
Пример #28
0
 /**
    * Moves the camera by the given distance in screen coordinates.
    */
 public void moveWorld(Vec2 screenDiff)
 {
     transform.getScreenVectorToWorld(screenDiff, worldDiff);
     if (!transform.isYFlip())
     {
         worldDiff.y = -worldDiff.y;
     }
     transform.setCenter(transform.getCenter().add(worldDiff));
 }
Пример #29
0
 public void getScreenVectorToWorld(Vec2 screen, Vec2 world)
 {
     box.R.invertToOut(ref inv);
     inv.mulToOut(screen, ref world);
     if (yFlip)
     {
         yFlipMat.mulToOut(world, ref world);
     }
 }
Пример #30
0
 public TestbedCamera(Vec2 initPosition, float initScale, float zoomScaleDiff)
 {
     this.transform = new OBBViewportTransform();
     transform.setCamera(initPosition.x, initPosition.y, initScale);
     this.initPosition.set(initPosition);
     this.initScale = initScale;
     upScale = Mat22.createScaleTransform(1 + zoomScaleDiff);
     downScale = Mat22.createScaleTransform(1 - zoomScaleDiff);
 }
Пример #31
0
 protected virtual bool TestBounds(Vec2 pos)
 {
     return(this.Bounds.HasPoint(pos));
 }
Пример #32
0
 public static void Create(Thing owner, Vec2 pos, ATProvider provider)
 {
     Create(owner, pos, new Config(provider));
 }
Пример #33
0
        public override Vec2 GetReactionForce(float inv_dt)
        {
            Vec2 v = this._impulse * this._J.Linear2;

            return(inv_dt * v);
        }
Пример #34
0
 /// <summary>
 /// Rotates an object around a target by adding the given angle in degrees to the current angle of the delta vector between the objects
 /// </summary>
 /// <param name="targetPoint"></param>
 /// <param name="deg"></param>
 public void RotateAroundDeg(Vec2 targetPoint, float deg)
 {
     this = this - targetPoint;
     RotateDegrees(deg);
     this = this + targetPoint;
 }
Пример #35
0
 public override void OnNetworkBulletsFired(Vec2 pos)
 {
     // do nothing
 }
Пример #36
0
 public Player()
 {
     this._health   = 100;
     this._position = new Vec2();
 }
Пример #37
0
 /// <summary>
 ///     Computes the x 1
 /// </summary>
 /// <param name="x1">The </param>
 /// <param name="a1">The </param>
 /// <param name="x2">The </param>
 /// <param name="a2">The </param>
 /// <returns>The float</returns>
 public float Compute(Vec2 x1, float a1, Vec2 x2, float a2)
 {
     return(Vec2.Dot(Linear1, x1) + Angular1 * a1 + Vec2.Dot(Linear2, x2) + Angular2 * a2);
 }
Пример #38
0
        /**
         * <summary>Sets the time horizon of a specified agent with respect to
         * other agents.</summary>
         *
         * <param name="agentNo">The number of the agent whose time horizon is
         * to be modified.</param>
         * <param name="timeHorizon">The replacement time horizon with respect
         * to other agents. Must be positive.</param>
         */
        //public void setAgentTimeHorizon(int agentNo, float timeHorizon)
        //{
        //    agents_[agentNo].timeHorizon_ = timeHorizon;
        //}

        /**
         * <summary>Sets the time horizon of a specified agent with respect to
         * obstacles.</summary>
         *
         * <param name="agentNo">The number of the agent whose time horizon with
         * respect to obstacles is to be modified.</param>
         * <param name="timeHorizonObst">The replacement time horizon with
         * respect to obstacles. Must be positive.</param>
         */
        //public void setAgentTimeHorizonObst(int agentNo, float timeHorizonObst)
        //{
        //    agents_[agentNo].timeHorizonObst_ = timeHorizonObst;
        //}

        /**
         * <summary>Sets the two-dimensional linear velocity of a specified
         * agent.</summary>
         *
         * <param name="agentNo">The number of the agent whose two-dimensional
         * linear velocity is to be modified.</param>
         * <param name="velocity">The replacement two-dimensional linear
         * velocity.</param>
         */
        public void setAgentVelocity(int agentID, Vec2 velocity)
        {
            id2agent_[agentID].velocity_ = velocity;
        }
Пример #39
0
 public static Vec2 Adjust(Vec2 a)
 {
     return(new Vec2(Scale * a.x, Scale * a.y));
 }
Пример #40
0
    public void ReSetPos(Vec2 pt, Vec2 cp)
    {
        Pos     = pt + Vec2.Up * 60;
        nowPos  = AdjustPos();
        nowWPos = cp;

        OnChoiceSel = (toType) =>
        {
            if (toType == "Cancel")
            {
                MG.UUIs.CancelSelUnit();
                return;
            }

            var info = UnitConfiguration.GetDefaultConfig(MG.UUIs.CurUnitType);

            if (MG.UUIs.CurUnitType == "Base")
            {
                var bus = MG.Room.GetUnitsInArea(cp, 1, (u) => u.UnitType == "Base");

                if (bus != null && bus.Length > 0)
                {
                    return;
                }

                var us = MG.Room.GetUnitsInArea(cp, 1, (u) => u.UnitType == "BaseStub");

                if (us != null && us.Length > 0)
                {
                    if (!MG.CheckPrerequisitesAndTip("Base") || !MG.CheckResourceRequirementAndTip("Base"))
                    {
                        return;
                    }

                    var conn = GameCore.Instance.ServerConnection;
                    var buff = conn.Send2Srv("ConstructBuilding");
                    buff.Write("Base");
                    buff.Write(us[0].Pos);
                    conn.End(buff);
                }
            }
            else if (MG.UUIs.CurUnitType == "CrystalMachine")
            {
                var pres = UnitConfiguration.GetDefaultConfig("CrystalMachine").Prerequisites;

                var preLst = new List <string>();

                for (int i = 0; i < pres.Length; i++)
                {
                    for (int j = 0; j < pres[i].Length; j++)
                    {
                        preLst.Add(pres[i][j]);
                    }
                }

                var us = MG.Room.GetUnitsInArea(cp, 1, (u) => preLst.Contains(u.UnitType));

                if (us != null && us.Length > 0)
                {
                    if (MG.Room.FindNextCrystalMachinePos(us[0]) == Vec2.Zero)
                    {
                        AddTip("没有多余的矿机位置");
                        return;
                    }

                    if (!us[0].BuildingCompleted || !MG.CheckPrerequisitesAndTip(MG.UUIs.CurUnitType) || !MG.CheckResourceRequirementAndTip(MG.UUIs.CurUnitType))
                    {
                        return;
                    }

                    var conn = GameCore.Instance.ServerConnection;
                    var buff = conn.Send2Srv("ConstructCrystalMachine");
                    buff.Write(us[0].UID);
                    conn.End(buff);
                }
            }
            else if (MG.UUIs.CurUnitType == "Accessory")
            {
                var pres = UnitConfiguration.GetDefaultConfig("Accessory").Prerequisites;

                var preLst = new List <string>();

                for (int i = 0; i < pres.Length; i++)
                {
                    for (int j = 0; j < pres[i].Length; j++)
                    {
                        preLst.Add(pres[i][j]);
                    }
                }

                var us = MG.Room.GetUnitsInArea(cp, 1, (u) => preLst.Contains(u.UnitType));

                if (us != null && us.Length > 0)
                {
                    if (MG.Room.FindNextAccessoryPos(us[0], "Accessory") == Vec2.Zero)
                    {
                        AddTip("无法建造更多仓库");
                        return;
                    }

                    if (!us[0].BuildingCompleted || !MG.CheckPrerequisitesAndTip(MG.UUIs.CurUnitType) || !MG.CheckResourceRequirementAndTip(MG.UUIs.CurUnitType))
                    {
                        return;
                    }

                    var conn = GameCore.Instance.ServerConnection;
                    var buff = conn.Send2Srv("ConstructAccessory");
                    buff.Write(us[0].UID);
                    buff.Write("Accessory");
                    conn.End(buff);
                }
            }
            else if ((!string.IsNullOrEmpty(info.ReconstructFrom)))
            {
                var us = MG.Room.GetUnitsInArea(cp, 1, (u) => u.UnitType == info.ReconstructFrom);

                if (us != null && us.Length > 0)
                {
                    if (!us[0].BuildingCompleted || !MG.CheckPrerequisitesAndTip(MG.UUIs.CurUnitType) || !MG.CheckResourceRequirementAndTip(MG.UUIs.CurUnitType))
                    {
                        return;
                    }
                    else
                    {
                        var conn = GameCore.Instance.ServerConnection;
                        var buff = conn.Send2Srv("ReconstructBuilding");
                        buff.Write(us[0].UID);
                        buff.Write(MG.UUIs.CurUnitType);
                        conn.End(buff);
                    }
                }
            }
            else
            {
                MG.OnClickMap(pt, cp);
            }

            MG.UUIs.CancelSelUnit();
        };
    }
Пример #41
0
 public static Vec2 UnAdjust(Vec2 scaled)
 {
     return(new Vec2(scaled.x / Scale, scaled.y / Scale));
 }
Пример #42
0
 //------------------------------------------------------------------------------------------------------------------------
 //														Dot()
 //------------------------------------------------------------------------------------------------------------------------
 public float Dot(Vec2 other)
 {
     return(this.x * other.x + this.y * other.y);
 }
Пример #43
0
 //------------------------------------------------------------------------------------------------------------------------
 //														RotateAroundDegrees()
 //------------------------------------------------------------------------------------------------------------------------
 public void RotateAroundDegrees(Vec2 _point, float _tempDeg)
 {
     RotateAroundRadians(_point, DegToRad(_tempDeg));
 }
Пример #44
0
        /**
         * <summary>Sets the maximum neighbor distance of a specified agent.
         * </summary>
         *
         * <param name="agentNo">The number of the agent whose maximum neighbor
         * distance is to be modified.</param>
         * <param name="neighborDist">The replacement maximum neighbor distance.
         * Must be non-negative.</param>
         */
        //public void setAgentNeighborDist(int agentNo, float neighborDist)
        //{
        //    agents_[agentNo].neighborDist_ = neighborDist;
        //}

        /**
         * <summary>Sets the two-dimensional position of a specified agent.
         * </summary>
         *
         * <param name="agentNo">The number of the agent whose two-dimensional
         * position is to be modified.</param>
         * <param name="position">The replacement of the two-dimensional
         * position.</param>
         */
        public void setAgentPosition(int agentID, Vec2 position)
        {
            id2agent_[agentID].position_ = position;
        }
Пример #45
0
 public Player(int health, Vec2 position)
 {
     this._health   = health;
     this._position = position;
 }
Пример #46
0
        /**
         * <summary>Sets the default properties for any new agent that is added.
         * </summary>
         *
         * <param name="neighborDist">The default maximum distance (center point
         * to center point) to other agents a new agent takes into account in
         * the navigation. The larger this number, the longer he running time of
         * the simulation. If the number is too low, the simulation will not be
         * safe. Must be non-negative.</param>
         * <param name="maxNeighbors">The default maximum number of other agents
         * a new agent takes into account in the navigation. The larger this
         * number, the longer the running time of the simulation. If the number
         * is too low, the simulation will not be safe.</param>
         * <param name="timeHorizon">The default minimal amount of time for
         * which a new agent's velocities that are computed by the simulation
         * are safe with respect to other agents. The larger this number, the
         * sooner an agent will respond to the presence of other agents, but the
         * less freedom the agent has in choosing its velocities. Must be
         * positive.</param>
         * <param name="timeHorizonObst">The default minimal amount of time for
         * which a new agent's velocities that are computed by the simulation
         * are safe with respect to obstacles. The larger this number, the
         * sooner an agent will respond to the presence of obstacles, but the
         * less freedom the agent has in choosing its velocities. Must be
         * positive.</param>
         * <param name="radius">The default radius of a new agent. Must be
         * non-negative.</param>
         * <param name="maxSpeed">The default maximum speed of a new agent. Must
         * be non-negative.</param>
         * <param name="velocity">The default initial two-dimensional linear
         * velocity of a new agent.</param>
         */
        public void setAgentDefaults(Fix64 neighborDist, int maxNeighbors, Fix64 timeHorizon, Fix64 timeHorizonObst, Fix64 radius, Fix64 maxSpeed, Vec2 velocity)
        {
            if (defaultAgent_ == null)
            {
                defaultAgent_ = new Agent();
            }

            defaultAgent_.maxNeighbors_     = maxNeighbors;
            defaultAgent_.maxSpeed_         = maxSpeed;
            defaultAgent_.maxSpeedByConfig_ = defaultAgent_.maxSpeed_;
            defaultAgent_.neighborDist_     = neighborDist;
            defaultAgent_.radius_           = radius;
            defaultAgent_.timeHorizon_      = timeHorizon;
            defaultAgent_.timeHorizonObst_  = timeHorizonObst;
            defaultAgent_.velocity_         = velocity;
        }
Пример #47
0
 public Player(Vec2 position)
 {
     this._health   = 100;
     this._position = position;
 }
Пример #48
0
 /// <summary>
 /// Rotates an object around a target by adding the given angle in radians to the current angle of the delta vector between the objects
 /// </summary>
 /// <param name="targetPoint"></param>
 /// <param name="rad"></param>
 public void RotateAroundRad(Vec2 targetPoint, float rad)
 {
     this = this - targetPoint;
     RotateRadians(rad);
     this = this + targetPoint;
 }
Пример #49
0
    /// <summary>
    /// This calculates the dot product and returns the product in a float. This function does not normalize a vector.
    /// </summary>
    /// <param name="other"></param>
    /// <returns></returns>
    public float Dot(Vec2 other)
    {
        float dotProduct = this.x * other.x + this.y * other.y;

        return(dotProduct);
    }
Пример #50
0
 /// <summary>
 /// Returns the angle of the vector in degrees
 /// </summary>
 /// <returns></returns>
 public float getAngleDeg()
 {
     return(Vec2.Rad2Deg(Mathf.Atan2(y, x)));
 }
Пример #51
0
 /**
  * <summary>Performs a visibility query between the two specified points
  * with respect to the obstacles.</summary>
  *
  * <returns>A boolean specifying whether the two points are mutually
  * visible. Returns true when the obstacles have not been processed.
  * </returns>
  *
  * <param name="point1">The first point of the query.</param>
  * <param name="point2">The second point of the query.</param>
  * <param name="radius">The minimal distance between the line connecting
  * the two points and the obstacles in order for the points to be
  * mutually visible (optional). Must be non-negative.</param>
  */
 public bool queryVisibility(Vec2 point1, Vec2 point2, Fix64 radius)
 {
     return(kdTree_.queryVisibility(point1, point2, radius));
 }
Пример #52
0
 public static void Create(Thing owner, Vec2 pos)
 {
     Create(owner, pos, Config.Default);
 }
Пример #53
0
 /// <summary>
 /// returns the angle of the delta vector between 2 points
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 public float GetAngleDeg2Points(Vec2 a, Vec2 b)
 {
     return(Rad2Deg(Mathf.Atan2(b.y - a.y, b.x - a.x)));
 }
Пример #54
0
    /// <summary>
    /// Sets the angle of the vector to a given angle in radians
    /// </summary>
    /// <param name="rad"></param>
    /// <returns></returns>
    public Vec2 SetAngleRad(float rad)
    {
        this = Vec2.GetUnitVecRad(rad) * Length;

        return(this);
    }
Пример #55
0
        /**
         * <summary>Adds a new agent to the simulation.</summary>
         *
         * <returns>The number of the agent.</returns>
         *
         * <param name="position">The two-dimensional starting position of this
         * agent.</param>
         * <param name="neighborDist">The maximum distance (center point to
         * center point) to other agents this agent takes into account in the
         * navigation. The larger this number, the longer the running time of
         * the simulation. If the number is too low, the simulation will not be
         * safe. Must be non-negative.</param>
         * <param name="maxNeighbors">The maximum number of other agents this
         * agent takes into account in the navigation. The larger this number,
         * the longer the running time of the simulation. If the number is too
         * low, the simulation will not be safe.</param>
         * <param name="timeHorizon">The minimal amount of time for which this
         * agent's velocities that are computed by the simulation are safe with
         * respect to other agents. The larger this number, the sooner this
         * agent will respond to the presence of other agents, but the less
         * freedom this agent has in choosing its velocities. Must be positive.
         * </param>
         * <param name="timeHorizonObst">The minimal amount of time for which
         * this agent's velocities that are computed by the simulation are safe
         * with respect to obstacles. The larger this number, the sooner this
         * agent will respond to the presence of obstacles, but the less freedom
         * this agent has in choosing its velocities. Must be positive.</param>
         * <param name="radius">The radius of this agent. Must be non-negative.
         * </param>
         * <param name="maxSpeed">The maximum speed of this agent. Must be
         * non-negative.</param>
         * <param name="velocity">The initial two-dimensional linear velocity of
         * this agent.</param>
         */
        public int addAgent(Vec2 position, Fix64 neighborDist, int maxNeighbors, Fix64 timeHorizon, Fix64 timeHorizonObst, Fix64 radius, Fix64 maxSpeed, Vec2 velocity)
        {
            int agentID = NextSeqNo;

            if (id2agent_.ContainsKey(agentID))
            {
                throw new Exception("agent id conflict: " + agentID);
            }

            Agent agent = new Agent();

            agent.simulator_        = this;
            agent.id_               = agentID; // agents_.Count;
            agent.maxNeighbors_     = maxNeighbors;
            agent.maxSpeed_         = maxSpeed;
            agent.maxSpeedByConfig_ = agent.maxSpeed_;
            agent.neighborDist_     = neighborDist;
            agent.position_         = position;
            agent.radius_           = radius;
            agent.timeHorizon_      = timeHorizon;
            agent.timeHorizonObst_  = timeHorizonObst;
            agent.velocity_         = velocity;
            agents_.Add(agent);
            id2agent_[agentID] = agent;

            kdTree_.dirty = true;

            return(agent.id_);
        }
Пример #56
0
 static Vector2 getVector2FromVec2(Vec2 vec)
 {
     return(new Vector2(vec.x / 255.0f, vec.y / 255.0f));
 }
Пример #57
0
        internal void Update(float dt)
        {
            if (Dead)
            {
                if (anim.state.Animation.Name != "dead")
                {
                    anim.state.SetAnimation("dead", false);
                }
                this.HP = 0;
                body.ApplyForce(new Vec2(-body.GetLinearVelocity().X, 0), new Vec2(.1f, .1f));
                return;
            }

            DisableTime -= dt;

            if (OnGround)
            {
                if (Controls.IsDown(Control.Left) && !Disabled)
                {
                    if (anim.state.Animation.Name != "walk")
                    {
                        anim.state.SetAnimation("walk", true);
                    }
                    body.ApplyForce(new Vec2(-(Speed / 10) - body.GetLinearVelocity().X, 0), new Vec2(.1f, .1f));
                    Direction = -1;
                }
                else if (Controls.IsDown(Control.Right) && !Disabled)
                {
                    if (anim.state.Animation.Name != "walk")
                    {
                        anim.state.SetAnimation("walk", true);
                    }
                    body.ApplyForce(new Vec2((Speed / 10) - body.GetLinearVelocity().X, 0), new Vec2(.1f, .1f));
                    Direction = 1;
                }
                else
                {
                    if (anim.state.Animation.Name != "idle")
                    {
                        anim.state.SetAnimation("idle", true);
                    }
                    body.ApplyForce(new Vec2(-body.GetLinearVelocity().X *(Speed), 0), new Vec2(.1f, .1f));
                }

                if (Controls.IsPressed(Control.Jump) && !Disabled)
                {
                    if (anim.state.Animation.Name != "jump")
                    {
                        anim.state.SetAnimation("jump", false);
                    }
                    Vec2 Vel = body.GetLinearVelocity();
                    body.ApplyForce(new Vec2(Vel.X, Speed * 5), new Vec2(.1f, .1f));
                }
            }


            if (!Disabled)
            {
                if (Controls.IsPressed(Control.Move0))
                {
                    CurrentMove = 0;
                    Move[0].OnUse(this);
                }

                if (Controls.IsPressed(Control.Move1))
                {
                    CurrentMove = 1;
                    Move[1].OnUse(this);
                }

                if (Controls.IsPressed(Control.Move2))
                {
                    CurrentMove = 2;
                    Move[2].OnUse(this);
                }

                if (Controls.IsPressed(Control.Move3))
                {
                    CurrentMove = 3;
                    Move[3].OnUse(this);
                }
            }
        }
Пример #58
0
 /// Test a point for containment in this fixture. This only works for convex shapes.
 /// @param xf the shape world transform.
 /// @param p a point in world coordinates.
 public bool TestPoint(Vec2 p)
 {
     return(Shape.TestPoint(Body.GetTransform(), p));
 }
Пример #59
0
        public static Vec2 Perpendicular(Vec2 direction)
        {
            var vec = new UnityEngine.Vector2(direction.x, direction.y);

            return(UnityEngine.Vector2.Perpendicular(vec));
        }
Пример #60
0
 protected abstract void HandleEvent(MouseEventID id, Vec2 pos);