public static int CreateCamera(GraphicsDevice gd, int entityTrackId) { ComponentManager cm = ComponentManager.GetInstance(); TransformComponent transform = new TransformComponent() { Position = new Vector3(-10, 350, -170), Rotation = Vector3.Right, Up = Vector3.Up }; CameraComponent camera = new CameraComponent() { FieldOfView = 45, NearPlaneDistance = 1, FarPlaneDistance = 10000, AspectRatio = gd.DisplayMode.AspectRatio, }; TrackingCameraComponent trackComp = new TrackingCameraComponent(entityTrackId, new Vector3(0, 10, 20)); int cam = cm.AddEntityWithComponents(new IComponent[] { camera, trackComp, transform }); return(cam); }
public static int CreateHeightMap(GraphicsDevice gd, string heightMapFilePath) { ComponentManager cm = ComponentManager.GetInstance(); HeightMapComponent hmComp = new HeightMapComponent(gd) { HeightMapFilePath = heightMapFilePath }; int hm = cm.AddEntityWithComponents(hmComp); return(hm); }
public static int CreateChopper(GraphicsDevice gd, string modelPath) { ComponentManager cm = ComponentManager.GetInstance(); ModelComponent modComp = new ModelComponent(modelPath) { IsActive = true }; TransformComponent transComp = new TransformComponent() { Position = new Vector3(20, 350, -170) }; NameComponent nameComp = new NameComponent("Chopper"); int chop = cm.AddEntityWithComponents(modComp, transComp, nameComp); return(chop); }
public static int CreateTrackingCamera(GraphicsDevice gd, int entityTrackId) { TransformComponent transform = new TransformComponent() { Position = new Vector3(-10, 350, -170), Rotation = Vector3.Right, Up = Vector3.Up }; CameraComponent camera = new CameraComponent() { FieldOfView = 45, NearPlaneDistance = 1, FarPlaneDistance = 10000, AspectRatio = gd.DisplayMode.AspectRatio, }; TrackingCameraComponent trackingCamera = new TrackingCameraComponent(entityTrackId, new Vector3(0, 3, 10)); return(cm.AddEntityWithComponents(camera, trackingCamera, transform)); }
public void Update(GameTime gameTime) { ComponentManager cm = ComponentManager.GetInstance(); foreach (var player in players) { PlayerComponent playerComponent = player.Item1; PlayerControlComponent controlComponent = player.Item2; PositionComponent playerPositionComponent = player.Item3; int closestInteractable = FindClosestInteractable(player.Entity, playerPositionComponent.Position); if (closestInteractable != -1) { if (controlComponent.Interact.IsButtonDown() && !cm.GetComponentForEntity <InventoryComponent>(player.Entity).IsOpen) { InteractComponent interComp = cm.GetComponentForEntity <InteractComponent>(closestInteractable); // Its a trap(Deal damage) if (interComp.Type == InteractType.Trap && cm.HasEntityComponent <AttackComponent>(closestInteractable)) { cm.GetComponentForEntity <HealthComponent>(player.Entity).IncomingDamage.Add(closestInteractable); } //Talk(show text) else if (interComp.Type == InteractType.Talk && cm.HasEntityComponent <TextComponent>(closestInteractable)) { foreach (var inter in cm.GetComponentsOfType <InteractComponent>()) { if (cm.HasEntityComponent <TextComponent>(inter.Key)) { cm.GetComponentForEntity <TextComponent>(inter.Key).IsActive = false; } } cm.GetComponentForEntity <TextComponent>(closestInteractable).IsActive = true; } //Loot(Give item to looter) else if (interComp.Type == InteractType.Loot && cm.HasEntityComponent <InventoryComponent>(player.Entity) && cm.HasEntityComponent <ItemComponent>(closestInteractable)) { if (cm.HasEntityComponent <HealthComponent>(closestInteractable) && cm.GetComponentForEntity <HealthComponent>(closestInteractable).IsAlive) { break; } InventoryComponent invenComp = cm.GetComponentForEntity <InventoryComponent>(player.Entity); if (invenComp.AmountOfItems < invenComp.Items.Length) { //Remove components cm.RemoveComponentFromEntity <InteractComponent>(closestInteractable); cm.RemoveComponentFromEntity <CollisionComponent>(closestInteractable); cm.RemoveComponentFromEntity <PositionComponent>(closestInteractable); //Give the item to the player cm.AddEntityWithComponents(new IComponent[] { (ItemComponent)cm.GetComponentForEntity <ItemComponent>(closestInteractable).Clone(), }); invenComp.ItemsToAdd.Add(closestInteractable); } } } } } }
public void Update(GameTime gameTime) { ComponentManager cm = ComponentManager.GetInstance(); GameStateManager gm = GameStateManager.GetInstance(); ActivateMenuButtons(); ActivateMenuBackground(); ClearMenu(); DecrementSelectCooldown = true; exitPause = false; bool enterPause = false; foreach (var controlEntity in cm.GetComponentsOfType <PlayerControlComponent>()) { PlayerControlComponent controlComp = (PlayerControlComponent)controlEntity.Value; // If we are in some kind of menu state if (GameStateManager.GetInstance().State == GameState.Menu) { // Apply effects on menu background foreach (var menuBackground in cm.GetComponentsOfType <MenuBackgroundComponent>()) { MenuBackgroundComponent men = (MenuBackgroundComponent)menuBackground.Value; if (men.HasFadingEffect && men.IsActive) { FadeEffect(gameTime, men); } if (men.HasMovingEffect && men.IsActive) { MoveEffect(gameTime, men); } } if (DecrementSelectCooldown) { SelectCooldown -= (float)gameTime.ElapsedGameTime.TotalSeconds; DecrementSelectCooldown = false; } // Makes the menu button selection smooth if (SelectCooldown <= 0.0f) { Vector2 stickDir = controlComp.Movement.GetDirection(); //Check navigation in the menu if (Math.Abs(stickDir.Y) > 0.5f) { //if the stick has been pushed in a direction Point direction = MoveSystem.CalcDirection(stickDir.X, stickDir.Y); cm.GetComponentForEntity <MenuButtonComponent>(ActiveButtonsList[SelectedButton]).Ishighlighted = false; //stop sound for last button if (cm.HasEntityComponent <SoundComponent>(ActiveButtonsList[SelectedButton])) { cm.GetComponentForEntity <SoundComponent>(ActiveButtonsList[SelectedButton]).Sounds["Selected"].Action = SoundAction.Stop; } SelectedButton = (SelectedButton + direction.Y) % ActiveButtonsList.Count; if (SelectedButton < 0) { SelectedButton = ActiveButtonsList.Count - 1; } cm.GetComponentForEntity <MenuButtonComponent>(ActiveButtonsList[SelectedButton]).Ishighlighted = true; //start sound for new button selected if (cm.HasEntityComponent <SoundComponent>(ActiveButtonsList[SelectedButton])) { cm.GetComponentForEntity <SoundComponent>(ActiveButtonsList[SelectedButton]).Sounds["Selected"].Action = SoundAction.Play; } SelectCooldown = MaxSelectCooldown; } } // Check if highlighted button was pressed "use" if (controlComp.Interact.IsButtonDown()) { if (cm.HasEntityComponent <SoundComponent>(ActiveButtonsList[SelectedButton])) { cm.GetComponentForEntity <SoundComponent>(ActiveButtonsList[SelectedButton]).Sounds["Pressed"].Action = SoundAction.Play; } cm.GetComponentForEntity <MenuButtonComponent>(ActiveButtonsList[SelectedButton]).Use(); } // 1 Player if (gm.State == GameState.OnePlayerGame) { //remove the temporary menu controller cm.RemoveEntity(controlEntity.Key); cm.AddEntityWithComponents(factory.CreatePlayerOne(100, 128)); MenuStateManager.GetInstance().State = MenuState.None; gm.State = GameState.Restart; break; } // 2 Players if (gm.State == GameState.TwoPlayerGame) { //remove the temporary menu controller cm.RemoveEntity(controlEntity.Key); cm.AddEntityWithComponents(factory.CreatePlayerOne(100, 128)); cm.AddEntityWithComponents(factory.CreatePlayerTwo(256, 128)); MenuStateManager.GetInstance().State = MenuState.None; gm.State = GameState.Restart; break; } } if (controlComp.Menu.IsButtonDown()) { //Debug.WriteLine(gm.State + " c " + gm.LastState); if (MenuStateManager.GetInstance().State == MenuState.PauseMainMenu && gm.State == GameState.Menu) { //// Exit the Pausemenu if menu button is pressed from GameState "Menu" Debug.WriteLine(gm.LastState + " a " + gm.State); gm.State = gm.LastState; MenuStateManager.GetInstance().State = MenuState.None; } else if ((gm.State == GameState.Game || gm.State == GameState.GameOver) && gm.LastState != GameState.Menu) { // Enter the PauseMenu if menu button is pressed from GameState "Game" Debug.WriteLine(gm.LastState + " b " + gm.State); gm.State = GameState.Menu; MenuStateManager.GetInstance().State = MenuState.PauseMainMenu; } else { gm.LastState = gm.State; } } if (gm.State == GameState.ExitToMenu) { ActiveButtonsList.Clear(); SelectedButton = 0; MenuStateManager.GetInstance().State = MenuState.MainMenu; } } }