Exemplo n.º 1
0
 private void SendUdpMessageTo(PlayerDummy to, ByteBufferWriter byteBuffer)
 {
     if (to.UdpLoaded)
     {
         _wrapperUdp.SendMessageTo(to.Udp, byteBuffer);
     }
 }
Exemplo n.º 2
0
        private void SendUdpMessageToAllExcept(PlayerDummy except, ByteBufferWriter byteBuffer)
        {
            foreach (var dummy in _players.Values)
            {
                if (Equals(dummy, except))
                {
                    continue;
                }

                SendUdpMessageTo(dummy, byteBuffer);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
    private void Init()
    {
        if (showAdvancedSettings)
        {
            showAdvancedSettings = false;
        }

        if (useExternalBody)
        {
            useExternalBody = false;
        }

        PlayerDummy player = node as PlayerDummy;

        if (!player)
        {
            return;
        }

        // decompose transformation
        position  = node.WorldPosition;
        direction = MathLib.Normalize(new vec3(-node.WorldTransform.AxisZ));

        camera = player.Camera;

        if (playerBody)
        {
            dummy = playerBody.Body as BodyDummy;
            if (dummy)
            {
                for (int i = 0; i < dummy.NumShapes; i++)
                {
                    if (!shape)
                    {
                        shape = dummy.GetShape(i) as ShapeCapsule;
                    }
                }

                if (shape)
                {
                    shape.Restitution = 0.0f;
                    shape.Continuous  = false;

                    PhysicalIntersectionMask = shape.PhysicsIntersectionMask;
                    CollisionMask            = shape.CollisionMask;
                    Mass            = shape.Mass;
                    CollisionRadius = shape.Radius;
                    CollisionHeight = shape.Height;
                }
            }
        }

        if (!dummy || !shape)
        {
            if (playerBody)
            {
                playerBody.Enabled = false;
            }

            playerBody = new ObjectDummy();
            dummy      = new BodyDummy();

            shape             = new ShapeCapsule(1.0f, 1.0f);
            shape.Restitution = 0.0f;
            shape.Continuous  = false;

            dummy.Enabled   = true;
            playerBody.Body = dummy;
            shape.Body      = dummy;

            PhysicalIntersectionMask = physicalIntersectionMask;
            CollisionMask            = collisionMask;
            Mass            = mass;
            CollisionRadius = collisionRadius;
            CollisionHeight = collisionHeight;
        }

        contacts = new List <ShapeContact>();

        UpdateTransform();

        maxSlopeAngle   = MathLib.Max(maxSlopeAngle, maxStaticSlopeAngle);
        maxSlidingSpeed = MathLib.Max(maxSlidingSpeed, minSlidingSpeed);

        if (showDebug)
        {
            Visualizer.Enabled   = true;
            Render.ShowTriangles = 1;
        }

        isInitialized = true;
    }
Exemplo n.º 5
0
 private void UpdatePlayer(PlayerDummy player, ByteBufferReader data)
 {
     player.SetPos(data.ReadVec2());
     player.Rotation = data.ReadVec2();
 }