예제 #1
0
 public void TurnOn()
 {
     if (!timed)
     {
         if (!Switch.Activated)
         {
             touchSfx.Play("event:/game/general/touchswitch_any", null, 0f);
             if (Switch.Activate())
             {
                 SoundEmitter.Play("event:/game/general/touchswitch_last_oneshot");
                 base.Add(new SoundSource("event:/game/general/touchswitch_last_cutoff"));
             }
         }
     }
     else
     {
         if (!TimedSwitch.Activated)
         {
             touchSfx.Play("event:/game/general/touchswitch_any", null, 0f);
             if (TimedSwitch.Activate())
             {
                 SoundEmitter.Play("event:/game/general/touchswitch_last_oneshot");
                 base.Add(new SoundSource("event:/game/general/touchswitch_last_cutoff"));
             }
         }
     }
 }
예제 #2
0
    //Old function, probably remove later
    void FireLaser()
    {
        RaycastHit hit;
        Vector3    endPosition;

        Vector3 rayOrigin    = rayOriginObject.transform.position;
        Vector3 rayDirection = rayOriginObject.transform.forward;

        Vector3 lineOrigin = lineOriginObject.transform.position;

        //Check if laser is hitting anything
        if (Physics.Raycast(rayOrigin, rayDirection, out hit))
        {
            //Check if the hit object is on the Reflective layer
            if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Reflective"))
            {
                //Find reflection vector
                Vector3 reflectDirection = Vector3.Reflect(rayDirection, hit.normal);



                //Reflect
                lineRenderer.positionCount = 3;
                lineRenderer.SetPosition(0, lineOrigin);
                lineRenderer.SetPosition(1, hit.point);
                lineRenderer.SetPosition(2, reflectDirection * laserMaxLength);
            }
            else if (hit.transform.gameObject.layer == LayerMask.NameToLayer("LaserActivated"))
            {
                Switch item = hit.transform.gameObject.GetComponent <Switch>();
                if (item.switchType == Switch.SwitchType.ActivatedByLaser)
                {
                    item.Activate();
                }
            }
            else
            {
                //End beam at hit object
                endPosition = hit.point;

                lineRenderer.positionCount = 2;
                lineRenderer.SetPosition(0, lineOrigin);
                lineRenderer.SetPosition(1, endPosition);
            }
        }
        else
        {
            //End beam at max laser distance
            endPosition = rayDirection * laserMaxLength;

            lineRenderer.positionCount = 2;
            lineRenderer.SetPosition(0, lineOrigin);
            lineRenderer.SetPosition(1, endPosition);
        }
    }
예제 #3
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     //Debug.Log("Object Detected from Hitbox");
     //if it's an enemy
     if (collision.gameObject.layer == 11)
     {
         if (collision.CompareTag("Enemy"))
         {
             EnemyStats enemy = collision.gameObject.GetComponentInParent <EnemyStats>();
             if (enemy != null)
             {
                 Vector3 tempKnockback = m_rigidbody.velocity.normalized * knockbackSpeed;
                 if (Mathf.Abs(tempKnockback.y) < minYKnockback)
                 {
                     tempKnockback.y = knockbackSpeed.y * 0.5f;
                 }
                 enemy.LogDamage(damage, tempKnockback);
             }
             Kill();
         }
         //Debug.Log("Enemy Hit: " + collision.gameObject.name);
     }
     //if we hit a door
     else if (collision.gameObject.layer == 12)
     {
         Door door = collision.gameObject.GetComponentInParent <Door>();
         if (door != null)
         {
             if (door.isClosed)
             {
                 door.Open(true);
             }
             else
             {
                 //don't kill fireball if we hit an open door
                 return;
             }
         }
         Kill();
     }
     //if we hit a switch
     else if (collision.gameObject.layer == 14)
     {
         Switch theSwitch = collision.gameObject.GetComponent <Switch>();
         if (theSwitch != null)
         {
             theSwitch.Activate();
         }
     }
     else
     {
         Kill();
     }
 }
예제 #4
0
        private void CreateSwitch()
        {
            Switch f;

            f = SwitchList.Find(x => x._CurrentState == Sprite.SpriteState.kStateInActive);
            //Vector2 newPos = new Vector2(ran.Next(20, 780), ran.Next(20, 460));
            Vector2 newPos = InputHelper.MouseScreenPos;

            if (f != null)
            {
                f.Activate(newPos);
            }
            else
            {
                f = new Switch();
                f.LoadContent(@"Art/Switch", Content);
                f.Activate(newPos);
                SwitchList.Add(f);
            }
        }
예제 #5
0
    void UseObject()
    {
        RaycastHit hit;
        Vector3    rayOrigin    = rayOriginObject.transform.position;
        Vector3    rayDirection = rayOriginObject.transform.forward;

        float playerReach = 2.0f;

        if (Physics.Raycast(rayOrigin, rayDirection, out hit, playerReach))
        {
            //Debug.DrawRay(rayOrigin, rayDirection * playerReach, Color.green, 100.0f);
            if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Switch"))
            {
                Switch item = hit.transform.gameObject.GetComponent <Switch>();
                if (item.switchType == Switch.SwitchType.ActivatedByKeyPress)
                {
                    item.Activate();
                }
            }
        }
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        // Only do this if player is alive
        if (is_alive)
        {
            // Get inputs
            if (Input.GetButtonDown("Jump") && on_ground)
            {
                // Set upward velocity to jump power
                Vector2 velocity = rigid_body.velocity;
                velocity.y          = jump_power;
                rigid_body.velocity = velocity;
                // play jump sound
                audio_source.Play();

                on_ground = false; // no longer on ground after jumping duh
            }
            else if (Input.GetAxis("Horizontal") > 0)
            {
                sprite_renderer.flipX = false;
                walking_direction     = 1;

                // Update animation timer
                if (on_ground)
                {
                    animation_time += Time.deltaTime;
                }
            }
            else if (Input.GetAxis("Horizontal") < 0)
            {
                sprite_renderer.flipX = true;
                walking_direction     = -1;

                // Update animation timer
                if (on_ground)
                {
                    animation_time += Time.deltaTime;
                }
            }
            else
            {
                walking_direction      = 0;
                animation_time         = 0;
                sprite_renderer.sprite = idle_sprite;
            }

            // Check if its time to change animation sprite
            if (animation_time >= animation_speed)
            {
                animation_time = 0;
                ChangeSprite();
            }

            // Change hand position
            if (!pushing_box)
            {
                if (on_ground)
                {
                    switch (walking_direction)
                    {
                    case -1:     // running left
                        front_hand.localPosition = new Vector3(-hand_positions[1].x, hand_positions[1].y, 0);
                        back_hand.localPosition  = new Vector3(-hand_positions[2].x, hand_positions[2].y, 0);
                        break;

                    case 1:     // running right
                        front_hand.localPosition = new Vector3(hand_positions[1].x, hand_positions[1].y, 0);
                        back_hand.localPosition  = new Vector3(hand_positions[2].x, hand_positions[2].y, 0);
                        break;

                    case 0:     // idle
                    default:
                        front_hand.localPosition = new Vector3(hand_positions[0].x, hand_positions[0].y, 0);
                        back_hand.localPosition  = new Vector3(hand_positions[0].x, hand_positions[0].y, 0);
                        break;
                    }
                }
                else if (is_falling)
                {
                    switch (walking_direction)
                    {
                    case -1:     // left input
                        front_hand.localPosition = new Vector3(-hand_positions[3].x, hand_positions[3].y, 0);
                        back_hand.localPosition  = new Vector3(-hand_positions[4].x, hand_positions[4].y, 0);
                        break;

                    case 1:     // right input
                        front_hand.localPosition = new Vector3(hand_positions[3].x, hand_positions[3].y, 0);
                        back_hand.localPosition  = new Vector3(hand_positions[4].x, hand_positions[4].y, 0);
                        break;

                    case 0:     // no input
                    default:
                        front_hand.localPosition = new Vector3(hand_positions[3].x, hand_positions[3].y, 0);
                        back_hand.localPosition  = new Vector3(hand_positions[4].x, hand_positions[4].y, 0);
                        break;
                    }
                }
            }

            // pressing a switch
            if (can_push_switch)
            {
                if (Input.GetButtonDown("Activate"))
                {
                    push_switch.Activate();
                }
            }
        }
    }
 public bool Activate()
 {
     return(switchComponent.Activate());
 }
예제 #8
0
    List <Vector3> FireLaserRecursive(Vector3 rayOrigin, Vector3 rayDirection, int recursions, List <Vector3> linePoints)
    {
        //Shoot beam, check if hit object or not
        //If hit reflective object, find reflection vector
        //Shoot new raycast along reflection vector
        //Count recursion
        //Recursive call

        RaycastHit hit;
        Vector3    endPosition;
        Vector3    lineOrigin = lineOriginObject.transform.position;


        //Use lineOrigin to draw the line but rayOrigin to calculate the raycast
        linePoints.Add(lineOrigin);
        linePoints.RemoveRange(recursions + 1, linePoints.Count - recursions - 1);


        //Shoot beam, check if hit object or not
        if (Physics.Raycast(rayOrigin, rayDirection, out hit))
        {
            linePoints.Add(hit.point);

            //Check if the hit object is on the Reflective layer
            if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Reflective"))
            {
                //Find reflection vector
                Vector3 reflectDirection = Vector3.Reflect(rayDirection, hit.normal);
                recursions++;


                //For now just a simple break if an infinite loop of reflections occurs
                if (recursions > 20)
                {
                    return(new List <Vector3>());
                }

                Vector3 reflectPoint = reflectDirection * laserMaxLength;
                linePoints.Add(reflectPoint);


                linePoints = FireLaserRecursive(hit.point, reflectDirection, recursions, linePoints);
                return(linePoints);
            }
            else if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Switch"))
            {
                Switch item = hit.transform.gameObject.GetComponent <Switch>();
                if (item.switchType == Switch.SwitchType.ActivatedByLaser)
                {
                    item.Activate();
                }
                return(linePoints);
            }
            else
            {
                return(linePoints);
            }
        }
        else
        {
            //End beam at max laser distance
            endPosition = rayDirection * laserMaxLength;

            linePoints.Add(endPosition);
            return(linePoints);
        }
    }
예제 #9
0
 private static void HandleSwitch(Switch s)
 {
     s.Activate();
 }
예제 #10
0
 private void ActivateSwitch()
 {
     scoreScript.DecrementCellCount();
     switchBoard.Activate();
 }