void Start() { systems = new ISystem[] { new LocomotionSystem(), new PositionOnTileSystem(), new InputSystem(), new H0nckerAnimationSystem(), new FeetSystem(), new BeakMagnetSystem(), new AntagonistSystem(), new InventorySystem(), new TimeSystem(), new BreakTossedSystem(), new SmackAgainstTheWallSystem(), new SharkAISystem(), new DoombaAISystem(), new TerminatorAISystem(), new ProjectileSystem() //new SUPERHONKSystem() }; for (int i = 0; i < systems.Length; i++) { systems[i].Cache(worldContext); } gameStateComponent = worldContext.Get <GameStateComponent>(0); }
protected override void OnUpdate() { Entity gameStateEntity = this.gameStateComponentQuery.GetSingletonEntity(); GameStateComponent gameStateComponent = this.EntityManager.GetComponentData <GameStateComponent>(gameStateEntity); //Prevent this from being null when scene is loaded from another scene (Something about the lifecycle of ECS not behaving well with normal gameobject instantiating -> i can not always guarantee that oncreate receives the gameobject) if (this.gameStateUIInjectorProxy == null) { this.gameStateUIInjectorProxy = UnityEngine.Object.FindObjectOfType <GameStateUIInjectorProxy>(); } switch (gameStateComponent.GameStateEnum) { case GameStateEnum.Menu: case GameStateEnum.InGame: case GameStateEnum.Pause: break; case GameStateEnum.Lost: this.gameStateUIInjectorProxy.GameLostText.enabled = true; break; case GameStateEnum.Win: this.gameStateUIInjectorProxy.GameWinText.enabled = true; break; default: break; } }
protected override void OnUpdate() { CollisionWorld collisionWorldForJob = this.physicsWorld.PhysicsWorld.CollisionWorld; //SystemBase Dependency for the Physics system -> This system must wait for the phyiscs world to complete in order to create a new batch of parallel jobs this.Dependency = JobHandle.CombineDependencies(this.Dependency, this.physicsWorld.FinalJobHandle); Entity gameStateEntity = this.gameStateQuery.GetSingletonEntity(); GameStateComponent gameStateComponent = this.EntityManager.GetComponentData <GameStateComponent>(gameStateEntity); EntityArchetype sfxArchetypeForJob = this.EntityManager.CreateSFXArchetype(); EntityCommandBuffer.Concurrent entityCommandBuffer = this.endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); this.Dependency = JobHandle.CombineDependencies(this.Dependency, this.Entities.WithAll <AltarTag>().ForEach((int entityInQueryIndex, in Translation position, in Rotation rotation, in PhysicsCollider collider) => { if (CollisionHelper.ColliderCast(position.Value, position.Value, rotation.Value, collisionWorldForJob, collider)) { gameStateComponent.GameStateEnum = GameStateEnum.Win; entityCommandBuffer.SetComponent <GameStateComponent>(entityInQueryIndex, gameStateEntity, gameStateComponent); //Add Fanfare SFX Entity sfx = entityCommandBuffer.CreateEntity(entityInQueryIndex, sfxArchetypeForJob); entityCommandBuffer.SetComponent <SFXComponent>(entityInQueryIndex, sfx, new SFXComponent { SFXType = SFXType.Fanfare }); } }).ScheduleParallel(this.Dependency));
public void Cache(WorldContext worldContext) { antagonistComponents = worldContext.GetComponentsContainer <AntagonistComponent>(); gameStateComponent = worldContext.Get <GameStateComponent>(0); vfxPoolComponent = worldContext.Get <VFXPoolComponent>(0); cameraComponent = worldContext.Get <CameraComponent>(0); canvasComponent = worldContext.Get <CanvasComponent>(0); }
/// <summary> /// Makes sure there is only ever one instance /// </summary> protected void Awake() { if (Instance == null) { DontDestroyOnLoad(gameObject); Instance = this; } else { Destroy(gameObject); } }
public static ServerCurrentStateTransferMessage BuildCurrentStateForPlayer(GameStateComponent gameState, Player player) { var result = ServerCurrentStateTransferMessage.Create(); var width = gameState.Map.GetLength(0); var height = gameState.Map.GetLength(1); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { result.Map.Add(!IsVisible(player, gameState.Exit.X, gameState.Exit.Y, x, y) ? RegionValue.Unknown : gameState.Map[x, y]); } } var idx = 0; foreach (var statePlayer in gameState.Players.Values) { result.AddPlayer(statePlayer.PlayerId, statePlayer.LevelScore, statePlayer.TotalScore); for (var j = 0; j < statePlayer.Units.Count; j++) { var b = statePlayer.Units[j]; if (!IsVisible(player, gameState.Exit.X, gameState.Exit.Y, b.Position.X, b.Position.Y) && player.PlayerId != statePlayer.PlayerId) { continue; } result.AddUnit(idx, b.UnitId, b.Position.X, b.Position.Y, b.Hp); } idx++; } if (IsVisible(player, gameState.Exit.X, gameState.Exit.Y, gameState.Exit.X, gameState.Exit.Y)) { result.SetExit(gameState.Exit.X, gameState.Exit.Y); } for (var i = 0; i < gameState.Doors.Count; i++) { var door = gameState.Doors[i]; if (!IsVisible(player, gameState.Exit.X, gameState.Exit.Y, door.X, door.Y)) { continue; } result.AddDoor(door.X, door.Y); } return(result); }
public void Start() { StateData = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameStateComponent>(); Colliders = new List <Collider>(gameObject.GetComponentsInChildren <Collider>()); foreach (var Col in Colliders) { Col.enabled = false; } Particles = new List <ParticleSystem>(gameObject.GetComponentsInChildren <ParticleSystem>()); foreach (var Part in Particles) { Part.Pause(); } }
public static void StartNewGame(GameStateComponent gameState) { gameState.AtEnd.Clear(); var maze = new RoomMazeGenerator().Generate(new RoomMazeGenerator.Settings { Width = 71, Height = 41, AdditionalPassages = 20, WindingPercent = 50, RoomSize = 3 }); gameState.Map = new RegionValue[maze.Regions.GetLength(0), maze.Regions.GetLength(1)]; gameState.Doors.Clear(); for (var i = 0; i < maze.Junctions.Count; i++) { gameState.Doors.Add(new Point(maze.Junctions[i].X, maze.Junctions[i].Y)); } for (var x = 0; x < gameState.Map.GetLength(0); x++) { for (var y = 0; y < gameState.Map.GetLength(1); y++) { gameState.Map[x, y] = maze.Regions[x, y] == null ? RegionValue.Wall : RegionValue.Path; } } var roomIdx = 0; foreach (var player in gameState.Players) { var room = maze.Rooms[roomIdx]; roomIdx++; player.Value.Units[0].Position = new Point(room.X + room.Width / 2 - 1, room.Y + room.Height / 2); player.Value.Units[1].Position = new Point(room.X + room.Width / 2 + 1, room.Y + room.Height / 2); player.Value.Units[2].Position = new Point(room.X + room.Width / 2, room.Y + room.Height / 2 - 1); player.Value.Units[3].Position = new Point(room.X + room.Width / 2, room.Y + room.Height / 2 + 1); player.Value.LevelScore = 0; for (var i = 0; i < player.Value.Units.Count; i++) { player.Value.Units[i].Hp = player.Value.Units[i].MaxHp; } } gameState.Exit = new Point(maze.Rooms[maze.Rooms.Count - 1].X + maze.Rooms[maze.Rooms.Count - 1].Width / 2, maze.Rooms[maze.Rooms.Count - 1].Y + maze.Rooms[maze.Rooms.Count - 1].Height / 2); }
protected override void OnUpdate() { Entity gameStateEntity = this.gameStateQuery.GetSingletonEntity(); GameStateComponent gameStateComponent = this.EntityManager.GetComponentData <GameStateComponent>(gameStateEntity); EntityCommandBuffer.Concurrent entityCommandBuffer = this.endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); this.Entities.WithAll <PlayerTag>().ForEach((int entityInQueryIndex, in PlayerInfo playerInfo) => { if (playerInfo.Health <= 0f) { gameStateComponent.GameStateEnum = GameStateEnum.Lost; entityCommandBuffer.SetComponent(entityInQueryIndex, gameStateEntity, gameStateComponent); } }).ScheduleParallel(); this.endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(this.Dependency); this.Dependency.Complete(); }
private void BuildOrderLineText(OrderProperties orderProperties, StringBuilder builder, GameStateComponent gameState, string itemColor) { var item = gameState.ResolveItemName(orderProperties); builder.Append("<color="); builder.Append(itemColor); builder.Append(">"); builder.Append(orderProperties.ToString(item)); builder.Append("\n"); }
void UpdateButtonPressed() { if (focusedButton == null) { return; } int commandType = 0; string command = null; if (InputManager.JustPressed(GameCommand.MenuConfirm) && focusedButton.PressCommand != null) { commandType = 1; command = focusedButton.PressCommand; } if (InputManager.JustPressed(GameCommand.MenuLeft) && focusedButton.LeftCommand != null) { commandType = 2; command = focusedButton.LeftCommand; } if (InputManager.JustPressed(GameCommand.MenuRight) && focusedButton.RightCommand != null) { commandType = 3; command = focusedButton.RightCommand; } if (commandType == 0) { return; } //SoundManager.PlaySound("tap2"); GameStateComponent gameState = sys.GetGameState(); if (scene.Name == "menu") { switch (command) { case "start": gameState.Request("danmaku"); break; case "options": gameState.Request("options"); break; case "quit": gameState.Request("quit"); break; } } else if (scene.Name == "options") { switch (command) { case "m-dn": SoundManager.MusicVolume = Math.Max(SoundManager.MusicVolume -= 0.1f, 0); break; case "m-up": SoundManager.MusicVolume = Math.Min(SoundManager.MusicVolume += 0.1f, 1); break; case "s-dn": SoundManager.SoundVolume = Math.Max(SoundManager.SoundVolume -= 0.1f, 0); break; case "s-up": SoundManager.SoundVolume = Math.Min(SoundManager.SoundVolume += 0.1f, 1); break; case "fs": InputManager.StickMouse(); if (gs.DisplayManager.Fullscreen) { gs.DisplayManager.SetFullscreen(false); } else { gs.DisplayManager.SetFullscreen(true); } break; case "zoom-up": InputManager.StickMouse(); if (Config.Zoom < Config.GameScales.Count - 1) { Config.Zoom++; } else { Config.Zoom = 0; } gs.DisplayManager.SetZoom(Config.GameScales[Config.Zoom]); break; case "zoom-dn": InputManager.StickMouse(); if (Config.Zoom > 0) { Config.Zoom--; } else { Config.Zoom = Config.GameScales.Count - 1; } gs.DisplayManager.SetZoom(Config.GameScales[Config.Zoom]); break; case "controls": gameState.Request("controls"); break; case "controls-r": InputManager.Default(); InputManager.AskSetControls = false; InputManager.SaveConfig(); InputManager.UpdateAliases(); break; case "return": Config.SaveConfig(); gameState.Request("return"); break; } UpdateText(); } InputManager.Reset(GameCommand.Action1); }
public void Start() { gameState = GameStateComponent.Instance; }
void Start() { gameState = GameStateComponent.Instance; isMouseDown = false; }
void UpdateInput(GameTime gameTime) { GameStateComponent gameState = sys.GetGameState(); if (conflictTimer > 0) { conflictTimer -= gameTime.ElapsedGameTime.TotalSeconds; } if (InputManager.JustPressed(GameCommand.SafeBack)) { //SoundManager.PlaySound("Throw2"); currentKey--; if (currentKey < 0) { scene.Disable(); gameState.Request("return"); } return; } if (InputManager.Held(GameCommand.SafeBack)) { return; } Keys[] pressedKeys = InputManager.GetKeyboardInput(); List <MouseInput> pressedMouseKeys = InputManager.GetMouseInput(); List <Buttons> pressedGamepadKeys = InputManager.GetGamepadInput(); if (pressedKeys.Length == 0 && pressedMouseKeys.Count == 0 && pressedGamepadKeys.Count == 0) { keysHeld = false; return; } if (!keysHeld) { // Bind keyboard input. if (pressedKeys.Length > 0) { keysHeld = true; Keys key = pressedKeys[0]; if (key != Keys.LeftAlt && key != Keys.RightAlt) { SetBinding(key, UniversalInputType.Keyboard); } } // Bind mouse input. else if (pressedMouseKeys.Count > 0) { keysHeld = true; MouseInput key = pressedMouseKeys[0]; SetBinding(key, UniversalInputType.Mouse); } // Bind gamepad input. else if (pressedGamepadKeys.Count > 0) { keysHeld = true; GamepadInput key = (GamepadInput)pressedGamepadKeys[0]; SetBinding(key, UniversalInputType.Gamepad); } } // If all customizable bindings are set, then leave this scene. if (currentKey >= (int)GameCommand.MenuUp) { success = true; // TODO: I don't think this is needed anymore. FinalizeKeybinds(); scene.Disable(); gameState.Request("return"); } }