コード例 #1
0
ファイル: OBB.cs プロジェクト: PssProgram/Lost-In-Trek
        public List<Vector2> GetPoints()
        {
            //构造OBB
            //body的方向
            Vector2 bodyDir = direction;
            if (bodyDir != Vector2.Zero)
                bodyDir.Normalize();
            //body的方向 的垂直方向
            Vector2 bodyDirC = new Vector2(bodyDir.Y, -bodyDir.X);
            if (bodyDirC != Vector2.Zero)
                bodyDirC.Normalize();

            Vector2 point1 = bodyDir * height + bodyDirC * width + center;
            Vector2 point2 = bodyDir * height + -bodyDirC * width + center;
            Vector2 point3 = -bodyDir * height + -bodyDirC * width + center;
            Vector2 point4 = -bodyDir * height + bodyDirC * width + center;

            List<Vector2> points = new List<Vector2>();
            points.Add(point1);
            points.Add(point2);
            points.Add(point3);
            points.Add(point4);

            return points;
        }
コード例 #2
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cooldown;
            if (state == null) cooldown = 1000;
            else cooldown = (int)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            var player = (Player)host.GetNearestEntity(distance, null);
            if (player != null)
            {
                Vector2 vect;
                vect = new Vector2(player.X - host.X, player.Y - host.Y);
                vect.Normalize();
                float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                host.ValidateAndMove(host.X + (-vect.X) * dist, host.Y + (-vect.Y) * dist);
                host.UpdateCount++;

                if (cooldown <= 0)
                {
                    Status = CycleStatus.Completed;
                    cooldown = 1000;
                }
                else
                {
                    Status = CycleStatus.InProgress;
                    cooldown -= time.thisTickTimes;
                }
            }

            state = cooldown;
        }
コード例 #3
0
ファイル: Chasing.cs プロジェクト: RoxyLalonde/Phoenix-Realms
        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed*GetSpeedMultiplier(Host.Self);

            var dist = radius;
            var entity = GetNearestEntity(ref dist, objType);
            if (entity != null && dist > targetRadius)
            {
                var tx = entity.X + rand.Next(-2, 2)/2f;
                var ty = entity.Y + rand.Next(-2, 2)/2f;
                if (tx != Host.Self.X || ty != Host.Self.Y)
                {
                    var x = Host.Self.X;
                    var y = Host.Self.Y;
                    var vect = new Vector2(tx, ty) - new Vector2(Host.Self.X, Host.Self.Y);
                    vect.Normalize();
                    vect *= (speed/1.5f)*(time.thisTickTimes/1000f);
                    ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                    Host.Self.UpdateCount++;
                }
                return true;
            }
            return false;
        }
コード例 #4
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if (!returned)
            {
                if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) return;
                var spd = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);

                Position pos = (host as Enemy).SpawnPoint;
                var tx = pos.X;
                var ty = pos.Y;
                if (Math.Abs(tx - host.X) > 1 || Math.Abs(ty - host.Y) > 1)
                {
                    var x = host.X;
                    var y = host.Y;
                    Vector2 vect = new Vector2(tx, ty) - new Vector2(host.X, host.Y);
                    vect.Normalize();
                    vect *= spd;
                    host.Move(host.X + vect.X, host.Y + vect.Y);
                    host.UpdateCount++;
                }

                if (host.X == pos.X && host.Y == pos.Y && once)
                {
                    once = true;
                    returned = true;
                }
            }
        }
コード例 #5
0
        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed * GetSpeedMultiplier(Host.Self);

            float dist = radius;
            Entity entity = GetNearestEntity(ref dist, objType);
            Character chr = Host as Character;
            if (entity != null && chr.HP < threshold)
            {
                var x = Host.Self.X;
                var y = Host.Self.Y;
                Vector2 vect = new Vector2(entity.X, entity.Y) - new Vector2(Host.Self.X, Host.Self.Y);
                vect.Normalize();
                vect *= -1 * (speed / 1.5f) * (time.thisTickTimes / 1000f);
                ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                Host.Self.UpdateCount++;

                if (!Host.StateStorage.ContainsKey(Key))
                {
                    chr.Owner.BroadcastPacket(new ShowEffectPacket()
                    {
                        EffectType = EffectType.Flashing,
                        PosA = new Position() { X = 1, Y = 1000000 },
                        TargetId = chr.Id,
                        Color = new ARGB(0xff303030)
                    }, null);
                    Host.StateStorage[Key] = true;
                }

                return true;
            }
            else return false;
        }
コード例 #6
0
ファイル: Maths.cs プロジェクト: PssProgram/Lost-In-Trek
 /// <summary>
 /// 标准化
 /// </summary>
 public static void Normalize(ref Vector2 v2)
 {
     if(v2 != Vector2.Zero)
     {
         v2 = v2.Normalize();
     }
 }
コード例 #7
0
ファイル: Segment.cs プロジェクト: aiv01/aiv-fast2d
        private void UpdatePoints()
        {
            // compute line points
            Vector2 lineVector = point2 - point1;
            // get the right vector of the line
            Vector2 right = new Vector2(-lineVector.Y, lineVector.X);
            right.Normalize();

            Vector2 leftStart = point1 + right * -lineWidth/2f;
            Vector2 rightStart = point1 + right * lineWidth/2f;

            Vector2 leftEnd = point2 + right * -lineWidth/2f;
            Vector2 rightEnd = point2 + right * lineWidth/2f;

            this.v = new float[]
            {
                leftStart.X, leftStart.Y,
                rightStart.X, rightStart.Y,
                leftEnd.X, leftEnd.Y,
                rightStart.X, rightStart.Y,
                rightEnd.X,rightEnd.Y,
                leftEnd.X, leftEnd.Y
            };
            this.UpdateVertex();
        }
コード例 #8
0
ファイル: SeaLink.cs プロジェクト: amiruqdah/ToFightTheSea
        // TODO: Figure out light stuffs
        public SeaLink(float x, float y, float babies, Vector2 offset)
            : base(x - offset.X, y - offset.Y, 4, 1.0f)
        {
            // Initialize sprite
            sprite.CenterOrigin();
            Graphic = sprite;

            this.babies = babies;

            dirStepAmount = 1.3f;

            // Set up colliders
            SetHitbox(28, 28, (int)Tags.ENEMY);
            personalSpace = new CircleCollider((int)(spaceAmount * 0.5), (int)Tags.SEALINK, (int)Tags.ENEMYATTACK);
            AddCollider(personalSpace);

            if (offset == Vector2.Zero) {
                velocity = new Vector2(0, speed);
                velocity = Util.Rotate(velocity, Rand.Angle);
            } else {
                velocity = offset;
                velocity.Normalize();
                velocity = Util.Rotate(velocity, 4);
            }

            sprite.Scale = 0.1f;
        }
コード例 #9
0
 /// <summary>
 /// Cargar valores iniciales del interpolador
 /// </summary>
 public void reset()
 {
     dir = end - init;
     distanceToTravel = dir.Length();
     dir.Normalize(); 
     current = init;
 }
コード例 #10
0
ファイル: FunctionHelper.cs プロジェクト: mokujin/DN
 public static float Vector2ToRadians(Vector2 velocity)
 {
     velocity.Normalize();
       //  float t1 = (float)Math.Acos(velocity.X / Math.Sqrt(velocity.X * velocity.X + velocity.Y * velocity.Y));
     float t1 = (float)Math.Atan2(velocity.Y, velocity.X);
     return t1;
 }
コード例 #11
0
ファイル: Orbit.cs プロジェクト: Club559/Travs-Domain-Server
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            var s = (OrbitState) state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            Entity entity = host.GetNearestEntity(acquireRange, target);
            if (entity != null)
            {
                double angle;
                if (host.Y == entity.Y && host.X == entity.X) //small offset
                    angle = Math.Atan2(host.Y - entity.Y + (Random.NextDouble()*2 - 1),
                        host.X - entity.X + (Random.NextDouble()*2 - 1));
                else
                    angle = Math.Atan2(host.Y - entity.Y, host.X - entity.X);
                float angularSpd = host.GetSpeed(s.Speed)/s.Radius;
                angle += angularSpd*(time.thisTickTimes/1000f);

                double x = entity.X + Math.Cos(angle)*radius;
                double y = entity.Y + Math.Sin(angle)*radius;
                Vector2 vect = new Vector2((float) x, (float) y) - new Vector2(host.X, host.Y);
                vect.Normalize();
                vect *= host.GetSpeed(s.Speed)*(time.thisTickTimes/1000f);

                host.ValidateAndMove(host.X + vect.X, host.Y + vect.Y);
                host.UpdateCount++;

                Status = CycleStatus.InProgress;
            }

            state = s;
        }
コード例 #12
0
ファイル: Vector2DTests.cs プロジェクト: glocklueng/agg-sharp
		public void GetLengthAndNormalize()
		{
			Vector2 Point3 = new Vector2(3, -4);
			Assert.IsTrue(Point3.Length > 4.999f && Point3.Length < 5.001f);

			Point3.Normalize();
			Assert.IsTrue(Point3.Length > 0.99f && Point3.Length < 1.01f);
		}
コード例 #13
0
        public void HandleImpostorInput()
        {
            Vector2 impostorMove = new Vector2(X, Y);
            impostorMove -= new Vector2(Global.theGhost.X + (float)Math.Sin(Y * X) * 50, Global.theGhost.Y + (float)Math.Sin(Y * X*X) * 50);
            impostorMove.Normalize();
            MoveInDirection(-impostorMove);

            ShootInDirection(impostorMove);
        }
コード例 #14
0
ファイル: Projectile.cs プロジェクト: amiruqdah/ToFightTheSea
 public Projectile(float x, float y, Vector2 direction, float speed, int radius, float lifespan, int damage, params int[] tags)
     : base(x, y)
 {
     direction.Normalize();
     this.velocity = direction * speed;
     this.lifespan = lifespan;
     Collider = new CircleCollider(radius, tags);
     Collider.CenterOrigin();
     this.damage = damage;
 }
コード例 #15
0
        public override Vector2 Tangent(float t)
        {
            var tx = Curve2d.TangentQuadraticBezier(t, v0.x, v1.x, v2.x);
            var ty = Curve2d.TangentQuadraticBezier(t, v0.y, v1.y, v2.y);

            // returns unit vector
            var tangent = new Vector2(tx, ty);
            tangent.Normalize();
            return tangent;
        }
コード例 #16
0
		protected override void Update(TimeSpan gameTime)
		{
			var impulse = new Vector2();

			impulse = Behaviors.Aggregate(impulse, (current, behavior) => behavior.Apply(current));

			if (impulse.Length() > MaxImpulseLength)
			{
				impulse.Normalize();
				impulse = impulse*MaxImpulseLength;
			}

			RigidBody.ApplyLinearImpulse(new Vector3(impulse.X, 0, impulse.Y));
		}
コード例 #17
0
ファイル: ToolBox.cs プロジェクト: Arys02/Underground
        public Vector4 CalcTangentVector(Vector3[] position, Vector2[] texCoord, Vector3 normal)
        {
            Vector4 tangent;

            Vector3 edge1 = new Vector3(position[1].X - position[0].X, position[1].Y - position[0].Y, position[1].Z - position[0].Z);
            Vector3 edge2 = new Vector3(position[2].X - position[1].X, position[2].Y - position[1].Y, position[2].Z - position[1].Z);

            edge1.Normalize();
            edge2.Normalize();

            Vector2 texEdge1 = new Vector2(texCoord[1].X - texCoord[0].X, texCoord[1].Y - texCoord[0].Y);
            Vector2 texEdge2 = new Vector2(texCoord[2].X - texCoord[1].X, texCoord[2].Y - texCoord[1].Y);

            texEdge1.Normalize();
            texEdge2.Normalize();

            Vector3 bitangent;
            float det = (texEdge1.X * texEdge2.Y) - (texEdge1.Y * texEdge2.X);

            if (Math.Abs(det) < 1e-6f)
            {
                tangent.X = 1.0f;
                tangent.Y = 0.0f;
                tangent.Z = 0.0f;

                bitangent = new Vector3(0.0f, 1.0f, 0.0f);
            }
            else
            {
                det = 1.0f / det;

                tangent.X = (texEdge2.Y * edge1.X - texEdge1.Y * edge2.X) * det;
                tangent.Y = (texEdge2.Y * edge1.Y - texEdge1.Y * edge2.Y) * det;
                tangent.Z = (texEdge2.Y * edge1.Z - texEdge1.Y * edge2.Z) * det;
                tangent.W = 0.0f;

                bitangent = new Vector3((-texEdge2.X * edge1.X + texEdge1.X * edge2.X) * det,
                                        (-texEdge2.X * edge1.Y + texEdge1.X * edge2.Y) * det,
                                        (-texEdge2.X * edge1.Z + texEdge1.X * edge2.Z) * det);

                tangent.Normalize();
                bitangent.Normalize();
            }

            Vector3 n = normal;
            Vector3 t = new Vector3(tangent.X, tangent.Y, tangent.Z);
            Vector3 b = Vector3.Cross(n, t);
            tangent.W = (Vector3.Dot(b, bitangent) < 0.0f) ? -1.0f : 1.0f;
            return tangent;
        }
コード例 #18
0
        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed * GetSpeedMultiplier(Host.Self);

            CirclingState state;
            object o;
            if (!Host.StateStorage.TryGetValue(Key, out o))
            {
                float dist = sight;
                Host.StateStorage[Key] = state = new CirclingState()
                {
                    target = WeakReference<Entity>.Create(GetNearestEntity(ref dist, objType)),
                    angle = (float)(2 * Math.PI * rand.NextDouble())
                };
            }
            else
            {
                state = (CirclingState)o;

                state.angle += angularSpeed * (time.thisTickTimes / 1000f);
                if (!state.target.IsAlive)
                {
                    Host.StateStorage.Remove(Key);
                    return false;
                }
                var target = state.target.Target;
                if (target == null || target.Owner == null)
                {
                    Host.StateStorage.Remove(Key);
                    return false;
                }

                double x = target.X + Math.Cos(state.angle) * radius;
                double y = target.Y + Math.Sin(state.angle) * radius;
                if (x != Host.Self.X || y != Host.Self.Y)
                {
                    Vector2 vect = new Vector2((float)x, (float)y) - new Vector2(Host.Self.X, Host.Self.Y);
                    vect.Normalize();
                    vect *= (speed / 1.5f) * (time.thisTickTimes / 1000f);
                    ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                    Host.Self.UpdateCount++;
                }
            }

            if (state.angle >= Math.PI * 2)
                state.angle -= (float)(Math.PI * 2);
            return true;
        }
コード例 #19
0
        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed*GetSpeedMultiplier(Host.Self);

            var pos = (Host as Enemy).SpawnPoint;
            var tx = pos.X;
            var ty = pos.Y;
            if (Math.Abs(tx - Host.Self.X) > 1 || Math.Abs(ty - Host.Self.Y) > 1)
            {
                var x = Host.Self.X;
                var y = Host.Self.Y;
                var vect = new Vector2(tx, ty) - new Vector2(Host.Self.X, Host.Self.Y);
                vect.Normalize();
                vect *= (speed/1.5f)*(time.thisTickTimes/1000f);
                ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                Host.Self.UpdateCount++;
                return true;
            }
            return false;
        }
コード例 #20
0
        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed * GetSpeedMultiplier(Host.Self);

            float dist = radius;
            Entity entity = GetNearestEntity(ref dist, objType);
            object obj;
            int t;
            if (Host.StateStorage.TryGetValue(Key, out obj))
                t = (int)obj;
            else
                t = this.time;

            if (entity != null && dist > targetRadius &&
                t > 0)
            {
                var tx = entity.X + rand.Next(-2, 2) / 2f;
                var ty = entity.Y + rand.Next(-2, 2) / 2f;
                if (tx != Host.Self.X || ty != Host.Self.Y)
                {
                    var x = Host.Self.X;
                    var y = Host.Self.Y;
                    Vector2 vect = new Vector2(tx, ty) - new Vector2(Host.Self.X, Host.Self.Y);
                    vect.Normalize();
                    vect *= (speed / 1.5f) * (time.thisTickTimes / 1000f);
                    ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                    Host.Self.UpdateCount++;
                }
                t -= time.thisTickTimes;
                Host.StateStorage[Key] = t;
                return false;
            }
            else
            {
                t = this.time;
                Host.StateStorage[Key] = t;
                return true;
            }
        }
コード例 #21
0
        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed * GetSpeedMultiplier(Host.Self);

            float dist = radius;
            Entity entity = GetNearestEntity(ref dist, objType);
            Character chr = Host as Character;
            if (entity != null && (entity.X != Host.Self.X || entity.Y != Host.Self.Y))
            {
                var x = Host.Self.X;
                var y = Host.Self.Y;
                Vector2 vect = new Vector2(entity.X, entity.Y) - new Vector2(Host.Self.X, Host.Self.Y);
                vect.Normalize();
                vect *= -1 * (speed / 1.5f) * (time.thisTickTimes / 1000f);
                ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                Host.Self.UpdateCount++;

                return true;
            }
            else return false;
        }
コード例 #22
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            var map = host.Owner.Map;
            var tile = map[(int)host.X, (int)host.Y];
            if (tile.Elevation != 0 && tile.Elevation < altitude)
            {
                Vector2 vect;
                vect = new Vector2(map.Width / 2 - host.X, map.Height / 2 - host.Y);
                vect.Normalize();
                float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                host.UpdateCount++;

                Status = CycleStatus.InProgress;
            }
            else
                Status = CycleStatus.Completed;
        }
コード例 #23
0
ファイル: Charge.cs プロジェクト: Club559/Travs-Domain-Server
        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed * GetSpeedMultiplier(Host.Self);

            Position target;
            object o;
            if (!Host.StateStorage.TryGetValue(Key, out o))
            {
                float dist = radius;
                var entity = GetNearestEntity(ref dist, objType);
                if (entity == null) return true;
                Host.StateStorage[Key] = target = new Position()
                {
                    X = entity.X,
                    Y = entity.Y
                };
            }
            else
                target = (Position)o;

            if (target.X != Host.Self.X || target.Y != Host.Self.Y)
            {
                Vector2 vect = new Vector2((float)target.X, (float)target.Y) - new Vector2(Host.Self.X, Host.Self.Y);
                vect.Normalize();
                vect *= (speed / 1.5f) * (time.thisTickTimes / 1000f);
                ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                Host.Self.UpdateCount++;
            }

            if (Dist(Host.Self.X, Host.Self.Y, target.X, target.Y) < 1)
            {
                Host.StateStorage.Remove(Key);
                return true;
            }
            else
                return false;
        }
コード例 #24
0
        public override void Update()
        {
            base.Update();

            // Fly towards player
            Vector2 VectorToPlayer = new Vector2(Global.theGhost.X - X, Global.theGhost.Y - Y - 10);

            if(VectorToPlayer.Length < 2)
            {
                Global.Score++;
                Sound bip = new Sound(Assets.SFX_GET);
                bip.Volume = 0.6f;

                bip.Pitch = Rand.Float(0.8f, 1.2f);
                bip.Play();
                RemoveSelf();
                //Global.theMusic.Pitch += 0.01f;
            }

            VectorToPlayer.Normalize();
            X += VectorToPlayer.X * 3;
            Y += VectorToPlayer.Y * 3;
        }
コード例 #25
0
ファイル: Ink.cs プロジェクト: amiruqdah/ToFightTheSea
        public Ink(float x, float y, float angle)
            : base(x, y)
        {
            // Init sprite
            sprite.Add(AnimType.Go, new Anim(new int[] { 0, 1, 2 }, new float[] { 8.0f }));
            sprite.Play(AnimType.Go);
            sprite.CenterOrigin();
            sprite.Angle = angle;
            offset = Util.Rotate(offset, sprite.Angle);
            sprite.OriginX += offset.X;
            sprite.OriginY += offset.Y;
            offset.Normalize();
            offset *= 2.7f;
            Graphic = sprite;

            // Set up collider
            Collider = new CircleCollider(250, (int)Tags.INK);
            Collider.CenterOrigin();

            // Get that sound
            snd.Volume = 0.01f;
            snd.Play();
        }
コード例 #26
0
        protected override bool TickCore(RealmTime time)
        {
            if (Host.Self.HasConditionEffect(ConditionEffects.Paralyzed)) return true;
            var speed = this.speed * GetSpeedMultiplier(Host.Self);

            CirclingState state;
            object o;
            if (!Host.StateStorage.TryGetValue(Key, out o))
            {
                var dist = radius;
                Host.StateStorage[Key] = state = new CirclingState
                {
                    center = new Position { X = Host.Self.X, Y = Host.Self.Y },
                    angle = (float)(2 * Math.PI * rand.NextDouble())
                };
            }
            else
            {
                state = (CirclingState)o;

                state.angle += angularSpeed * (time.thisTickTimes / 1000f);
                var x = state.center.X + Math.Cos(state.angle) * radius;
                var y = state.center.Y + Math.Sin(state.angle) * radius;
                if (x != Host.Self.X && y != Host.Self.Y)
                {
                    var vect = new Vector2((float)x, (float)y) - new Vector2(Host.Self.X, Host.Self.Y);
                    vect.Normalize();
                    vect *= speed / 1.5f * (time.thisTickTimes / 1000f);
                    ValidateAndMove(Host.Self.X + vect.X, Host.Self.Y + vect.Y);
                    Host.Self.UpdateCount++;
                }
            }

            if (state.angle >= Math.PI * 2)
                state.angle -= (float)(Math.PI * 2);
            return true;
        }
コード例 #27
0
ファイル: Path.cs プロジェクト: jakakordez/Eternal
 public static Vector3[] CreateCurve(Vector3[] roadLine, int Segments, float Offset, bool Invert)
 {
     Vector2[] roadCurve = Misc.GetBezierApproximation(roadLine.Select(p=>p.Xz).ToArray(), Segments);
     Vector2[] heightLine = new Vector2[roadLine.Length];
     Vector2 prevPoint = roadLine[0].Xz;
     for (int i = 0; i < heightLine.Length; i++)
     {
         heightLine[i] = new Vector2((roadLine[i].Xz - prevPoint).Length, roadLine[i].Y);
         prevPoint = roadLine[i].Xz;
     }
     Vector2[] heightCurve = Misc.GetBezierApproximation(heightLine, Segments);
     Vector3[] PathNodes = new Vector3[Segments + 1];
     for (int i = 0; i < Segments + 1; i++)
     {
         Vector2 dir = new Vector2();
         if (i== 0) dir = (roadCurve[i] - roadCurve[i+1]);
         else if (i == Segments) dir = (roadCurve[i - 1] - roadCurve[i]);
         else dir = (roadCurve[i - 1] - roadCurve[i]) + (roadCurve[i] - roadCurve[i + 1]);
         dir.Normalize();
         dir *= Offset;
         PathNodes[(Invert) ? Segments - i : i] = new Vector3(roadCurve[i].X + dir.Y, heightCurve[i].Y, roadCurve[i].Y - dir.X);
     }
     return PathNodes;
 }
コード例 #28
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if (instant) return;
            if (!returned)
            {
                if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) return;
                var spd = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);

                if (Math.Abs(X - host.X) > 0.5 || Math.Abs(Y - host.Y) > 0.5)
                {
                    Vector2 vect = new Vector2(X, Y) - new Vector2(host.X, host.Y);
                    vect.Normalize();
                    vect *= spd;
                    host.Move(host.X + vect.X, host.Y + vect.Y);
                    host.UpdateCount++;

                    if (host.X == X && host.Y == Y && once)
                    {
                        once = true;
                        returned = true;
                    }
                }
            }
        }
コード例 #29
0
ファイル: Road.cs プロジェクト: jakakordez/Eternal
        public void Build(Map currentMap)
        {
            List<Vector3> BezierCurve = new List<Vector3>();
            List<Node> PointsForPath = new List<Node>();
            Vector3[] BezierControlPoints = new Vector3[4];

            Vector2 dir = new Vector2();
            Node first = FirstEndpoint.getPosition(currentMap.ObjectCollection);
            if (first != null)
            {
                dir = Misc.getCartesian(first.Rotation.Y);
                first.Rotation = new Vector3(dir.X, 0, dir.Y);
                PointsForPath.Add(first); // First endpoint exists, so add it to the list
            }
            PointsForPath.AddRange(Points);
            Node last = LastEndpoint.getPosition(currentMap.ObjectCollection);
            if (last != null)
            {
                // Set rotation for the last endpoint
                dir = Misc.getCartesian(last.Rotation.Y);
                last.Rotation = new Vector3(-dir.X, 0, -dir.Y);
                PointsForPath.Add(last); // Last endpoint exists, so add it to the list
            }

            for (int i = 0; i < PointsForPath.Count; i++)
            {
                if((i > 0 || first == null)&&(i < PointsForPath.Count-1 || last == null))
                {
                    if (i == 0) dir = PointsForPath[i + 1].Location.Xz - PointsForPath[i].Location.Xz;
                    else if(i == PointsForPath.Count - 1) dir = PointsForPath[i].Location.Xz - PointsForPath[i - 1].Location.Xz;
                    else
                    {
                        dir = (PointsForPath[i].Location.Xz - PointsForPath[i - 1].Location.Xz);
                        dir += (PointsForPath[i + 1].Location.Xz - PointsForPath[i].Location.Xz);
                    }
                    dir.Normalize();
                    PointsForPath[i].Rotation = new Vector3(dir.X, 0, dir.Y);
                }
            }
            for (int i = 0; i < PointsForPath.Count - 1; i++)
            {
                float segments = (PointsForPath[i + 1].Location.Xz - PointsForPath[i].Location.Xz).Length * 0.25f;
                BezierControlPoints[0] = PointsForPath[i].Location;
                BezierControlPoints[1] = PointsForPath[i].Location + (PointsForPath[i].Rotation*segments);
                BezierControlPoints[2] = PointsForPath[i + 1].Location - (PointsForPath[i + 1].Rotation*segments);
                BezierControlPoints[3] = PointsForPath[i + 1].Location;

                Vector3[] roadEdgeRight = CreateCurve(BezierControlPoints, (int)segments, RoadWidth/2, false);
                Vector3[] roadEdgeLeft = CreateCurve(BezierControlPoints, (int)segments, -RoadWidth/2, false);
                for (int j = 0; j < roadEdgeLeft.Length; j++)
                {
                    BezierCurve.Add(roadEdgeLeft[j]);
                    BezierCurve.Add(roadEdgeRight[j]);
                }
            }

            Vector3[] Vertices = new Vector3[BezierCurve.Count * 2];
            int[] Indices = new int[(BezierCurve.Count) * 3];
            Vector2[] TextureCoordinates = new Vector2[BezierCurve.Count * 2];
            for (int i = 0; i < (BezierCurve.Count/2)-1; i++)
            {
                Indices[(i * 6) + 0] = (i * 2) + 0;
                Indices[(i * 6) + 1] = (i * 2) + 1;
                Indices[(i * 6) + 2] = (i * 2) + 2;
                Indices[(i * 6) + 3] = (i * 2) + 2;
                Indices[(i * 6) + 4] = (i * 2) + 1;
                Indices[(i * 6) + 5] = (i * 2) + 3;

                Vertices[(i * 2) + 0] = BezierCurve[(i * 2) + 0];
                Vertices[(i * 2) + 1] = BezierCurve[(i * 2) + 1];
                Vertices[(i * 2) + 2] = BezierCurve[(i * 2) + 2];
                Vertices[(i * 2) + 3] = BezierCurve[(i * 2) + 3];

                TextureCoordinates[(i * 4) + 0] = new Vector2(1, 0);
                TextureCoordinates[(i * 4) + 1] = new Vector2(0, 0);
                TextureCoordinates[(i * 4) + 2] = new Vector2(1, 0.2f);
                TextureCoordinates[(i * 4) + 3] = new Vector2(0, 0.2f);
            }
            RoadMesh.GenerateCollisionShape = !Graphics.StaticView;
            RoadMesh.Load(BezierCurve.ToArray(), Indices, TextureName, TextureCoordinates);

            if (!Graphics.StaticView)
            {
                RoadSurface = World.CreateRigidBody(0, Matrix4.Identity, RoadMesh.GetCollisionShape());
                if (!Tools.PhysicsDebugDrawer.DrawRoads) RoadSurface.CollisionFlags |= CollisionFlags.DisableVisualizeObject;
            }
        }
コード例 #30
0
 public static Vector2 MinLength(Vector2 value, float minLength) => value.Length() < minLength?Vector2.Normalize(value) * minLength : value;
コード例 #31
0
 public static Vector2 MaxLength(Vector2 value, float maxLength) => value.Length() > maxLength?Vector2.Normalize(value) * maxLength : value;
コード例 #32
0
ファイル: Unit.cs プロジェクト: arcticnw/Wildmen
    /// <summary>
    /// Moves towards the order target
    /// </summary>
    private void UpdateMoveToOrder()
    {
      if (Vector2.Distance(this.MapPosition, this.OrderPosition) < OrderRange)
      {
        State = GameObjectState.DoOrder;
        return;
      }

      Vector2 direction = this.OrderPosition - this.MapPosition;
      Vector2 ort = new Vector2(-direction.Y, direction.X);

      if (Math.Abs(direction.X) > Math.Abs(direction.Y) && Math.Sign(direction.X) != Math.Sign(ort.X) ||
        Math.Abs(direction.X) < Math.Abs(direction.Y) && Math.Sign(direction.Y) != Math.Sign(ort.Y))
        ort *= -1;

      direction.Normalize();
      ort.Normalize();

      Vector2[] moveAttempts = new Vector2[3];
      moveAttempts[0] = direction * 0.5f * entry.Speed;
      moveAttempts[1] = ort * 0.5f * entry.Speed;
      moveAttempts[2] = ort * -0.5f * entry.Speed;

      Vector2 moveAttempt = direction * 0.5f * entry.Speed;
      bool success = false;

      for (int i = 0; i < 3; i++)
      {
        Tile newTile = game.Map.GetTileFlat(this.MapPosition + moveAttempts[i] * 3);

        if (newTile == null) continue;

        if (NearestTile == null) { Debug.Assert(RecalculatePosition); return; }
        if ((Math.Abs(newTile.Elevation - NearestTile.Elevation) > MapBoard.CLIFF_THRESHOLD)) continue;
        if ((newTile.Elevation < MapBoard.SEA_LEVEL)) continue;
        else
        {
          moveAttempt = moveAttempts[i];
          success = true;
          break;
        }
      }

      if (success)
      {
        this.MapPosition = this.MapPosition + moveAttempt;
        this.RecalculatePosition = true;
      }
      else
      {
        CancelOrders(true);
      }
    }