void Awake() { if (mInstance != null) { throw new UnityException("Error in CGame(). You are not allowed to instantiate it more than once."); } //CGameConstants.HIGH_SCORE =int.Parse( System.IO.File.ReadAllText("score.txt")); mInstance = this; CMouse.init(); CurrentStageData.init(); LevelsInfo.init(); imgBackground = new CSprite(); //Handheld.PlayFullScreenMovie("IntroGame2.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput); setState(new CMenuState()); mSpriteManager = new CSpriteManager(); //setImage("Sprites/Placeholders_Prototype/level_Background"); }
public CSurvivalState(CInfo stageInfo) { CGame.inst().setImage("Sprites/level_Background00"); CurrentStageData.clearData(); SoundList.instance.playLevelMusic(); tryAgainInfo = stageInfo; switch (stageInfo.Kaiju) { case 1: monster = new Dinosaur(stageInfo.startStage, stageInfo.firstStage, stageInfo.secondStage); break; case 2: monster = new Kong(stageInfo.startStage, stageInfo.firstStage, stageInfo.secondStage); break; case 3: monster = new Kraken(stageInfo.startStage, stageInfo.firstStage, stageInfo.secondStage); break; } current_state = STATE_PLAYING; CurrentStageData.difficulty = 0; mBoard = new Board(1); building = new Enemy(0); timeLeft = new CText("Time: ", CText.alignment.TOP_CENTER); timeLeft.setX(0); timeLeft.setY(0); timeLeft.setColor(Color.black); scoreText = new CText("SCORE :", CText.alignment.TOP_CENTER); scoreText.setX(400); scoreText.setY(0); scoreText.setColor(Color.black); btnNextScreen = new CSprite(); btnNextScreen.setSortingLayer("TextUI"); mBoard.targetScore = stageInfo.TargetScore; // MOVE TO CLASS float scoreCoefficient = (float)70 / (float)mBoard.targetScore; skills = new SkillBar(stageInfo.Kaiju); mTimer = new Timer(); CurrentStageData.assignData(monster, mBoard, scoreCoefficient, skills); CurrentStageData.assignTimer(mTimer); screenDim = new CSprite(); screenDim.setSortingLayer("ScreenShade"); screenDim.setName("Sombra"); backMenuBttn = new CSprite(); backMenuBttn.setSortingLayer("TextUI"); tryAgainBttn = new CSprite(); tryAgainBttn.setSortingLayer("TextUI"); optionsBttn = new CSprite(); optionsBttn.setImage(Resources.Load <Sprite>("Sprites/Buttons/Pause_Button")); optionsBttn.setXY(680, 40); optionsBttn.setSortingLayer("TextUI"); }
public void destroy() { CMouse.destroy(); CurrentStageData.destroy(); //CSpriteManager.destroy(); if (mState != null) { mState.destroy(); mState = null; } mInstance = null; }
public CLevelState(int stageNumber) { SoundList.instance.playLevelMusic(); CInfo stageInfo = LevelsInfo.getLevel(stageNumber); CGame.inst().setImage("Sprites/level_Background0" + stageInfo.building.ToString()); CurrentStageData.currentStage = stageNumber; switch (stageInfo.Kaiju) { case 1: monster = new Dinosaur(stageInfo.startStage, stageInfo.firstStage, stageInfo.secondStage); break; case 2: monster = new Kong(stageInfo.startStage, stageInfo.firstStage, stageInfo.secondStage); break; case 3: monster = new Kraken(stageInfo.startStage, stageInfo.firstStage, stageInfo.secondStage); break; } current_state = STATE_PLAYING; CurrentStageData.difficulty = stageInfo.dif; mBoard = new Board(0); //monster = new Kong(1, 53, 76); building = new Enemy(stageInfo.building); mText = new CText("TEST", CText.alignment.TOP_CENTER); mText.setX(0); mText.setY(0); mText.setColor(Color.black); mBoard.movementsLeft = stageInfo.movements; // MOVE TO CLASS mBoard.targetScore = stageInfo.TargetScore; // MOVE TO CLASS float scoreCoefficient = (float)70 / (float)mBoard.targetScore; skills = new SkillBar(stageInfo.Kaiju); CurrentStageData.assignData(monster, mBoard, scoreCoefficient, skills); screenDim = new CSprite(); screenDim.setSortingLayer("ScreenShade"); screenDim.setName("Sombra"); backMenuBttn = new CSprite(); backMenuBttn.setSortingLayer("TextUI"); tryAgainBttn = new CSprite(); tryAgainBttn.setSortingLayer("TextUI"); btnNextScreen = new CSprite(); btnNextScreen.setSortingLayer("TextUI"); optionsBttn = new CSprite(); optionsBttn.setImage(Resources.Load <Sprite>("Sprites/Buttons/Pause_Button")); optionsBttn.setXY(680, 40); optionsBttn.setSortingLayer("TextUI"); }
public string[] GetEditorMapData() { //CurrentStageData int sizey = CurrentStageData.GetLength(0); int sizex = CurrentStageData.GetLength(1); EditorStageData = new string[sizey]; string tempstr = ""; for (int y = 0; y < sizey; y++) { tempstr = ""; for (int x = 0; x < sizex; x++) { tempstr = string.Format("{0}{1}", tempstr, CurrentStageData[y, x]); } EditorStageData[y] = tempstr; } return(EditorStageData); }
override public void update() { base.update(); //CSpriteManager.update(); CMouse.update(); if (current_state == STATE_PAUSE) { if (nextScreenClick()) { screenDim.setImage(null); backMenuBttn.setImage(null); btnNextScreen.setImage(null); current_state = STATE_PLAYING; } if (backToMenuClick()) { SoundList.instance.stopMusic(); SoundList.instance.playMenuMusic(); CGame.inst().setState(new CMenuState()); return; } return; } mBoard.update(); monster.update(); building.update(); screenDim.update(); mTimer.update(); optionsBttn.update(); skills.update(); backMenuBttn.update(); tryAgainBttn.update(); btnNextScreen.update(); timeLeft.setText("TIME: " + (int)(CurrentStageData.currentTimer.getTimeLeft())); timeLeft.update(); scoreText.setText("SCORE: " + (CurrentStageData.score * 10)); scoreText.update(); switch (current_state) { case STATE_PLAYING: if (optionsClick()) { current_state = STATE_PAUSE; backMenuBttn.setImage(Resources.Load <Sprite>("Sprites/BackMenuButton")); backMenuBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2); screenDim.setImage(Resources.Load <Sprite>("Sprites/screenShade")); screenDim.setX(0); screenDim.setY(0); btnNextScreen.setImage(Resources.Load <Sprite>("Sprites/Buttons/Button_Continue")); btnNextScreen.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2 + 150); return; } if (mBoard.current_state == 0) { if (CurrentStageData.currentKaiju.scale >= 100) { current_state = STATE_WIN; SoundList.instance.stopMusic(); monster.setState(4); building.setState(1); } else { screenDim.setImage(Resources.Load <Sprite>("Sprites/screenShade")); screenDim.setX(0); screenDim.setY(0); current_state = STATE_LOSE; backMenuBttn.setImage(Resources.Load <Sprite>("Sprites/BackMenuButton")); backMenuBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2); tryAgainBttn.setImage(Resources.Load <Sprite>("Sprites/tryAgainButton")); tryAgainBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2 + 100); monster.setState(2); } } break; case STATE_WIN: CGameConstants.HIGH_SCORE = CurrentStageData.score; //System.IO.File.WriteAllText("score.txt", CurrentStageData.score.ToString()); tryAgainInfo.TargetScore = CurrentStageData.score; if (!building.building.isEnded()) { CurrentStageData.cameraShake(); } else { screenDim.setImage(Resources.Load <Sprite>("Sprites/screenShade")); screenDim.setX(0); screenDim.setY(0); backMenuBttn.setImage(Resources.Load <Sprite>("Sprites/BackMenuButton")); backMenuBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2); tryAgainBttn.setImage(Resources.Load <Sprite>("Sprites/tryAgainButton")); tryAgainBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2 + 100); if (backToMenuClick()) { CurrentStageData.clearData(); SoundList.instance.stopMusic(); SoundList.instance.playMenuMusic(); CGame.inst().setState(new CMenuState()); return; } if (tryAgainClick()) { CurrentStageData.clearData(); CGame.inst().setState(new CSurvivalState(tryAgainInfo)); return; } if (Camera.main.transform.position.x > 360) { Camera.main.transform.Translate(new Vector3(-15, 0, 0)); } if (Camera.main.transform.position.x < 360) { Camera.main.transform.Translate(new Vector3(15, 0, 0)); } } break; case STATE_LOSE: if (backToMenuClick()) { CurrentStageData.clearData(); SoundList.instance.stopMusic(); SoundList.instance.playMenuMusic(); CGame.inst().setState(new CMenuState()); return; } if (tryAgainClick()) { CurrentStageData.clearData(); CGame.inst().setState(new CSurvivalState(tryAgainInfo)); return; } break; } }
public void countScore() { float totalScore = 0; int lastType; //recorrida por fila for (int i = 0; i < matrixBoard.Count(); i++) { for (int j = 0; j < matrixBoard[i].Count(); j++) { int count = 1; lastType = -1; if (matrixBoard[i][j].food.matched & j + 1 < matrixBoard[i].Count()) { while (matrixBoard[i][j + 1].food.Type == matrixBoard[i][j].food.Type) { lastType = matrixBoard[i][j].food.Type; count++; j++; if (j >= matrixBoard[i].Count() - 1) { break; } } if (count >= 3) { float auxScore = 3; float multiplier = 1; if (lastType == 3) { auxScore = 2; } if (lastType == CurrentStageData.currentKaiju.prefferedFood) { auxScore = 5; CurrentStageData.currentKaiju.setState(1); SoundList.instance.playComer(); } else if (lastType == 4) { SoundList.instance.playBomb(); auxScore = -4; } switch (count) { case 3: multiplier = 1; break; case 4: multiplier = 1.5f; break; case 5: multiplier = 2.0f; break; case 6: multiplier = 2.5f; break; } auxScore = auxScore * multiplier; totalScore += auxScore; } count = 1; } } } //recorrida por columna for (int j = 0; j < matrixBoard.Count(); j++) { for (int i = 0; i < matrixBoard.Count(); i++) { int count = 1; lastType = -1; if (matrixBoard[i][j].food.matched & i + 1 < matrixBoard.Count()) { while (matrixBoard[i + 1][j].food.Type == matrixBoard[i][j].food.Type) { lastType = matrixBoard[i][j].food.Type; count++; i++; if (i >= matrixBoard.Count() - 1) { break; } } if (count >= 3) { float auxScore = 3; float multiplier = 1; if (lastType == 3) { auxScore = 2; } if (lastType == CurrentStageData.currentKaiju.prefferedFood) { auxScore = 5; CurrentStageData.currentKaiju.setState(1); SoundList.instance.playComer(); } else if (lastType == 4) { SoundList.instance.playBomb(); auxScore = -4; } switch (count) { case 3: multiplier = 1; break; case 4: multiplier = 1.5f; break; case 5: multiplier = 2.0f; break; case 6: multiplier = 2.5f; break; } auxScore = auxScore * multiplier; totalScore += auxScore; } count = 1; } } } if (totalScore < 0) { CSpriteManager.inst().add(new ArrowAnimation(4)); } else if (totalScore < 3) { CSpriteManager.inst().add(new ArrowAnimation(3)); } else if (totalScore < 5) { CSpriteManager.inst().add(new ArrowAnimation(3)); CSpriteManager.inst().add(new ArrowAnimation(3, 1)); } else { CSpriteManager.inst().add(new ArrowAnimation(2)); } if (totalScore > 9) { CSpriteManager.inst().add(new ArrowAnimation(2)); CSpriteManager.inst().add(new ArrowAnimation(2, 1)); } if (totalScore > 15) { CSpriteManager.inst().add(new ArrowAnimation(2, 2)); } if (totalScore > 0) { SoundList.instance.playMatch(); } CurrentStageData.addScore(totalScore); }
override public void update() { base.update(); //CSpriteManager.update(); CMouse.update(); if (current_state == STATE_PAUSE) { if (nextScreenClick()) { screenDim.setImage(null); backMenuBttn.setImage(null); btnNextScreen.setImage(null); current_state = STATE_PLAYING; } if (backToMenuClick()) { SoundList.instance.stopMusic(); SoundList.instance.playMenuMusic(); CGame.inst().setState(new CMenuState()); return; } return; } mBoard.update(); monster.update(); building.update(); screenDim.update(); mText.setText("Moves: " + mBoard.getMovementsLeft().ToString()); mText.update(); btnNextScreen.update(); optionsBttn.update(); skills.update(); backMenuBttn.update(); tryAgainBttn.update(); switch (current_state) { case STATE_PLAYING: if (optionsClick()) { current_state = STATE_PAUSE; backMenuBttn.setImage(Resources.Load <Sprite>("Sprites/BackMenuButton")); backMenuBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2); screenDim.setImage(Resources.Load <Sprite>("Sprites/screenShade")); screenDim.setX(0); screenDim.setY(0); btnNextScreen.setImage(Resources.Load <Sprite>("Sprites/Buttons/Button_Continue")); btnNextScreen.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2 + 150); return; } if (mBoard.current_state == 0) { if (CurrentStageData.currentKaiju.scale >= 100) { current_state = STATE_WIN; SoundList.instance.stopMusic(); monster.setState(4); building.setState(1); } else { screenDim.setImage(Resources.Load <Sprite>("Sprites/screenShade")); screenDim.setX(0); screenDim.setY(0); //nextScreen.setVisible(true); current_state = STATE_LOSE; backMenuBttn.setImage(Resources.Load <Sprite>("Sprites/BackMenuButton")); backMenuBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2); tryAgainBttn.setImage(Resources.Load <Sprite>("Sprites/tryAgainButton")); tryAgainBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2 + 150); monster.setState(2); } } break; case STATE_WIN: if (!building.building.isEnded()) { CurrentStageData.cameraShake(); } else { screenDim.setImage(Resources.Load <Sprite>("Sprites/screenShade")); screenDim.setX(0); screenDim.setY(0); btnNextScreen.setImage(Resources.Load <Sprite>("Sprites/Buttons/Button_Continue")); btnNextScreen.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2); if (nextScreenClick()) { CurrentStageData.clearData(); if (CurrentStageData.currentStage >= LevelsInfo.getLevelsAmount()) { SoundList.instance.stopMusic(); SoundList.instance.playMenuMusic(); CGame.inst().setState(new CMenuState()); } else { CGame.inst().setState(new CLevelState(CurrentStageData.currentStage + 1)); } } if (Camera.main.transform.position.x > 360) { Camera.main.transform.Translate(new Vector3(-15, 0, 0)); } if (Camera.main.transform.position.x < 360) { Camera.main.transform.Translate(new Vector3(15, 0, 0)); } } break; case STATE_LOSE: if (backToMenuClick()) { backMenuBttn.setImage(Resources.Load <Sprite>("Sprites/BackMenuButton_P")); current_state = GO_BACKMENU; return; } if (tryAgainClick()) { tryAgainBttn.setImage(Resources.Load <Sprite>("Sprites/tryAgainButton_P")); current_state = GO_TRYAGAIN; return; } break; case GO_BACKMENU: CurrentStageData.clearData(); SoundList.instance.stopMusic(); SoundList.instance.playMenuMusic(); CGame.inst().setState(new CMenuState()); return; case GO_TRYAGAIN: CurrentStageData.clearData(); CGame.inst().setState(new CLevelState(CurrentStageData.currentStage)); return; } }