/// <summary> /// Initialize this system to a working state. /// </summary> /// <param name="game"> /// The <see cref="IGame"/> game, that requested the initialization. That is the game, /// the system will be running in. /// </param> public override void Initialize(IGame game) { base.Initialize(game); // Register the component types, required by this system. Since this // system uses a state machine, it also needs to register all types // of components, required by the individual states. this.Game.ComponentSystem.RegisterComponentType <LevelComponent>(); this.Game.ComponentSystem.RegisterComponentType <BallComponent>(); this.Game.ComponentSystem.RegisterComponentType <DestructableComponent>(); this.Game.ComponentSystem.RegisterComponentType <PlayerComponent>(); // Register the events, required by this system this.Game.EventManager.RegisterListener(BreakoutEvents.LoadLevel, this.OnLoadLevel); // These events are contained in state implementations, when using the // StateMachine-based implementation. They are registered and removed // when entering and exiting the LevelPlayingState respectively. Because // the registration is done here, the event handlers need to check their // state of course. this.Game.EventManager.RegisterListener(ComponentSystemEvents.ComponentDestroyed, this.OnComponentDestroyed); this.Game.EventManager.RegisterListener(BreakoutEvents.LevelLoaded, this.OnLevelLoaded); // And finally, set the initial state this.state = LevelStates.Spawn; }
// Use this for initialization void Start() { Time.timeScale = 0.0f; //Set the current State currentState = LevelStates.Introduction; //suiosfa //gameRewards = Instantiate(gameRewards) as Rewards; //Create the stats. BreathlessStats = Instantiate(GameObjectTracker.instance._PlayerData.BlankStatistics) as Statistics; //SocialCenter.Instance.LoadLeaderboard("Highscore_PPS"); //SocialCenter.Instance.ProcessLeaderboardScores(); opentimer = 0.0f; //Start time. if (!ToyBox.GetPandora()) { Debug.LogError("NO F TOYBOX!"); return; } ToyBox.GetPandora().TimePaused = true; ToyBox.GetPandora().SceneBallStack.NumberBalls = 30; //started = true; }
/// <summary> /// Update the system in paused state. /// </summary> private void EnterSpawnState() { this.state = LevelStates.Spawn; int ballCount = 0; foreach (PlayerComponent player in this.Game.ComponentSystem.Components <PlayerComponent>()) { if (player.Lives > 0) { this.Game.EventManager.QueueEvent(new HelGamesEvent(BreakoutEvents.SpawnBallsForPlayer, player)); ballCount++; } } if (ballCount > 0) { this.EnterPausedState(); } else { this.EnterLevelFailedState(); } }
public void toggleState() { if (currentLevelState.Equals(LevelStates.Build)) { currentLevelState = LevelStates.Workday; timeOfDayText.text = "Workday"; currentHour = 0; generalTimer1 = 0; generalTimer2 = (0.1f * bossLevel * 10.0f) + 10.0f; makeMoney = true; buildPhaseOnlyUIItems.SetActive(false); } else if (currentLevelState.Equals(LevelStates.Workday)) { currentLevelState = LevelStates.Night; timeOfDayText.text = "Night"; makeMoney = true; buildPhaseOnlyUIItems.SetActive(false); } else if (currentLevelState.Equals(LevelStates.Night)) { currentLevelState = LevelStates.Build; timeOfDayText.text = "Early Morning"; curTimeText.text = "7:59 am"; makeMoney = false; ++bossLevel; currentDayText.text = "Day " + bossLevel; Inventory.inv.increasePay(bossLevel * 5); buildPhaseOnlyUIItems.SetActive(true); } }
/// <summary> /// Update the system in paused state. /// </summary> private void UpdateLevelFailedState() { if (Input.GetButtonUp(this.PlayPauseButtonName)) { this.Game.EventManager.QueueEvent(new HelGamesEvent(BreakoutEvents.LoadLevel, this.StartLevelIndex)); this.state = LevelStates.Loading; } }
public override void Load() { SetCostume("levelup"); Scale = 0.5f; GhostEffect = 100; Layer = 60; State = LevelStates.Waiting; Hide(); }
IEnumerator PlayIntro() { _introAnimationRunning = true; IntroAnimationReady.SetTrigger("Ready"); yield return(new WaitForSeconds(IntroDuration)); _introAnimationRunning = false; onStateChange(LevelManager.LevelStates.Running); currentState = LevelStates.Running; }
// display a message that a checkpoint has been reached // trigger this through a camera transition post delay event // // *** now it's triggered through the checkpoint system event *** public void CheckpointReached() { StartCoroutine(CoCheckpointReached()); // switch to the checkpoint state levelState = LevelStates.Checkpoint; // as an example we'll move a wall to block us in and disable the trigger Vector3 wallPos = wallLeft.transform.position; wallPos.x = wallLeftXPos1; wallLeft.transform.position = wallPos; //checkpointTrigger.SetActive(false); }
public void SetStage(byte stage) { if (stage >= 1 && stage <= 3) { this.currStage = (LevelStates)stage; RespawnData.CurrStage = (byte)this.currStage; hasChanged = true; } else { Debug.Log("INVALID STAGE NUMBER"); } }
public override void CannonPickedUp() { // //If we are at the intro stage, move on to the start of the game upon picking up the cannon. if (currentState == LevelStates.Introduction) { //Begin the phasing level. currentState = LevelStates.Phasing; //Stop our audio. //audio.Stop(); //Start teh game statistics counter. GameObjectTracker.GetGOT().StartGame(); } }
public void setState(LevelStates state) { currentLevelState = state; if (currentLevelState.Equals(LevelStates.Workday)) { timeOfDayText.text = "Workday"; generalTimer1 = 0; generalTimer2 = (0.15f * bossLevel * 10.0f) + 10.0f; } else if (currentLevelState.Equals(LevelStates.Build)) { buildPhaseOnlyUIItems.SetActive(true); } }
public void gotCaught() { makeMoney = false; generalTimer1 = generalTimer2; currentLevelState = LevelStates.Night; if (!Inventory.inv.penalty(generalTimer1 / generalTimer2, bossLevel)) { //Lost the game messagesScript.firedMessage(); StartCoroutine(fired()); } else { messagesScript.displayMessage(); } }
private void LoadAnimation() { if (_lvlState != LevelStates.LsLoadFields) { return; } var allReady = true; allReady &= _levelFeld[_startXy[0], _startXy[1]].State == Field.FieldStates.FsAlive; allReady &= _rCube.State == RollingCube.CubeStates.CsAlive; if (allReady) { _lvlState = LevelStates.LsPlaying; } }
void onStateCycle() { switch (currentState) { case LevelManager.LevelStates.Setup: onStateChange(LevelManager.LevelStates.Intro); currentState = LevelStates.Intro; _introDelayTimer = Time.time + IntroDuration; LevelText.text = GameManager.Instance.CurrentLevel.ToString(); break; case LevelManager.LevelStates.Intro: if (!_introAnimationRunning) { StartCoroutine(PlayIntro()); } break; case LevelManager.LevelStates.Running: if (_levelLengthTimer == 0) { _levelLengthTimer = Time.time + LevelLength; } else { if (Time.time >= _levelLengthTimer) { currentState = LevelStates.Complete; onStateChange(LevelStates.Complete); } } break; case LevelManager.LevelStates.Paused: break; case LevelStates.GameOver: DisplayGameOver(); break; case LevelStates.Complete: GameManager.Instance.CompleteLevel(); DisplayLevelComplete(); break; } }
private void WeaponPartCollected() { /* * this is our cue that the player has captured the weapon part and we * should signal the game manager to end the level, tally up the points, * and move on to the level selection screen to pick another boss */ // get start time startTime = Time.time; // play victory theme clip SoundManager.Instance.MusicSource.volume = 1f; SoundManager.Instance.PlayMusic(victoryThemeClip, false); // freeze the player and input GameManager.Instance.FreezePlayer(true); // switch state the player victory levelState = LevelStates.PlayerVictory; }
private void ResetLevel() { _lvlState = LevelStates.LsLoadFields; foreach (var feld in _levelFeld) { if (feld != null) { feld.ResetField(); } } if (_rCube != null) { _rCube.ResetCube(_startXy[0], _startXy[1]); } }
private void Update() { switch (currentLevelState) { case LevelStates.Prepare: break; case LevelStates.MainGame: MovePlayer(); //MoveWithKeyboard(); SelectObject(); break; case LevelStates.Finish: break; case LevelStates.War: SelectAtWar(); break; default: throw new ArgumentOutOfRangeException(); } if (Input.GetKeyDown(KeyCode.E)) { playerController.playerAnimator.SetTrigger("Spiderman"); } if (currentLevelState != LevelStates.Finish && currentLevelState != LevelStates.Prepare) { dayTimer += Time.deltaTime; timerText.text = (maxDayTime - dayTimer).ToString(".0"); if (dayTimer >= maxDayTime) { currentLevelState = LevelStates.Finish; ShowDayPanel(); } } }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime) { if (State == LevelStates.Appearing) { GhostEffect -= 1f; if (GhostEffect < 1) { State = LevelStates.Fading; } } if (State == LevelStates.Fading) { GhostEffect += 1f; if (GhostEffect > 99) { Disappear(); } } }
/// <summary> /// Update the system in paused state. /// </summary> private void UpdateLevelFinishedState() { if (Input.GetButtonUp(this.PlayPauseButtonName)) { // Load the new level additive int nextLevelIndex = Application.loadedLevel + 1; if (nextLevelIndex >= Application.levelCount) { nextLevelIndex = this.StartLevelIndex; } // Now queue the component manager update and send the transition event. this.Game.EventManager.QueueEvent(new HelGamesEvent(BreakoutEvents.LoadLevel, nextLevelIndex)); // Since there is no explicit call to enter the loading state (because it doesn't // require any additional logic), the state is set directly. This could easily // be done in a separate method, but since it is only one line, it is acceptable // to just do it here directly. Should any logic be added to entering the failed // state, it would need its own method. this.state = LevelStates.Loading; } }
// Use this for initialization void Awake() { // Debug.Log("Demo Level: " + RespawnData.HasRestarted); // Debug.Log("Demo Level: " + RespawnData.CurrStage); Physics2D.IgnoreLayerCollision(8, 10); player = GameObject.FindGameObjectWithTag("Player"); if (RespawnData.HasRestarted == true) { currStage = (LevelStates)RespawnData.CurrStage; switch (currStage) { case LevelStates.STAGE1: Debug.Log("STAGE 1"); player.transform.position = Stage1Pos; break; case LevelStates.STAGE2: Debug.Log("STAGE 2"); Stage2(); player.transform.position = Stage2Pos; break; case LevelStates.STAGE3: Debug.Log("STAGE 3"); Stage3(); player.transform.position = Stage3Pos; break; } RespawnData.HasRestarted = false; } else { currStage = LevelStates.STAGE1; } }
private void DeadLevel() { _lvlState = LevelStates.LsDying; _rCube.DeadCube(); }
public void Restart() { state = LevelStates.Restarting; }
// Reset common settings and change state private void ChangeLevelState(LevelStates _ls) { AttackTimer = 0; AttackStage = 0; LevelState = _ls; }
private void LoadAnimation() { if (_lvlState != LevelStates.LsLoadFields) return; var allReady = true; allReady &= _levelFeld[_startXy[0], _startXy[1]].State == Field.FieldStates.FsAlive; allReady &= _rCube.State == RollingCube.CubeStates.CsAlive; if (allReady) _lvlState = LevelStates.LsPlaying; }
/// <summary> /// Enter the level finished state. /// </summary> private void EnterLevelFailedState() { this.state = LevelStates.LevelFailed; this.Game.EventManager.QueueEvent(new HelGamesEvent(BreakoutEvents.Pause, null)); this.Game.EventManager.QueueEvent(new HelGamesEvent(BreakoutEvents.LevelFailed, null)); }
// Update is called once per frame void Update() { // this is for seeing the run time of the scene and is helpful for making // the storytelling triggers - use checkbox in inspector to turn it off runTimeText.text = showRunTime ? String.Format("RunTime: {0:0.00}", runTime) : ""; switch (levelState) { case LevelStates.Exploration: if (player != null) { if (player.transform.position.x >= startSniperJoePoint && !sniperJoeEnabled) { // find Sniper Joe and enable his AI GameObject sniperJoe = GameObject.Find("SniperJoe"); if (sniperJoe != null) { sniperJoeEnabled = true; sniperJoe.GetComponent <SniperJoeController>().EnableAI(true); } } if (player.transform.position.x >= startSeqBeginPoint1 && player.transform.position.y < 0.3f) { // get start time startTime = Time.time; // freeze the player input and stop movement player.GetComponent <PlayerController>().Invincible(true); player.GetComponent <PlayerController>().FreezeInput(true); Vector2 playerVelocity = player.GetComponent <Rigidbody2D>().velocity; player.GetComponent <Rigidbody2D>().velocity = new Vector2(0, playerVelocity.y); // freeze everything during little cutscene GameManager.Instance.FreezeEverything(true); // don't allow the game to be paused GameManager.Instance.AllowGamePause(false); // go to the dr. light hologram state levelState = LevelStates.Hologram; } // warp ahead to skip the intro to speed along development if (Input.GetKeyDown(KeyCode.W)) { // move player, set new camera coords and bounds, advance level state player.transform.position = new Vector2(18f, -1.14f); Camera.main.transform.position = new Vector3(18f, 0, -10f); Camera.main.GetComponent <CameraFollow>().boundsMin = new Vector3(12.2f, 0); Camera.main.GetComponent <CameraFollow>().boundsMax = new Vector3(18f, 0.3f); levelState = LevelStates.Checkpoint; } } break; case LevelStates.Hologram: // how long has this sequence been running for runTime = Time.time - startTime; // move player forward a bit and stop to show hologram if (UtilityFunctions.InTime(runTime, 2.0f, 5.0f)) { if (player.transform.position.x <= startSeqEndPoint1) { player.GetComponent <PlayerController>().SimulateMoveRight(); } else { player.GetComponent <PlayerController>().SimulateMoveStop(); } } // allow the dr. light storyline to be skipped by pressing any key // start at the 5 second mark so megaman can run into position // advance ahead to 24 seconds where the dialogue is removed // and dr. light's hologram will flicker out if (UtilityFunctions.InTime(runTime, 5.0f, 24.0f)) { if (Input.anyKey) { // only allow this one time if (!skipDrLightDialogue) { skipDrLightDialogue = true; // advance the runtime marker // and adjust the start time runTime = 24.0f; startTime = Time.time - runTime; } } } // dr. light says he can't stay long if (UtilityFunctions.InTime(runTime, 5.0f)) { dialogueBox.SetActive(true); dialogueText.text = dialogueStrings[0]; } // dr. light says his hologram is unstable if (UtilityFunctions.InTime(runTime, 9.0f)) { dialogueText.text = dialogueStrings[1]; } // megaman says he hasn't seen any disturbance if (UtilityFunctions.InTime(runTime, 13.0f)) { dialogueText.text = dialogueStrings[2]; } // dr. light says keep looking if (UtilityFunctions.InTime(runTime, 17.0f)) { dialogueText.text = dialogueStrings[3]; } // megaman says he'll contact dr. light soon if (UtilityFunctions.InTime(runTime, 21.0f)) { dialogueText.text = dialogueStrings[4]; } // hide dialogue box if (UtilityFunctions.InTime(runTime, 24.0f)) { dialogueText.text = ""; dialogueBox.SetActive(false); } // flicker out dr. light hologram if (UtilityFunctions.InTime(runTime, 25.0f)) { StartCoroutine(FlickerOutHologram()); } // give user player control back and move to next state if (UtilityFunctions.InTime(runTime, 28.0f)) { player.GetComponent <PlayerController>().Invincible(false); player.GetComponent <PlayerController>().FreezeInput(false); // unfreeze everything after little cutscene GameManager.Instance.FreezeEverything(false); // allow the game to be paused GameManager.Instance.AllowGamePause(true); // explore some more and proceed to the checkpoint levelState = LevelStates.KeepLooking; } break; case LevelStates.KeepLooking: // now out of the hologram state // we don't really do anything here // we'll use our checkpoint function to switch states break; case LevelStates.Checkpoint: // player can't move back so we look for the player reaching // x coordinate to activate the boss fight intro state if (player != null) { if (player.transform.position.x >= startSeqBeginPoint2) { // get start time startTime = Time.time; // freeze the player input and stop movement player.GetComponent <PlayerController>().FreezeInput(true); Vector2 playerVelocity = player.GetComponent <Rigidbody2D>().velocity; player.GetComponent <Rigidbody2D>().velocity = new Vector2(0, playerVelocity.y); // don't allow the game to be paused GameManager.Instance.AllowGamePause(false); // go to the boss fight intro state levelState = LevelStates.BossFightIntro; } } break; case LevelStates.BossFightIntro: // how long has this sequence been running for runTime = Time.time - startTime; // move player forward a bit and stop in front of the boss if (UtilityFunctions.InTime(runTime, 2.0f, 5.0f)) { if (player.transform.position.x <= startSeqEndPoint2) { player.GetComponent <PlayerController>().SimulateMoveRight(); } else { player.GetComponent <PlayerController>().SimulateMoveStop(); } } // move the left wall to block in megaman and the boss plus change the camera bounds if (UtilityFunctions.InTime(runTime, 2.0f)) { // move the left wall Vector3 wallPos = wallLeft.transform.position; wallPos.x = wallLeftXPos2; wallLeft.transform.position = wallPos; // change the camera bounds and speed // snap the camera to our boss fight area Camera.main.GetComponent <CameraFollow>().timeOffset = timeOffset; Camera.main.GetComponent <CameraFollow>().boundsMin = minCamBounds; Camera.main.GetComponent <CameraFollow>().boundsMax = maxCamBounds; } // start fight music if (UtilityFunctions.InTime(runTime, 3.5f)) { SoundManager.Instance.StopMusic(); SoundManager.Instance.MusicSource.volume = 1f; SoundManager.Instance.PlayMusic(bossFightClip); } // show the enemy health bar if (UtilityFunctions.InTime(runTime, 5.0f)) { UIEnergyBars.Instance.SetValue(UIEnergyBars.EnergyBars.EnemyHealth, 0); UIEnergyBars.Instance.SetImage(UIEnergyBars.EnergyBars.EnemyHealth, UIEnergyBars.EnergyBarTypes.BombMan); UIEnergyBars.Instance.SetVisibility(UIEnergyBars.EnergyBars.EnemyHealth, true); } // do bombman's pose if (UtilityFunctions.InTime(runTime, 6.5f)) { enemy.GetComponent <BombManController>().Pose(); } // fill enemy health bar and play sound clip if (UtilityFunctions.InTime(runTime, 7.0f)) { StartCoroutine(FillEnemyHealthBar()); } // battle starts, enable boss ai and give player control if (UtilityFunctions.InTime(runTime, 8.5f)) { enemy.GetComponent <BombManController>().EnableAI(true); player.GetComponent <PlayerController>().FreezeInput(false); // allow the game to be paused GameManager.Instance.AllowGamePause(true); // move on to BossFight state levelState = LevelStates.BossFight; } break; case LevelStates.BossFight: /* * do stuff during the boss fight state (anything really) * * we have an event function that gets called when the boss is defeated and * there is an action attached to the bonus item event listener (Weapon Part) * when the player captures the weapon part then we can finish the level * * what we'll do during our boss fight is watch the music's time position * and reset it to a position so it will constantly loop while the fight is * going. if you listen to the music it's different in the beginning from * where it loops. an alternative is to break the audio into two clips * and play the "intro" first and then the "loop". I find it a little much. * * The values I use for the clip loop start and end are guesstimates. Trying * to figure out precisely where a sound loops in an audio file is like meh. */ // look for time end and set new position when found if (SoundManager.Instance.MusicSource.time >= 15.974f) { SoundManager.Instance.MusicSource.time = 3.192f; } break; case LevelStates.PlayerVictory: // how long has this sequence been running for runTime = Time.time - startTime; // have game manager do the score tally if (UtilityFunctions.InTime(runTime, 7.0f)) { GameManager.Instance.TallyPlayerScore(); } // reset the points collected and go to next scene state if (UtilityFunctions.InTime(runTime, 15.0f)) { GameManager.Instance.ResetPointsCollected(true, false); // switch to the next scene state levelState = LevelStates.NextScene; } break; case LevelStates.NextScene: // tell GameManager to trigger the next scene if (!calledNextScene) { GameManager.Instance.StartNextScene(GameManager.GameScenes.MainScene); calledNextScene = true; } break; } }
/// <summary> /// Enter the paused state. /// </summary> private void EnterPlayingState() { this.state = LevelStates.Playing; this.Game.EventManager.QueueEvent(new HelGamesEvent(BreakoutEvents.Continue, null)); }
void Update() { TargetsDestroyed = 0; if (f_t[0].IsDisabled) { TargetsDestroyed++; } if (f_t[1].IsDisabled) { TargetsDestroyed++; } if (f_t[2].IsDisabled) { TargetsDestroyed++; } if (f_t[3].IsDisabled) { TargetsDestroyed++; } if (f_t[4].IsDisabled) { TargetsDestroyed++; } ScoreScript.tgt = TargetsDestroyed; PlayerPosition = ServiceProvider.Instance.PlayerAircraft.MainCockpitPosition; if (ClosestDistanceScript.closest < 3000) { FailMission = true; } if (LevelState == LevelStates.Start) { // Squadron is near the player if ((fighters[0].transform.position - PlayerPosition).magnitude < 5000) { for (int i = 0; i < fighters.Length; i++) { fighters[i].EnemyState = FighterScript.EnemyStates.Behind; } AttackTimer = Random.Range(30f, 50f); LevelState = LevelStates.StartAttack; } } else if (LevelState == LevelStates.StartAttack) { AttackTimer -= Time.deltaTime; if (AttackTimer <= 0) { if (DogfightState == DogfightStates.Start) { DogfightState = DogfightStates.NoneAhead; } // Select alive enemy EnemyObj = Random.Range(0, 5 - TargetsDestroyed - (EnemyAhead == -1 ? 0 : 1)); for (int i = 0; i < EnemyObj; i++) { if (fighters[i].EnemyState == FighterScript.EnemyStates.Destroyed || fighters[i].EnemyState == FighterScript.EnemyStates.Ahead) { EnemyObj++; } } BomberTimer = 30; ShownBomberAlert = false; fighters[EnemyObj].EnemyState = FighterScript.EnemyStates.Bomber; AttackTimer = 0; LevelState = LevelStates.Attack; } } else if (LevelState == LevelStates.Attack) { AttackTimer += Time.deltaTime; BomberTimer -= Time.deltaTime; if (AttackTimer >= 10 && !ShownBomberAlert) { ServiceProvider.Instance.GameWorld.ShowStatusMessage("An aircraft broke off and is headed towards our airfield! Intercept it now!"); ShownBomberAlert = true; } if (fighters[EnemyObj].EnemyState == FighterScript.EnemyStates.Destroyed) { LevelState = LevelStates.Break; } if (BomberTimer <= 0 && (PlayerPosition - fighters[EnemyObj].transform.position).magnitude < 7000) { fighters[EnemyObj].EnemyState = FighterScript.EnemyStates.Behind; LevelState = LevelStates.Break; } } else if (LevelState == LevelStates.Break) { EnemyObj = -1; AttackTimer = Random.Range(25f, 35f); LevelState = LevelStates.StartAttack; } if (DogfightState == DogfightStates.NoneAhead) { EnemyAhead = CheckEnemyAhead(); if (EnemyAhead != -1) { fighters[EnemyAhead].EnemyState = FighterScript.EnemyStates.Ahead; DogfightState = DogfightStates.EnemyAhead; } } else if (DogfightState == DogfightStates.EnemyAhead) { if ((EnemyAhead == 0 && (ptfl.relpos0.z < 0 || fighters[0].EnemyState == FighterScript.EnemyStates.Destroyed)) || (EnemyAhead == 1 && (ptfl.relpos1.z < 0 || fighters[1].EnemyState == FighterScript.EnemyStates.Destroyed)) || (EnemyAhead == 2 && (ptfl.relpos2.z < 0 || fighters[2].EnemyState == FighterScript.EnemyStates.Destroyed)) || (EnemyAhead == 3 && (ptfl.relpos3.z < 0 || fighters[3].EnemyState == FighterScript.EnemyStates.Destroyed)) || (EnemyAhead == 4 && (ptfl.relpos4.z < 0 || fighters[4].EnemyState == FighterScript.EnemyStates.Destroyed))) { if (fighters[EnemyAhead].EnemyState != FighterScript.EnemyStates.Destroyed) { fighters[EnemyAhead].EnemyState = FighterScript.EnemyStates.Behind; } DogfightState = DogfightStates.NoneAhead; EnemyAhead = -1; } } if (TargetsDestroyed != 5) { ScoreScript.score = Mathf.Clamp(20000 - Mathf.RoundToInt(LevelTimer * 30), 0, 20000); } LevelTimer += Time.deltaTime; }
/* * The LoadContent function of level is one of the most * important functions in the game. It loads the level, * players and objects. It also loads all the * spawn positions. */ public void LoadContent(Menu gameMenu) { //Hier wordt de informatie vanuit het menu geladen in het level fragLimit = gameMenu.fragLimit; timeLimit = gameMenu.timeLimit * 60 * 60; //Audio initialization. audio = new Audio(); musicVolume = gameMenu.musicVol; soundVolume = gameMenu.soundVol; playerTotal = gameMenu.numPlayers; if (timeLimit == 0) { timeLimit = int.MaxValue - countdownTime - countdownTime; } if (fragLimit == 0) { fragLimit = int.MaxValue; } if (gameMenu.levelName != null) { levelName = gameMenu.levelName; } currentTime = timeLimit + countdownTime; //Console.Write("Timelimit: " + timeLimit + " Fraglimit: " + fragLimit + "\n"); //Load some resources: levelTimer = Game1.INSTANCE.Content.Load<SpriteFont>("LevelTimer"); countDownFont = Game1.INSTANCE.Content.Load<SpriteFont>("Menu"); pauzeScreenOverlay = Game1.INSTANCE.Content.Load<Texture2D>("Images/Miscellaneous/pauseScreen"); crowntex[0] = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/Crown4"); crowntex[1] = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/Crown3"); crowntex[2] = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/Crown2"); crowntex[3] = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/Crown1"); //Create an filestream. FileStream fstream = new FileStream(levelName, FileMode.Open, FileAccess.Read); byte[] filecontent = new byte[fstream.Length]; //Create an array to put our data in. string[][] leveldata = new string[filecontent.Length][]; //Read the file and put data in the filecontent. for (int i = 0; i < fstream.Length; i++) { fstream.Read(filecontent, i, 1); } //Split up the file in "words". int currentAt = 0; int currentAt2 = 0; for (int i = 0; i < filecontent.Length; i++) { if (leveldata[currentAt] == null) { leveldata[currentAt] = new string[255]; } if ((char)filecontent[i] == ' ') { currentAt2++; } else if ((char)filecontent[i] == (char)10) { currentAt2 = 0; currentAt++; } else { leveldata[currentAt][currentAt2] += (char)filecontent[i]; } } //Go through every data in leveldata. for (int i = 0; i < leveldata.Length; ++i) { if (leveldata[i] != null) { if (leveldata[i][0].Contains("background:")) { backgroundTex = Game1.INSTANCE.Content.Load<Texture2D>("Images/Maps/" + leveldata[i][1]); } else if (leveldata[i][0].Contains("backgroundmusic:")) { audio.LoadMusic(leveldata[i][1]); } else if (leveldata[i][0].Contains("object:")) { objects.Add(new Object(leveldata[i][1], int.Parse(leveldata[i][2]), int.Parse(leveldata[i][3]), int.Parse(leveldata[i][4]), int.Parse(leveldata[i][5]))); } else if (leveldata[i][0].Contains("moveableobj:")) { objects.Add(new Object(leveldata[i][1], int.Parse(leveldata[i][2]), int.Parse(leveldata[i][3]), int.Parse(leveldata[i][4]), int.Parse(leveldata[i][5]), int.Parse(leveldata[i][6]), int.Parse(leveldata[i][7]), int.Parse(leveldata[i][8]))); } else if (leveldata[i][0].Contains("item:")) { items.Add(new Items(int.Parse(leveldata[i][2]), int.Parse(leveldata[i][3]), leveldata[i][1])); } else if (leveldata[i][0].Contains("\r")) { } else if (leveldata[i][0].Contains("spawn:")) { spawnPositions.Add(new SpawnPosition(int.Parse(leveldata[i][1]), int.Parse(leveldata[i][2]), leveldata[i][3])); } } } //What if no background is found? if (backgroundTex == null) { backgroundTex = Game1.INSTANCE.Content.Load<Texture2D>("Images/Maps/BasicShapes/Rectangle"); } // Initiate 4 players: for (int i = 0; i < playerTotal; i++) { animPlayers[i] = new AnimPlayer(this, i); } // Start the game, we *could* add a start game countdown screen here. levelState = LevelStates.StartCountdown; }
private void WinLevel() { _lvlState = LevelStates.LsWinning; _rCube.WinningCube(); }
/* * The update function in level makes sure the audio is running * if there is any in the level. Also updates every player in the * game and decreases the currentTime. If the currentTime is reached * it also activates the endGame boolean to end the game. The * function also checks if a player reached the fraglimit and if * it is reached it will also end the game. */ public void Update(GameTime gameTime) { if (!audio.musicPlaying && audio.song != null) { audio.PlayMusic(); audio.musicPlaying = true; } if (levelState == LevelStates.StartCountdown) { if (currentTime == timeLimit + 4 * 60) { audio.PlaySound("3", soundVolume); countText = 3; } else if (currentTime == timeLimit + 3 * 60) { audio.PlaySound("2", soundVolume); countText = 2; } else if (currentTime == timeLimit + 2 * 60) { audio.PlaySound("1", soundVolume); countText = 1; } else if (currentTime == timeLimit + 1 * 60) { audio.PlaySound("start", soundVolume); countText = 0; } else if (currentTime == timeLimit) { levelState = LevelStates.Play; } currentTime--; } // Toggle the Pauze game state. foreach (AnimPlayer somePlayer in animPlayers) { if (somePlayer != null && somePlayer.inputDevice != null) { //OPTIONAL: Here we could take notion of whomever pressed the pauzebutton... if (somePlayer.inputDevice.isStartPause() && levelState != LevelStates.StartCountdown) levelState = LevelStates.Pause; if (somePlayer.inputDevice.isStopPause() && levelState != LevelStates.StartCountdown) levelState = LevelStates.Play; if (somePlayer.inputDevice.isGobackToMenu() && levelState == LevelStates.Pause && levelState != LevelStates.StartCountdown) endGame = true; } } // Halt execution if the level state is not "play". if (levelState != LevelStates.Play) return; // Update any items in the game. These are mainly weapon pickups: foreach (Items item in items) { if (item != null) { item.Update(gameTime); } } foreach (Object obj in objects) { if (obj != null) { obj.Update(); } } foreach (AnimPlayer somePlayer in animPlayers) { // Dispatch the update event to all players: if (somePlayer != null) { somePlayer.Update(gameTime); // Check whether the player has managed to get himself killed: somePlayer.checkOutOfLevel(); // Hit-test this player against all game objects: foreach (Object obj in objects) { if (obj != null) somePlayer.checkObjectCollision(obj); } foreach (Items item in items) { if (item != null) somePlayer.checkItemCollision(item); } // Hit-test this player's bullets against other players and objects: foreach (Weapons.AbstractBullet bullet in somePlayer.weaponManager.allBullets) { if (bullet.isDestroyed) continue; // This bullet has already "hit" something. // Bullet VS all players: foreach (AnimPlayer testingPlayer in animPlayers) { if (testingPlayer != null) { if (testingPlayer == somePlayer) continue; // Suicide not allowed. // Hit-test bullet against player: testingPlayer.checkBulletCollision(bullet); } } // Bullet VS all objects: foreach (Object obj in objects) { bullet.CheckObjectCollision(obj); } } // Check if the kill (frag) limit has been reached: if (somePlayer.playerKills >= fragLimit) { endGame = true; } } } // Handle the time limit and game clock: if (currentTime == 660) audio.PlaySound("10 seconds left", soundVolume); else if (currentTime == 270) audio.PlaySound("3", soundVolume); else if (currentTime == 180) audio.PlaySound("2", soundVolume); else if (currentTime == 120) audio.PlaySound("1", soundVolume); else if (currentTime == 60) audio.PlaySound("endgame", soundVolume); if (currentTime <= 0) endGame = true; if (currentTime > 0) currentTime--; }
/// <summary> /// Initialize this system to a working state. /// </summary> /// <param name="game"> /// The <see cref="IGame"/> game, that requested the initialization. That is the game, /// the system will be running in. /// </param> public override void Initialize(IGame game) { base.Initialize(game); // Register the component types, required by this system. Since this // system uses a state machine, it also needs to register all types // of components, required by the individual states. this.Game.ComponentSystem.RegisterComponentType<LevelComponent>(); this.Game.ComponentSystem.RegisterComponentType<BallComponent>(); this.Game.ComponentSystem.RegisterComponentType<DestructableComponent>(); this.Game.ComponentSystem.RegisterComponentType<PlayerComponent>(); // Register the events, required by this system this.Game.EventManager.RegisterListener(BreakoutEvents.LoadLevel, this.OnLoadLevel); // These events are contained in state implementations, when using the // StateMachine-based implementation. They are registered and removed // when entering and exiting the LevelPlayingState respectively. Because // the registration is done here, the event handlers need to check their // state of course. this.Game.EventManager.RegisterListener(ComponentSystemEvents.ComponentDestroyed, this.OnComponentDestroyed); this.Game.EventManager.RegisterListener(BreakoutEvents.LevelLoaded, this.OnLevelLoaded); // And finally, set the initial state this.state = LevelStates.Spawn; }
// Update is called once per frame void Update() { // this is for seeing the run time of the scene and is helpful for making // the storytelling triggers - use checkbox in inspector to turn it off runTimeText.text = showRunTime ? String.Format("RunTime: {0:0.00}", runTime) : ""; switch (levelState) { case LevelStates.Exploration: if (player != null) { if (player.transform.position.x >= startSeqBeginPoint) { // get start time startTime = Time.time; // freeze the player input and stop movement player.GetComponent <PlayerController>().FreezeInput(true); Vector2 playerVelocity = player.GetComponent <Rigidbody2D>().velocity; player.GetComponent <Rigidbody2D>().velocity = new Vector2(0, playerVelocity.y); // go to the dr. light hologram state levelState = LevelStates.Hologram; } } break; case LevelStates.Hologram: // how long has this sequence been running for runTime = Time.time - startTime; // move player forward a bit and stop to show hologram if (UtilityFunctions.InTime(runTime, 2.0f, 5.0f)) { if (player.transform.position.x <= startSeqEndPoint) { player.GetComponent <PlayerController>().SimulateMoveRight(); } else { player.GetComponent <PlayerController>().SimulateMoveStop(); } } // dr. light says he can't stay long if (UtilityFunctions.InTime(runTime, 5.0f)) { dialogueBox.SetActive(true); dialogueText.text = dialogueStrings[0]; } // dr. light says his hologram is unstable if (UtilityFunctions.InTime(runTime, 9.0f)) { dialogueText.text = dialogueStrings[1]; } // megaman says he hasn't seen any disturbance if (UtilityFunctions.InTime(runTime, 13.0f)) { dialogueText.text = dialogueStrings[2]; } // dr. light says keep looking if (UtilityFunctions.InTime(runTime, 17.0f)) { dialogueText.text = dialogueStrings[3]; } // megaman says he'll contact dr. light soon if (UtilityFunctions.InTime(runTime, 21.0f)) { dialogueText.text = dialogueStrings[4]; } // hide dialogue box if (UtilityFunctions.InTime(runTime, 24.0f)) { dialogueText.text = ""; dialogueBox.SetActive(false); } // flicker out dr. light hologram if (UtilityFunctions.InTime(runTime, 25.0f)) { StartCoroutine(FlickerOutHologram()); } // give user player control back and move to next state if (UtilityFunctions.InTime(runTime, 28.0f)) { player.GetComponent <PlayerController>().FreezeInput(false); // explore some more and proceed to the checkpoint levelState = LevelStates.KeepLooking; } break; case LevelStates.KeepLooking: // now out of the hologram state // we don't really do anything here // we'll use our checkpoint function to switch states break; case LevelStates.Checkpoint: // add more stuff if we had a complete level break; } }
public SavedLevelData(/*UInt32 score*/) { //this.score = score; score = 0; state = LevelStates.UNTOUCHED; }
public void StartGame() { currentLevelState = LevelStates.MainGame; DetermineOrder(); playerController.playerAnimator.SetBool("Run", true); }
public void Complete() { LevelState = LevelStates.Completed; }
private void Disappear() { GhostEffect = 0; Hide(); State = LevelStates.Waiting; }
/// <summary> /// Update the system in paused state. /// </summary> private void EnterSpawnState() { this.state = LevelStates.Spawn; int ballCount = 0; foreach (PlayerComponent player in this.Game.ComponentSystem.Components<PlayerComponent>()) { if (player.Lives > 0) { this.Game.EventManager.QueueEvent(new HelGamesEvent(BreakoutEvents.SpawnBallsForPlayer, player)); ballCount++; } } if (ballCount > 0) { this.EnterPausedState(); } else { this.EnterLevelFailedState(); } }
private void ResetLevel() { _lvlState = LevelStates.LsLoadFields; foreach (var feld in _levelFeld) if (feld != null) feld.ResetField(); if (_rCube != null) _rCube.ResetCube(_startXy[0], _startXy[1]); }
public void LevelUp() { State = LevelStates.Appearing; Show(); GhostEffect = 100; }