private void SpawnNext(int centerOffset = 0) { var next = _curPattern.GetNext(); if (next != null) { _lastSpawned2 = _lastSpawned1; _lastSpawned1 = next; var v = next.transform.position; v.x += v.x > 0 ? -centerOffset : centerOffset; next.transform.position = v; Unit u; if (Level.Tutorial && _2hpTutorialSpawned < 1 && (u = next.GetComponent <Unit>()).HP == 2) { _2hpTutorialSpawned++; var uh = UnitHint.CreateUnitText("^\n2 HP", u); Utils.Animate(new Color(0.3f, 0.3f, 0.3f), new Color(0.9f, 0.9f, 0.9f), 3f, (c) => { uh.Tint.Color = c; }, null, true); } } if (!_curPattern.Ended()) { return; } _curPattern.Reset(); if (_cl >= _patterns.Count) { return; } _ci += Random.Range(1, _patterns[_cl].Count - 1); _ci %= _patterns[_cl].Count; _curPattern = _patterns[_cl][_ci]; }
private void Update() { if (Menu.Instance.isActiveAndEnabled && !Menu.Instance.CanvasHidden) { return; } bool leftDown = Input.GetButtonDown("Left"), rightDown = Input.GetButtonDown("Right"); if (Input.GetKeyDown(KeyCode.R)) { TakeDmg(this, 999); return; } // if (Input.GetKeyDown(KeyCode.G)) // { // Godmode = !Godmode; // } if (Input.touchCount > 0) { for (var i = 0; i < Input.touchCount; ++i) { if (Input.GetTouch(i).phase != TouchPhase.Began) { continue; } var pos = Input.GetTouch(i).position.x / Camera.main.pixelWidth; if (pos > 0.5f) { rightDown = true; } else { leftDown = true; } } } if (Godmode) { Unit u; // ReSharper disable once AssignmentInConditionalExpression if (u = Level.Instance.Get(Position.IntX() + 1)) { if (!(u is DownTriangleEnemy)) { u.HP = 1; rightDown = true; } // ReSharper disable once AssignmentInConditionalExpression } else if (u = Level.Instance.Get(Position.IntX() - 1)) { if (!(u is DownTriangleEnemy)) { u.HP = 1; leftDown = true; } } } var dir = leftDown ? -1 : (rightDown ? 1 : 0); if (TutorialHitChanceDir != 0 && TutorialHitChanceDir != dir) { dir = 0; } if (dir == 0) { return; } if (Menu.Instance.isActiveAndEnabled && !Level.Tutorial) { var gm = GridMarks.Instance; if (gm.FieldSize() > 2) { gm.ShiftBorder(dir); } } else if (Level.Tutorial && !Level.Spawning && !_tutSpawned && !Menu.Instance.HintCanvas.activeSelf) { Debug.LogWarning("tutorial spawn"); _tutSpawned = true; var e = BasicEnemy.Prefab.Instantiate(); e.transform.position = new Vector3(-dir, 0, 0); var u = e.GetComponent <Unit>(); u.HP = 1; UnitHint.CreateUnitText("^\nKILL", u); u.DieEvent += () => { var e1 = BasicEnemy.Prefab.Instantiate(); e1.transform.position = new Vector3(dir * 2, 0, 0); var ud1 = e1.GetComponent <Unit>(); UnitHint.CreateUnitText("^\nKILL", ud1); ud1.HP = 1; e1 = BasicEnemy.Prefab.Instantiate(); e1.transform.position = new Vector3(-dir * 2, 0, 0); var ud2 = e1.GetComponent <Unit>(); UnitHint.CreateUnitText("^\nKILL", ud2); ud2.HP = 1; ud2.DieEvent += () => { if (ud1 != null) { return; } var e2 = BasicEnemy.Prefab.Instantiate(); e2.transform.position = new Vector3(dir, 0, 0); var u2 = e2.GetComponent <Unit>(); UnitHint.CreateUnitText("^\nKILL", u2); u2.HP = 1; u2.DieEvent += () => { Level.Instance.StartLevel(); GridMarks.Instance.BringBackTint(-1); GridMarks.Instance.BringBackTint(1); // GridMarks.Instance.SetBorders(0, 0); GridMarks.Instance.ShiftBorder(1, false); GridMarks.Instance.ShiftBorder(-1, false); }; }; ud1.DieEvent += () => { if (ud2 != null) { return; } var e2 = BasicEnemy.Prefab.Instantiate(); e2.transform.position = new Vector3(-dir, 0, 0); var u2 = e2.GetComponent <Unit>(); UnitHint.CreateUnitText("^\nKILL", u2); u2.HP = 1; u2.DieEvent += () => { Level.Instance.StartLevel(); GridMarks.Instance.BringBackTint(-1); GridMarks.Instance.BringBackTint(1); GridMarks.Instance.SetBorders(0, 0); }; }; }; } MoveOrAttack(dir); }
public void OnEnable() { if (DebugSlowMo) { Time.timeScale = 0.4f; AudioSource.pitch = 0.4f; } else { Time.timeScale = 1f; AudioSource.pitch = 1f; } Spawning = false; Updating = true; GameOver = false; _started = false; if (PlayerData.Instance.Scores[CurrentLevel] != "0") { BT.gameObject.SetActive(true); BestTimeText.gameObject.SetActive(true); BestTimeText.text = PlayerData.Instance.Scores[CurrentLevel]; } else { BT.gameObject.SetActive(false); BestTimeText.gameObject.SetActive(false); } Enemies.Clear(); TickAction = () => { }; GameOverAction += () => { if (KillerUnit != null) { UnitHint.CreateUnitText("^\nAVENGE", KillerUnit); } }; _levelSpawner = new LevelSpawner(CurrentLevel); _grid = new Grid(30); if (!NextLevelStart) { Player.Prefab.Instantiate(); StartedLevel = CurrentLevel; } else { InitPos(Player.Instance); } var offset = LevelSpawner.Distance; Action a = () => { }; Action ad = () => Player.Instance.TakeDmg(Player.Instance, 999); if (CurrentLevel == 0 && !Tutorial) { GridMarks.Instance.Set("", "", -1, 1, -offset, offset, a, a, true, true); GridMarks.Instance.DisplayBorders(true, false); GridMarks.Instance.RemoveTint(-1); GridMarks.Instance.RemoveTint(1); } else { GridMarks.Instance.Set("", "", -1, 1, -offset, offset, ad, ad, true, true); GridMarks.Instance.RemoveTint(-1); GridMarks.Instance.RemoveTint(1); GridMarks.Instance.LeftSolid = false; GridMarks.Instance.RightSolid = false; GridMarks.Instance.DisplayBorders(false); } if (Tutorial) { GridMarks.Instance.HandlerLeft = a; GridMarks.Instance.HandlerRight = a; GridMarks.Instance.LeftSolid = true; GridMarks.Instance.RightSolid = true; GridMarks.Instance.DisplayBorders(true, false); } GridMarks.Instance.RemoveTint(0); if (!IsFirstStart && Tutorial) { MusicDelay = 0.88f; MusicStart = 2f; } IsFirstStart = false; if (Tutorial && ControlsText.isActiveAndEnabled) { var c = ControlsText.color; c.a = 1; ControlsText.color = c; var ut = ControlsText.GetComponent <UnitedTint>(); c = ut.Color; c.a = 1; ut.Color = c; } else { StartLevel(); } }
public void Move(int relDir, bool onlyAnim = false, bool noSpikes = false) { if (this is Player) { var gm = GridMarks.Instance; if (gm.RightSolid && gm.RightBorder.transform.position.x < Position.x + relDir) { AttackAnim(relDir); GridMarks.Instance.HandlerRight(); return; } if (gm.LeftSolid && gm.LeftBorder.transform.position.x > Position.x + relDir) { AttackAnim(relDir); GridMarks.Instance.HandlerLeft(); return; } } else if (Level.Tutorial && Player.Instance.HasTutorialHitChance) { var near = Level.Instance.Get(Position.IntX() + relDir * 2); if (near is Player) { Player.Instance.HasTutorialHitChance = false; Player.Instance.TutorialHitChanceDir = -relDir; var str = Player.Instance.TutorialHitChanceDir == 1 ? ">" : "<"; var hintGo = UnitHint.CreateUnitText(str, this, 0f, 0f, 2f, Color.white); Utils.Animate(0f, 1f, 1f, (v) => { if (hintGo == null) { return; } var d = Math.Round(v / 0.05f) % 2 == 0; var k = 0.1f; hintGo.transform.position += Vector3.right * (d ? k : -k); }, hintGo, true); Time.timeScale = 0.1f; Utils.Animate(1f, 0.1f, 0.05f, (v) => Level.Instance.AudioSource.pitch = v, null, true); } } var change = new Vector3(0.5f, -0.5f); Utils.Animate(Vector3.zero, change, AnimationWindow / 2, v => transform.localScale += v, this); Utils.InvokeDelayed(() => Utils.Animate(change, Vector3.zero, AnimationWindow / 2, v => transform.localScale += v, this), AnimationWindow / 3 * 2, this); var p = this as Player; if (p != null && !noSpikes) { var vec = relDir > 0 ? new Vector3(0.5f, 0f) : new Vector3(-0.5f, 0f); Utils.Animate(Vector3.zero, vec, AnimationWindow / 2, (v) => { p.Spikes.transform.localPosition += v; p.Spikes.transform.localScale += v * 5; }, this); Utils.Animate(vec, Vector3.zero, AnimationWindow / 2, (v) => { p.Spikes.transform.localPosition += v; p.Spikes.transform.localScale += v * 5; }, this, false, AnimationWindow); } if (!onlyAnim) { Level.Instance.Move(Position.IntX() + relDir, this); } Position += new Vector3(relDir, 0, 0); if (onlyAnim) { _actPos -= new Vector3(relDir, 0, 0); } }