Exemple #1
0
    private void CheckSurroundings()
    {
        // ---- CHECK FOR GROUND

        RaycastHit2D onGround = Physics2D.Raycast(onGroundCheck.position, Vector2.down, groundCheckDistance, groundLayerMask);

        Debug.DrawRay(onGroundCheck.position, Vector2.down * groundCheckDistance, Color.red);

        RaycastHit2D toeHitGround = Physics2D.Raycast(toeGroundCheck.position, Vector2.down, groundCheckDistance, groundLayerMask);

        Debug.DrawRay(toeGroundCheck.position, Vector2.down * groundCheckDistance, Color.yellow);

        RaycastHit2D heelHitGround = Physics2D.Raycast(heelGroundCheck.position, Vector2.down, groundCheckDistance, groundLayerMask);

        Debug.DrawRay(heelGroundCheck.position, Vector2.down * groundCheckDistance, Color.yellow);

        if (onGround.collider != null)
        {
            isOnGround = true;

            int currentLayer = onGround.collider.gameObject.layer;

            if (currentLayer == breakableObjectsLayer)
            {
                BreakableObject bo = onGround.collider.gameObject.GetComponent <BreakableObject>();

                if (bo == null)
                {
                    Debug.LogError("Object on Breakable Objects layer does not have Breakable Object component!");
                }
                else if (bo.isPlatform && !bo.isFallingApart)
                {
                    bo.TriggerPlatformCollapse();
                }
            }
            else if (currentLayer == breakableFloorsLayer)
            {
                BreakableFloor bf = onGround.collider.gameObject.GetComponent <BreakableFloor>();

                if (bf == null)
                {
                    Debug.LogError("Object on Breakable Floors layer does not have Breakable Floors component!");
                }
                else if (inAir)
                {
                    bf.TriggerObjectShake();
                }
            }
            else if (currentLayer == slidingSurfaceLayer && !isPressingJumpButton && !magBootsOn)
            {
                SlidingSurface ss = onGround.collider.gameObject.GetComponent <SlidingSurface>();

                if (ss == null)
                {
                    Debug.LogError("Object on Sliding Surface layer does not have Sliding Surface component!");
                }
                else
                {
                    SlopeSlide(ss.direction);
                }
            }
            else if (currentLayer != slidingSurfaceLayer && isGroundSliding || isGroundSliding && magBootsOn)
            {
                print("Stop");
                StopSlopeSlide();
            }
        }
        else if (onGround.collider == null && isGroundSliding)
        {
            if (direction == Vector2.right)
            {
                move.x = 16;
            }
            else
            {
                move.x = -16;
            }

            targetVelocity.x = move.x;
        }
        else if (onGround.collider == null)
        {
            if (toeHitGround.collider != null && heelHitGround.collider == null && !hasJumped)
            {
                move.x = -3f;
            }
            else if (toeHitGround.collider == null && heelHitGround.collider != null && !hasJumped)
            {
                move.x = 3f;
            }
            else if (toeHitGround.collider == null && heelHitGround.collider == null)
            {
                isOnGround = false;
            }
        }

        // ---- CHECK FOR WALLS

        if (canMove && !isDisabled)
        {
            ContactFilter2D contactFilter = new ContactFilter2D();
            contactFilter.SetLayerMask(wallLayerMask);
            RaycastHit2D[] hit = new RaycastHit2D[1];
            isTouchingWall = Physics2D.Raycast(wallCheck.position, direction, contactFilter, hit, wallCheckDistance) > 0;
            Debug.DrawRay(wallCheck.position, direction * wallCheckDistance, Color.red);

            isTouchingLedge = Physics2D.Raycast(ledgeCheck.position, direction, ledgeCheckDistance, wallLayerMask);
            Debug.DrawRay(ledgeCheck.position, direction * ledgeCheckDistance, Color.red);

            // Check for ledge grab
            if (isTouchingWall && !isTouchingLedge && !ledgeDetected)// << ----------- OPTION TO PUT MANUAL LEDGE GRAB HERE
            {
                ledgeDetected = true;
                // playerposition = hitpointx - wallcheck
                transform.position = new Vector3(hit[0].point.x + (direction == Vector2.right ? wallCheckDistance : -wallCheckDistance), transform.position.y, transform.position.z);
                ledgePosBot        = wallCheck.position;
            }

            // Check for crumbling wall
            if (isWallSliding)
            {
                RaycastHit2D hitWall = Physics2D.Raycast(wallCheck.position, direction, wallCheckDistance, groundLayerMask);

                if (hitWall.collider != null)
                {
                    int currentLayer = hitWall.collider.gameObject.layer;

                    if (currentLayer == breakableObjectsLayer)
                    {
                        BreakableObject crumblingWall = hitWall.collider.gameObject.GetComponent <BreakableObject>();

                        if (crumblingWall != null)
                        {
                            print("hit crumbling wall");
                            crumblingWall.TriggerPlatformCollapse();
                            StopWallSliding();
                        }
                        else
                        {
                            Debug.LogError("Object on Breakable Object layer does not have Breakable Object component!");
                        }
                    }
                }
            }
        }
    }
    private void BreakableFloor(Collider2D c2d)
    {
        BreakableFloor bf = c2d.gameObject.GetComponent <BreakableFloor>();

        bf.StartDestroying();
    }
Exemple #3
0
    /**
     * Erstellt die richtige Art Feld anhand des eingelesenen Symboles und gibt
     * dieses zurück. Das eingegebene Symbol muss eines der aufgelisteten sein.
     * Wirft eine Exception,falls das Symbol nicht existiert.
     * "#": Wand
     * " ": Weg
     * "P":	Spieler
     * "B": Box
     * "G":	Zielfeld
     * @precondition Das eingegebene Symbol muss existieren.
     * @params symbol welches eingelesen werden soll. Muss existieren.
     * @params x Koordinate des Feldes.
     * @params y Koordinate des Feldes.
     * @param board auf welchem gearbeitet wird.
     * @return Das erstellte neue Feld.
     */
    public Square makeSquare(string symbol, int x, int y, Board board, Vector3 position)
    {
        Square square;

        switch (symbol)
        {
        case FLOOR_SYMBOL:
            square = new Floor(x, y, board, position);
            break;

        case WALL_SYMBOL:
            square = new Wall(x, y, board, position);
            break;

        case BREAKABLE_WALL_SYMBOL:
            BreakableWall bw = new BreakableWall(x, y, board, position);
            square = new Floor(x, y, board, position);
            square.setMovableSquare(bw);
            break;

        case PLAYER_SYMBOL:
            Player player = new Player(x, y, board, position);
            square = new Floor(x, y, board, position);
            square.setMovableSquare(player);
            break;

        case BOX_SYMBOL:
            Box box = new Box(x, y, board, position);
            square = new Floor(x, y, board, position);
            square.setMovableSquare(box);
            break;

        case GOAL_SYMBOL:
            square = new Goal(x, y, board, position);
            break;

        case BOMB_SYMBOL:
            Bomb bomb = new Bomb(x, y, board, position);
            square = new Floor(x, y, board, position);
            square.setMovableSquare(bomb);
            break;

        case "1":
            square = new BreakableFloor(x, y, board, position, 1);
            break;

        case "2":
            square = new BreakableFloor(x, y, board, position, 2);
            break;

        case "3":
            square = new BreakableFloor(x, y, board, position, 3);
            break;

        case "4":
            square = new BreakableFloor(x, y, board, position, 4);
            break;

        case "5":
            square = new BreakableFloor(x, y, board, position, 5);
            break;

        case "6":
            square = new BreakableFloor(x, y, board, position, 6);
            break;

        case "7":
            square = new BreakableFloor(x, y, board, position, 7);
            break;

        case "8":
            square = new BreakableFloor(x, y, board, position, 8);
            break;

        case "9":
            square = new BreakableFloor(x, y, board, position, 9);
            break;

        default:
            throw new UnknownSymbolException();
        }
        return(square);
    }