예제 #1
0
파일: Game.cs 프로젝트: mgartz/skwer_unity
	void FixedUpdate (){
		if (isBlockingGUIInput) {
			if (++isBlockingGUIInputCounter == isBlockingGUIInputPeriod)
				isBlockingGUIInput = false;
		}
		beaconCounter++;
		if (beaconCounter >= beaconPeriod)
			beaconCounter = 0;
		if (!started) {
			livesArray.setLives(livesLeft);
			if (!isQuickGame) {
				readStack ();
				for (int i=0; i<10; i++)
					tilesArray [i].GetComponent<TilesArray> ().loadPuzzle ();
				started = true;
				isStartingAnimation = true;
				startAnimationCounter = 0;
				levelIndicators [0].GetComponent<LevelIndicator> ().setCurrent ();
				if (!isTutorial)
					summaryLevelIndicators [0].GetComponent<LevelIndicator> ().setSkipped ();
				Global.isGameActive = true;
				toggleStackOrder ();
			} else {
				isStartingAnimation = true;
				started = true;
				tilesArray [0].GetComponent<TilesArray> ().newRandomPuzzle (3);
				tilesArray [0].GetComponent<TilesArray> ().loadPuzzle ();
				tilesArray [1].GetComponent<TilesArray> ().newRandomPuzzle (3);
				tilesArray [1].GetComponent<TilesArray> ().loadPuzzle ();
				toggleZoom ();
				levelIndicators [0].GetComponent<LevelIndicator> ().setCurrent ();
				
				Global.isGameActive = true;
				showGUI ();

				activeTilesArray.bringForward ();
				activeTilesArray.resetPuzzle ();
				toggleStackOrder ();
				checkStack ();
			}
		}
		if (isStartingAnimation) {
			startAnimationCounter++;
			if (!isQuickGame) {
				cameraArray.transform.position = new Vector3 (0, -600 + 950 * startAnimationCounter / startAnimationPeriod, 0);
				if (startAnimationCounter == startAnimationPeriod) {
					isStartingAnimation = false;
					isFlashing = true;
					if ((!isZoomedIn && activeTilesArray.GetComponent<TilesArray> ().puzzle.isZoomedIn) ||
						(isZoomedIn && !activeTilesArray.GetComponent<TilesArray> ().puzzle.isZoomedIn))
						toggleZoom ();
					if (isTutorial) {
						tutorialText1.GetComponent<TextMesh>().text = "clicking on red affects the color of the surrounding tiles";
						tutorialText1.GetComponent<TutorialText>().appear ();
						activeTilesArray.setTutorialHints();
					}
				}
				
				if (startAnimationCounter < startAnimationPeriod * 0.9f) {
					guiRightPanel.transform.localPosition = new Vector3 (0, 180, 0);
					guiLeftPanel.transform.localPosition = new Vector3 (0, 180, 0);
				} else {
					if (!isShowingGUI) {
						showGUI ();
					}
				}
				for (int i=0; i<10; i++)
					if (startAnimationCounter == 10 * (i + 1) - 9) {
						tilesArray [9 - i].GetComponent<TilesArray> ().drawPuzzle ();
						if (i == 9) {
							activeTilesArray.bringForward ();
							activeTilesArray.resetPuzzle ();
							puzzleNumMoves = activeTilesArray.puzzle.size;
							puzzleStack [0] = activeTilesArray.stack [0];
							puzzleStack [1] = activeTilesArray.stack [1];
							puzzleStack [2] = activeTilesArray.stack [2];
							checkStack ();
						}
					}
			} else {
				if (startAnimationCounter == startAnimationPeriod)
					isStartingAnimation = false;
				upperLight.GetComponent<Light> ().intensity = startAnimationCounter / startAnimationPeriod * 5.5f;
			}
		}
		if (isGoingToMenu) {
			cameraArray.transform.localPosition = new Vector3 (cameraArray.transform.localPosition.x, cameraArray.transform.localPosition.y + 20, cameraArray.transform.localPosition.z);
			supportingTilesArray.transform.localPosition = new Vector3 (0, 350 - 1000 * (1 - goingToMenuCounter / goingToMenuPeriod), 0);

			if (++goingToMenuCounter == goingToMenuPeriod) {
				if (isGoingToFirstLevel)
					Application.LoadLevel ("GameScene");
				else if (isQuickGame || isTutorial)
					Application.LoadLevel ("MenuScene");
				else
					Application.LoadLevel ("StackMenuScene");
				isGoingToMenu = false;
				isGoingToFirstLevel = false;				
			}
				
		}
		if (isRebuildingStack) {
			cameraArray.transform.position = Vector3.Lerp (rebuildingStartingLocation, rebuildingTargetLocation, rebuildingStackCounter / rebuildingStackPeriod);
			if (rebuildingStackCounter % rebuildingStackPeriodPerLevel == 0) {
				if (level > 0) {
					level--;
					tilesArray [level].GetComponent<TilesArray> ().rebuildStack ();
				}
			}
			rebuildingStackCounter++;
			if (rebuildingStackCounter > rebuildingStackPeriod) {
				livesLeft = Global.getGameLives();
				livesArray.setLives(livesLeft);
				isRebuildingStack = false;
				showGUI ();
				activeTilesArray = tilesArray [0].GetComponent<TilesArray> ();
				activeTilesArray.resetPuzzleFromScratch ();
				activeTilesArray.bringForward ();
				for (int i=level+1; i<10; i++)
					tilesArray [i].GetComponent<TilesArray> ().setBack2 (activeTilesArray.puzzle.baseState);
				
				checkStack ();
				levelIndicators [0].GetComponent<LevelIndicator> ().setCurrent ();
				for (int i=1; i<10; i++)
					levelIndicators [i].GetComponent<LevelIndicator> ().setNull ();
			}
		}
		if (isShowingGUI) {
			showingGUICounter++;
			guiRightPanel.transform.localPosition = new Vector3 (0, 180 - 180 * showingGUICounter / showingGUIPeriod, 0);
			guiLeftPanel.transform.localPosition = new Vector3 (0, 180 - 180 * showingGUICounter / showingGUIPeriod, 0);
			if (showingGUICounter == showingGUIPeriod)
				isShowingGUI = false;
		}
		if (isHidingGUI) {
			hidingGUICounter++;
			guiRightPanel.transform.localPosition = new Vector3 (0, 180 * hidingGUICounter / hidingGUIPeriod, 0);
			guiLeftPanel.transform.localPosition = new Vector3 (0, 180 * hidingGUICounter / hidingGUIPeriod, 0);
			if (hidingGUICounter == hidingGUIPeriod)
				isHidingGUI = false;
		}
		if (isShowingGameSummary) {
			showingGameSummaryCounter++;
			gameSummary.transform.localPosition = new Vector3 (0, 10 - 195 * showingGameSummaryCounter / showingGameSummaryPeriod, 0);
			if (showingGameSummaryCounter == showingGameSummaryPeriod)
				isShowingGameSummary = false;
		}
		if (isHidingGameSummary) {
			hidingGameSummaryCounter++;
			gameSummary.transform.localPosition = new Vector3 (0, -185 + 195 * hidingGameSummaryCounter / hidingGameSummaryPeriod, 0);
			if (hidingGameSummaryCounter == hidingGameSummaryPeriod) {
				isHidingGameSummary = false;
				if (!isQuickGame) {
					gameSummary.GetComponent<GameSummary> ().hideGameSummary ();
					if (!isTutorial){
						summaryLevelIndicators [0].GetComponent<LevelIndicator> ().setSkipped ();
						for (int i=1; i<10; i++)
							summaryLevelIndicators [i].GetComponent<LevelIndicator> ().setNull ();
					}
				}
			}
		}
		if (isShowingGameEndedScreen) {
			showingGameEndedScreenCounter++;
			gameEndedScreen.transform.localPosition = new Vector3 (0, 10 - 195 * showingGameEndedScreenCounter / showingGameEndedScreenPeriod, 0);
			if (showingGameEndedScreenCounter == showingGameEndedScreenPeriod)
				isShowingGameEndedScreen = false;
		}
		if (isHidingGameEndedScreen) {
			hidingGameEndedScreenCounter++;
			gameEndedScreen.transform.localPosition = new Vector3 (0, -185 + 195 * hidingGameEndedScreenCounter / hidingGameEndedScreenPeriod, 0);
			if (hidingGameEndedScreenCounter == hidingGameEndedScreenPeriod)
				isHidingGameEndedScreen = false;
		}
		if (isShowingPauseScreen) {
			showingPauseScreenCounter++;
			pauseScreen.transform.localPosition = new Vector3 (0, -175 * showingPauseScreenCounter / showingPauseScreenPeriod, 0);
			if (showingPauseScreenCounter == showingPauseScreenPeriod)
				isShowingPauseScreen = false;
		}
		if (isFlashing) {
			effectsLightArray.transform.position = new Vector3 (0, -600 + 3000 * flashCounter / flashPeriod, 0);
			flashCounter++;
			if (flashCounter == flashPeriod)
				flashCounter = 0;
		}
		if (isZoomingIn) {
			zoomCounter++;
			cameraArray.transform.localPosition = new Vector3 (cameraArray.transform.localPosition.x, 350 - level * 50 + 300 * (1 - zoomCounter / zoomPeriod), cameraArray.transform.localPosition.z);
			upperLight.transform.localPosition = new Vector3 (0, -100 - 300 * (1 - zoomCounter / zoomPeriod), 0);
			supportingTilesArray.transform.localPosition = new Vector3 (0, 350 - 1000 * (1 - zoomCounter / zoomPeriod), 0);
			if (zoomCounter == zoomPeriod) {
				isZoomingIn = false;
				isZoomedIn = true;
			}
		}
		if (isZoomingOut) {
			zoomCounter++;
			cameraArray.transform.localPosition = new Vector3 (cameraArray.transform.localPosition.x, 350 - level * 50 + 300 * (zoomCounter / zoomPeriod), cameraArray.transform.localPosition.z);
			upperLight.transform.localPosition = new Vector3 (0, -100 - 300 * (zoomCounter / zoomPeriod), 0);
			supportingTilesArray.transform.localPosition = new Vector3 (0, 350 - 1000 * (zoomCounter / zoomPeriod), 0);
			if (zoomCounter == zoomPeriod)
				isZoomingOut = false;
		}
		if (isOpeningMenu) {
			openMenuCounter++;
			if (openMenuCounter > openMenuPeriod)
				isOpeningMenu = false;
		}
		if (isAdvancingLevel) {
			advancingLevelCounter++;
			cameraArray.transform.localPosition = new Vector3 (cameraArray.transform.localPosition.x, cameraArray.transform.localPosition.y - 2, cameraArray.transform.localPosition.z);
			if (advancingLevelCounter == advancingLevelPeriod) {
				isAdvancingLevel = false;
			}
		}
	}
예제 #2
0
파일: Game.cs 프로젝트: mgartz/skwer_unity
	public void nextLevel (bool passed){
		if (isQuickGame) {
			if (isBeaconOn)
				toggleBeacon ();
			
			if (passed) {
				quickGameScore += (3 - activeTilesArray.livesUsed) * activeTilesArray.puzzle.size * (3 - activeTilesArray.livesUsed) * activeTilesArray.puzzle.size;
				quickGameScoreNumber.GetComponent<TextMesh> ().text = quickGameScore.ToString ();
				level++;
			} else {
				if (level > 10) 
					level = 10;
				else if (level > 6)
					level = 6;
				else if (level > 3)
					level = 3;
				else if (level > 1)
					level = 1;
			}
			
			if (livesLeft > 1)
				resetButton.GetComponent<ResetButton>().makeAvailable ();
			
			isAdvancingLevel = true;
			advancingLevelCounter = 0;
			if (activeTilesArray == tilesArray [0].GetComponent<TilesArray> ())
				activeTilesArray = tilesArray [1].GetComponent<TilesArray> ();
			else
				activeTilesArray = tilesArray [0].GetComponent<TilesArray> ();
			activeTilesArray.bringForward ();
			
			for (int i=0; i<5; i++)
				levelIndicators [i].GetComponent<LevelIndicator> ().setNull ();
			if (level < 2)
				levelIndicators [0].GetComponent<LevelIndicator> ().setCurrent ();
			else if (level < 4)
				levelIndicators [1].GetComponent<LevelIndicator> ().setCurrent ();
			else if (level < 7)
				levelIndicators [2].GetComponent<LevelIndicator> ().setCurrent ();
			else if (level < 11)
				levelIndicators [3].GetComponent<LevelIndicator> ().setCurrent ();
			else
				levelIndicators [4].GetComponent<LevelIndicator> ().setCurrent ();
			activeTilesArray.newQuickPlayPuzzle ();
			activeTilesArray.resetPuzzle ();

			puzzleNumMoves = activeTilesArray.puzzle.size;
			puzzleStack [0] = activeTilesArray.stack [0];
			puzzleStack [1] = activeTilesArray.stack [1];
			puzzleStack [2] = activeTilesArray.stack [2];
			checkStack ();
		} else {
			if (isTutorial) {
				if (level == 0) {
					tutorialText2.GetComponent<TextMesh> ().text = "clicking green affects tiles along its row and column";
					tutorialText1.GetComponent<TutorialText> ().disappear ();
					tutorialText2.GetComponent<TutorialText> ().appear ();
				} else if (level == 1) {
					tutorialText1.GetComponent<TextMesh> ().text = "clicking blue affects tiles diagonally";
					tutorialText2.GetComponent<TutorialText> ().disappear ();
					tutorialText1.GetComponent<TutorialText> ().appear ();
				} else if (level == 2) {
					tutorialText2.GetComponent<TextMesh> ().text = "to solve the puzzle you need to restore the base color to all tiles";
					tutorialText1.GetComponent<TutorialText> ().disappear ();
					tutorialText2.GetComponent<TutorialText> ().appear ();
				} else if (level == 3) {
					tutorialText1.GetComponent<TextMesh> ().text = "you can see the available moves and suggested order on the left";
					tutorialText2.GetComponent<TutorialText> ().disappear ();
					tutorialText1.GetComponent<TutorialText> ().appear ();
					GameObject.Find("StackOrder0").GetComponent<StackOrderImage>().blinkTutorial();
					GameObject.Find("StackOrder1").GetComponent<StackOrderImage>().blinkTutorial();
					GameObject.Find("TutorialArrow").transform.localRotation = Quaternion.Euler(0,0,0);
					GameObject.Find("TutorialArrow").transform.localPosition = new Vector3(-230,-700,4);
				} else if (level == 4) {
					tutorialText2.GetComponent<TextMesh> ().text = "look for patterns in the outer tiles to help you find the solution";
					tutorialText1.GetComponent<TutorialText> ().disappear ();
					tutorialText2.GetComponent<TutorialText> ().appear ();
					GameObject.Find("StackOrder0").GetComponent<StackOrderImage>().isBlinkingTutorial = false;
					GameObject.Find("StackOrder1").GetComponent<StackOrderImage>().isBlinkingTutorial = false;
					GameObject.Find("TutorialArrow").transform.localRotation = Quaternion.Euler(0,0,180);
					GameObject.Find("TutorialArrow").transform.localPosition = new Vector3(-200,-700,100);
				} else if (level == 5) {
					if (!isBeaconOn)
						toggleBeacon ();
					tutorialText1.GetComponent<TextMesh> ().text = "failing a puzzle will cost you a life and restart the puzzle";
					tutorialText2.GetComponent<TutorialText> ().disappear ();
					tutorialText1.GetComponent<TutorialText> ().appear ();
					GameObject.Find("TutorialArrow").transform.localPosition = new Vector3(185,-700,138);
				} else if (level == 6) {
					tutorialText2.GetComponent<TextMesh> ().text = "move the mouse over a tile to see a preview of your movement";
					tutorialText1.GetComponent<TutorialText> ().disappear ();
					tutorialText2.GetComponent<TutorialText> ().appear ();
					GameObject.Find("TutorialArrow").transform.localPosition = new Vector3(-230,0,4);
				} else if (level == 7) {
					tutorialText1.GetComponent<TextMesh> ().text = "each level consists of 10 puzzles";					
					tutorialText2.GetComponent<TutorialText> ().disappear ();
					tutorialText1.GetComponent<TutorialText> ().appear ();
					GameObject.Find("TutorialArrow").transform.localPosition = new Vector3(220,-700,4);
				} else if (level == 8) {
					tutorialText2.GetComponent<TextMesh> ().text = "solve 6 or more to pass the level";
					tutorialText1.GetComponent<TutorialText> ().disappear ();
					tutorialText2.GetComponent<TutorialText> ().appear ();
				} else if (level == 9) {
					tutorialText1.GetComponent<TextMesh> ().text = "";
					tutorialText2.GetComponent<TutorialText> ().disappear ();
					GameObject.Find("TutorialArrow").transform.localPosition = new Vector3(220,0,4);
				}
				
			}
			
			if (!isTutorial || level > 5)
				if (isBeaconOn)
					toggleBeacon ();
			if (livesLeft > 1 && !isTutorial)
				resetButton.GetComponent<ResetButton> ().makeAvailable ();
			if (passed)
				levelStars++;
			else
				numPuzzlesSkipped++;
			if (passed) {
				levelIndicators [level].GetComponent<LevelIndicator> ().setPassed ();
				if (!isTutorial)
					summaryLevelIndicators [level].GetComponent<LevelIndicator> ().setPassed ();
			} else {
				levelIndicators [level].GetComponent<LevelIndicator> ().setSkipped ();
				if (!isTutorial)
					summaryLevelIndicators [level].GetComponent<LevelIndicator> ().setSkipped ();
			}

			level++;
			if (level == 10) {
				level--;
				hideGUI ();
				showGameEndedScreen ();
			} else {
				levelIndicators [level].GetComponent<LevelIndicator> ().setCurrent ();
				if (!isTutorial)
					summaryLevelIndicators [level].GetComponent<LevelIndicator> ().setSkipped ();
				isAdvancingLevel = true;
				advancingLevelCounter = 0;
				activeTilesArray = tilesArray [level].GetComponent<TilesArray> ();
				activeTilesArray.bringForward ();
				activeTilesArray.resetPuzzle ();
				for (int i=level+1; i<10; i++)
					tilesArray [i].GetComponent<TilesArray> ().setBack ();
				puzzleNumMoves = activeTilesArray.puzzle.size;
				puzzleStack [0] = activeTilesArray.stack [0];
				puzzleStack [1] = activeTilesArray.stack [1];
				puzzleStack [2] = activeTilesArray.stack [2];
				checkStack ();
				if ((!isZoomedIn && activeTilesArray.GetComponent<TilesArray> ().puzzle.isZoomedIn) ||
					(isZoomedIn && !activeTilesArray.GetComponent<TilesArray> ().puzzle.isZoomedIn))
					toggleZoom ();
			}
			if (isTutorial && level < 3)
				activeTilesArray.setTutorialHints();
			if (isTutorial && level == 5)
				activeTilesArray.setTutorialHintsOuter();
			if (isTutorial && level == 6){
				activeTilesArray.tiles[2,2].beaconCount++;
				activeTilesArray.tiles[4,2].beaconCount--;
				activeTilesArray.tiles[4,3].beaconCount--;
			}
		}
	}
예제 #3
0
파일: Game.cs 프로젝트: mgartz/skwer_unity
	public void quickRebuild (){
		level = 0;
		cameraArray.transform.position = rebuildingTargetLocation;
		isRebuildingStack = false;
		for (int i=0; i<10; i++)
			tilesArray [i].GetComponent<TilesArray> ().quickRebuildStack ();
		for (int i=1; i<10; i++)
			tilesArray [i].GetComponent<TilesArray> ().setBack2 (tilesArray[0].GetComponent<TilesArray>().puzzle.baseState);

		livesLeft = Global.getGameLives();
		livesArray.setLives(livesLeft);

		showGUI ();
		activeTilesArray = tilesArray [0].GetComponent<TilesArray> ();
		activeTilesArray.resetPuzzleFromScratch ();
		activeTilesArray.bringForward ();
		
		checkStack ();
		levelIndicators [0].GetComponent<LevelIndicator> ().setCurrent ();
		for (int i=1; i<10; i++)
			levelIndicators [i].GetComponent<LevelIndicator> ().setNull ();
	}