Ejemplo n.º 1
0
        public Vector2 GetShotLandedPosition(Vector2 pos, Vector2 dir)
        {
            var lastDist = Single.MaxValue;

            foreach (var box in _collisionBoxes)
            {
                if (RayHelper.Intersects(box, pos, dir, out var hit) && hit < lastDist)
                {
                    lastDist = hit;
                }
            }

            return(lastDist * dir);
        }
Ejemplo n.º 2
0
        private void PlayerShot(PlayerDummy player, ByteBufferReader data)
        {
            var pos = data.ReadVec2();
            var dir = data.ReadVec2();

            var hit = new List <Tuple <float, PlayerDummy> >();

            foreach (var playerDummy in _players.Values)
            {
                if (player == playerDummy || playerDummy.Health <= 0)
                {
                    continue;
                }

                if (RayHelper.Intersects(playerDummy.GetBoundingBox(), pos, dir, out var dist))
                {
                    hit.Add(new Tuple <float, PlayerDummy>(dist, playerDummy));
                }
            }

            var damageToDeal = 35f;

            foreach (var tuple in hit.OrderBy(el => el.Item1))
            {
                var plr = tuple.Item2;

                if (plr.Respawning)
                {
                    continue;
                }

                plr.Health -= damageToDeal;

                if (plr.Health <= 0)
                {
                    plr.BeginRespawn();
                }

                damageToDeal /= 2;
            }

            dir *= float.MaxValue;

            var payload = new ByteBufferWriter(data.Code);

            payload.WriteVec2(pos);
            payload.WriteVec2(dir);

            SendUdpMessageToAllExcept(player, payload);
        }