public void Cache(WorldContext worldContext) { inputComponent = worldContext.Get <InputComponent>(0); superhonkComponent = worldContext.Get <SUPERHONKComponent>(0); timeComponent = worldContext.Get <TimeComponent>(0); }
public void Cache(WorldContext worldContext) { doombaAIComponents = worldContext.GetComponentsContainer <DoombaAIComponent>(); tileFieldComponent = worldContext.Get <TileFieldComponent>(0); timeComponent = worldContext.Get <TimeComponent>(0); obstaclesLayer = LayerMask.GetMask("Obstacles"); }
public void Cache(WorldContext worldContext) { feetComponents = worldContext.GetComponentsContainer <FeetComponent>(); tileFieldComponent = worldContext.Get <TileFieldComponent>(0); antagonistComponent = worldContext.Get <AntagonistComponent>(0); vfxPoolComponent = worldContext.Get <VFXPoolComponent>(0); }
public void Cache(WorldContext worldContext) { tossedComponents = worldContext.GetComponentsContainer <TossedComponent>(); vfxPoolComponent = worldContext.Get <VFXPoolComponent>(0); antagonistComponent = worldContext.Get <AntagonistComponent>(0); obstacleLayer = LayerMask.NameToLayer("Obstacles"); enemiesLayer = LayerMask.NameToLayer("Enemies"); }
public void Cache(WorldContext worldContext) { h0nckerAnimationComponents = worldContext.GetComponentsContainer <H0nckerAnimationComponent>(); vfxPoolComponent = worldContext.Get <VFXPoolComponent>(0); cameraComponent = worldContext.Get <CameraComponent>(0); canvasComponent = worldContext.Get <CanvasComponent>(0); antagonistComponent = worldContext.Get <AntagonistComponent>(0); }
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); }
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); }
public void Cache(WorldContext worldContext) { projectileComponents = worldContext.GetComponentsContainer <ProjectileComponent>(); timeComponent = worldContext.Get <TimeComponent>(0); vfxPoolComponent = worldContext.Get <VFXPoolComponent>(0); antagonistComponent = worldContext.Get <AntagonistComponent>(0); obstacleLayer = LayerMask.NameToLayer("Obstacles"); itemsLayer = LayerMask.NameToLayer("Items"); enemiesLayer = LayerMask.NameToLayer("Enemies"); playerLayer = LayerMask.NameToLayer("Player"); }
public void Cache(WorldContext worldContext) { terminatorAIComponents = worldContext.GetComponentsContainer <TerminatorAIComponent>(); h0ncker = worldContext.Get <InputComponent>(0).Entity; playersPositionComponent = h0ncker.GetComponent <PositionComponent>(); timeComponent = worldContext.Get <TimeComponent>(0); vfxPoolComponent = worldContext.Get <VFXPoolComponent>(0); obstaclesLayer = LayerMask.GetMask("Obstacles"); playerLayer = LayerMask.GetMask("Player"); navMeshPath = new NavMeshPath(); }
public void Cache(WorldContext worldContext) { sharkAIComponents = worldContext.GetComponentsContainer <SharkAIComponent>(); h0ncker = worldContext.Get <InputComponent>(0).Entity; playersPositionComponent = h0ncker.GetComponent <PositionComponent>(); timeComponent = worldContext.Get <TimeComponent>(0); vfxPoolComponent = worldContext.Get <VFXPoolComponent>(0); antagonistComponent = worldContext.Get <AntagonistComponent>(0); obstaclesLayer = LayerMask.NameToLayer("Obstacles"); itemsLayer = LayerMask.NameToLayer("Items"); enemiesLayer = LayerMask.NameToLayer("Enemies"); playerLayer = LayerMask.NameToLayer("Player"); }
public void Handle(WorldContext worldContext) { for (int i = projectileComponents.Count - 1; i >= 0; i--) { var projectileComponent = (ProjectileComponent)projectileComponents[i]; var triggerComponent = projectileComponent.Entity.GetComponent <TriggerComponent>(); triggerComponent.Collisions.RemoveAll(item => item == null); bool alive = true; //foreach (var collision in triggerComponent.Collisions) for (int j = 0; j < triggerComponent.Collisions.Count; j++) { var collision = triggerComponent.Collisions[j]; if (collision == null) { continue; } if (collision.gameObject.layer == obstacleLayer) { alive = false; } if (collision.gameObject == projectileComponent.Source.gameObject) { continue; } if (collision.gameObject.layer == playerLayer) { worldContext.Get <GameStateComponent>(0).GameState = GameState.DEFEAT; return; } if (collision.gameObject.layer == itemsLayer) { alive = false; var target = collision.gameObject.GetComponent <Entity>(); if (target.HasComponent <BreakableComponent>()) { var particlesFX = vfxPoolComponent.VFXPool.Pop("Shattering", 3f); particlesFX.GameObject.transform.position = target.transform.position; particlesFX.GameObject.SetActive(true); antagonistComponent.Score += antagonistComponent.Settings.ScorePerItemBroken; var vfxInstance = vfxPoolComponent.VFXPool.Pop("Score message", 1.6f); vfxInstance.GameObject.transform.position = target.transform.position; vfxInstance.GameObject.transform.GetChild(0).GetComponent <TextMeshPro>().text = string.Format("+{0}", antagonistComponent.Settings.ScorePerItemBroken); vfxInstance.GameObject.SetActive(true); GameObject.Destroy(target.gameObject); } else { GameObject.Destroy(target.gameObject); } } if (collision.gameObject.layer == enemiesLayer) { var particlesFX = vfxPoolComponent.VFXPool.Pop("Shattering", 3f); particlesFX.GameObject.transform.position = collision.gameObject.transform.position; particlesFX.GameObject.SetActive(true); antagonistComponent.Score += antagonistComponent.Settings.ScorePerUnitKilled; var vfxInstance = vfxPoolComponent.VFXPool.Pop("Score message", 1.6f); vfxInstance.GameObject.transform.position = collision.gameObject.transform.position; vfxInstance.GameObject.transform.GetChild(0).GetComponent <TextMeshPro>().text = string.Format("+{0}", antagonistComponent.Settings.ScorePerUnitKilled); vfxInstance.GameObject.SetActive(true); GameObject.Destroy(collision.gameObject); } } if (!alive) { GameObject.Destroy(projectileComponent.gameObject); } } }
public void Handle(WorldContext worldContext) { for (int i = 0; i < antagonistComponents.Count; i++) { var antagonistComponent = (AntagonistComponent)antagonistComponents[i]; if (antagonistComponent.IsMonologuing) { continue; } if (antagonistComponent.CurrentStage >= antagonistComponent.Settings.StageSettings.Length) { worldContext.Get <GameStateComponent>(0).GameState = GameState.VICTORY; return; } var currentStage = antagonistComponent.Settings.StageSettings[antagonistComponent.CurrentStage]; int scoreCap = currentStage.ScoreCap; if (antagonistComponent.Score >= scoreCap) { gameStateComponent.GameState = GameState.PAUSED; var vfxInstance = vfxPoolComponent.VFXPool.Pop("Message (long)", currentStage.TextTypingDuration + 0.41f); var typer = vfxInstance.GameObject.GetComponent <Typer>(); typer.Text = currentStage.TextVariants[UnityEngine.Random.Range(0, currentStage.TextVariants.Length)]; typer.TextColor = currentStage.TextColor; vfxInstance.GameObject.transform.SetParent(canvasComponent.Canvas.transform, true); Transform messageTransform = antagonistComponent.MessageTransform; vfxInstance.GameObject.transform.position = messageTransform.position; vfxInstance.GameObject.GetComponent <AnimatedPopup>().StayDuration = currentStage.TextTypingDuration; Sequence sequence = DOTween.Sequence(); sequence.Append(cameraComponent.Camera.transform.DOShakePosition( currentStage.TextTypingDuration + 0.41f, new Vector3(1f, 1f, 0f).normalized *currentStage.CameraShakeStrength, 15)); sequence.InsertCallback( currentStage.TextTypingDuration + 0.41f, () => { gameStateComponent.GameState = GameState.RUNNING; antagonistComponent.IsMonologuing = false; }); vfxInstance.GameObject.SetActive(true); antagonistComponent.CurrentStage++; antagonistComponent.IsMonologuing = true; } } }
public void Handle(WorldContext worldContext) { for (int i = 0; i < h0nckerAnimationComponents.Count; i++) { var animationComponent = (H0nckerAnimationComponent)h0nckerAnimationComponents[i]; var inputComponent = animationComponent.Entity.GetComponent <InputComponent>(); animationComponent.animator.SetBool("Walking", inputComponent.IsWalking); animationComponent.animator.SetBool("Flapping wings", inputComponent.IsFlappingWings); if (inputComponent.Honk) { animationComponent.animator.SetTrigger("Honk"); var vfxInstance = vfxPoolComponent.VFXPool.Pop("Message (small)", 0.71f); vfxInstance.GameObject.GetComponent <AnimatedPopup>().LeftToRight = inputComponent.LastInputXSign > 0f; vfxInstance.GameObject.transform.GetChild(2).GetComponent <Text>().text = "HONK!"; vfxInstance.GameObject.transform.SetParent(canvasComponent.Canvas.transform, true); Transform messageTransform = animationComponent.Entity.GetComponent <BeakComponent>().MessageTransform; vfxInstance.GameObject.transform.position = messageTransform.position; vfxInstance.GameObject.SetActive(true); inputComponent.Honk = false; } if (inputComponent.PickUp) { animationComponent.animator.SetTrigger("Pick up"); inputComponent.PickUp = false; var sequence = DOTween.Sequence(); sequence.InsertCallback(0.5f, () => { animationComponent.Entity.GetComponent <BeakComponent>().MagnetActive = true; }); } if (inputComponent.Toss) { inputComponent.Toss = false; Vector3 targetPosition = cameraComponent.Camera.ScreenToWorldPoint(Input.mousePosition); targetPosition = new Vector3(targetPosition.x, targetPosition.y, animationComponent.transform.position.z); var tile = worldContext.Get <TileFieldComponent>(0).TileField.GetTile(new Vector2(targetPosition.x, targetPosition.y)); if (tile == null) { break; } animationComponent.animator.SetTrigger("Honk"); var beakComponent = animationComponent.Entity.GetComponent <BeakComponent>(); beakComponent.MagnetActive = true; var target = beakComponent.Contents; var tossedComponent = target.gameObject.AddComponent <TossedComponent>(); tossedComponent.StartPoint = animationComponent.transform.position; tossedComponent.EndPoint = targetPosition; float distance = (targetPosition - animationComponent.transform.position).magnitude; float duration = distance / beakComponent.TossSpeed; var sequence = DOTween.Sequence(); tossedComponent.Sequence = sequence; sequence.Append(target.transform.DOJump(targetPosition, 1f, 1, duration).SetEase(Ease.Linear)); sequence.InsertCallback( duration, () => { if (target.HasComponent <BreakableComponent>()) { var particlesFX = vfxPoolComponent.VFXPool.Pop("Shattering", 3f); particlesFX.GameObject.transform.position = target.transform.position; particlesFX.GameObject.SetActive(true); antagonistComponent.Score += antagonistComponent.Settings.ScorePerItemBroken; var vfxInstance = vfxPoolComponent.VFXPool.Pop("Score message", 1.6f); vfxInstance.GameObject.transform.position = target.transform.position; vfxInstance.GameObject.transform.GetChild(0).GetComponent <TextMeshPro>().text = string.Format("+{0}", antagonistComponent.Settings.ScorePerItemBroken); vfxInstance.GameObject.SetActive(true); GameObject.Destroy(target.gameObject); } else { GameObject.Destroy(tossedComponent); } }); } var scale = animationComponent.transform.localScale; scale.x = inputComponent.LastInputXSign * Mathf.Abs(scale.x); animationComponent.transform.localScale = scale; } }
public void Cache(WorldContext worldContext) { beakComponents = worldContext.GetComponentsContainer <BeakComponent>(); tileFieldComponent = worldContext.Get <TileFieldComponent>(0); }
public void Cache(WorldContext worldContext) { locomotionComponents = worldContext.GetComponentsContainer <LocomotionComponent>(); timeComponent = worldContext.Get <TimeComponent>(0); }
public void Cache(WorldContext worldContext) { positionOnTileComponents = worldContext.GetComponentsContainer <PositionOnTileComponent>(); tileFieldComponent = worldContext.Get <TileFieldComponent>(0); }
public void Cache(WorldContext worldContext) { inventoryComponents = worldContext.GetComponentsContainer <InventoryComponent>(); inventoryWindowComponent = worldContext.Get <InventoryWindowComponent>(0); }
public void Handle(WorldContext worldContext) { for (int i = 0; i < sharkAIComponents.Count; i++) { var sharkAIComponent = (SharkAIComponent)sharkAIComponents[i]; Vector3 scale; switch (sharkAIComponent.CurrentState) { case SharkAIStates.IDLE: var positionComponent = sharkAIComponent.Entity.GetComponent <PositionComponent>(); var locomotionComponent = sharkAIComponent.Entity.GetComponent <LocomotionComponent>(); var distance = (positionComponent.RectTransform.anchoredPosition - playersPositionComponent.RectTransform.anchoredPosition).magnitude; if (distance < sharkAIComponent.VisionRadius) { sharkAIComponent.CurrentState = SharkAIStates.SHOOTING; sharkAIComponent.CurrentCooldown = sharkAIComponent.ShootingDuration; locomotionComponent.Velocity = Vector2.zero; Vector2 direction = playersPositionComponent.RectTransform.anchoredPosition - positionComponent.RectTransform.anchoredPosition; sharkAIComponent.LazerDirection = new Vector3(direction.x, direction.y, 0f); RaycastHit hitInfo; Physics.Raycast( sharkAIComponent.transform.position, sharkAIComponent.LazerDirection, out hitInfo, 100f, obstaclesLayer, QueryTriggerInteraction.Ignore); sharkAIComponent.EndPoint = hitInfo.Equals(default(RaycastHit)) ? sharkAIComponent.transform.position + sharkAIComponent.LazerDirection.normalized * 100f : hitInfo.point; var vfxInstance = vfxPoolComponent.VFXPool.Pop("Lazer beam", sharkAIComponent.ShootingDuration); vfxInstance.GameObject.transform.position = Vector3.zero; var lineRenderer = vfxInstance.GameObject.GetComponent <LineRenderer>(); lineRenderer.SetPosition(0, sharkAIComponent.transform.position); lineRenderer.SetPosition(1, sharkAIComponent.EndPoint); Color redTransparent = new Color(1f, 0f, 0f, 0f); var sequence = DOTween.Sequence(); sequence.Append(lineRenderer.DOColor(new Color2(redTransparent, redTransparent), new Color2(Color.red, Color.red), sharkAIComponent.LazerHeatingUpDuration)); sequence.InsertCallback(sharkAIComponent.ShootingDuration, () => { vfxInstance.GameObject.SetActive(false); }); vfxInstance.GameObject.SetActive(true); sharkAIComponent.LazerBeam = vfxInstance.GameObject; scale = sharkAIComponent.transform.localScale; scale.x = Mathf.Sign(positionComponent.RectTransform.anchoredPosition.x - playersPositionComponent.RectTransform.anchoredPosition.x) * Mathf.Abs(scale.x); sharkAIComponent.transform.localScale = scale; break; } var velocity = locomotionComponent.Speed * sharkAIComponent.CurrentDirection * timeComponent.CustomTimeScale; /* * var boxCollider = sharkAIComponent.GetComponent<BoxCollider>(); * * Vector3 center = sharkAIComponent.transform.position + boxCollider.center; * * Vector3 size = boxCollider.size; * * if (Physics.BoxCast( * center, * size / 2f, * new Vector3(velocity, 0f, 0f), * Quaternion.identity, * Mathf.Abs(velocity) / 2f, * obstaclesLayer, * QueryTriggerInteraction.Ignore)) * sharkAIComponent.CurrentDirection *= -1f; */ sharkAIComponent.CurrentCooldown += Time.deltaTime * timeComponent.CustomTimeScale; if (sharkAIComponent.CurrentCooldown > 5f) { sharkAIComponent.CurrentCooldown = 0f; sharkAIComponent.CurrentDirection *= -1f; } scale = sharkAIComponent.transform.localScale; scale.x = -sharkAIComponent.CurrentDirection * Mathf.Abs(scale.x); sharkAIComponent.transform.localScale = scale; locomotionComponent.Velocity = new Vector2(locomotionComponent.Speed * sharkAIComponent.CurrentDirection, 0f); break; case SharkAIStates.SHOOTING: positionComponent = sharkAIComponent.Entity.GetComponent <PositionComponent>(); bool startsUsingLaser = sharkAIComponent.CurrentCooldown < sharkAIComponent.ShootingDuration - sharkAIComponent.LazerHeatingUpDuration; sharkAIComponent.CurrentCooldown -= Time.deltaTime * timeComponent.CustomTimeScale; if (!startsUsingLaser && sharkAIComponent.CurrentCooldown < sharkAIComponent.ShootingDuration - sharkAIComponent.LazerHeatingUpDuration) { startsUsingLaser = true; sharkAIComponent.LazerBeam.transform.DOShakePosition( sharkAIComponent.CurrentCooldown, new Vector3(0.05f, 0.05f, 0f), 20, fadeOut: false); } if (sharkAIComponent.CurrentCooldown < sharkAIComponent.ShootingDuration - sharkAIComponent.LazerHeatingUpDuration) { var lineRenderer = sharkAIComponent.LazerBeam.GetComponent <LineRenderer>(); lineRenderer.SetPosition(0, sharkAIComponent.transform.position + sharkAIComponent.LazerBeam.transform.localPosition); lineRenderer.SetPosition(1, sharkAIComponent.EndPoint + sharkAIComponent.LazerBeam.transform.localPosition); } if (sharkAIComponent.CurrentCooldown < sharkAIComponent.ShootingDuration - sharkAIComponent.LazerHeatingUpDuration) { RaycastHit[] hits = Physics.RaycastAll( sharkAIComponent.transform.position, sharkAIComponent.LazerDirection, sharkAIComponent.LazerDirection.magnitude, LayerMask.GetMask("Items", "Enemies", "Player")); for (int j = 0; j < hits.Length; j++) { var collision = hits[j].collider; if (collision == null) { continue; } if (collision.gameObject == sharkAIComponent.gameObject) { continue; } if (collision.gameObject.layer == playerLayer) { worldContext.Get <GameStateComponent>(0).GameState = GameState.DEFEAT; return; } if (collision.gameObject.layer == itemsLayer) { var target = collision.gameObject.GetComponent <Entity>(); if (target.HasComponent <BreakableComponent>()) { var particlesFX = vfxPoolComponent.VFXPool.Pop("Shattering", 3f); particlesFX.GameObject.transform.position = target.transform.position; particlesFX.GameObject.SetActive(true); antagonistComponent.Score += antagonistComponent.Settings.ScorePerItemBroken; var vfxInstance = vfxPoolComponent.VFXPool.Pop("Score message", 1.6f); vfxInstance.GameObject.transform.position = target.transform.position; vfxInstance.GameObject.transform.GetChild(0).GetComponent <TextMeshPro>().text = string.Format("+{0}", antagonistComponent.Settings.ScorePerItemBroken); vfxInstance.GameObject.SetActive(true); GameObject.Destroy(target.gameObject); } else { GameObject.Destroy(target.gameObject); } } if (collision.gameObject.layer == enemiesLayer) { var particlesFX = vfxPoolComponent.VFXPool.Pop("Shattering", 3f); particlesFX.GameObject.transform.position = collision.gameObject.transform.position; particlesFX.GameObject.SetActive(true); antagonistComponent.Score += antagonistComponent.Settings.ScorePerUnitKilled; var vfxInstance = vfxPoolComponent.VFXPool.Pop("Score message", 1.6f); vfxInstance.GameObject.transform.position = collision.gameObject.transform.position; vfxInstance.GameObject.transform.GetChild(0).GetComponent <TextMeshPro>().text = string.Format("+{0}", antagonistComponent.Settings.ScorePerUnitKilled); vfxInstance.GameObject.SetActive(true); GameObject.Destroy(collision.gameObject); } } } if (sharkAIComponent.CurrentCooldown < 0f) { sharkAIComponent.CurrentState = SharkAIStates.COOLDOWN; sharkAIComponent.CurrentCooldown = sharkAIComponent.CooldownDuration; sharkAIComponent.LazerDirection = Vector3.zero; sharkAIComponent.EndPoint = Vector3.zero; sharkAIComponent.LazerBeam = null; break; } break; case SharkAIStates.COOLDOWN: positionComponent = sharkAIComponent.Entity.GetComponent <PositionComponent>(); distance = (positionComponent.RectTransform.anchoredPosition - playersPositionComponent.RectTransform.anchoredPosition).magnitude; if (distance < sharkAIComponent.VisionRadius) { sharkAIComponent.CurrentState = SharkAIStates.SHOOTING; sharkAIComponent.CurrentCooldown = sharkAIComponent.ShootingDuration; Vector2 direction = playersPositionComponent.RectTransform.anchoredPosition - positionComponent.RectTransform.anchoredPosition; sharkAIComponent.LazerDirection = new Vector3(direction.x, direction.y, 0f); RaycastHit hitInfo; Physics.Raycast( sharkAIComponent.transform.position, sharkAIComponent.LazerDirection, out hitInfo, 100f, obstaclesLayer, QueryTriggerInteraction.Ignore); sharkAIComponent.EndPoint = hitInfo.Equals(default(RaycastHit)) ? sharkAIComponent.transform.position + sharkAIComponent.LazerDirection.normalized * 100f : hitInfo.point; var vfxInstance = vfxPoolComponent.VFXPool.Pop("Lazer beam", sharkAIComponent.ShootingDuration); var lineRenderer = vfxInstance.GameObject.GetComponent <LineRenderer>(); lineRenderer.SetPosition(0, sharkAIComponent.transform.position); lineRenderer.SetPosition(1, sharkAIComponent.EndPoint); Color redTransparent = new Color(1f, 0f, 0f, 0f); var sequence = DOTween.Sequence(); sequence.Append(lineRenderer.DOColor(new Color2(redTransparent, redTransparent), new Color2(Color.red, Color.red), sharkAIComponent.LazerHeatingUpDuration)); sequence.InsertCallback(sharkAIComponent.ShootingDuration, () => { vfxInstance.GameObject.SetActive(false); }); vfxInstance.GameObject.SetActive(true); sharkAIComponent.LazerBeam = vfxInstance.GameObject; scale = sharkAIComponent.transform.localScale; scale.x = Mathf.Sign(positionComponent.RectTransform.anchoredPosition.x - playersPositionComponent.RectTransform.anchoredPosition.x) * Mathf.Abs(scale.x); sharkAIComponent.transform.localScale = scale; break; } sharkAIComponent.CurrentCooldown -= Time.deltaTime * timeComponent.CustomTimeScale; if (sharkAIComponent.CurrentCooldown < 0f) { sharkAIComponent.CurrentState = SharkAIStates.IDLE; sharkAIComponent.CurrentCooldown = 0; break; } break; } } }
public void Cache(WorldContext worldContext) { timeComponent = worldContext.Get <TimeComponent>(0); }