// Update is called once per frame void Update() { coinText.text = "" + coins; nudgeText.text = "Nudges: " + nudges; betText.text = "Bet: " + curBet; maxBet = coins; HingeJoint curJoint; bool hasStopped = true; if (curState == stateTypes.READY && coins <= 0 && nudges == 0 && !cheatsOn) { GameOver(); } if (curState == stateTypes.ALLSTOPPED) { for (int i = 0; i < 3; i++) { curJoint = reels[i].GetComponent <HingeJoint>(); if (curJoint.velocity > 0) { hasStopped = false; } } if (hasStopped) { //and check for a win CheckSlots(); curState = stateTypes.READY; } } }
void GameOver() { //do stuff curState = stateTypes.GAMEOVER; winText.text = "GAME OVER!"; //other stuff }
void stopMotor(GameObject toStop) { HingeJoint curHinge = toStop.GetComponent <HingeJoint>(); JointSpring curSpring = curHinge.spring; curHinge.useMotor = false; //curHinge.spring = curSpring; curState = stateTypes.PAUSE; StartCoroutine("snapOnStop", toStop); }
public virtual void RunGame() { bool isWinOrLoss; outOfTime = CQTimer.updateTimer (); if (outOfTime == true) { CurrentState = stateTypes.EndGame; } outOfTime = CQTimer.updateTimer (); }
IEnumerator spinReels() { curState = stateTypes.PAUSE;//i.e. getting ready to spin winText.text = ""; HingeJoint curHinge; JointMotor curMotor; if (activeFlags[(int)modifierTypes.SLOWREELS]) { minForce /= slowFactor; maxForce /= slowFactor; minVelocity /= slowFactor; maxVelocity /= slowFactor; } if (activeFlags[(int)modifierTypes.FASTREELS]) { minForce *= hasteFactor; maxForce *= hasteFactor; minVelocity *= hasteFactor; maxVelocity *= hasteFactor; } if (activeFlags[(int)modifierTypes.CRAZYREELS]) { minForce /= crazyFactor; maxForce *= crazyFactor; minVelocity /= crazyFactor; maxVelocity *= crazyFactor; } //only this part activates reels //TRANSLATE METHOD /*for (int i = 0; i < 3; ++i) * { * curScript = reels[i].GetComponent<reelScript>(); * curScript.SetVelocity(minVelocity + (Random.value * (maxVelocity - minVelocity))); * curScript.StartReel(); * }*/ //PHYSICS METHOD for (int i = 0; i < 3; i++)//get reels up to speed { curHinge = reels[i].GetComponent <HingeJoint>(); curMotor = curHinge.motor; curMotor.force = minForce + (Random.value * (maxForce - minForce)); curMotor.targetVelocity = minVelocity + (Random.value * (maxVelocity - minVelocity)); curHinge.motor = curMotor; //randomness ensures different rates of rotation, creating a more interesting slot machine curHinge.useMotor = true; } yield return(new WaitForSeconds(0.5f));//let the motor get up to speed curState = stateTypes.SPINNING; }
private void Update() { if (walkTimer >= 0) { walkTimer -= Time.deltaTime; } // Debug.Log(walkLeft); if (Mathf.Abs(player.transform.position.x - transform.position.x) > waitDistance) { currentState = stateTypes.WAIT; rbody.velocity = new Vector2(0, rbody.velocity.y); anim.Play("idle"); } else { currentState = stateTypes.WALK; } // Debug.Log(currentState); if (currentState == stateTypes.WALK) { Walk(); if (walkTimer <= 0) { walkTimer = walkTime; if (walkLeft) { walkLeft = false; } else if (!walkLeft) { walkLeft = true; } } } if (opossum.isDead) { Debug.Log("girdim"); Destroy(gameObject); } }
public IEnumerator snapOnStop(GameObject toStop) { yield return(new WaitForFixedUpdate()); HingeJoint joint = toStop.GetComponent <HingeJoint>(); Transform transform = toStop.GetComponent <Transform>(); while (joint.velocity > 0.5) { yield return(null); //wait until stop } int springSector = Mathf.FloorToInt((transform.eulerAngles.y / 360f) * slotDivisions); float targetPosition = (springSector * (360f / slotDivisions)) + (180f / slotDivisions);//centre on reel transform.Rotate(new Vector3(0, targetPosition - transform.eulerAngles.y, 0)); source.PlayOneShot(stop); yield return(new WaitForFixedUpdate());//wait one tick for degree to auto-adjust if (joint == reels[0].GetComponent <HingeJoint>()) { curState = stateTypes.FIRSTSTOPPED; results[0] = springSector; } else if (joint == reels[1].GetComponent <HingeJoint>()) { curState = stateTypes.SECONDSTOPPED; results[1] = springSector; } else if (joint == reels[2].GetComponent <HingeJoint>()) { curState = stateTypes.ALLSTOPPED; maxForce = maximumForce; maxVelocity = maximumVelocity; minForce = minimumForce; minVelocity = minimumVelocity; foreach (GameObject button in buttons) { if (button != buttons[(int)ButtonTypes.NUDGEBUTTON]) { button.GetComponent <UnityEngine.UI.Button>().interactable = true; } } results[2] = springSector; } }
public void AnimChanger(bool isJump, bool isIdle, bool isWalk, bool isRun, bool isPunch, bool isSlide, bool isRunPunch, bool isDead) { if (isIdle) { currentState = stateTypes.IDLE; } if (isWalk) { currentState = stateTypes.WALK; } if (isRun) { currentState = stateTypes.RUN; } if (isRunPunch) { currentState = stateTypes.RUNPUNCH; } if (isPunch) { currentState = stateTypes.PUNCH; } if (isJump) { currentState = stateTypes.JUMP; } if (isSlide) { currentState = stateTypes.SLIDE; } if (isDead) { currentState = stateTypes.DEAD; if (anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 1.3f) { GameController.Instance.GameOver = true; } } }
void StateSelector() { if (Mathf.Abs(player.transform.position.x - transform.position.x) > waitDistance) { currentState = stateTypes.WAIT; anim.Play("idle"); } if (Mathf.Abs(player.transform.position.x - transform.position.x) < attackDistance) { currentState = stateTypes.ATTACK; } switch (currentState) { case stateTypes.WAIT: rbody.velocity = new Vector2(0, rbody.velocity.y); break; case stateTypes.ATTACK: Attack(); break; } }
public virtual void StartGame() { CurrentState = stateTypes.RunGame; }
public virtual void RestartGame() { CurrentState = stateTypes.StartGame; //myGameTimer.reset(); }
IEnumerator spinReels() { curState = stateTypes.PAUSE;//i.e. getting ready to spin winText.text = ""; HingeJoint curHinge; JointMotor curMotor; if(activeFlags[(int)modifierTypes.SLOWREELS]) { minForce /= slowFactor; maxForce /= slowFactor; minVelocity /= slowFactor; maxVelocity /= slowFactor; } if(activeFlags[(int)modifierTypes.FASTREELS]) { minForce *= hasteFactor; maxForce *= hasteFactor; minVelocity *= hasteFactor; maxVelocity *= hasteFactor; } if(activeFlags[(int)modifierTypes.CRAZYREELS]) { minForce /= crazyFactor; maxForce *= crazyFactor; minVelocity /= crazyFactor; maxVelocity *= crazyFactor; } //only this part activates reels //TRANSLATE METHOD /*for (int i = 0; i < 3; ++i) { curScript = reels[i].GetComponent<reelScript>(); curScript.SetVelocity(minVelocity + (Random.value * (maxVelocity - minVelocity))); curScript.StartReel(); }*/ //PHYSICS METHOD for (int i = 0; i < 3; i++)//get reels up to speed { curHinge = reels[i].GetComponent<HingeJoint>(); curMotor = curHinge.motor; curMotor.force = minForce + (Random.value * (maxForce - minForce)); curMotor.targetVelocity = minVelocity + (Random.value * (maxVelocity - minVelocity)); curHinge.motor = curMotor; //randomness ensures different rates of rotation, creating a more interesting slot machine curHinge.useMotor = true; } yield return new WaitForSeconds(0.5f);//let the motor get up to speed curState = stateTypes.SPINNING; }
public IEnumerator snapOnStop(GameObject toStop) { yield return new WaitForFixedUpdate(); HingeJoint joint = toStop.GetComponent<HingeJoint>(); Transform transform = toStop.GetComponent<Transform>(); while (joint.velocity > 0.5) yield return null;//wait until stop int springSector = Mathf.FloorToInt((transform.eulerAngles.y / 360f) * slotDivisions); float targetPosition = (springSector * (360f / slotDivisions)) + (180f / slotDivisions);//centre on reel transform.Rotate(new Vector3(0,targetPosition - transform.eulerAngles.y, 0)); source.PlayOneShot(stop); yield return new WaitForFixedUpdate();//wait one tick for degree to auto-adjust if (joint == reels[0].GetComponent<HingeJoint>()) { curState = stateTypes.FIRSTSTOPPED; results[0] = springSector; } else if (joint == reels[1].GetComponent<HingeJoint>()) { curState = stateTypes.SECONDSTOPPED; results[1] = springSector; } else if (joint == reels[2].GetComponent<HingeJoint>()) { curState = stateTypes.ALLSTOPPED; maxForce = maximumForce; maxVelocity = maximumVelocity; minForce = minimumForce; minVelocity = minimumVelocity; foreach(GameObject button in buttons) { if(button != buttons[(int)ButtonTypes.NUDGEBUTTON]) button.GetComponent<UnityEngine.UI.Button>().interactable = true; } results[2] = springSector; } }
void stopMotor(GameObject toStop) { HingeJoint curHinge = toStop.GetComponent<HingeJoint>(); JointSpring curSpring = curHinge.spring; curHinge.useMotor = false; //curHinge.spring = curSpring; curState = stateTypes.PAUSE; StartCoroutine("snapOnStop", toStop); }
// Update is called once per frame void Update () { coinText.text = "" + coins; nudgeText.text = "Nudges: " + nudges; betText.text = "Bet: " + curBet; maxBet = coins; HingeJoint curJoint; bool hasStopped = true; if (curState == stateTypes.READY && coins <= 0 && nudges == 0 && !cheatsOn) { GameOver(); } if (curState == stateTypes.ALLSTOPPED) { for(int i = 0; i < 3; i++) { curJoint = reels[i].GetComponent<HingeJoint>(); if (curJoint.velocity > 0) hasStopped = false; } if (hasStopped) { //and check for a win CheckSlots(); curState = stateTypes.READY; } } }