예제 #1
0
    void Update()
    {
        if (gc.GetIsGameplay() && needsEnable && !isDefeated && !gc.GetIsPaused())
        {
            Debug.Log("Waking rigidbody");
            rb.velocity    = new Vector2(0, 0);
            currentTimer   = 0.0f;
            rb.constraints = RigidbodyConstraints2D.None;
            anim.SetBool("isGameplay", true);
            needsEnable = false;
        }
        else if (gc.GetIsBuilding() && !needsEnable || gc.GetIsPaused() && !needsEnable || isDefeated)
        {
            Debug.Log("Sleeping rigidbody");
            rb.constraints = RigidbodyConstraints2D.FreezePosition;
            needsEnable    = true;
            anim.SetBool("isGameplay", false);

            rb.velocity             = new Vector2(0, 0);
            isDefeated              = false;
            currentTimer            = 0.0f;
            this.transform.position = thisObject.GetDefaultPosition();
            this.transform.rotation = Quaternion.Euler(0, 0, 0);
        }
        if (gc.GetIsGameplay() && !gc.GetIsPaused() && !isDefeated)
        {
            if (currentTimer <= 0.0f)
            {
                currentTimer = maxTimer;
            }
            if (currentTimer > 0.0f)
            {
                currentTimer -= Time.deltaTime;
                if (currentTimer <= 0.0f)
                {
                    Debug.Log("Flipping");
                    Flip();
                }
            }
            transform.Translate(Vector2.right * speed * Time.deltaTime);
        }
    }
예제 #2
0
파일: AIShoot.cs 프로젝트: therandommer/FYP
 void Update()
 {
     if (gc.GetIsGameplay() && !gc.GetIsPaused() && currentTimer <= 0.0f)
     {
         currentTimer = interval;
         Shoot();
     }
     if (currentTimer > 0.0f)
     {
         currentTimer -= Time.deltaTime;
     }
     if (gc.GetIsBuilding())
     {
         currentTimer = 0.0f;
     }
 }
예제 #3
0
 void Update()
 {
     if (gc.GetIsGameplay())         //gameplay specific in here
     {
         if (!needReset)             //allows for a reset when the player goes to gameplay
         {
             needReset = true;
         }
         if (build.GetPlayerSpawned() && needPlayer)             //initialises the player this loop
         {
             Debug.Log("Initialising player(Platforming)");
             player     = FindObjectOfType <Player>();
             needPlayer = false;
         }
         if (!hasInitialised)             //initalises values for this script on play
         {
             player         = null;
             timeLeft       = build.GetTime();
             timeText.text  = "Time: " + timeLeft;
             coinText.text  = "Coins: " + coins;
             scoreText.text = "Score: " + score;
             hasInitialised = true;
         }
         if (player == null)
         {
             player = FindObjectOfType <Player>();
         }
         if (!gc.GetIsPaused())
         {
             timeLeft -= Time.deltaTime;
         }
         roundedTime = Mathf.FloorToInt(timeLeft);
         if (player != null)
         {
             UpdateUI();
         }
         if (timeLeft <= 0.0f)            //boot to build if failed clear in time
         {
             gc.SetIsBuilding(true);
         }
     }
     if (gc.GetIsBuilding() && needReset)         //resets, etc. here when entering building
     {
         ResetPlatformStats();
     }
 }
예제 #4
0
 private void FixedUpdate()
 {
     #region movement and grounding
     //ground check
     isGrounded = false;
     Collider2D[] colliders = Physics2D.OverlapCircleAll(groundCheck.position, groundRadius, whatIsGround);
     for (int i = 0; i < colliders.Length; ++i)         //if the groundcheck circle collides with the correct layer, sets grounded to true
     {
         if (colliders[i].gameObject != gameObject)
         {
             isGrounded = true;
             anim.SetBool("isGrounded", true);
         }
         else
         {
             anim.SetBool("isGrounded", false);                 //help prevent animation short loops
         }
     }
     ///modifying movement vector based on input
     if (!gc.GetIsPaused())
     {
         //horizontal movement
         float moveHorizontal = Input.GetAxis("Horizontal") * moveScalar;
         //vertical movement
         if (Input.GetAxis("Jump") != 0 || Input.GetAxis("Vertical") != 0)
         {
             //regular jumps
             if (isNormalJump && isGrounded)
             {
                 moveVertical = Input.GetAxis("Jump") * jumpForce;
                 isGrounded   = false;
                 anim.SetBool("isGrounded", false);
             }
             if (isNormalJump && Input.GetAxis("Vertical") > 0 && isGrounded)
             {
                 moveVertical = Input.GetAxis("Vertical") * jumpForce;
                 isGrounded   = false;
                 anim.SetBool("isGrounded", false);
             }
         }
         movementVector = new Vector2(moveHorizontal, moveVertical);
         //flipping sprite to look like it's moving the correct direction
         if (movementVector.x > 0 && !isFacingRight)
         {
             Flip();
         }
         else if (movementVector.x < 0 && isFacingRight)
         {
             Flip();
         }
         if (movementVector.x > 10.0f)
         {
             movementVector.x = 10.0f;
         }
         if (movementVector.x != 0)
         {
             anim.SetBool("isWalking", true);
         }
         else
         {
             anim.SetBool("isWalking", false);
         }
         rb.AddForce(movementVector);
         moveVertical = 0.0f;
         thisVelocity = rb.velocity;
         //clamping velocities to limit max speeds
         if (thisVelocity.x > maxXVelocity)
         {
             thisVelocity.x = maxXVelocity;
         }
         if (thisVelocity.x < minXVelocity)
         {
             thisVelocity.x = minXVelocity;
         }
         if (thisVelocity.y > maxYVelocity)
         {
             thisVelocity.y = maxYVelocity;
         }
         if (thisVelocity.y < minYVelocity)
         {
             thisVelocity.y = minYVelocity;
         }
         rb.velocity = thisVelocity;
         #endregion
     }
 }
예제 #5
0
파일: Pointer.cs 프로젝트: therandommer/FYP
    void Update()
    {
        if (!gc.GetIsBuilding() || gc.GetIsPaused() && heldID != 16)         //sets the cursor to a null object while in gameplay or paused
        {
            SetHeldID(16);
            box.enabled = false;
        }
        if (gc.GetIsBuilding() && !gc.GetIsPaused() && heldID == 16)
        {
            SetHeldID(0);
            box.enabled = true;
        }
        if (heldID == 6)         //base colour needed for green water
        {
            baseColour = new Color(0, 255, 0);
        }
        else if (heldID != 6)         //every other object has white base colour
        {
            baseColour = Color.white;
        }
        if (heldID != 19)                                                    //only certain objects are scaled by 3x
        {
            if (heldID == 13 || heldID == 9 || heldID == 10 || heldID == 18) //player,etc. scaling
            {
                transform.localScale = new Vector3(3, 3, 3);
                box.size             = boxSize;
            }
            else if (heldID != 13 && heldID != 9 && heldID != 10 && heldID != 18)
            {
                transform.localScale = new Vector3(1, 1, 1);
                box.size             = boxSize;
            }
        }
        else if (heldID == 19 && transform.localScale != new Vector3(eraseScale, eraseScale, eraseScale))         //different while erasing
        {
            transform.localScale = new Vector3(eraseScale, eraseScale, eraseScale);
        }
        if (heldID == 9)         //certain objects need rotating, eg. Fireball
        {
            transform.rotation = Quaternion.Euler(0, 0, 90);
        }
        else if (heldID != 9)         //fireball only one rotated
        {
            transform.rotation = Quaternion.Euler(0, 0, 0);
        }

        if (currentBuildDelay > 0.0f)
        {
            currentBuildDelay -= Time.deltaTime;
        }
        if (currentBuildDelay <= 0.0f && isLocationValid)         //prevents most duplicate placements
        {
            EnablePlacement();
        }
        pointingLocation = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //keeps objects to a grid based system
        roundedLocation.x       = Mathf.RoundToInt(pointingLocation.x);
        roundedLocation.y       = Mathf.RoundToInt(pointingLocation.y);
        heldObject.sprite       = placeableObjects[heldID].GetComponentInChildren <SpriteRenderer>().sprite;  //displays sprite render to player
        this.transform.position = roundedLocation;
        if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        {
            if (Input.GetMouseButton(0) && isLocationValid && gc.GetIsBuilding() && !gc.GetIsPaused())
            {
                if (heldID != 19)
                {
                    Instantiate(placeableObjects[heldID], new Vector3(roundedLocation.x, roundedLocation.y, 0), transform.rotation, parentObject.transform);
                    DisablePlacement();
                    currentBuildDelay = buildDelay;
                    if (heldID == 13 || heldID == 14)          //reset to empty block after player is placed, prevents multiple spawns
                    {
                        SetHeldID(15);                         //allows player to specify next block
                    }
                    currentBuildDelay = buildDelay;
                }
                else
                {
                    Debug.Log("Doing something else with left click");
                }
            }
        }
    }
예제 #6
0
    void Update()
    {
        if (gc.GetIsGameplay() && !initialFlip)
        {
            Debug.Log("Rotating initial");
            FlipThis();
            initialFlip = true;
        }
        if (isMoving && currentDelay > 0.0f)
        {
            isMoving = false;
        }
        if (currentDelay > 0.0f)
        {
            currentDelay -= Time.deltaTime;
        }
        if (currentDelay <= 0.0f && !gc.GetIsPaused())
        {
            isMoving = true;
        }
        if (gc.GetIsBuilding())
        {
            ResetThis();
        }
        if (gc.GetIsPaused() && hasActivated)
        {
            isMoving = false;
        }
        if (!gc.GetIsPaused() && hasActivated)
        {
            if (!isMoving)
            {
                Debug.Log("Moving");
                isMoving = true;
            }
        }
        if (gc.GetIsGameplay() && isMoving)         //allows projectile to move at a static rate
        {
            rb.velocity  = Vector3.zero;
            thisVelocity = rb.velocity;

            if (transform.position.y >= obj.GetDefaultPosition().y&& isFacingForward)              //prevents spazzing while stopped
            {
                Debug.Log("Offset");
                thisVelocity  = Vector3.zero;
                hasReachedMax = true;
                didReachMax   = true;
            }
            if (hasReachedMax == true)
            {
                Debug.Log("Reached Max");
                FlipThis();
                hasReachedMax = false;
            }
            if (isFacingForward)
            {
                tmp = 1;
            }
            else if (!isFacingForward)
            {
                tmp = -1;
            }
            thisVelocity.y = speed * tmp;
        }
        rb.velocity = thisVelocity;
        if (!isMoving)         //stops object when not moving
        {
            rb.velocity = Vector3.zero;
        }
    }