// Update is called once per frame
    void Update()
    {
        timeToNextBoulder -= Time.deltaTime;
        if (timeToNextBoulder <= 0)
        {
            GameObject  boulder   = Instantiate(Boulder, new Vector3(-6, 3.5f, 0), new Quaternion()) as GameObject;
            Rigidbody2D rigidbody = boulder.GetComponent <Rigidbody2D>();
            //			Rigidbody2D rigidbody = boulder.rigidbody2D;
            boulderScript                    = (BoulderScript)boulder.GetComponent("BoulderScript");
            boulderScript.goingDown          = true;
            boulderScript.goingRight         = true;
            boulderScript.potentialYVelocity = 2f;
            timeToNextBoulder                = Random.Range(30, 30);


            GameObject  boulder2   = Instantiate(Boulder, new Vector3(-6, 2.0f, 0), new Quaternion()) as GameObject;
            Rigidbody2D rigidbody2 = boulder2.GetComponent <Rigidbody2D>();
            //			Rigidbody2D rigidbody = boulder.rigidbody2D;
            boulderScript2                    = (BoulderScript)boulder2.GetComponent("BoulderScript");
            boulderScript2.goingDown          = true;
            boulderScript2.goingRight         = true;
            boulderScript2.potentialYVelocity = 2f;

            GameObject  boulder3   = Instantiate(Boulder, new Vector3(-6, -3.6f, 0), new Quaternion()) as GameObject;
            Rigidbody2D rigidbody3 = boulder3.GetComponent <Rigidbody2D>();
            //			Rigidbody2D rigidbody = boulder.rigidbody2D;
            boulderScript3                    = (BoulderScript)boulder3.GetComponent("BoulderScript");
            boulderScript3.goingDown          = true;
            boulderScript3.goingRight         = true;
            boulderScript3.potentialYVelocity = 2f;
        }
    }
示例#2
0
    void ProcessInput()
    {
        // jump flag flip irrespective of fixed update time
        if (Input.GetButtonDown(playerButton("Jump")) == true && (grounded == true || doubleJump == false))
        {
            if (grounded == false && doubleJump == false)
            {
                doubleJump = true;

                // reset y velocity so second jump is as powerful as first one
                GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, 0.0f);
            }

            float jump = jumpForce;
            if (heldBoulder != null)
            {
                BoulderScript heldBoulderScript = heldBoulder.GetComponentInParent <BoulderScript>();
                float         percentBonus      = heldBoulderScript.JumpBonus() / 100.0f;
                if (percentBonus > 0.0f)
                {
                    jump += jump * percentBonus;
                }
            }

            GetComponent <Rigidbody2D>().AddForce(new Vector2(0.0f, jump));
            PlayJumpSound();
        }

        if (Input.GetButtonUp(playerButton("Action")) == true)
        {
            chargeBar.StopCharging();
        }

        if (Input.GetButtonDown(playerButton("Action")) == true && (potentialBoulder != null || heldBoulder != null))
        {
            chargeBar.Charge();
        }

        float currentDashInterval = dashInterval;

        if (heldBoulder != null)
        {
            BoulderScript heldBoulderScript = heldBoulder.GetComponentInParent <BoulderScript>();
            float         percentBonus      = heldBoulderScript.DashBonus() / 100.0f;
            if (percentBonus > 0.0f)
            {
                currentDashInterval -= currentDashInterval * percentBonus;
            }
        }

        if (Input.GetButtonDown(playerButton("Dash")) == true && dashing == false && timeSinceLastDash >= currentDashInterval)
        {
            dashing = true;
            PlayDashSound();
        }
    }
示例#3
0
    void CheckForBoulderDamage(GameObject boulderObject)
    {
        if (detectedCollisionBoulder == null)
        {
            BoulderObject body          = boulderObject.GetComponent <BoulderObject>();
            GameObject    visuals       = body.visuals;
            BoulderScript boulderScript = boulderObject.GetComponentInParent <BoulderScript>();

            Rigidbody2D rigidBody        = visuals.GetComponent <Rigidbody2D>();
            float       boulderMagnitude = rigidBody.velocity.sqrMagnitude;
            if (boulderMagnitude > 9.0f)
            {
                detectedCollisionBoulder = boulderObject;
                //print("Boulder velocity squared magnitude " + boulderMagnitude);

                // check held boulder shield
                float healthReduction = boulderScript.baseDamage + boulderScript.DamageBonus();
                if (heldBoulder != null)
                {
                    BoulderScript heldBoulderScript = heldBoulder.GetComponentInParent <BoulderScript>();
                    float         percentReduction  = heldBoulderScript.ShieldBonus() / 100.0f;
                    if (percentReduction > 0.0f)
                    {
                        healthReduction -= healthReduction * percentReduction;
                    }
                }

                // take damage
                health          -= healthReduction;
                healthBar.charge = health;

                PlayHitSound();

                // Death
                if (health <= 0.0f)
                {
                    ShowEndGameText();

                    // hide UI bars
                    healthBar.gameObject.SetActive(false);
                    chargeBar.gameObject.SetActive(false);

                    // dying
                    this.gameObject.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                    //this.gameObject.SetActive(false);
                }
            }
        }
    }
示例#4
0
    void PerformMovement(Direction direction)
    {
        // add movement
        int directionMultiplier = 0;

        if (direction == Direction.DirectionLeft)
        {
            directionMultiplier = -1;
        }
        else if (direction == Direction.DirectionRight)
        {
            directionMultiplier = 1;
        }

        if (hitWall == false)
        {
            if (directionMultiplier != 0)
            {
                animator.SetInteger("PlayerAnimationState", (int)AnimationState.AnimationStateToWalk);
            }
            else
            {
                animator.SetInteger("PlayerAnimationState", (int)AnimationState.AnimationStateToIdle);
            }

            // block movement while picking up a boulder
            if (potentialBoulder != null && heldBoulder == null && chargeBar.isCharging == true)
            {
                GetComponent <Rigidbody2D>().velocity = new Vector2(0.0f, 0.0f);
                return;
            }

            float speed = maxSpeed;
            if (heldBoulder != null)
            {
                BoulderScript heldBoulderScript = heldBoulder.GetComponentInParent <BoulderScript>();
                float         percentBonus      = heldBoulderScript.SpeedBonus() / 100.0f;
                if (percentBonus > 0.0f)
                {
                    speed += speed * percentBonus;
                }
            }

            GetComponent <Rigidbody2D>().velocity = new Vector2(directionMultiplier * speed, GetComponent <Rigidbody2D>().velocity.y);

            // dashing
            if (dashing == true)
            {
                if (currentDashDuration > 0.0f)
                {
                    currentDashDuration -= Time.deltaTime;

                    int dir = 1;
                    if (facingRight == false)
                    {
                        dir = -1;
                    }

                    GetComponent <Rigidbody2D>().AddForce(new Vector2(dir * dashForce, 0.0f));
                }
                else
                {
                    timeSinceLastDash   = 0.0f;
                    dashing             = false;
                    currentDashDuration = dashDuration;
                }
            }

            // play step sound
            if (directionMultiplier != 0 && grounded == true && HasEnoughTimePassedSinceLastStep() == true)
            {
                PlayWalkingSound();
            }
        }

        // update held boulder position
        if (heldBoulder != null)
        {
            BoulderObject obj = heldBoulder.GetComponent <BoulderObject>();

            Vector3 boulderPosition = this.transform.position;
            boulderPosition.y += 1.0f;
            obj.visuals.transform.position = boulderPosition;
        }

        // update UI bar positions
        // anochor to parent game object
        healthBar.UpdateWithParentPosition(this.transform.position);
        chargeBar.UpdateWithParentPosition(this.transform.position);
    }
示例#5
0
    public WorldData(ControllerScript controller)
    {
        time = controller.time;
        ambientTemperature = controller.ambientTemperature;
        playerTemperature  = controller.playerTemperature;
        currentSeason      = controller.currentSeason;
        currentDay         = controller.currentDay;
        currentDayInSeason = controller.currentDayInSeason;
        health             = controller.playerInventoryScript.GetComponent <PlayerScript> ().health;
        hunger             = controller.playerInventoryScript.GetComponent <PlayerScript> ().hunger;
        happiness          = controller.playerInventoryScript.GetComponent <PlayerScript> ().happiness;

        droppedItems   = new SaveSystem.MyDroppedItem[controller.GetComponent <SaveSystemScript>().items.Length];
        terrains       = new SaveSystem.MyTerrain[controller.GetComponent <SaveSystemScript> ().terrains.Length];
        buildings      = new SaveSystem.Buildings.BasicBuildingSaveProperties[controller.GetComponent <SaveSystemScript>().buildings.Length];
        mobs           = new SaveSystem.Mobs.BasicMobAttributes[controller.GetComponent <SaveSystemScript>().mobs.Length];
        playerPosition = new MyVector3(controller.playerInventoryScript.transform.position);

        playerInventory = new SerializedInventoryItem[controller.playerInventoryScript.playerInventory.Length];
        for (int i = 0; i < playerInventory.Length; i++)
        {
            playerInventory [i] = controller.playerInventoryScript.playerInventory [i].convertToSave();
        }
        for (int i = 0; i < droppedItems.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().items [i] != null)
            {
                droppedItems [i] = new SaveSystem.MyDroppedItem(controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.name, controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.quantity, new MyVector3(controller.GetComponent <SaveSystemScript> ().items [i].transform.position));
            }
        }

        for (int i = 0; i < terrains.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().terrains [i] != null)
            {
                GameObject terrain = controller.GetComponent <SaveSystemScript> ().terrains [i];
                terrains [i] = new SaveSystem.MyTerrain(terrain.GetComponent <TerrainScript> ().terrainName, terrain.transform.position);
            }
        }
        for (int i = 0; i < mobs.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().mobs [i] != null)
            {
                GameObject mob = controller.GetComponent <SaveSystemScript> ().mobs [i];
                if (mob.GetComponent <PassiveFourLegs> () != null)
                {
                    mobs [i] = new SaveSystem.Mobs.BasicMobAttributes(mob.GetComponent <PassiveFourLegs>().mobName, mob.GetComponent <PassiveFourLegs> ().health, mob.GetComponent <PassiveFourLegs> ().maxHealth, mob.transform.position, mob.transform.eulerAngles);
                }
                else if (mob.GetComponent <Sheep> () != null)
                {
                    mobs [i] = new SaveSystem.Mobs.Sheep(mob.GetComponent <Sheep>().mobName, mob.GetComponent <Sheep> ().health, mob.GetComponent <Sheep> ().maxHealth, mob.transform.position, mob.transform.eulerAngles);
                }
            }
        }
        for (int i = 0; i < buildings.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().buildings [i] != null)
            {
                GameObject building = controller.GetComponent <SaveSystemScript> ().buildings [i];

                TreeScript       treeScript        = null;
                BoulderScript    boulderScript     = null;
                GrassScript      grassScript       = null;
                BushScript       bushScript        = null;
                BerryBushScript  berryBushScript   = null;
                FireScript       fireScript        = null;
                GroundFoodScript naturalFoodScript = null;

                if (building.GetComponent <TreeScript> () != null)
                {
                    treeScript = building.GetComponent <TreeScript> ();
                }
                if (building.GetComponent <BoulderScript> () != null)
                {
                    boulderScript = building.GetComponent <BoulderScript> ();
                }
                if (building.GetComponent <GrassScript> () != null)
                {
                    grassScript = building.GetComponent <GrassScript> ();
                }
                if (building.GetComponent <BushScript> () != null)
                {
                    bushScript = building.GetComponent <BushScript> ();
                }
                if (building.GetComponent <BerryBushScript> () != null)
                {
                    berryBushScript = building.GetComponent <BerryBushScript> ();
                }
                if (building.GetComponent <FireScript> () != null)
                {
                    fireScript = building.GetComponent <FireScript> ();
                }
                if (building.GetComponent <GroundFoodScript> () != null)
                {
                    naturalFoodScript = building.GetComponent <GroundFoodScript> ();
                }

                if (treeScript != null || boulderScript != null)
                {
                    //natural barriers
                    if (treeScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalBarriers("tree", treeScript.transform.position, treeScript.transform.eulerAngles, treeScript.health);
                    }
                    else if (boulderScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalBarriers("boulder", boulderScript.transform.position, boulderScript.transform.eulerAngles, boulderScript.health);
                    }
                }
                else if (grassScript != null || bushScript != null || berryBushScript != null)
                {
                    if (grassScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalCrops("grassPatch", grassScript.transform.position, grassScript.transform.eulerAngles, grassScript.cut, grassScript.growTimer);
                    }
                    if (bushScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalCrops("bush", bushScript.transform.position, bushScript.transform.eulerAngles, bushScript.cut, bushScript.growTimer);
                    }
                    else if (berryBushScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalCrops("berryBush", berryBushScript.transform.position, berryBushScript.transform.eulerAngles, berryBushScript.cut, berryBushScript.growTimer);
                    }
                }
                else if (fireScript != null)
                {
                    buildings [i] = new SaveSystem.Buildings.Campfire("campfire", fireScript.transform.position, fireScript.transform.eulerAngles, fireScript.fuel);
                }
                else if (naturalFoodScript != null)
                {
                    buildings [i] = new SaveSystem.Buildings.BasicBuildingSaveProperties(naturalFoodScript.buildingIDName, naturalFoodScript.transform.position, naturalFoodScript.transform.eulerAngles);
                }
            }
        }
    }