/// <summary> /// onSceneUpdate this function handles the logic for the state which should be run durring the update partion of the game. /// For example this could be to check for conditions to continue to the next state of the gameplay. /// </summary> public void onSceneUpdate() { HealthSystem hs = (HealthSystem)SystemManager.Instance.RetrieveSystem <IUpdate>("HealthSystem"); List <int> players = ComponentManager.Instance.GetAllEntitiesWithComponentType <PlayerComponent>(); foreach (int p in players) { PositionComponent pc = ComponentManager.Instance.GetEntityComponent <PositionComponent>(p); if (ComponentManager.Instance.CheckIfEntityHasComponent <OnFloorComponent>(p) && pc.position.Y < 700) { OnFloorComponent fc = ComponentManager.Instance.GetEntityComponent <OnFloorComponent>(p); ComponentManager.Instance.RemoveComponentFromEntity(p, fc); } if (hs != null) { List <int> dt = hs.getLivingPlayers(); if (dt != null && dt.Count == 1) { SpawnPowerUpSystem sps = (SpawnPowerUpSystem)SystemManager.Instance.RetrieveSystem <IUpdate>("SpawnPowerUpSystem"); sps.Initialize(); sps.run = false; ChangeCubesSystem ccs = (ChangeCubesSystem)SystemManager.Instance.RetrieveSystem <IUpdate>("ChangeCubesSystem"); ccs.Respawn(0); AudioManager.Instance.StopSong(); int id = dt.First(); entitiesInState.Remove(id); SceneSystem.Instance.clearScene(entitiesInState); SceneSystem.Instance.setCurrentScene(new EndingScene()); } } } }
/// <summary> /// onSceneCreated this function is called whenever the current gamestate is changed. This function should contain logic that /// needs to be processed before the state is shown for the player. This could be enteties that's not able to be created pre-runtime. /// </summary> public void onSceneCreated() { ChangeCubesSystem ccs = (ChangeCubesSystem)SystemManager.Instance.RetrieveSystem <IUpdate>("ChangeCubesSystem"); ccs.Respawn(3); SpawnPowerUpSystem sps = (SpawnPowerUpSystem)SystemManager.Instance.RetrieveSystem <IUpdate>("SpawnPowerUpSystem"); sps.Initialize(); List <int> maps = ComponentManager.Instance.GetAllEntitiesWithComponentType <DrawableTextComponent>(); if (maps.Count == 1) { int temp = maps.First(); DrawableTextComponent draw = ComponentManager.Instance.GetEntityComponent <DrawableTextComponent>(temp); switch (draw.text) { case "Whiteboard": WhiteboardMap(); break; case "Temp": tempMap(); break; case "Random": randomMap(); break; } } SceneSystem.Instance.clearScene(maps); List <int> Players = ComponentManager.Instance.GetAllEntitiesWithComponentType <PlayerComponent>(); int i = 1; Random rand = new Random(); foreach (var play in Players) { DrawableComponent tempDraw = ComponentManager.Instance.GetEntityComponent <DrawableComponent>(play); KeyBoardComponent tempkey = ComponentManager.Instance.GetEntityComponent <KeyBoardComponent>(play); PositionComponent temppos = ComponentManager.Instance.GetEntityComponent <PositionComponent>(play); Keys key; tempkey.keyBoardActions.TryGetValue(ActionsEnum.Up, out key); entitiesInState.Add(GameEntityFactory.Instance.CreatePlayer(true, false, Buttons.A, key, new Vector2(rand.Next((int)(Game.Instance.GraphicsDevice.Viewport.Width)), rand.Next((int)(Game.Instance.GraphicsDevice.Viewport.Height * 0.6))), "Player " + i, Direction.Right, PlayerIndex.One, tempDraw.colour)); i++; ComponentManager.Instance.RemoveEntity(play); //ComponentManager.Instance.RecycleID(play); } entitiesInState.Add(GameEntityFactory.Instance.CreateAIPlayer(Direction.Right, new Vector2(rand.Next((int)(Game.Instance.GraphicsDevice.Viewport.Width)), rand.Next((int)(Game.Instance.GraphicsDevice.Viewport.Height * 0.8))), true, "AI one", Color.Red)); }