Exemple #1
0
        public void Move()
        {
            var beforePos    = Position;
            var beforeHeight = Height;

            var curSpeed = speed + speedLeft;
            var x        = (int)curSpeed.X;
            var y        = (int)curSpeed.Y;
            var z        = (int)curSpeed.Z;

            DistanceTravelled += (int)new CPos(x, y, 0).FlatDist;

            speedLeft = new Vector(curSpeed.X - x, curSpeed.Y - y, curSpeed.Z - z);

            Position += new CPos(x, y, 0);
            Height   += z;

            if (Height < 0 || !World.IsInWorld(Position))
            {
                Detonate(new Target(Position, 0));
            }

            rayPhysics.Start        = beforePos;
            rayPhysics.StartHeight  = beforeHeight;
            rayPhysics.Target       = Position;
            rayPhysics.TargetHeight = Height;
            rayPhysics.CalculateEnd(new[] { Origin.Physics });

            if ((beforePos - rayPhysics.End).Dist < (beforePos - Position).Dist)
            {
                Detonate(new Target(rayPhysics.End, rayPhysics.EndHeight));
            }
        }
        public void Move()
        {
            var beforePos    = Position;
            var beforeHeight = Height;

            var curSpeed = speed + speedLeft;
            var x        = (int)curSpeed.X;
            var y        = (int)curSpeed.Y;
            var z        = (int)curSpeed.Z;

            DistanceTravelled += (int)new CPos(x, y, 0).FlatDist;

            speedLeft = new Vector(curSpeed.X - x, curSpeed.Y - y, curSpeed.Z - z);

            Position += new CPos(x, y, 0);
            Height   += z;
            speed    += new Vector(projectile.Force.X, projectile.Force.Y, projectile.Force.Z);

            if (Math.Abs(speed.X) > projectile.MaxSpeed)
            {
                speed = new Vector(Math.Sign(speed.X) * projectile.MaxSpeed, speed.Y, speed.Z);
            }
            if (Math.Abs(speed.Y) > projectile.MaxSpeed)
            {
                speed = new Vector(speed.X, Math.Sign(speed.Y) * projectile.MaxSpeed, speed.Z);
            }
            if (Math.Abs(speed.Z) > projectile.MaxSpeed)
            {
                speed = new Vector(speed.X, speed.Y, Math.Sign(speed.Z) * projectile.MaxSpeed);
            }

            if (Height == 0 && z < 0 || !World.IsInWorld(Position))
            {
                Detonate(new Target(Position, 0));
            }

            rayPhysics.Start        = beforePos;
            rayPhysics.StartHeight  = beforeHeight;
            rayPhysics.Target       = Position;
            rayPhysics.TargetHeight = Height;
            rayPhysics.CalculateEnd(new[] { Origin.Physics });

            if ((beforePos - rayPhysics.End).Dist < (beforePos - Position).Dist)
            {
                Detonate(new Target(rayPhysics.End, rayPhysics.EndHeight));
            }
        }
        public override void Tick()
        {
            if (World.Game.Editor)
            {
                return;
            }

            if (Program.SharedRandom.NextDouble() > projectile.HitChance)
            {
                Dispose();
                return;
            }

            var physics = new RayPhysics(World)
            {
                Start        = Position,
                StartHeight  = Height,
                Target       = Target.Position,
                TargetHeight = Target.Height
            };

            physics.CalculateEnd(ignoreActors: true);

            if ((physics.End - Position).Dist < (Position - Target.Position).Dist)
            {
                Detonate(new Target(physics.End, physics.EndHeight));
            }
            else if (projectile.Splash)
            {
                Detonate(new Target(Target.Position, Target.Height));
            }
            else
            {
                Detonate(Target);
            }
        }
        public override void Tick()
        {
            if (Disposed || World.Game.Editor)
            {
                return;
            }

            if (buildupduration-- == 0)
            {
                useTexture(projectile.Beam);
            }

            if (duration == 0 && projectile.BeamCooldown != null)
            {
                useTexture(projectile.BeamCooldown);
            }

            if (curTick-- < 0)
            {
                if (frame++ >= renderables.Length - 1)
                {
                    frame = 0;
                }

                curTick = tick;
            }

            setPosition();

            rayPhysics.Target       = TargetPosition;
            rayPhysics.TargetHeight = TargetHeight;
            rayPhysics.CalculateEnd(new[] { Origin.Physics });
            Position = rayPhysics.End;
            Height   = rayPhysics.EndHeight;

            var dist = (originPos - Position).SquaredFlatDist;

            if (dist > (Type.MaxRange * RangeModifier) * (Type.MaxRange * RangeModifier))
            {
                Position = clampToMaxRange(originPos, (originPos - TargetPosition).FlatAngle);
                Height   = 0;
            }

            if (projectile.Directed && dist > (originPos - TargetPosition).SquaredFlatDist)
            {
                Position = TargetPosition;
                Height   = 0;
            }

            var distance = originPos - Position;

            sound?.SetPosition(Position + distance / new CPos(2, 2, 1));

            if (duration > 0 && buildupduration <= 0)
            {
                if (projectile.BeamParticles != null && duration % projectile.BeamParticleTick == 0)
                {
                    var angle      = distance.FlatAngle;
                    var fit        = distance.FlatDist / projectile.BeamParticleDistance;
                    var heightdiff = (originHeight - Height) / projectile.BeamParticleDistance;

                    var offset = CPos.FromFlatAngle(angle, projectile.BeamParticleDistance);

                    for (int i = 0; i < fit; i++)
                    {
                        World.Add(projectile.BeamParticles.Create(World, originPos + new CPos(offset.X * i, offset.Y * i, 0), originHeight + heightdiff * i));
                    }
                }

                if (impactInterval-- <= 0)
                {
                    Detonate(new Target(Position, Height), false);
                    impactInterval = projectile.ImpactInterval;
                }
            }

            if (buildupduration < 0 && duration-- < 0 && endduration-- < 0)
            {
                Dispose();
            }
        }