Exemple #1
0
        private BaseTile CreateTileByString(string tileName)
        {
            BaseTile tile;

            switch (tileName)
            {
            case "Tile":
                tile = new Tile();
                break;

            case "Start":
                tile = new StartTile();
                _startTiles.Add(tile);
                break;

            case "Rest":
                tile = new RestTile();
                break;

            case "Switch":
                tile = new SwitchTile();
                _switches.Add(tile);
                break;

            case "Ship":
                tile = new ShipTile();
                break;

            default:
                tile = new Tile();
                break;
            }
            return(tile);
        }
Exemple #2
0
 internal virtual void OnStartTurn()
 {
     if (!IsFlying())
     {
         SwitchTile switchTile = myTile.GetComponent <SwitchTile>();
         if (switchTile && !switchTile.isOn)
         {
             Die();
         }
     }
     hasBegunPlay   = true;
     hasBeenSpotted = false;
     if (GetKeywords().Contains("Recover"))
     {
         size = Math.Min(GetSize(), size + 1);
     }
     if (GetKeywords().Contains("Stunned"))
     {
         baseKeywords.Remove("Stunned");
     }
     else
     {
         hasUsedAction = false;
         movesLeft     = GetSpeed();
     }
 }
    private static String GetTextForTile(Tile tile, List <OccupiedTile> occupiedList)
    {
        if (tile == null)
        {
            return("null \n");
        }

        switch (tile.ToString())
        {
        case "1Tile":
            return("NTile(1) \n");

        case "2Tile":
            return("NTile(2) \n");

        case "JumpTile":
            return("JumpTile(2) \n");

        case "OccupiedTile":
            return("OccupiedTile(" + occupiedList.IndexOf((OccupiedTile)tile) + ") \n");

        case "SwitchTile":
            SwitchTile switchTile = (SwitchTile)tile;
            return("SwitchTile(" + occupiedList.IndexOf(switchTile.FreeTile) + ") \n");

        default:
            return("null \n");
        }
    }
Exemple #4
0
 internal void ConnectSwitches()
 {
     foreach (SwitchBridge switchBridge in DungeonManager.instance.switchBridges)
     {
         foreach (SwitchBridge.SwitchTileAssignment assignment in switchBridgeAssignments)
         {
             if (switchBridge.myTile.xCoord == assignment.terminalLocation.x && switchBridge.myTile.zCoord == assignment.terminalLocation.z)
             {
                 switchBridge.controlledTilesDisabled = new List <SwitchTile>();
                 switchBridge.controlledTilesEnabled  = new List <SwitchTile>();
                 foreach (Vector3Int tileCoords in assignment.controlLocations)
                 {
                     SwitchTile tile = (SwitchTile)DungeonManager.instance.grid.GetTile(tileCoords.x, tileCoords.z);
                     if (tile.isOn)
                     {
                         switchBridge.controlledTilesEnabled.Add(tile);
                     }
                     else
                     {
                         switchBridge.controlledTilesDisabled.Add(tile);
                     }
                 }
             }
         }
     }
 }
Exemple #5
0
        public async Task <IActionResult> Save(SwitchTile tile)
        {
            if (ModelState.IsValid)
            {
                return(await SaveBaseTile(ConfigStore, tile));
            }

            return(View("Add", tile));
        }
        public async Task <IActionResult> Save([FromRoute] string page, SwitchTile tile)
        {
            if (ModelState.IsValid)
            {
                return(await SaveBaseTile(page, ConfigStore, tile));
            }

            await PopulateSelectLists();

            return(View("Add", tile));
        }
    private void FixedUpdate()
    {
        if (!isDead)
        {
            #region Movement
            // Determine accel and decel values based on if the player is grounded or not
            float acceleration = grounded ? walkAcceleration : airAcceleration;
            float deceleration = grounded ? groundDeceleration : 0;

            if (canMove || movingToTargetPos || forcedInput)
            {
                if (movingToTargetPos || forcedInput)
                {
                    moveInput = forcedMoveInput;
                }

                if (moveInput != 0)
                {
                    // Accelerate when moving
                    velocity.x = Mathf.MoveTowards(velocity.x, speed * moveInput, acceleration * Time.deltaTime);
                }
                else
                {
                    // Decelerate when not moving
                    velocity.x = Mathf.MoveTowards(velocity.x, 0, deceleration * Time.deltaTime);
                }
            }

            if (movingToTargetPos)
            {
                Debug.Log("Moving target");
                float targetDistance = Mathf.Abs(targetPosX - transform.position.x);

                if (targetDistance <= .2f)
                {
                    Debug.Log(movingToTargetPos);
                    velocity.x        = 0f;
                    movingToTargetPos = false;
                }
            }

            velocity.y += currentGravity * Time.deltaTime; // Vertical movement
            if (velocity.y < maxFallSpeed)
            {
                velocity.y = maxFallSpeed;                  // Terminal velocity
            }
            transform.Translate(velocity * Time.deltaTime); // Horizontal movement
            grounded = false;                               // Resets grounded state
            #endregion

            #region Collision
            // Get overlapping colliders after velocity is applied
            Collider2D[] hits = Physics2D.OverlapBoxAll(transform.position, col.size, 0);

            // Wall cling and ceiling checking
            leftCheck  = Physics2D.Raycast(transform.position, Vector2.left, .5f, whatIsCling);  // Left side
            rightCheck = Physics2D.Raycast(transform.position, Vector2.right, .5f, whatIsCling); // Right side
            //Debug.DrawRay(transform.position, new Vector2(-.5f, 0f), Color.green);
            //Debug.DrawRay(transform.position, new Vector2(.5f, 0f), Color.red);

            RaycastHit2D ceilingCheck = Physics2D.BoxCast(transform.position, new Vector2(.75f, .1f), 0f, Vector2.up, .35f, whatIsCeiling); // Ceiling check

            // If the cling buffer time doesn't apply anymore
            if (clingBufferTimeCurrent <= 0)
            {
                // Determines if the player is clinged to a wall. If both are true, the player is inside the ground and isn't clinging.
                isClinged = leftCheck ^ rightCheck;
            }
            // Otherwise, continue counting down the cling buffer time
            else
            {
                clingBufferTimeCurrent -= Time.deltaTime;
            }

            // Fix for ensuring landed is false when player is in the air
            if (hits.Length == 1 && !isClinged)
            {
                landed = false;
            }

            // Reset teleportating bool
            isTeleporting = false;

            // Ground checking
            foreach (Collider2D hit in hits)
            {
                // Ignore own collider
                if (hit == col)
                {
                    continue;
                }

                ColliderDistance2D colliderDistance = hit.Distance(col);

                // Are we still overlapping this collider?
                if (colliderDistance.isOverlapped)
                {
                    // Deathbox collision
                    if (hit.gameObject.CompareTag("Deathbox"))
                    {
                        AudioManager.am.Play("Death");
                        Invoke("DelayTransition", .5f);
                        Instantiate(deathParticle, transform.position, Quaternion.identity);
                        groundParticle.gameObject.SetActive(false);
                        eyes.gameObject.SetActive(false);
                        body.gameObject.SetActive(false);
                        isDead = true;
                        return;
                    }

                    // Endpoint collision
                    if (hit.gameObject.CompareTag("Endpoint"))
                    {
                        hit.gameObject.GetComponent <LevelEndpoint>().EndLevel(this);
                        LevelController.levelController.DisableSaturation();
                        return;
                    }

                    // Teleport collision
                    if (hit.gameObject.CompareTag("Teleport") && !isTeleporting)
                    {
                        TeleportTile teleport = hit.GetComponentInParent <TeleportTile>().GetOtherTeleporter();
                        Vector3      newPos   = teleport.GetTeleportPos();
                        transform.position = newPos;
                        bufferedVelocity   = velocity;

                        landed        = false;
                        grounded      = false;
                        isTeleporting = true;
                        isClinged     = false;
                    }

                    overlap = true;
                    transform.Translate(colliderDistance.pointA - colliderDistance.pointB);

                    // If the object beneath us intersects, grounded is true
                    if (Vector2.Angle(colliderDistance.normal, Vector2.up) < 90 && velocity.y < 0 && !isTeleporting)
                    {
                        isJumping      = false;
                        touchingGround = true;
                        isWallJumping  = false;
                        grounded       = true;
                        canMove        = true;
                        velocity.y     = 0f;

                        // Ensures particle only spawns once
                        if (!landed)
                        {
                            AudioManager.am.Play("Land");
                            eyes.localScale = new Vector2(eyes.localScale.x, 0f);
                            Instantiate(jumpParticle, new Vector2(transform.position.x, transform.position.y - .5f), Quaternion.identity);
                            landed   = true;
                            grounded = true;
                        }

                        // Bounce
                        if (hit.gameObject.CompareTag("Bounce"))
                        {
                            BounceTile bounceTile = hit.GetComponentInParent <BounceTile>();

                            // Assuming the bounce tile will boost the Y-axis
                            if (!bounceTile.GetAxis())
                            {
                                AudioManager.am.Play("Bounce");

                                // Somehow fixed by having tile colliders having IsTrigger set to false
                                // What if we stopped making games like all of them :)

                                /*
                                 * RaycastHit2D castToGround = Physics2D.Raycast(transform.position, Vector2.down, .5f, whatIsCling); // Right side
                                 *
                                 * // Adjust player position to ensure player does not end up inside tile
                                 * if (castToGround.collider != null && castToGround.collider.gameObject.CompareTag("Bounce"))
                                 * {
                                 *  Vector2 gridPos = TilemapUtils.GetGridPosition(tilemap, castToGround.point);
                                 *  Vector2 tilePos = TilemapUtils.GetGridWorldPos(tilemap, (int)gridPos.x, (int)gridPos.y);
                                 *
                                 *  transform.position = new Vector2(transform.position.x, tilePos.y + .25f);
                                 *
                                 * }
                                 */

                                velocity.y = Mathf.Sqrt(bounceForceY * jumpHeight * Mathf.Abs(currentGravity));
                                isClinged  = false;
                                landed     = false;
                                grounded   = false;
                                if (moveInput == 0)
                                {
                                    velocity.x = 0f;
                                }
                            }
                        }
                    }
                    else
                    {
                        touchingGround = false;
                    }
                }
                else
                {
                    touchingGround = false;
                    overlap        = false;

                    // If dialogueActive is true
                    // Call WriteText to disable text
                }
            }

            RaycastHit2D groundCheck = Physics2D.Raycast(transform.position, Vector2.down, .5f, whatIsCling);
            if (isClinged && groundCheck)
            {
                velocity.x = 0f;
                isClinged  = false;
            }

            if (((leftCheck && moveInput == 1) || (rightCheck && moveInput == -1)) && isClinged)
            {
                if (currentDetachWaitTime > 0)
                {
                    detachActive           = false;
                    currentDetachWaitTime -= Time.deltaTime;
                }
                else
                {
                    detachActive = true;
                }
            }
            else
            {
                detachActive          = false;
                currentDetachWaitTime = detachWaitTime;
            }

            // If player is clinged, stop and lock movement
            if (!detachActive && isClinged)
            {
                currentGravity = 0f;
                velocity       = Vector2.zero;
                moveInput      = 0f;
                canMove        = false;
                isWallJumping  = false;

                // Ensures particle only spawns once
                if (!landed)
                {
                    AudioManager.am.Play("Land");
                    eyes.localScale = new Vector2(eyes.localScale.x, 0f);
                    Collider2D tileCol = leftCheck ? leftCheck.collider : rightCheck.collider;

                    // TILE INTERACTIONS

                    // Switch
                    if (tileCol.CompareTag("Switch"))
                    {
                        SwitchTile switchTile = tileCol.GetComponentInParent <SwitchTile>();
                        switchTile.ChangeLockState();
                    }

                    // Pressure
                    if (tileCol.CompareTag("Pressure"))
                    {
                        PressureTile pressureTile = tileCol.GetComponentInParent <PressureTile>();
                        pressureTile.ChangeMoveState(true);
                    }

                    // Bounce
                    if (tileCol.CompareTag("Bounce"))
                    {
                        AudioManager.am.Play("Bounce");

                        BounceTile bounceTile = tileCol.GetComponentInParent <BounceTile>();
                        // Assuming the bounce tile will boost the X-axis
                        if (bounceTile.GetAxis())
                        {
                            isWallJumping  = true;
                            currentGravity = gravity;
                            speedX         = leftCheck ? speed : -speed; // Are we clinged on the left or right?
                            velocity       = new Vector2(bounceForceX * speedX, Mathf.Sqrt(2f * jumpHeight * Mathf.Abs(currentGravity)));

                            isClinged             = false;
                            landed                = false;
                            grounded              = false;
                            detachActive          = false;
                            currentDetachWaitTime = detachWaitTime;
                            StartCoroutine(SetCanMove(.66f));
                        }
                    }

                    if (tileCol.CompareTag("Teleport") && !isTeleporting)
                    {
                        TeleportTile teleport = tileCol.GetComponentInParent <TeleportTile>().GetOtherTeleporter();
                        Vector3      newPos   = teleport.GetTeleportPos();
                        transform.position = newPos;
                        bufferedVelocity   = velocity;

                        landed        = false;
                        grounded      = false;
                        isTeleporting = true;
                        isClinged     = false;
                    }

                    // Spawn particles when colliding with wall
                    if (leftCheck)
                    {
                        Instantiate(jumpParticle, new Vector2(transform.position.x - .5f, transform.position.y), Quaternion.Euler(0f, 0f, -90f));
                    }
                    else
                    {
                        Instantiate(jumpParticle, new Vector2(transform.position.x + .5f, transform.position.y), Quaternion.Euler(0f, 0f, 90f));
                    }

                    landed = true;
                }

                // Wall jump
                if (jumpActive && allowJumping)
                {
                    Collider2D tileCol = leftCheck ? leftCheck.collider : rightCheck.collider;
                    if (tileCol.CompareTag("Pressure"))
                    {
                        PressureTile pressureTile = tileCol.GetComponentInParent <PressureTile>();
                        pressureTile.ChangeMoveState(false);
                    }

                    float pitch = 1 + Random.Range(-.25f, .25f);
                    AudioManager.am.Play("Jump", pitch);
                    currentGravity         = gravity;
                    speedX                 = leftCheck ? speed : -speed; // Are we clinged on the left or right?
                    velocity               = new Vector2(speedX, Mathf.Sqrt(2f * jumpHeight * Mathf.Abs(currentGravity)));
                    clingBufferTimeCurrent = clingBufferTime;

                    isJumping             = true;
                    isWallJumping         = true;
                    isClinged             = false;
                    landed                = false;
                    grounded              = false;
                    detachActive          = false;
                    currentDetachWaitTime = detachWaitTime;
                    StartCoroutine(SetCanMove(true));
                }
            }
            else if (detachActive && isClinged)
            {
                Collider2D tileCol = leftCheck ? leftCheck.collider : rightCheck.collider;
                if (tileCol.CompareTag("Pressure"))
                {
                    PressureTile pressureTile = tileCol.GetComponentInParent <PressureTile>();
                    pressureTile.ChangeMoveState(false);
                }

                currentGravity         = gravity;
                speedX                 = leftCheck ? speed : -speed; // Are we clinged on the left or right?
                velocity               = new Vector2(speedX / 4, 0f);
                clingBufferTimeCurrent = clingBufferTime;

                isClinged             = false;
                isJumping             = true;
                isWallJumping         = true;
                landed                = false;
                grounded              = false;
                detachActive          = false;
                currentDetachWaitTime = detachWaitTime;
                canMove               = true;
            }
            else
            {
                currentGravity = gravity;
            }

            // Stops upward velocity if player hits ceiling
            if (ceilingCheck)
            {
                bool         hittingCeiling = true;
                Collider2D[] ceilingHits    = Physics2D.OverlapBoxAll(transform.position, col.size, 0);

                // If colliding with a Bounce tile, the player is not hitting the ceiling
                foreach (Collider2D hit in ceilingHits)
                {
                    if (hit.transform.tag == "Bounce")
                    {
                        hittingCeiling = false;
                    }
                }

                if (hittingCeiling)
                {
                    velocity.y = 0f;
                }
            }

            #endregion

            #region Animations

            // Changes position of eyes based on velocity of player
            if (allowInput || movingToTargetPos || forcedInput)
            {
                eyesTargetPos = new Vector2(Mathf.Lerp(eyes.localPosition.x, velocity.x / 80, .25f), Mathf.Lerp(eyes.localPosition.y, velocity.y / 100, .25f));
            }
            else
            {
                eyesTargetPos = new Vector2(Mathf.Lerp(eyes.localPosition.x, eyesDialoguePosX, .25f), 0f);
            }

            eyes.localPosition = eyesTargetPos;

            // Eyes blinking
            if (!lockBlink)
            {
                if (isBlinking)
                {
                    eyes.localScale = new Vector2(eyes.localScale.x, Mathf.Lerp(eyes.localScale.y, 0f, .33f));

                    if (eyes.localScale.y <= .025f)
                    {
                        isBlinking = false;
                    }
                }
                else
                {
                    eyes.localScale = new Vector2(eyes.localScale.x, Mathf.Lerp(eyes.localScale.y, 1f, .33f));
                }

                // Hotfix for alleviating lerp issues relative to scale
                if (eyes.localScale.y >= .995f)
                {
                    eyes.localScale = new Vector2(eyes.localScale.x, 1f);
                }

                // Hotfix for alleviating lerp issues relative to position
                if (eyes.localPosition.y < .01f && eyes.localPosition.y > -.01f && velocity.y > -1 && velocity.y < 0)
                {
                    eyes.localPosition = new Vector2(eyes.localPosition.x, 0f);
                }

                // Plays particles if moving, stops particles if not moving
                if ((velocity.y > -1.5f && velocity.y < .25f && velocity.x > -.25f && velocity.x < .25f) || isClinged)
                {
                    playOnce = true;
                    groundParticle.Stop();
                }
                else if (playOnce)
                {
                    playOnce = false;
                    groundParticle.Play();
                }
            }

            #endregion

            #region Debug

            // Debug text
            if (debugText != null)
            {
                debugText.text = "Velocity X: " + velocity.x + "\n" +
                                 "Velocity Y: " + velocity.y + "\n" +
                                 "Grounded: " + grounded + "\n" +
                                 "Landed: " + landed + "\n" +
                                 "Can Move: " + canMove + "\n" +
                                 "Clinging: " + isClinged + "\n" +
                                 "Colliding with Object: " + overlap + "\n" +
                                 "Colliding with Ground?: " + touchingGround;
            }
            #endregion
        }
    }