Ejemplo n.º 1
0
    public void OnPointerUp(BaseEventData bed)
    {
        PointerEventData ped = (PointerEventData)bed;

        if (this.targetLB != null) {
            this.endPos = ped.position;

            Vector3 offset = Vector3.ClampMagnitude ((this.endPos - this.startPos), this.maxDistance);
            Vector3 startPos3 = this.targetCamera.ScreenToWorldPoint (new Vector3 (this.startPos.x, this.startPos.y, -this.targetCamera.transform.position.z));
            Vector3 endPos3 = this.targetCamera.ScreenToWorldPoint (new Vector3 (this.endPos.x, this.endPos.y, -this.targetCamera.transform.position.z));

            // Send LB in direction of drag.
            if (offset.magnitude >= this.minDistance && offset.magnitude <= this.maxDistance) {
                Vector2 velocity = new Vector2 (endPos3.x - startPos3.x, endPos3.y - startPos3.y);
                this.targetLB.SetVelocity (velocity);
            }
            // Stop LB from moving.
            else {
                this.targetLB.SetVelocity (Vector2.zero);
            }
        }

        this.targetLB = null;
        this.startPos = Vector2.zero;
        this.endPos = Vector2.zero;
    }
Ejemplo n.º 2
0
    public override List <LightBeam> ComputeOutgoingLightBeams(LightBeam input)
    {
        List <LightBeam> outputs = new List <LightBeam>(2);

        outputs.Add(new LightBeam(input.Color, (8 + Heading - 1) % 8));
        outputs.Add(new LightBeam(input.Color, (8 + Heading + 1) % 8));
        return(outputs);
    }
Ejemplo n.º 3
0
 //----------------------------------------------------\\
 //						OnLightBeam					  \\
 //----------------------------------------------------\\
 public void OnLightBeam()
 {
     if (_activated == false)
     {
         _activated = true;
         LightBeam lightBeam = new LightBeam(this, _reflectAngle, 16);
         world.AddBody(lightBeam);
     }
 }
Ejemplo n.º 4
0
    protected virtual void OnDiscovered()
    {
        LightBeam beam = Instantiate(UI.Instance.lightBeam, transform.position, Quaternion.identity);

        beam.beamColor = beamColor;

        onPing += beam.Ping;

        UI.Instance.pingables.Add(this);
    }
Ejemplo n.º 5
0
    //CALCULATES output light(s)
    protected override void CalculateOutput()
    {
        LightBeam input = inputList.ElementAt(0);
        LightBeam output1;
        LightBeam output2;

        // if output light beams don't yet exist, instantiate them
        if (outputList.Count == 0)
        {
            GameObject tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject;
            output1 = tempObj.GetComponent <LightBeam>();

            tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject;
            output2 = tempObj.GetComponent <LightBeam>();

            outputList.AddFirst(output1);
            outputList.AddLast(output2);
        }

        output1 = outputList.ElementAt(0);
        output2 = outputList.ElementAt(1);

        // COLOR
        if (input.GetColor() == cyan)
        {
            // Erstelle blauen und grünen Strahl
            output1.SetColor(blue);
            output2.SetColor(green);
        }
        else if (input.GetColor() == yellow)
        {
            // Erstelle roten und grünen Strahl
            output1.SetColor(green);
            output2.SetColor(red);
        }
        else if (input.GetColor() == magenta)
        {
            // Erstelle roten und blauen Strahl
            output1.SetColor(red);
            output2.SetColor(blue);
        }
        else
        {
            ChangeError(ErrorState.ERRORINPUT);
        }

        // DIRECTION
        output1.SetDirection(Quaternion.Euler(0, -60, 0) * input.GetRaycastHit().collider.transform.forward);
        output2.SetDirection(Quaternion.Euler(0, 60, 0) * input.GetRaycastHit().collider.transform.forward);

        // SET ACTIVE
        output1.Enable();
        output2.Enable();
    }
Ejemplo n.º 6
0
    public override List <LightBeam> ComputeOutgoingLightBeams(LightBeam input)
    {
        var result = new List <LightBeam>(5);

        result.Add(new LightBeam(input.Color, (Heading - 2) % 8));
        result.Add(new LightBeam(input.Color, (Heading - 1) % 8));
        result.Add(new LightBeam(input.Color, (Heading - 0) % 8));
        result.Add(new LightBeam(input.Color, (Heading + 1) % 8));
        result.Add(new LightBeam(input.Color, (Heading + 2) % 8));
        return(result);
    }
Ejemplo n.º 7
0
    //CALCULATES output light(s)
    protected override void CalculateOutput()
    {
        LightBeam input = inputList.ElementAt(0);

        Debug.Log(inputList.ElementAt(0));
        LightBeam output1;
        LightBeam output2;

        // if output light beams don't yet exist, instantiate them
        if (outputList.Count == 0)
        {
            GameObject tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject;
            output1 = tempObj.GetComponent <LightBeam>();

            tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject;
            output2 = tempObj.GetComponent <LightBeam>();

            outputList.AddFirst(output1);
            outputList.AddLast(output2);
        }

        output1 = outputList.ElementAt(0);
        output2 = outputList.ElementAt(1);

        // color
        output1.SetColor(input.GetColor());
        output2.SetColor(input.GetColor());

        // direction
        // blocked side is forward (positive z axis)
        if (input.GetRaycastHit().collider.name == "LightColliderLeft")
        {
            output1.SetDirection(transform.right);
            output2.SetDirection(transform.forward * (-1));
        }
        else if (input.GetRaycastHit().collider.name == "LightColliderRight")
        {
            output1.SetDirection(transform.right * (-1));
            output2.SetDirection(transform.forward * (-1));
        }
        else if (input.GetRaycastHit().collider.name == "LightColliderBack")
        {
            output1.SetDirection(transform.right);
            output2.SetDirection(transform.right * (-1));
        }

        // set active
        output1.Enable();
        output2.Enable();
    }
Ejemplo n.º 8
0
    // REMOVES a light from the list of lights, which are entering the object
    public virtual void RemoveInputLight(LightBeam light)
    {
        var node = inputList.First;

        while (node != null)
        {
            var nextNode = node.Next;
            if (node.Value.GetID() == light.GetID())
            {
                inputList.Remove(node);
                Debug.Log("Removed " + light.GetID() + " from " + this);
            }
            node = nextNode;
        }
    }
Ejemplo n.º 9
0
    public LightNode March(Vector2Int position, LightBeam beam, Dictionary <PlayObject, List <LightBeam> > collisions, int depth)
    {
        Vector2Int vHeading = Vector2IntHeadings[beam.Heading];
        Vector2Int nextCell = position + vHeading;

        if (depth < 0)
        {
            return(new LightNode {
                Position = nextCell
            });
        }

        if (!InBounds(nextCell))
        {
            return(new LightNode {
                Position = position + vHeading * 100
            });
        }

        PlayObject target = GetObjectAtCell(nextCell);

        if (target)
        {
            LightNode targetNode = new LightNode {
                Object = target, Position = nextCell
            };

            if (!collisions.ContainsKey(target))
            {
                collisions[target] = new List <LightBeam>();
            }
            collisions[target].Add(beam);

            targetNode.LightBeams = target.ComputeOutgoingLightBeams(beam);

            foreach (LightBeam lb in targetNode.LightBeams)
            {
                targetNode.LightNodes.Add(March(nextCell, lb, collisions, depth - 1));
            }
            return(targetNode);
        }
        else
        {
            return(March(nextCell, beam, collisions, depth));
        }
    }
Ejemplo n.º 10
0
    public void OnPointerDown(BaseEventData bed)
    {
        PointerEventData ped = (PointerEventData)bed;

        // Cast a ray out from the camera to see if lightbeam is being targeted.
        Ray ray = this.targetCamera.ScreenPointToRay (ped.position);
        RaycastHit hit;

        if (Physics.Raycast (ray, out hit, 1000)) {
            LightBeam lb = hit.collider.GetComponent <LightBeam>();
            if (lb != null) {
                Debug.Log ("hit");
                this.targetLB = lb;
                this.startPos = ped.position;
            }
        }
    }
Ejemplo n.º 11
0
    public override List <LightBeam> ComputeOutgoingLightBeams(LightBeam input)
    {
        List <LightBeam> result = new List <LightBeam>();

        // TODO: I don't really love this... maybe change?
        // Only generate beam on start, not on collision.
        if (input != null)
        {
            return(result);
        }

        foreach (var spec in BeamConfiguration.BeamSpecs)
        {
            result.Add(new LightBeam(spec, Heading));
        }
        return(result);
    }
Ejemplo n.º 12
0
    //CALCULATES output light(s)
    protected override void CalculateOutput()
    {
        LightBeam input1 = inputList.ElementAt(0);
        LightBeam input2 = inputList.ElementAt(1);
        LightBeam output;

        // if output light beams don't yet exist, instantiate them
        if (outputList.Count == 0)
        {
            GameObject tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject;
            output = tempObj.GetComponent <LightBeam>();

            outputList.AddFirst(output);
        }

        output = outputList.ElementAt(0);

        // COLOR
        if (input1.GetColor() == red && input2.GetColor() == green ||
            input2.GetColor() == red && input1.GetColor() == green)
        {
            output.SetColor(yellow);
        }
        else if (input1.GetColor() == red && input2.GetColor() == blue ||
                 input2.GetColor() == red && input1.GetColor() == blue)
        {
            output.SetColor(magenta);
        }
        else if (input1.GetColor() == green && input2.GetColor() == blue ||
                 input2.GetColor() == green && input1.GetColor() == blue)
        {
            output.SetColor(cyan);
        }
        else
        {
            ChangeError(ErrorState.ERRORINPUT);
        }

        // DIRECTION
        output.SetDirection(Vector3.Normalize(input1.GetDirection() + input2.GetDirection()));

        // SET ACTIVE
        output.Enable();
    }
Ejemplo n.º 13
0
    // Use this for initialization
    void Awake()
    {
        GameObject tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, Quaternion.Euler(0, -45, 0) * transform.rotation, transform) as GameObject;

        red = tempObj.GetComponent <LightBeam>();
        red.SetColor(AbstractOpticalElement.blue);

        tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject;
        green   = tempObj.GetComponent <LightBeam>();
        green.SetColor(AbstractOpticalElement.green);

        tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, Quaternion.Euler(0, 45, 0) * transform.rotation, transform) as GameObject;
        blue    = tempObj.GetComponent <LightBeam>();
        blue.SetColor(AbstractOpticalElement.red);

        tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, Quaternion.Euler(0, 180, 0) * transform.rotation, transform) as GameObject;
        white   = tempObj.GetComponent <LightBeam>();
        white.SetColor(Color.white);
    }
Ejemplo n.º 14
0
    // Use this for initialization
    public override void Start()
    {
        base.Start();
        interruptableByNormalAttack = false;

        TrajectoryDetector.OnTrigger += TrajectoryGestureTriggered;
        HandUpDetector.OnTrigger     += HandUpGestureTriggered;
        GrabDetector.OnGrab          += GrabGestureTriggered;

        skillAntiGravity  = new AntiGravity();
        skillGrabbing     = new Grabbing();
        skillSpike        = new EarthSpikes();
        skillBeam         = new LightBeam();
        skillFireBall     = new FireBallSpell();
        skillLightning    = new LightningStrike();
        skillSummonHelper = new SummonHelper();
        skillHeal         = new Heal();
        skillSpeedUp      = new SpeedUp();
    }
Ejemplo n.º 15
0
    void RenderLightNode(LightNode node, float width)
    {
        for (int i = 0; i < node.LightBeams.Count; i++)
        {
            LightBeam    lb          = node.LightBeams[i];
            LightNode    ln          = node.LightNodes[i];
            LineRenderer lr          = LineRenderers[LineRendererIndex++];
            Vector3      origin      = GridToWorldPosition(node.Position);
            Vector3      destination = GridToWorldPosition(ln.Position);

            lr.gameObject.SetActive(true);
            lr.positionCount = 2;
            lr.SetPosition(0, origin);
            lr.SetPosition(1, destination);
            lr.startWidth = width;
            lr.endWidth   = width;
            lr.material   = GetBeamMaterial(lr, lb);
            RenderLightNode(ln, width);
        }
    }
Ejemplo n.º 16
0
    public override List <LightBeam> ComputeOutgoingLightBeams(LightBeam input)
    {
        var result = new List <LightBeam>();

        // Reflection map for a mirror with orientation "0".
        // outputOrientation = reflectionMap[inputOrientation] for that 0-oriented mirror.
        // To find reflections for arbitrary headings, we put the heading into the mirror's orientation space,
        // get the reflection, then convert back to global heading.
        int[] reflectionMap     = { 8, 7, 6, 5, -1, 3, 2, 1, 0, 15, 14, 13, -1, 11, 10, 9 };
        int   inputOrientation  = input.Heading * 2; // heading is 0-7, orientation is 0-15
        int   adjustedInput     = (16 + inputOrientation - (int)this.Orientation) % 16;
        int   outputOrientation = reflectionMap[adjustedInput];

        if (outputOrientation != -1)
        {
            int adjustedOutput = (outputOrientation + (int)this.Orientation) % 16;

            result.Add(new LightBeam(input.Color, adjustedOutput / 2));
        }
        return(result);
    }
Ejemplo n.º 17
0
    //----------------------------------------------------\\
    //						shoot                         \\
    //----------------------------------------------------\\
    private void shoot()
    {
        if (canJump && _abilityTimer == -1)
        {
            isBeamActivated = true;
            switch (_lastDirection)
            {
            case Key.RIGHT:
            default:
                LightBeam rightBeam = new LightBeam(this, 0, 16);
                world.AddBody(rightBeam);
                break;

            case Key.LEFT:
                LightBeam leftBeam = new LightBeam(this, 180, 16);
                world.AddBody(leftBeam);
                break;
            }
            _abilityTimer = _abilityCooldown;
            new Sound("LightBeam.wav", false).Play();
        }
    }
Ejemplo n.º 18
0
    //CALCULATES output light(s)
    protected override void CalculateOutput()
    {
        // iterate over all inputs
        for (int i = 0; i < inputList.Count; i++)
        {
            LightBeam input = inputList.ElementAt(i);

            // if there are too little beams in the output list, create one more
            if (outputList.Count == 0 || outputList.Count < i + 1)
            {
                GameObject tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject;
                outputList.AddLast(tempObj.GetComponent <LightBeam>());
            }

            // hit point
            outputList.ElementAt(i).transform.position = new Vector3(input.GetRaycastHit().point.x, 0, input.GetRaycastHit().point.z);

            // color
            outputList.ElementAt(i).SetColor(input.GetColor());

            // direction
            Vector3 mirrorAxis   = Vector3.Dot(transform.right, input.GetDirection()) / Mathf.Sqrt(transform.right.magnitude) * transform.right;
            Vector3 mirrorNormal = Vector3.Dot(transform.forward, input.GetDirection()) / Mathf.Sqrt(transform.forward.magnitude) * transform.forward;

            outputList.ElementAt(i).SetDirection(mirrorAxis - mirrorNormal);

            // set active
            outputList.ElementAt(i).Enable();
        }

        if (outputList.Count >= inputList.Count)
        {
            for (int i = inputList.Count; i < outputList.Count; i++)
            {
                outputList.ElementAt(i).Disable();
            }
        }
    }
Ejemplo n.º 19
0
    // ADDS a light to the list of lights, which are entering the object
    public virtual void AddInputLight(LightBeam light)
    {
        // check wheather light already exists in the list
        var  node     = inputList.First;
        bool newInput = true;

        while (node != null)
        {
            var nextNode = node.Next;
            if (node.Value.GetID() == light.GetID())
            {
                newInput = false;
            }
            node = nextNode;
        }

        // if light isn't already in the list, add it
        if (newInput)
        {
            inputList.AddLast(light);
            //Debug.Log("Added " + light.GetID() + " to " + this);
        }
    }
Ejemplo n.º 20
0
        private void resolveLightOverlap(LightBeam body1, Body body2, float distance)
        {
            for (int i = 0; i < distance + (int)body1.halfWidth * 4; i += (int)body1.halfWidth * 4)
            {
                LightBeam beamTile = new LightBeam(body1.plOwner, (int)body1.velocity.GetAngleDegrees());
                beamTile.rotation = body1.velocity.GetAngleDegrees();
                beamTile.x        = body1.plOwner.x + body1.velocity.x / body1._speed * i;
                beamTile.y        = body1.plOwner.y + body1.velocity.y / body1._speed * i;
                AddBody(beamTile);
            }
            RemoveBody(body1);

            if (body2 is StaticCrystal)
            {
                StaticCrystal c = body2 as StaticCrystal;
                c.OnLightBeam();
            }

            if (body2 is Sapling && (body2 as Sapling).isActivated == false)
            {
                Sapling s = body2 as Sapling;
                s.isActivated = true;
                for (int i = bodies.Count; i > 0; i--)
                {
                    if (bodies[i - 1] is Gate && (bodies[i - 1] as Gate)._activateID == s._activateID)
                    {
                        Gate g = bodies[i - 1] as Gate;
                        // play sound here I guess
                        Smoke smoke = new Smoke(g.x, g.y, 2);
                        game.AddChild(smoke);
                        RemoveBody(g);
                        new Sound("PlantSeed.wav", false).Play();
                    }
                }
            }
            _beamTimer = TIME_BEFORE_REMOVEBEAM;
        }
Ejemplo n.º 21
0
    // Update is called once per frame
    void Update()
    {
        lightRay = LightBeam.Cast(transform.position, transform.up, LayerMask.NameToLayer("BounceLightBeams"));

        int nBounces = lightRay.endPoints.Count;

        lr.positionCount = nBounces + 1;
        lr.SetPosition(0, transform.position + new Vector3(0, 0, -1f));
        for (int i = 0; i < nBounces; i++)
        {
            lr.SetPosition(i + 1, new Vector3(lightRay.endPoints[i].x, lightRay.endPoints[i].y, -1));
        }

        destinations.Clear();
        foreach (GameObject touchedObject in lightRay.touchedObjects)
        {
            LightBeamReceptor receptor = touchedObject.GetComponent <LightBeamReceptor>();
            if (receptor != null)
            {
                destinations.Add(receptor);
                receptor.BeginReceivingLight(this);
            }
        }
    }
Ejemplo n.º 22
0
    // Returns all contact points from a bouncing ray at the specified position and moving in the specified direction.
    public static LightBeam Cast(Vector2 position, Vector2 direction, int bounceLayer, int nbReflexions = 100, float magnitude = 1000)
    {
        // Initialize the return data.
        LightBeam lightRay = new LightBeam
        {
            touchedObjects = new List <GameObject>(),
            endPoints      = new List <Vector2>(),
            finalDirection = direction.normalized
        };

        lightRay.endPoints.Add(position);

        Vector2 currPosition       = position;
        Vector2 currDirection      = direction;
        float   magnitudeRemaining = magnitude;

        for (int i = 0; i < nbReflexions; i++)
        {
            currDirection.Normalize();

            // Fire out initial vector.
            RaycastHit2D hit = Physics2D.Raycast(currPosition, currDirection, magnitudeRemaining);

            // Calculate our bounce conditions.
            bool hitSucceeded       = hit.collider != null && hit.distance > 0;
            bool canReachNextBounce = hit.distance < magnitudeRemaining;

            // we didn't hit anything
            if (!hitSucceeded || !canReachNextBounce)
            {
                currPosition = currPosition + currDirection * magnitudeRemaining;
                lightRay.endPoints.Add(currPosition);
                break;
            }

            // we hit something.

            // Add the contact point & hit object th their lists.
            lightRay.endPoints.Add(hit.point);

            GameObject hitObject = hit.collider.gameObject;
            if (!lightRay.touchedObjects.Contains(hitObject))
            {
                lightRay.touchedObjects.Add(hitObject);
            }

            // we hit a non reflexive object, no more bounce allowed
            if (hitObject.layer != bounceLayer)
            {
                break;
            }

            // Reflect the hit.
            currDirection = Vector2.Reflect(currDirection.normalized, hit.normal);
            // offset the next emission point to prevent self hit
            currPosition = hit.point + bounceOffset * hit.normal;
        }

        for (int i = 1; i < lightRay.endPoints.Count; i++)
        {
            Debug.DrawLine(lightRay.endPoints[i - 1], lightRay.endPoints[i], Color.green);
        }

        // Return the current position & direction as final.
        return(lightRay);
    }
Ejemplo n.º 23
0
 public override List <LightBeam> ComputeOutgoingLightBeams(LightBeam input)
 {
     return(new List <LightBeam>());
 }
Ejemplo n.º 24
0
 public static void Collide(Mirror m0, LightBeam lb0)
 {
     Console.WriteLine("Special Collision: Mirror {0}[{1}] and LightBeam {2}[{3}].", m0.Name, m0.ID, lb0.Name, lb0.ID);
 }
Ejemplo n.º 25
0
 Material GetBeamMaterial(LineRenderer renderer, LightBeam beam)
 {
     renderer.material.SetColor("_EmissionColor", beam.Color * BeamIntensity);
     return(renderer.material);
 }
Ejemplo n.º 26
0
        private void resolveOverlap(Body body1, Body body2, Vec2 normal, float distance, bool floored)
        {
            Vec2 separation = normal * distance /** 0.5f*/;

            // ignore collisions with static light beam tiles:
            if ((body1 is LightBeam && (body1 as LightBeam)._speed == 0) ||
                (body2 is LightBeam && (body2 as LightBeam)._speed == 0))
            {
                return;
            }

            // ignore any possible collision between Player1 and Player2:
            if (body1 is Player1 && body2 is Player2)
            {
                return;
            }

            // ignore any collision between light beams and the object shooting them:
            if (body2 is LightBeam)
            {
                if (body1 == (body2 as LightBeam).plOwner)
                {
                    return;
                }
            }

            // ignore collisions between gates and tiles (do not push tiles with gates behind them):
            if (body1 is Gate && body2 is Tile)
            {
                return;
            }

            // stop light beam from advancing on non-Player2 surfaces
            // and return (skip actual resolve checks to emulate non-solid):
            if (body1 is Player2 == false && body2 is LightBeam)
            {
                LightBeam b = body2 as LightBeam;
                resolveLightOverlap(b, body1, b.travelDist);
                return;
            }

            // BUTTON collision:
            // on collision (after clipping) between seed/slime and ground
            // button, destroy gate that button is linked to:
            if (body2 is Button)
            {
                Button button = body2 as Button;
                if (button.isActivated == false)
                {
                    if (button._buttonType == (int)Button.bType.SEED)
                    {
                        if (body1 is Seed)
                        {
                            button.isActivated = true;
                            for (int i = bodies.Count; i > 0; i--)
                            {
                                if (bodies[i - 1] is Gate && (bodies[i - 1] as Gate)._activateID == button._activateID)
                                {
                                    // play sound here I guess
                                    bodies[i - 1].LateDestroy();
                                    Smoke smoke = new Smoke(bodies[i - 1].x, bodies[i - 1].y, 2);
                                    game.AddChild(smoke);
                                    RemoveBody(body1);
                                    RemoveBody(bodies[i - 1]);
                                    new Sound("PlantSeed.wav", false).Play();
                                    button.SetFrame(1);
                                }
                            }
                        }
                    }
                    if (button._buttonType == (int)Button.bType.SLIME)
                    {
                        if (body1 is Player1)
                        {
                            button.isActivated = true;
                            #region REMOVE GATE (DISABLED)

                            /*for (int i = bodies.Count; i > 0; i--)
                             * {
                             *  if (bodies[i - 1] is Gate && (bodies[i - 1] as Gate)._activateID == button._activateID)
                             *  {
                             *      // play sound here I guess
                             *      RemoveBody(bodies[i - 1]);
                             *      bodies[i - 1].LateDestroy();
                             *  }
                             * }*/
                            #endregion
                            // spawn sapling instead
                            Sapling s = new Sapling(99);
                            s.rotation = 270;
                            AddBody(s);
                            s.SetPosition(384, 576);
                        }
                    }
                }
            }

            // restore jump on floor:
            if (body1 is Player1 && floored)
            {
                (body1 as Player1).canJump = true;
            }
            if (body1 is Player2 && floored)
            {
                (body1 as Player2).canJump = true;
            }

            // crush rocks:
            if (body1 is Player1 && (body1 as Player1)._scale > 1 && body2 is Rock)
            {
                StaticCrystal crystal = new StaticCrystal(90, 1);
                crystal.SetPosition(body2.position.x, body2.position.y);
                crystal.acceleration = new Vec2(0, 0);
                AddBody(crystal);
                (body2 as Rock).Delete();
                RemoveBody(body2);
                new Sound("RockCrushed.wav", false).Play();
            }

            // change scene on exit:
            else if ((body1 is Player1 || body1 is Player2) && body2 is Exit)
            {
                // TODO: End game SOMEHOW
                return;
            }

            // move movable body together with pusher:
            else if (body2.movable && normal.y == 0)
            {
                if (normal.x < 0)
                {
                    body2.position -= separation * body1.velocity.x;
                    body1.position += separation * body1.velocity.x;
                }
                else if (normal.x > 0)
                {
                    body2.position += separation * body1.velocity.x;
                    body1.position -= separation * body1.velocity.x;
                }
                return;
            }

            // clip on top of clippable only from movement from the side:
            else if (body2 is Box && (body2 as Box).clippable && normal.y == 0)
            {
                body1.position.y = body2.position.y - (body2 as Box).halfHeight - (body1 as Box).halfHeight;
                return;
            }

            // apply separation (main collision resolve) and kill relevant velocity:
            body1.position += separation;
            if (normal.x == 0)
            {
                body1.velocity.y = 0;
            }
            if (normal.y == 0)
            {
                body1.velocity.x = 0;
            }
        }
Ejemplo n.º 27
0
        private void OverlayEntities(MapElement entities, Bitmap map, VirtualMap <char> solids, bool background)
        {
            CassetteBlock.Blocks.Clear();

            using (Graphics g = Graphics.FromImage(map)) {
                List <Entity> ents = new List <Entity>();
                for (int i = entities.Children.Count - 1; i >= 0; i--)
                {
                    MapElement child = entities.Children[i];

                    Entity entity = null;
                    if (child.Name.IndexOf("spikes", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        entity = background ? Spikes.FromElement(child) : null;
                    }
                    else if (child.Name.IndexOf("triggerSpikes", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        entity = background ? TriggerSpikes.FromElement(child) : null;
                    }
                    else if (child.Name.IndexOf("strawberry", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        entity = background ? Strawberry.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("goldenBerry", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Strawberry.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("redBlocks", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("greenBlocks", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("yellowBlocks", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("clutterCabinet", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterCabinet.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("introCar", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? IntroCar.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("clothesLine", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClothesLine.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("colorSwitch", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ColorSwitch.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("memorialTextController", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Strawberry.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bonfire", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Bonfire.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("trapDoor", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TrapDoor.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("movingPlatform", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? MovingPlatform.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("sinkingPlatform", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? SinkingPlatform.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("clutterDoor", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterDoor.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bridge", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Bridge.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bridgeFixed", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? BridgeFixed.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("jumpThru", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? JumpThru.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("door", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Door.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("blockField", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? BlockField.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("lamp", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Lamp.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("hahaha", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Haha.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("waterFall", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? WaterFall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("water", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Water.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("key", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Key.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("resortLantern", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ResortLantern.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bird", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Bird.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("memorial", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Memorial.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("player", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? PlayerSpawn.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("zipMover", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ZipMover.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("wire", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Wire.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("crumbleBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? CrumbleBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("refill", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Refill.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("spring", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Spring.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("fakeWall", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FakeWall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("exitBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FakeWall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("lightBeam", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? LightBeam.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("cobweb", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Cobweb.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("cassette", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Cassette.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("flutterBird", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FlutterBird.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("checkpoint", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Checkpoint.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("fallingBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FallingBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("introCrusher", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FallingBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("cassetteBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? CassetteBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("dashBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DashBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("coverupWall", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? CoverupWall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("npc", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? NPC.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("birdForsakenCityGem", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ForsakenCityGem.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("soundSource", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? SoundSource.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("friendlyGhost", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FriendlyGhost.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("floatingDebris", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FloatingDebris.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("hangingLamp", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? HangingLamp.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("lockBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? LockBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("heartGem", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? HeartGem.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("blackGem", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? HeartGem.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("dreamMirror", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DreamMirror.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("darkChaser", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DarkChaser.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("dreamBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DreamBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("touchSwitch", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TouchSwitch.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("switchGate", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? SwitchGate.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("invisibleBarrier", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? InvisibleBarrier.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("payphone", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Payphone.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("spinner", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Spinner.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("rotateSpinner", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? RotateSpinner.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("trackSpinner", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TrackSpinner.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("towerViewer", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TowerViewer.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("foregroundDebris", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = !background?ForegroundDebris.FromElement(child) : null;
                    }
                    else if (background)
                    {
                        Console.WriteLine(child.Name);
                    }
                    if (entity != null)
                    {
                        ents.Add(entity);
                    }
                }

                ents.Sort(delegate(Entity one, Entity two) {
                    int comp = two.Depth.CompareTo(one.Depth);
                    return(comp == 0 ? one.ID.CompareTo(two.ID) : comp);
                });

                for (int i = 0; i < ents.Count; i++)
                {
                    Entity entity = ents[i];
                    entity.Render(g, solids);
                }
            }
        }
Ejemplo n.º 28
0
 public static void Collide(LightBeam lb0, Mirror m0)
 {
     Collide(m0, lb0);
 }