Esempio n. 1
0
    public void Render()
    {
        GUIUtility.RotateAroundPivot(Rotation, Position.ToUnity());

        GUI.DrawTexture(new Rect(Position.x - Circle.Radius, Position.y - Circle.Radius, visual.width, visual.height), visual);

        float p                = DevMath.DevMath.Clamp(chargeTime, .0f, MAX_CHARGE_TIME) / MAX_CHARGE_TIME;
        float fireVelocity     = DevMath.DevMath.Lerp(MIN_PROJECTILE_START_VELOCITY, MAX_PROJECTILE_START_VELOCITY, p);
        float fireAcceleration = DevMath.DevMath.Lerp(MIN_PROJECTILE_START_ACCELERATION, MAX_PROJECTILE_START_ACCELERATION, p);

        float distanceTraveled = DevMath.DevMath.DistanceTraveled(fireVelocity, fireAcceleration, Projectile.LIFETIME);

        DevMath.Line line = new DevMath.Line();
        line.Position  = Position;
        line.Direction = Direction;
        line.Length    = distanceTraveled;

        Color originalGUIColor = GUI.color;

        foreach (var _enemy in Game.Instance.Enemies)
        {
            if (line.IntersectsWith(_enemy.Circle))
            {
                GUI.color = Color.red; Debug.Log("Ik raak de enemy aan");
            }
        }

        GUI.DrawTexture(new Rect(Position.x, Position.y, distanceTraveled, 1.0f), pixel);
        GUI.color = originalGUIColor;
        //Implementeer de Line class met de IntersectsWith(Circle) functie en gebruik deze om de lijn rood te kleuren wanneer je een enemy zou raken
        GUI.DrawTexture(new Rect(Position.x, Position.y, distanceTraveled, 1.0f), pixel);

        GUI.matrix = Matrix4x4.identity;
    }
Esempio n. 2
0
    public void Render(List <Enemy> enemies)
    {
        Matrix4x4 originalMatrix = GUI.matrix;

        //GUIUtility.RotateAroundPivot(Rotation, Position.ToUnity());
        GUI.matrix *= Matrix4x4.Translate(Position.ToUnity()) * Matrix4x4.Rotate(Quaternion.Euler(0, 0, Rotation)) * Matrix4x4.Translate(Position.ToUnity()).inverse;

        GUI.DrawTexture(new Rect(Position.x - Circle.Radius, Position.y - Circle.Radius, visual.width, visual.height), visual);

        float p                = DevMath.DevMath.Clamp(chargeTime, .0f, MAX_CHARGE_TIME) / MAX_CHARGE_TIME;
        float fireVelocity     = DevMath.DevMath.Lerp(MIN_PROJECTILE_START_VELOCITY, MAX_PROJECTILE_START_VELOCITY, p);
        float fireAcceleration = DevMath.DevMath.Lerp(MIN_PROJECTILE_START_ACCELERATION, MAX_PROJECTILE_START_ACCELERATION, p);

        float distanceTraveled = DevMath.DevMath.DistanceTraveled(fireVelocity, fireAcceleration, Projectile.LIFETIME);

        //Implementeer de Line class met de IntersectsWith(Circle) functie en gebruik deze om de lijn rood te kleuren wanneer je een enemy zou raken
        DevMath.Line shootingLine = new DevMath.Line(Position, Direction, distanceTraveled);
        foreach (Enemy enemy in enemies)
        {
            if (shootingLine.IntersectsWith(enemy.Circle))
            {
                GUI.color = Color.red;
                break;
            }
        }

        //GUI.DrawTexture(new Rect(Position.x, Position.y, distanceTraveled, 1.0f), pixel);
        GUI.DrawTexture(new Rect(shootingLine.Position.x, shootingLine.Position.y, shootingLine.Length, 1.0f), pixel);

        //GUI.matrix = Matrix4x4.identity;
        GUI.matrix = originalMatrix;
    }
Esempio n. 3
0
    public void Render()
    {
        GUIUtility.RotateAroundPivot(Rotation, Position.ToUnity());

        GUI.DrawTexture(new Rect(Position.x - Circle.Radius, Position.y - Circle.Radius, visual.width, visual.height), visual);

        float p                = DevMath.DevMath.Clamp(chargeTime, .0f, MAX_CHARGE_TIME) / MAX_CHARGE_TIME;
        float fireVelocity     = DevMath.DevMath.Lerp(MIN_PROJECTILE_START_VELOCITY, MAX_PROJECTILE_START_VELOCITY, p);
        float fireAcceleration = DevMath.DevMath.Lerp(MIN_PROJECTILE_START_ACCELERATION, MAX_PROJECTILE_START_ACCELERATION, p);

        float distanceTraveled = DevMath.DevMath.DistanceTraveled(fireVelocity, fireAcceleration, Projectile.LIFETIME);

        DevMath.Line line = new DevMath.Line();
        line.Position  = Position;
        line.Length    = distanceTraveled;
        line.Direction = Direction;

        //Implementeer de Line class met de IntersectsWith(Circle) functie en gebruik deze om de lijn rood te kleuren wanneer je een enemy zou raken
        if (line.IntersectsWith(enemy))
        {
            GUI.color = Color.red;
        }
        else
        {
            GUI.color = Color.white;
        }

        GUI.DrawTexture(new Rect(Position.x, Position.y, distanceTraveled, 1.0f), pixel);

        GUI.color = Color.white;

        GUI.matrix = Matrix4x4.identity;

        if (Input.GetKey(KeyCode.Q))
        {
            GUILayout.BeginVertical();
            GUILayout.Label($"Velocity X: {rigidbody.Velocity.x / Time.deltaTime}, Y: {rigidbody.Velocity.y / Time.deltaTime} pixels/second");
            GUILayout.Label($"Acceleration: {rigidbody.Acceleration / Time.deltaTime} pixels/second^2");
            GUILayout.EndVertical();
        }
    }
Esempio n. 4
0
    public void Render()
    {
        GUIUtility.RotateAroundPivot(Rotation, Position.ToUnity());

        GUI.DrawTexture(new Rect(Position.x - Circle.Radius, Position.y - Circle.Radius, visual.width, visual.height), visual);

        float p                = DevMath.DevMath.Clamp(chargeTime, .0f, MAX_CHARGE_TIME) / MAX_CHARGE_TIME;
        float fireVelocity     = DevMath.DevMath.Lerp(MIN_PROJECTILE_START_VELOCITY, MAX_PROJECTILE_START_VELOCITY, p);
        float fireAcceleration = DevMath.DevMath.Lerp(MIN_PROJECTILE_START_ACCELERATION, MAX_PROJECTILE_START_ACCELERATION, p);

        float distanceTraveled = DevMath.DevMath.DistanceTraveled(fireVelocity, fireAcceleration, Projectile.LIFETIME);

        //Implementeer de Line class met de IntersectsWith(Circle) functie en gebruik deze om de lijn rood te kleuren wanneer je een enemy zou raken
        DevMath.Line line = new DevMath.Line
        {
            Position  = new DevMath.Vector2(Position.x, Position.y),
            Direction = DevMath.Vector2.DirectionFromAngle(Rotation),
            Length    = distanceTraveled
        };

        //get the first enemy with a position higher than 500 (example)
        //var temp = Game.Instance.enemies.OrderBy((e) => e.Position.x).FirstOrDefault((e) => e.Position.x > 500);

        foreach (Enemy enemy in Game.Instance.enemies)
        {
            if (enemy.Circle.CollidesWith(line))
            {
                GUI.color = Color.red;
            }
        }

        GUI.DrawTexture(new Rect(Position.x, Position.y, distanceTraveled, 1.0f), pixel);
        GUI.color = Color.white;

        GUI.matrix = Matrix4x4.identity;
    }