/// <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> /// Handles Player versus Wall collision /// </summary> /// <param name="Player"> Id of the player entity </param> /// <param name="WallEnt"> Id of the wall entity </param> private void PlayerVsWallColl(int Player, int WallEnt, GameTime gameTime) { PlayerComponent playerComp = ComponentManager.Instance.GetEntityComponent <PlayerComponent>(Player); VelocityComponent pvc = ComponentManager.Instance.GetEntityComponent <VelocityComponent>(Player); DirectionComponent pdc = ComponentManager.Instance.GetEntityComponent <DirectionComponent>(Player); CollisionRectangleComponent crc1 = ComponentManager.Instance.GetEntityComponent <CollisionRectangleComponent>(WallEnt); CollisionRectangleComponent crc2 = ComponentManager.Instance.GetEntityComponent <CollisionRectangleComponent>(Player); PositionComponent pc = ComponentManager.Instance.GetEntityComponent <PositionComponent>(Player); PositionComponent pcwall = ComponentManager.Instance.GetEntityComponent <PositionComponent>(WallEnt); WallComponent wall = ComponentManager.Instance.GetEntityComponent <WallComponent>(WallEnt); if (wall.wall == Wall.LeftWall) { if (crc2.CollisionRec.X + crc2.CollisionRec.Width * 0.5 < crc1.CollisionRec.X) { pc.position.X = Game.Instance.GraphicsDevice.Viewport.Width - 1 - crc2.CollisionRec.Width * 0.5f; } } else if (wall.wall == Wall.RightWall) { if (crc2.CollisionRec.X + crc2.CollisionRec.Width * 0.5 > crc1.CollisionRec.X) { pc.position.X = 1 - crc2.CollisionRec.Width * 0.5f; } } else if (wall.wall == Wall.TopWall && !playerComp.isFalling) { if (pdc.directio != Direction.Still) { changeDir(pdc); pdc.preDir = pdc.directio; pdc.directio = Direction.Still; } pvc.velocity.Y = 0; pvc.velocity.Y += 500 * (float)gameTime.ElapsedGameTime.TotalSeconds; playerComp.isFalling = true; HealthComponent hc = ComponentManager.Instance.GetEntityComponent <HealthComponent>(Player); //hc.health -= 1; } else if (wall.wall == Wall.BottomWall) { //@TODO // only loose life when the player jump on the floor, not when the player falls to the ground // and have some kind of timer unti you can jump away OnFloorComponent fc = ComponentManager.Instance.GetEntityComponent <OnFloorComponent>(Player); playerComp.isFalling = false; if (pdc.directio != Direction.Still) { pvc.velocity.Y = 0; changeDir(pdc); pdc.preDir = pdc.directio; pdc.directio = Direction.Still; } //else if(pdc.directio == Direction.Still) //{ // pvc.velocity.Y = 0; //} pvc.velocity.Y = 0; pvc.velocity.Y -= 500F * (float)gameTime.ElapsedGameTime.TotalSeconds; HealthComponent hc = ComponentManager.Instance.GetEntityComponent <HealthComponent>(Player); if (fc == null) { fc = new OnFloorComponent(); ComponentManager.Instance.AddComponentToEntity(Player, fc); hc.health -= 1; ComponentManager.Instance.AddComponentToEntity(Player, new SoundEffectComponent("splat")); } } }