float gameOverRange = 15F; //X Position the card should be in to cause game over. // Use this for initialization void Start() { cardScene = this; gameState = GameState.StartingUp; energyBalls = 1; tools = Tools.Me; if (tools == null) { Debug.LogWarning("Tools reference in GameManager is null"); } guiMan = CardSceneGui.Me; if (guiMan == null) { Debug.LogWarning("GuiMan reference in GameManager is null"); } cardMan = CardMan.Me; if (cardMan == null) { Debug.LogWarning("CardMan reference in GameManager is null"); } StartCoroutine(InitiateWave_cr()); }
public IEnumerator GameLost_cr() { if (dangerState != DangerState.GameOver) { SFXMan.StopSong(); gameState = GameState.GameLost; CardMan.CardCascade(); SFXMan.sfx_GameOver.Play(); dangerState = DangerState.GameOver; yield return(new WaitForSeconds(3)); StartCoroutine(InitiateWave_cr()); SceneManager.LoadScene("MainMenu"); } }
IEnumerator InitiateWave_cr() { //Present wave SFXMan.sfx_StartWave.Play(); var wave = MainGame.Wave; CardSceneGui.DisplayGuiMessage(string.Format("Clear {1} cards!", wave, wave * (CardMan.cardPairsPerWave * 2)), Color.white); yield return(new WaitForSeconds(3)); SFXMan.PlayAsSong(SFXMan.sng_CardSong); dangerState = DangerState.VerySafe; GravityStrength = 1f; InvokeRepeating("SlowUpdate", 0, 1F); CardMan.SetupWave(); gameState = GameState.GameOn; }
// Update is called once per frame void Update() { if (CurrentState == ViewState.Roles) { return; } if (Input.GetKeyDown("w")) { if (CurrentState == ViewState.Cards) { CardMan.RoleUp(); } else { BookMan.RoleUp(); } } if (Input.GetKeyDown("s")) { if (CurrentState == ViewState.Cards) { CardMan.RoleDown(); } else { BookMan.RoleDown(); } } touches = Input.touchCount; if (touches > 0 || Input.GetMouseButtonDown(0)) { Debug.Log("OOOOH"); foreach (Touch touch in Input.touches) { switch (touch.phase) { case TouchPhase.Began: /* this is a new touch */ isSwipe = true; fingerStartTime = Time.time; fingerStartPos = touch.position; break; case TouchPhase.Canceled: /* The touch is being canceled */ isSwipe = false; break; case TouchPhase.Ended: float gestureTime = Time.time - fingerStartTime; float gestureDist = (touch.position - fingerStartPos).magnitude; if (isSwipe && gestureTime < maxSwipeTime && gestureDist > minSwipeDist) { Vector2 direction = touch.position - fingerStartPos; Vector2 swipeType = Vector2.zero; if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y)) { // the swipe is horizontal: swipeType = Vector2.right * Mathf.Sign(direction.x); } else { // the swipe is vertical: swipeType = Vector2.up * Mathf.Sign(direction.y); } if (swipeType.x != 0.0f) { if (swipeType.x > 0.0f) { // MOVE RIGHT } else { // MOVE LEFT } } if (swipeType.y != 0.0f) { if (swipeType.y > 0.0f) { // MOVE UP CBUG.Log("VERT SWIPE UP"); if (CurrentState == ViewState.Cards) { CardMan.RoleUp(); } else { BookMan.RoleUp(); } } else { CBUG.Log("VERT SWIPE Down"); if (CurrentState == ViewState.Cards) { CardMan.RoleDown(); } else { BookMan.RoleDown(); // MOVE DOWN } } } } break; } } } }
void Awake() { Me = this; }
// Use this for initialization public CardGrid(int waveIndex) { this.waveIndex = waveIndex; var amountOfCards = CardMan.cardPairsPerWave * 2; cards = new List <Card> (amountOfCards); // Get a list of random textures as big as half the amount of cards in wave. So a wave with 8 cards will have 4 textures and created 4 pairs. List <Texture> textures = new List <Texture> (amountOfCards / 2); for (int i = 0; i < amountOfCards / 2; i++) { var randomTexture = CardMan.GetRandomTexture(); //ADD EACH TEXTURE TWICE TO ENSURE PAIRS textures.Add(randomTexture); textures.Add(randomTexture); } for (int i = 0; i < amountOfCards; i++) { //create card var card = CardMan.CreateNewCardPrefab(); //IS CARD IN TOP OR BOTTOM ROW? card.IsTopRow = i < (amountOfCards / 2) ? true : false; //Get one of the texture index left in list var textureIndex = Random.Range(0, textures.Count); //Set the texture to the card card.SetImage(textures [textureIndex]); //REMOVE TEXTURE SO THAT IT DOES NOT GET USED AGAIN. THIS ASSURES THAT THERE IS ALWAYS EVEN PAIRS IN EACH WAVE. textures.RemoveAt(textureIndex); //position cards on top or bottom row int xWaveMultiplier = (amountOfCards / 2) * (waveIndex); //add x for each prior wave of cards. Each wave is amountOfCard/2 cards wide. float cardWidth = card.Box().width; int margin = CardMan.cardMargin; float width = cardWidth + margin; float x = CardMan.cardStartingX; float columnIndex; // column position of card relative to all cards in all waves float y; if (card.IsTopRow) { //CARD IS IN TOP ROW columnIndex = xWaveMultiplier + i; x += columnIndex * width; y = CardMan.topRowY; } else { // CARD IS ON BOTTOM ROW columnIndex = xWaveMultiplier + (i - amountOfCards / 2); //starts on bottom row x += columnIndex * width; y = CardMan.bottomRowY; } card.transform.position = new Vector3(x, y, CardMan.cardStartingZ); cards.Add(card); } }