Beispiel #1
0
    public void ShootLaser(SimpleRay2D ray, PlayerPawn owner)
    {
        List <PlayerPawn> playersHit = CastRay(ray);

        Network.Log("Laser hits " + playersHit.Count + " players.");
        float laserPower       = owner.GetLaserDamage();
        float powerAccumulator = 0.0f;

        for (int i = 0; i < playersHit.Count; ++i)
        {
            if (playersHit[i] == owner)
            {
                continue;
            }

            powerAccumulator += playersHit[i].ReceiveDamage(laserPower);
        }

        owner.AddPower(powerAccumulator);

        ShotEvent se = new ShotEvent();

        se.m_direction       = ray.direction;
        se.m_point           = owner.Position;
        se.m_who             = owner.Id;
        se.m_reliableEventId = Network.Server.GetNewReliableEventId();
        foreach (int id in m_players.Keys)
        {
            Network.Server.Send(se, id, true);
        }
    }
Beispiel #2
0
    public void ShootAtDirection(Vector2 direction)
    {
        Network.Log("Player " + Id + " shot at direction " + direction);
        SimpleRay2D ray = new SimpleRay2D();

        ray.origin    = m_position;
        ray.direction = direction;
        ray.length    = m_laserLength;
        world.ShootLaser(ray, this);
    }
Beispiel #3
0
    List <PlayerPawn> CastRay(SimpleRay2D ray)
    {
        List <PlayerPawn> result = new List <PlayerPawn>();

        foreach (var kvp in m_players)
        {
            if (kvp.Value != null)
            {
                if (kvp.Value.Intersects(ray))
                {
                    result.Add(kvp.Value);
                }
            }
        }

        return(result);
    }
Beispiel #4
0
    public bool Intersects(SimpleRay2D ray)
    {
        Vector2 L   = m_position - ray.origin;
        float   tca = Vector2.Dot(L, ray.direction);

        if (tca < 0)
        {
            return(false);
        }

        float d2 = Vector2.Dot(L, L) - tca * tca;

        if (d2 > Radius * Radius)
        {
            return(false);
        }

        float thc = Radius - Mathf.Sqrt(d2);
        float t0  = tca - thc;
        float t1  = tca + thc;

        if (t0 > t1)
        {
            if (t0 > ray.length)
            {
                return(false);
            }
        }
        else
        {
            if (t1 > ray.length)
            {
                return(false);
            }
        }

        return(true);
    }