Exemple #1
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (card.face)
         {
             flipper.Flip(card.front, card.back);
         }
         else
         {
             flipper.Flip(card.back, card.front);
         }
     }
 }
Exemple #2
0
 private void OnFlip()
 {
     if (!WinChecker())
     {
         Flipper.Flip();
     }
 }
Exemple #3
0
    private void FixedUpdate()
    {
        if (!GameState.isGameLocked && active)
        {
            if (flipper.lookingRight && target.transform.position.x > transform.position.x)
            {
                flipper.Flip();
            }

            if (!flipper.lookingRight && target.transform.position.x < transform.position.x)
            {
                flipper.Flip();
            }

            transform.position = Vector2.MoveTowards(transform.position, target.transform.position, speed[GameState.difficulty]);
        }
    }
Exemple #4
0
 /// <summary>
 /// Move to the next item if available.
 /// </summary>
 public bool Dequeue()
 {
     _locks.A.Take();
     if (_queues.A.Next())
     {
         Current = _queues.A.Current;
         _locks.A.Release();
         return(true);
     }
     _locks.B.Take();
     _queues.Flip();
     _locks.B.Release();
     if (_queues.A.Next())
     {
         Current = _queues.A.Current;
         _locks.A.Release();
         return(true);
     }
     _locks.A.Release();
     return(false);
 }
Exemple #5
0
    public void FixedUpdate()
    {
        if (!GameState.isGameLocked && active)
        {
            var xMoveSpeed = even ? 0f : (going? -speed : speed);
            var yMoveSpeed = even ? (goingUp ? speed : -speed) : 0f;
            if (nextPoint.x > currentPoint.x && transform.position.x < nextPoint.x ||
                nextPoint.x < currentPoint.x && transform.position.x > nextPoint.x ||
                nextPoint.y > currentPoint.y && transform.position.y < nextPoint.y ||
                nextPoint.y < currentPoint.y && transform.position.y > nextPoint.y
                )
            {
                transform.Translate(new Vector2(xMoveSpeed, yMoveSpeed));
            }
            else
            {
                // Calculate the next point and switch variables for the movement update.
                even = !even;
                nextSwitch++;
                if (nextSwitch == 2)
                {
                    nextSwitch = 0;
                    goingUp    = !goingUp;
                }
                currentPoint = nextPoint;
                step++;
                if (step == 5)
                {
                    step  = going ? 2 : 0;
                    going = !going;
                }
                var nextPointX = currentPoint.x + (even ? 0f : (going ? -xDistance : xDistance));
                if (flipper.lookingRight && nextPointX < currentPoint.x)
                {
                    flipper.Flip();
                }
                nextPoint = new Vector2(
                    nextPointX,
                    currentPoint.y + (even ? (goingUp ? yDistance : -yDistance) : 0f)
                    );
            }

            if (Time.time - nextCooldown > timeBetweenBombs)
            {
                DropBomb(transform.position);
            }

            if (target != null && lastShot + fireRate < Time.time)
            {
                Shoot();
            }
        }
    }
Exemple #6
0
    // Update is called once per frame
    void Update()
    {
        //Flipper Control
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            flipperleft.Flip(true);
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            flipperright.Flip(true);
        }

        if (Input.GetKeyUp(KeyCode.LeftArrow))
        {
            flipperleft.Flip(false);
        }

        if (Input.GetKeyUp(KeyCode.RightArrow))
        {
            flipperright.Flip(false);
        }

        //Plunger Control @todo turn off if game running
        if (Input.GetKey(KeyCode.DownArrow))
        {
            currentpower += Time.deltaTime / TimeToFullPower;
            currentpower  = Mathf.Clamp(currentpower, 0, 1);
            plunger.SetPower(currentpower);
            powertext.text = currentpower.ToString();
        }
        if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            //FireBall();
            currentpower   = 0;
            powertext.text = currentpower.ToString();
            plunger.Release();
        }
    }
Exemple #7
0
    // Update is called once per frame
    void FixedUpdate()
    {
        grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
        anim.SetBool("Ground", grounded);

        anim.SetFloat("vSpeed", rigid.velocity.y);

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

        anim.SetFloat("Speed", Mathf.Abs(move));

        rigid.velocity = new Vector2(move * maxSpeed, rigid.velocity.y);

        if ((move > 0 && !flipper.facingRight) || (move < 0 && flipper.facingRight))
        {
            flipper.Flip();
        }
    }
Exemple #8
0
    public void FlipAt(int position)
    {
        if (flipper.IsFlipping || faller.IsFalling)             //Extra insurance that the meta stack won't be flipped when the flipper isn't finished
        {
            return;
        }

        List <GameObject> chipsToFlip = new List <GameObject> ();

        for (int i = position; i < transform.childCount; i++)
        {
            chipsToFlip.Add(transform.GetChild(i).gameObject);
        }

        crushChipsMeta = meta.FlipStackAt(position);
        flipper.Flip(chipsToFlip, transform);

        Debug.LogFormat("<color=yellow>Flipping at {0}.</color> Updated stack: {1})", position, meta.ToStringShort());
    }
Exemple #9
0
 private void Flip()
 {
     transform.localScale = Flipper.Flip(transform);
     isFacingRight        = !isFacingRight;
 }
Exemple #10
0
    private void Update()
    {
        DebugModeHotkeys();

        if (!GameState.isGameLocked)
        {
            // Time the character has been idle.
            lastAction += Time.deltaTime;

            var downPressed  = inputManager.IsActionPressed(GameCommand.DOWN);
            var upPressed    = inputManager.IsActionPressed(GameCommand.UP);
            var leftPressed  = inputManager.IsActionPressed(GameCommand.LEFT);
            var rightPressed = inputManager.IsActionPressed(GameCommand.RIGHT);

            // Hit management on overlapping objects
            if (overlapping != null)
            {
                if (overlapping && overlapping.activeSelf && overlapping.CompareTag(Tags.ENEMY_HIT) && !invuln.IsInvulnerable())
                {
                    EnemyHit();
                }
            }

            // Halo management, if active.
            if (haloActive && !invuln.IsInvulnerable())
            {
                haloActive = false;
                invulnerableAura.SetActive(false);
            }

            // Crouch management.
            if (crouching && !inputManager.IsActionPressed(GameCommand.DOWN))
            {
                Uncrouch();
            }

            // Looking up management.
            if (!inputManager.IsActionPressed(GameCommand.UP))
            {
                lookingUp = false;
            }

            // Control grounded state and the related animations.
            if (controller.isGrounded)
            {
                AchievementManager.jumpKills = 0;
                velocity.y = 0;
                if (crouching)
                {
                    SetAnimation(Animations.NUN_CROUCHING);
                }
                if (lookingUp && !leftPressed && !rightPressed)
                {
                    SetAnimation(Animations.NUN_LOOKING_UP);
                }
            }
            else
            {
                // Clean parent from moving platforms if falling or jumping.
                if (transform.parent != null)
                {
                    transform.parent = null;
                }
            }

            // Restore one way platform being detected if not pressing crouch+jump
            if (controller.ignoringOneWayPlatforms && (!downPressed || !inputManager.IsActionPressed(GameCommand.JUMP)))
            {
                controller.ignoringOneWayPlatforms = false;
            }

            // Horizontal movement.
            if (canMove && rightPressed)
            {
                shootingDirection         = Direction.RIGHT;
                lastAction                = 0;
                normalizedHorizontalSpeed = 1;
                if (controller.isGrounded && !crouching)
                {
                    SetAnimation(Animations.NUN_WALKING);
                }
                if (!flipper.lookingRight)
                {
                    flipper.Flip();
                    shootingDirection = Direction.RIGHT;
                }
            }
            else if (canMove && leftPressed)
            {
                shootingDirection         = Direction.LEFT;
                lastAction                = 0;
                normalizedHorizontalSpeed = -1;
                if (controller.isGrounded && !crouching)
                {
                    SetAnimation(Animations.NUN_WALKING);
                }
                if (flipper.lookingRight)
                {
                    flipper.Flip();
                    shootingDirection = Direction.LEFT;
                }
            }
            else
            {
                normalizedHorizontalSpeed = 0;
                velocity.x = 0;

                // Set the standing up idle animation if there's no movement.
                if (canMove && !crouching && !lookingUp && controller.isGrounded && lastAction < 4.99f)
                {
                    SetAnimation(Animations.NUN_IDLE);
                }
            }

            // Shooting
            if (canMove && inputManager.IsActionPressed(GameCommand.SHOOT) && Time.time - lastProjectile >= projectileRatio)
            {
                AudioManager.GetInstance().PlayEffect(Sfx.SHOOT);
                lastAction = 0;
                ShootProjectile();
            }

            // Jump only while grounded.
            // If you're holding down, jump down a platform.
            if (canMove && controller.isGrounded && inputManager.IsActionPressedOnce(GameCommand.JUMP))
            {
                if (downPressed)
                {
                    transform.parent = null;
                    controller.ignoringOneWayPlatforms = true;
                }
                else
                {
                    Jump(false);
                }
            }

            // This controls the variable jump. If the key stops being pressed, the velocity is set to 0.
            if (!ignoreJumpVariable && velocity.y > 0 && velocity.y < 6f && !inputManager.IsActionPressed(GameCommand.JUMP))
            {
                velocity.y = 0;
            }

            // Crouch action.
            if (canMove && controller.isGrounded && downPressed)
            {
                lastAction = 0;
                Crouch();
            }

            // Look up, only possible while in an idle animation (not moving).
            if (canMove && controller.isGrounded && upPressed && idleAnims.Contains(currentAnimation))
            {
                lastAction = 0;
                lookingUp  = true;
            }

            // Apply horizontal speed.
            var smoothedMovementFactor = controller.isGrounded ? groundDamping : inAirDamping;
            var actualRunSpeed         = speedBuffed ? runSpeed * 2 : runSpeed;
            if (crouching)
            {
                actualRunSpeed /= 2;
            }
            velocity.x = Mathf.Lerp(velocity.x, normalizedHorizontalSpeed * actualRunSpeed, Time.deltaTime * smoothedMovementFactor);

            // Apply gravity before moving.
            velocity.y += gravity * Time.deltaTime;
            velocity.y  = Mathf.Clamp(velocity.y, -18f, 18f);

            // Jumping sprite
            if (velocity.y > 0.8f || velocity.y < -0.8f)
            {
                SetAnimation(Animations.NUN_JUMPING);
            }

            controller.move(velocity * Time.deltaTime);

            // Grab our current velocity to use as a base for all calculations.
            velocity = controller.velocity;

            // Speed booooooooost
            if (speedBuffed && Time.time - speedBuffApplied >= GameplayValues.GetSpeedBuffDuration())
            {
                speedBuffed = false;
                audioManager.UndoFasterSong();
            }

            // Idle animation when no movement after 5 seconds.
            if (lastAction > 5f && lastAction <= 7.5f)
            {
                SetAnimation(Animations.NUN_WAITING);
            }
            if (lastAction > 7.5f && lastAction <= 16f)
            {
                SetAnimation(Animations.NUN_BORED);
            }
            if (lastAction > 16f)
            {
                SetAnimation(Animations.NUN_PRAYING);
            }
        }
    }
Exemple #11
0
    private void FixedUpdate()
    {
        if (!GameState.isGameLocked && active)
        {
            if (pos == 0)
            {
                var ymov = 0f;
                if (transform.position.y > minY && transform.position.x < midWay)
                {
                    ymov = -verticalSpeed;
                }
                else if (transform.position.y <= 3.2f && transform.position.x > midWay)
                {
                    ymov = verticalSpeed;
                }
                transform.Translate(new Vector2(horizontalSpeed, ymov));

                if (transform.position.x >= rightX)
                {
                    pos = 1;
                    lastDownwardsShot = Time.time;
                }
            }

            if (pos == 1)
            {
                if (transform.position.x > leftX)
                {
                    transform.Translate(new Vector2(-horizontalSpeed, 0f));
                    if (Time.time - lastDownwardsShot > timesBetweenDownwards[GameState.difficulty])
                    {
                        DropShot();
                    }
                }
                else
                {
                    pos = 2;
                }
            }

            if (pos == 2)
            {
                if (transform.position.x < rightX)
                {
                    transform.Translate(new Vector2(horizontalSpeed, 0f));
                    if (Time.time - lastDownwardsShot > timesBetweenDownwards[GameState.difficulty])
                    {
                        DropShot();
                    }
                }
                else
                {
                    pos = 3;
                }
            }

            if (pos == 3)
            {
                var ymov = 0f;
                if (transform.position.y > minY && transform.position.x > midWay)
                {
                    ymov = -verticalSpeed;
                }
                else if (transform.position.y <= 3.2f && transform.position.x < midWay)
                {
                    ymov = verticalSpeed;
                }
                transform.Translate(new Vector2(-horizontalSpeed, ymov));

                if (transform.position.x <= leftX)
                {
                    pos = 0;
                }
            }

            if (pos != 1 && pos != 2 && Time.time - lastBomb >= timesBetweenBombs[GameState.difficulty])
            {
                var dbomb = GetNextBomb();
                dbomb.GetComponent <DesertBomb>().Activate(Direction.ALL);
                lastBomb = Time.time;
            }

            if (flipper.lookingRight && target.transform.position.x < transform.position.x)
            {
                flipper.Flip();
            }

            if (!flipper.lookingRight && target.transform.position.x > transform.position.x)
            {
                flipper.Flip();
            }
        }
    }
Exemple #12
0
    private void FixedUpdate()
    {
        if (!GameState.isGameLocked && active)
        {
            if (isMovingLeft)
            {
                if (transform.position.x > initialPosition.x - 5f)
                {
                    transform.Translate(new Vector2(-0.03f, 0f));
                }
                else
                {
                    isMovingLeft = !isMovingLeft;
                    flipper.Flip();
                }
            }

            if (!isMovingLeft)
            {
                if (transform.position.x < initialPosition.x + 1f)
                {
                    transform.Translate(new Vector2(0.03f, 0f));
                }
                else
                {
                    isMovingLeft = !isMovingLeft;
                    flipper.Flip();
                }
            }

            // Shooting
            if (Time.time > lastShot + fireRate)
            {
                animator.Play(Animations.NUDE_NUN_CROSS);
                lastShot = Time.time;
                if (GameState.difficulty == Difficulty.VERY_EASY || pattern == 1)
                {
                    var fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(Vector2.right * shootingSpeed);
                    fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(Vector2.left * shootingSpeed);
                    fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(Vector2.up * shootingSpeed);
                    fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(Vector2.down * shootingSpeed);
                    pattern = 2;
                }
                else
                {
                    var fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(new Vector2(0.66f, 0.66f) * shootingSpeed);
                    fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(new Vector2(0.66f, -0.66f) * shootingSpeed);
                    fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(new Vector2(-0.66f, 0.66f) * shootingSpeed);
                    fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(new Vector2(-0.66f, -0.66f) * shootingSpeed);
                    pattern = 1;
                }
                animator.Play(Animations.NUDE_NUN_MOVING);
            }
        }
    }
Exemple #13
0
        /// <summary>
        /// Return a task if there is one.
        /// </summary>
        public override bool Next(out ActionAct task)
        {
            // has the needle been paused or is the lock already taken?
            if (_paused)
            {
                // yes, return no task
                task = null;
                return(false);
            }

            // if currently running
            if (_running)
            {
                // try get the A side lock
                if (_lockA.TryTake)
                {
                    var tasks = _tasks.A;

                    // get the next task
                    while (tasks.Next() && !tasks.Loop)
                    {
                        if (tasks.Current.Remove)
                        {
                            tasks.RemoveCurrent();
                            tasks.Current.Remove = false;
                        }

                        task = tasks.Current;

                        // should the task be run?
                        if (task.ToRun && task.Ready)
                        {
                            _current = task;
                            // set the current item
                            task.Ready = false;

                            _lockA.Release();
                            return(true);
                        }
                    }

                    if (_flip)
                    {
                        _flip = false;

                        _lockB.Take();
                        _tasks.Flip();
                        _lockB.Release();

                        tasks = _tasks.A;

                        // get the next task
                        while (tasks.Next() && !tasks.Loop)
                        {
                            if (tasks.Current.Remove)
                            {
                                tasks.RemoveCurrent();
                                tasks.Current.Remove = false;
                            }

                            task = tasks.Current;

                            // should the task be run?
                            if (task.ToRun && task.Ready)
                            {
                                _current = task;
                                // set the current item
                                task.Ready = false;

                                _lockA.Release();
                                return(true);
                            }
                        }
                    }

                    // return to wait for delta time
                    _running = false;

                    // release the a lock
                    _lockA.Release();
                }
                else
                {
                    task = null;
                    return(false);
                }
            }

            if (!_lockA.TryTake)
            {
                task = null;
                return(false);
            }

            // if delta is greater than target it's time for another loop of tasks
            if (Time.Timestamp >= _nextTimestamp)
            {
                // add the target number of ticks
                _nextTimestamp = _nextTimestamp + _targetTicks;

                // this is running
                _running = true;
                _flip    = true;

                // log of target ticks vs actual
//        if(Delta == 1000) {
//          Log.D(System.Threading.Thread.CurrentThread.Name + " Offset " + (_nextTimestamp - _targetTicks - Time.Timestamp));
//        }

                var tasks = _tasks.A;

                // get the next task
                while (tasks.Next() && !tasks.Loop)
                {
                    if (tasks.Current.Remove)
                    {
                        tasks.RemoveCurrent();
                        tasks.Current.Remove = false;
                    }

                    task = tasks.Current;

                    // should the task be run?
                    if (task.ToRun && task.Ready)
                    {
                        _current = task;
                        // set the current item
                        task.Ready = false;

                        _lockA.Release();
                        return(true);
                    }
                }

                if (_flip)
                {
                    _flip = false;

                    _lockB.Take();
                    _tasks.Flip();
                    _lockB.Release();

                    tasks = _tasks.A;

                    // get the next task
                    while (tasks.Next() && !tasks.Loop)
                    {
                        if (tasks.Current.Remove)
                        {
                            tasks.RemoveCurrent();
                            tasks.Current.Remove = false;
                        }

                        task = tasks.Current;

                        // should the task be run?
                        if (task.ToRun && task.Ready)
                        {
                            _current = task;
                            // set the current item
                            task.Ready = false;

                            _lockA.Release();
                            return(true);
                        }
                    }
                }

                _running = false;
            }

            // release the a lock
            _lockA.Release();

            // no task return
            task = null;
            return(false);
        }
Exemple #14
0
    private void FixedUpdate()
    {
        if (!GameState.isGameLocked && active)
        {
            // He's moving from starting point to the next one.
            if (!isInPosition && !isMoving)
            {
                nextPos  = xLeftPosition + sequence[step];
                isMoving = true;
                var isCurrentlyMovingLeft = isMovingLeft;
                isMovingLeft = nextPos < transform.position.x;
                if (isCurrentlyMovingLeft != isMovingLeft)
                {
                    flipper.Flip();
                }
            }

            if (isMoving && transform.position.x == nextPos)
            {
                isMoving  = false;
                goingDown = true;
            }

            if (!isInPosition && isMoving)
            {
                transform.position = Vector2.MoveTowards(transform.position, new Vector2(nextPos, transform.position.y), 0.03f);
            }

            if (goingDown)
            {
                if (transform.position.y > yFloor)
                {
                    transform.Translate(new Vector2(0f, -0.03f));
                }
                else
                {
                    goingDown    = false;
                    isInPosition = true;
                }
            }

            if (isInPosition && !goingDown)
            {
                if (transform.position.y < yPosition)
                {
                    transform.Translate(new Vector2(0f, 0.03f));
                }
                else
                {
                    isInPosition = false;
                    isMoving     = false;
                    step++;
                    if (step == 10)
                    {
                        step = 0;
                    }
                }
            }

            // Shooting
            if (Time.time > lastShot + fireRate)
            {
                lastShot = Time.time;
                var fireBall = GetNextFireball();
                fireBall.GetComponent <Rigidbody2D>().AddForce(Vector2.right * shootingSpeed);
                fireBall = GetNextFireball();
                fireBall.GetComponent <Rigidbody2D>().AddForce(Vector2.left * shootingSpeed);
                fireBall = GetNextFireball();
                fireBall.GetComponent <Rigidbody2D>().AddForce(Vector2.down * shootingSpeed);
                if (GameState.difficulty != Difficulty.VERY_EASY)
                {
                    fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(new Vector2(0.66f, -0.66f) * shootingSpeed);
                    fireBall = GetNextFireball();
                    fireBall.GetComponent <Rigidbody2D>().AddForce(new Vector2(-0.66f, -0.66f) * shootingSpeed);
                }
            }
        }
    }
    private void FixedUpdate() {
        if (!GameState.isGameLocked && active) {
            if (down && vertical <= -0.5f) {
                down = false;
            }
            if (!down && vertical >= 0.5f) {
                down = true;
            }

            var yMove = down ? -0.01f : 0.01f;
            vertical += yMove;

            if (isMovingLeft) {
                if (transform.position.x > initialPosition.x - 5f) {
                    transform.Translate(new Vector2(-moveSpeed, yMove));
                } else {
                    isMovingLeft = !isMovingLeft;
                    flipper.Flip();
                }
            }

            if (!isMovingLeft) {
                if (transform.position.x < initialPosition.x + 1f) {
                    transform.Translate(new Vector2(moveSpeed, yMove));
                } else {
                    isMovingLeft = !isMovingLeft;
                    flipper.Flip();
                }
            }

            // Pill dropping.
            if (GameState.difficulty > Difficulty.VERY_EASY && Time.time > lastShot + fireRate) {
                lastShot = Time.time;
                pill.transform.position = transform.position;
                pill.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
                pill.GetComponent<Rigidbody2D>().angularVelocity = 0f;
                pill.SetActive(true);
            }

            // Fetus dropping.
            if (Time.time > lastFetus + fireRate * 2) {
                var add = even ? 0.5f : 0f;
                lastFetus = Time.time;
                fetuses[0].transform.position = new Vector2(92.08f + add, altitude);
                fetuses[0].SetActive(true);
                fetuses[1].transform.position = new Vector2(93.21f + add, altitude);
                fetuses[1].SetActive(true);
                fetuses[2].transform.position = new Vector2(94.62f + add, altitude);
                fetuses[2].SetActive(true);
                if (GameState.difficulty > Difficulty.VERY_EASY) {
                    fetuses[3].transform.position = new Vector2(95.32f + add, altitude);
                    fetuses[3].SetActive(true);
                    if (GameState.difficulty > Difficulty.EASY) {
                        fetuses[4].transform.position = new Vector2(96.52f + add, altitude);
                        fetuses[4].SetActive(true);
                    }
                }
                even = !even;
            }

            if (invulnerable) {
                // TODO: Refactor tu use a flasher component
                StartCoroutine("Flash");
            }
        }
    }