Exemplo n.º 1
0
    // I realize the "weaknesses" and "strengths" terminology is a little backwards here
    // but being hit by a "weakness" has an advantageous effect (usually) and being hit
    // by a "strength" has a disadvantageous effect (usually)

    public override void Interact(int potionFlags)
    {
        foreach (Elements element in weaknesses)
        {
            if (PersistentInteraction.Recognized(potionFlags, element))
            {
                SpriteRenderer sprite = transform.Find("Light").GetComponent <SpriteRenderer>();
                if (!sprite.enabled)
                {
                    sprite.enabled = true;
                    OnLight();
                }
            }
        }
        foreach (Elements element in strengths)
        {
            if (PersistentInteraction.Recognized(potionFlags, element))
            {
                SpriteRenderer sprite = transform.Find("Light").GetComponent <SpriteRenderer>();
                if (sprite.enabled)
                {
                    sprite.enabled = false;
                    OnFizzle();
                }
            }
        }
    }
Exemplo n.º 2
0
 public virtual void Interact(int potionFlags)
 {
     foreach (Elements element in weaknesses)
     {
         if (PersistentInteraction.Recognized(potionFlags, element))
         {
             Damage(1);
         }
     }
 }
Exemplo n.º 3
0
    protected virtual void OnCollisionStay2D(Collision2D other)
    {
        HomebrewFlags flagData = other.gameObject.GetComponent <HomebrewFlags>();

        if (flagData != null)
        {
            foreach (Elements element in weaknesses)
            {
                if (PersistentInteraction.Recognized(flagData.Flags, element))
                {
                    OnStay(flagData.Flags);
                }
            }
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        //This makes the enemy move
        if (Vector2.Distance(transform.position, player.position) < nearDistance)
        {
            transform.position = Vector2.MoveTowards(transform.position, player.position, -speed * Time.deltaTime);
        }
        else if (Vector2.Distance(transform.position, player.position) > stoppingDistance)
        {
            transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
        }
        else if (Vector2.Distance(transform.position, player.position) < stoppingDistance && Vector2.Distance(transform.position, player.position) > nearDistance)
        {
            transform.position = transform.position;
        }

        // This makes the enemy shoot
        if (timeBetweenShots <= 0)
        {
            GameObject fired = Instantiate(shot, transform.position, Quaternion.identity);
            fired.transform.position = transform.position;
            fired.GetComponent <Rigidbody2D>().isKinematic = false;
            //fired.GetComponent<Rigidbody2D>().velocity = pvelocity * bottleSpeed;

            if (player.transform.position.x > transform.position.x)
            {
                fired.GetComponent <Rigidbody2D>().velocity = new Vector2(1f, 0f) * bottleSpeed;
            }
            else
            {
                fired.GetComponent <Rigidbody2D>().velocity = new Vector2(-1f, 0f) * bottleSpeed;
            }

            // I don't like this
            PersistentInteraction.ApplyToBottle(fired, Elements.FIRE, Elements.FIRE, gameObject);

            timeBetweenShots = startTimeBetweenShots;
        }
        else
        {
            timeBetweenShots -= Time.deltaTime;
        }
    }
Exemplo n.º 5
0
    public void OnDestroy()
    {
        allBottles.Remove(this);
        Instantiate(HomebrewGame.Me.prefabDeadBottle).transform.position = transform.position;
        GameAudio.Me.PlaySmash();

        if (Flags == PersistentInteraction.Combination(Elements.WATER, Elements.EARTH))
        {
            HazardMud.SpawnBlob(gameObject);
        }
        if (Flags == PersistentInteraction.Combination(Elements.FIRE, Elements.EARTH))
        {
            HazardMagma.SpawnBlob(gameObject);
        }
        if (Flags == PersistentInteraction.Combination(Elements.FIRE, Elements.WATER))
        {
            HazardSteam.SpawnBlob(gameObject);
        }
    }
Exemplo n.º 6
0
    // This used to be FixedUpdate but it was causing inputs to be skipped whenever the FixedUpdate was
    // fired at a different time than regular Update because screw you too Unity
    protected override void Update()
    {
        base.Update();

        // because bad things would probably happen if you were allowed to move in the pause menu,
        // where Time.timeScale = 0
        if (HomebrewGame.Me.menu.IsPaused)
        {
            return;
        }
        // invincibility

        if (IFrames > 0f)
        {
            IFrames = Mathf.Max(IFrames - Time.deltaTime, 0f);

            Renderer body = GetComponent <Renderer>();

            if (IFrames > 0f)
            {
                IFrameTime = Mathf.Max(IFrameTime - Time.deltaTime);
                if (IFrameTime <= 0f)
                {
                    body.enabled = (IFrames > 0f ? !body.enabled : true);
                    IFrameTime   = 1 / IFRAME_HZ;
                }
            }
            else
            {
                body.enabled = true;
            }
        }

        float horizontal = Input.GetAxis("Horizontal");

        /*
         * Running
         */

        if (Mathf.Abs(horizontal) > MOVE_THRESHOLD)
        {
            if (Input.GetButtonDown("Run"))
            {
                if (timeToDash > 0f)
                {
                    autodashing = true;
                }
                else
                {
                    timeToDash = DASH_THRESHOLD;
                }
            }

            if (Input.GetButton("Run"))
            {
                dashing    = true;
                timeToDash = DASH_THRESHOLD;
            }
            else
            {
                dashing = false;
            }
        }

        timeToDash = Mathf.Max(0f, timeToDash - Time.deltaTime);

        /*
         * Move around
         */

        if (Mathf.Abs(horizontal) < MOVE_THRESHOLD)
        {
            dashing     = false;
            autodashing = false;
        }

        if (Mathf.Abs(horizontal) > 0.25f)
        {
            Vector3 scale = transform.localScale;
            scale.x = Mathf.Abs(scale.x) * Mathf.Sign(horizontal);
            transform.localScale = scale;
        }

        float f = speedFactor;

        if (dashing || autodashing)
        {
            f = DASH_MULTIPLIER;
        }

        Rigidbody2D plugandplay = GetComponent <Rigidbody2D>();

        if (GameSettings.MovementStyle == MovementStyles.SMOOTH)
        {
            // SMOOTH MOVEMENT
            plugandplay.AddForce(new Vector2(horizontal * f, 0f), ForceMode2D.Impulse);
        }
        else
        {
            // SNAPPY MOVEMENT
            Vector2 currentVelocity = GetComponent <Rigidbody2D>().velocity;
            GetComponent <Rigidbody2D>().velocity = new Vector2(Mathf.Round(horizontal) * f * maxSpeed, currentVelocity.y);
        }

        Vector2 velocity = plugandplay.velocity;

        velocity.x = Mathf.Clamp(velocity.x, -maxSpeed * f, maxSpeed * f);

        bool grounded = Physics2D.OverlapPoint(new Vector2(transform.position.x, transform.position.y - 0.75f), HomebrewFlags.EnvironmentalCollisionMask());

        if (grounded)
        {
            if (Input.GetButtonDown("Jump"))
            {
                timeSinceJump = 0f;
            }

            velocity.x = Mathf.Lerp(velocity.x, 0f, friction);
        }

        timeSinceJump = timeSinceJump + Time.deltaTime;

        plugandplay.velocity = velocity;

        // after the velocity has been set, process jumping. this re-reads and resets the velocity so if
        // you do it before it's set above it'll get overwritten.

        if (GameSettings.MovementStyle == MovementStyles.SMOOTH)
        {
            // SMOOTH MOVEMENT
            if (timeSinceJump < 0.15f && Input.GetButton("Jump"))
            {
                plugandplay.gravityScale = 0f;
                Jump();
            }
            else
            {
                plugandplay.gravityScale = 1f;
            }
        }
        else
        {
            // SNAPPY MOVEMENT
            plugandplay.gravityScale = 1f;
            if (grounded && Input.GetButtonDown("Jump"))
            {
                // this magic number would produce *about-ish* the same jump height as holding your finger
                // down on the button in Smooth mode
                Jump(10f);
                // fact: mathematics tells me the value should be more like 7.3f but that value isn't working
                // and i don't want to touch it now
            }
        }

        /*
         * Throw, but only if the overlay(s) aren't shown
         */

        if (!selectorOverlay.activeInHierarchy)
        {
            Vector3 mousePos2D = Input.mousePosition;
            mousePos2D.z = -Camera.main.transform.position.z;
            Vector3 mousePos3d = Camera.main.ScreenToWorldPoint(mousePos2D);
            Vector3 mouseDelta = mousePos3d - transform.position;

            if (aimingMode && Input.GetButtonUp("Potion Chuck"))
            {
                aimingMode = false;

                Vector3 pvelocity = mouseDelta;
                pvelocity.Normalize();

                GameObject bottleClone = Instantiate(bottle);

                bottleClone.transform.position = transform.position;
                bottleClone.GetComponent <Rigidbody2D>().isKinematic = false;
                bottleClone.GetComponent <Rigidbody2D>().velocity    = pvelocity * bottlespeed;

                bottleClone.transform.position = reticle.transform.position;

                PersistentInteraction.ApplyToBottle(bottleClone, elements[0], elements[1], gameObject);

                reticle.SetActive(false);

                GameAudio.Me.PlayBottle();
            }

            if (Input.GetButtonDown("Potion Chuck"))
            {
                //the player has pressed the mouse button down while over the slingshot
                aimingMode = true;

                reticle.SetActive(true);
            }

            if (aimingMode)
            {
                //limit mouse delta to the radius of the slingshot spherecollider
                float maxmagnitude = launchRadius;

                Vector3 absMouseDelta = mouseDelta;
                absMouseDelta.Normalize();
                absMouseDelta = absMouseDelta * maxmagnitude;

                if (mouseDelta.magnitude > maxmagnitude)
                {
                    mouseDelta.Normalize();
                    mouseDelta *= maxmagnitude;
                }

                reticle.transform.position = transform.position + absMouseDelta;
            }

            GetComponent <Animator>().SetFloat("Speed", Mathf.Abs(horizontal));
        }


        /*
         * Cycle selected element
         */

        if (Input.GetButtonDown("Cycle"))
        {
            activeElement = (++activeElement) % elements.Length;
            SetElementText();
        }

        /*
         * Potions menu: bottom left: (0, 0); top right: (W, H)
         */

        Vector2 position = new Vector2((Input.mousePosition.x / Screen.width) - 0.5f, (Input.mousePosition.y / Screen.height) - 0.5f);

        if (selectorOverlay.activeInHierarchy)
        {
            foreach (GameObject what in quadrants)
            {
                what.SetActive(false);
            }

            if (position.magnitude > 0.1f)
            {
                quadrants[Quadrant(position)].SetActive(true);
            }

            if (Input.GetButtonDown("Select"))
            {
                selectorOverlay.SetActive(false);
                Time.timeScale = 1f;

                if (position.magnitude > 0.1f)
                {
                    elements[activeElement] = (Elements)elementMap[Quadrant(position)];
                    SetElementText();
                }
            }
        }
        else
        {
            if (Input.GetButtonDown("Potion Menu"))
            {
                for (int i = 0; i < 4; i++)
                {
                    Text text = quadrantText[i];
                    text.text = ownedElements[elementMap[i]] ? PersistentInteraction.Me.elementNames[elementMap[i]] : "None";
                }

                selectorOverlay.SetActive(true);
                Time.timeScale = SELECTOR_TIME_SCALE;
            }
        }
    }