Ejemplo n.º 1
0
 public Probe(ColliderBase collider)
 {
     parent   = collider;
     Position = collider.Position;
     Size     = collider.Size;
     IsSolid  = false;
 }
Ejemplo n.º 2
0
 public override bool IsCollidingWith(ColliderBase other)
 {
     if (other == parent)
     {
         return(false);
     }
     return(base.IsCollidingWith(other));
 }
Ejemplo n.º 3
0
 static void OnRandomText(ColliderBase sender, ColliderBase collidor)
 {
     if (collidor == map.MainPlayer && triggerOnce)
     {
         ShowDialog("The end of the semester is coming! Quick run before the deadlines are catching up!\nPress Esc to continue...");
         map.MainPlayer.IsStatic = true;
         triggerOnce             = false;
     }
 }
Ejemplo n.º 4
0
            ///Defining collision mechanics for maps
            ///MAP 6 Deadline

            static void OnDeadlineCollison(ColliderBase sender, ColliderBase collidor)
            {
                if (collidor == map.MainPlayer)
                {
                    ShowDialog("Deadline of Tools of software projects caught you! You failed!\nPress Esc to close!");
                    enemy.IsStatic = true;
                    map.MainPlayer.ApplyDamage(999);
                    map.MainPlayer.IsStatic = true;
                }
            }
Ejemplo n.º 5
0
        private void LoadPickedMap(int level)
        {
            if (timer != null)
            {
                timer.Stop();
            }
            ColliderBase.ClearAllColliders();
            LoadMap.PreLoad(level);
            LoadMap.PostLoad();

            var tempMap = LoadMap.map;

            map = tempMap;

            map.MainPlayer.MovementSpeed.Y = 0;
            map.MainPlayer.MovementSpeed.X = 0;

            renderer.CurrentMap = tempMap;
        }
Ejemplo n.º 6
0
        private static ColliderBase GetClosestCollider(ColliderBase collider, IEnumerable <ColliderBase> colliders, Func <ColliderBase, ColliderBase, float> distance)
        {
            if (colliders.Count() == 0)
            {
                return(null);
            }

            ColliderBase closest = colliders.First();
            float        min     = distance(collider, closest);

            foreach (var other in colliders)
            {
                float dist = distance(collider, other);
                if (dist < min)
                {
                    closest = other;
                    min     = dist;
                }
            }
            return(closest);
        }
Ejemplo n.º 7
0
 private static float DistanceY(ColliderBase first, ColliderBase second)
 {
     return(Math.Abs(first.Position.Y - second.Position.Y) - (first.Size.Y + second.Size.Y) / 2);
 }
Ejemplo n.º 8
0
 private static float DistanceX(ColliderBase first, ColliderBase second)
 {
     return(Math.Abs(first.Position.X - second.Position.X) - (first.Size.X + second.Size.X) / 2);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Moves the actor based on it's speed and properties, factoring in gravity and friction.
        /// </summary>
        /// <param name="actor">the Actor to be moved</param>
        public static void ApplyPhysics(ActorBase actor)
        {
            if (actor.IsStatic)
            {
                return;
            }

            // apply friction
            actor.MovementSpeed.X = Math.Sign(actor.MovementSpeed.X) * Math.Max(Math.Abs(actor.MovementSpeed.X) - friction, 0f);

            // apply gravity
            if (actor.IsAffectedByGravity)
            {
                actor.MovementSpeed.Y -= gravity;
            }

            // enforce speed limits
            Vector4 speedLimits = CalculateSpeedLimit(actor);

            if (Math.Sign(actor.MovementSpeed.X) >= 0)
            {
                actor.MovementSpeed.X = 1 * Math.Min(Math.Abs(actor.MovementSpeed.X), speedLimits.W); // right (+x)
            }
            else
            {
                actor.MovementSpeed.X = -1 * Math.Min(Math.Abs(actor.MovementSpeed.X), speedLimits.Z); // left (-x)
            }
            if (Math.Sign(actor.MovementSpeed.Y) >= 0)
            {
                actor.MovementSpeed.Y = 1 * Math.Min(Math.Abs(actor.MovementSpeed.Y), speedLimits.X); // up (+y)
            }
            else
            {
                actor.MovementSpeed.Y = -1 * Math.Min(Math.Abs(actor.MovementSpeed.Y), speedLimits.Y); // down (-y)
            }
            // move actor
            {
                Probe probe = new Probe(actor);
                probe.Position.X += actor.MovementSpeed.X;
                IEnumerable <ColliderBase> colliders = probe.GetColliders().Where(c => c.IsSolid);
                if (colliders.Count() > 0)
                {
                    probe.Position.X -= actor.MovementSpeed.X;
                    ColliderBase closest = GetClosestCollider(probe, colliders, DistanceX);
                    if (closest is null)
                    {
                        actor.Position.X += actor.MovementSpeed.X;
                    }
                    else
                    {
                        actor.Position.X     += Math.Sign(actor.MovementSpeed.X) * (DistanceX(actor, closest) - 1);
                        actor.MovementSpeed.X = 0;
                    }
                }
            }
            {
                Probe probe = new Probe(actor);
                probe.Position.Y += actor.MovementSpeed.Y;
                IEnumerable <ColliderBase> colliders = probe.GetColliders().Where(c => c.IsSolid);
                if (colliders.Count() > 0)
                {
                    probe.Position.Y -= actor.MovementSpeed.Y;
                    ColliderBase closest = GetClosestCollider(probe, colliders, DistanceY);
                    if (closest is null)
                    {
                        actor.Position.Y += actor.MovementSpeed.Y;
                    }
                    else
                    {
                        actor.Position.Y     += Math.Sign(actor.MovementSpeed.Y) * (DistanceY(actor, closest) - 1);
                        actor.MovementSpeed.Y = 0;
                        actor.CanJump         = true;
                    }
                }
            }
        }
Ejemplo n.º 10
0
 private static void OnEnemyTouch(ColliderBase sender, ColliderBase collider)
 {
     map.MainPlayer.ApplyDamage(10);
 }
Ejemplo n.º 11
0
 private static void OnFinishLevel(ColliderBase sender, ColliderBase collider)
 {
     CurrentLevel++;
     SwitchMap?.Invoke(null, EventArgs.Empty);
 }
Ejemplo n.º 12
0
 private static void OnTouchKillZone(ColliderBase sender, ColliderBase collider)
 {
     map.MainPlayer.ApplyDamage(1000);
     //ShowDialog("You died!");
 }