public override void Act() { base.Act(); // if (state == States.Waiting) { waitTime -= 1 * Time.deltaTime; if (waitTime <= 0) { ChangeState(States.Moving); } } else { // *** Only project heading if we are NOT busy! if (!awareOfCore && !curious) { if (Helper.PointDistance(pos, destinationPos) < cc.radius) { destinationPos = pos + rb.velocity * 1000; // *** Go indefinitely into that direction! } } // Direction = Mathf.MoveTowardsAngle(Direction, Helper.PointDirection(transform.position, destinationPos), turnRate / Helper.SECOND); // *** If you leave the area, you're dead! Roomgrid rg = Roomgrid.Instance(); if (!rg.ActorInBounds(this)) { Die(); } } }
/// <summary> /// Creates the base game object that all other create events use. /// </summary> /// <param name="spot"></param> /// <returns></returns> private GameObject _CreateObject(Vector2 spot) { Roomgrid rg = Roomgrid.Instance(); GameManager gm = GameManager.Instance(); // // GameObject go = new GameObject("_gameobject"); go.transform.parent = gm.gameStateMap[GameManager.GameStates.Game].transform; // *** Place it into the "game" area. // go.transform.localPosition = new Vector3(rg.Width * spot.x, rg.Height * spot.y, rg.GroundZ - 0.1f); go.transform.localScale = Vector3.one * 0.25f; // *** 25% smaller... return(go); }
/// <summary> /// Creates a Backdrop, a static, visual object. /// </summary> /// <param name="name"></param> /// <param name="spot"></param> /// <returns></returns> public Backdrop CreateBackdrop(string name, Vector2 spot) { Roomgrid rg = Roomgrid.Instance(); GameObject go = _CreateObject(spot); go.name = "_backdrop"; go.transform.localPosition = new Vector3(go.transform.localPosition.x, go.transform.localPosition.y, rg.GroundZ); go.transform.localScale = Vector3.one * 1.0f; // *** Normal size go.layer = 8; // Backdrop b = go.AddComponent <Backdrop>(); b.AssignSprite(name); b.sprite.sr.material = (Material)Resources.Load("GroundMat"); // return(b); }
/// <summary> /// Gets called every step, but NOT by the built-in update function! /// </summary> /// <param name="gm"></param> internal void Run(GameManager gm) { phaseTime += 1; // Joystick j = Joystick.Instance(); Roomgrid rg = Roomgrid.Instance(); switch (phase) { // *** Allow 1 step for things to initialize and start. case Phases.Initialize: ChangePhase(Phases.Begin); break; case Phases.Begin: ChangePhase(Phases.PlaceCore); break; case Phases.PlaceCore: coreObj.transform.Translate(gameCursor.transform.position.x - coreObj.transform.position.x, gameCursor.transform.position.y - coreObj.transform.position.y, 0); // coreObj.pos = gameCursor.transform.position; // if (coreObj.colCount > 0) { gameCursor.lite.color = Color.red; } else { gameCursor.lite.color = Color.white; if (!rg.PointInBounds(coreObj.pos)) { } // *** Intentionally using "point", not "actor", because I don't want it to hang off the side of the screen... else if (j.mouseLeftClick) { coreObj.OnSpawn(); // ChangePhase(Phases.PlaceTurrets); } } break; case Phases.PlaceTurrets: if (placeTurret == null) { placeTurret = CreateStructure(levelInfo.turrets[_placementIndex], new Vector2(0.0f, 0.2f)); } // placeTurret.pos = gameCursor.transform.position; // if (placeTurret.colCount > 0) { gameCursor.lite.color = Color.red; } else { gameCursor.lite.color = Color.white; if (!rg.PointInBounds(placeTurret.pos)) { } // *** Intentionally using "point", not "actor", because I don't want it to hang off the side of the screen... else if (j.mouseLeftClick) { placeTurret.OnSpawn(); // _placementIndex++; placeTurret = null; // if (_placementIndex >= levelInfo.turrets.Count) { ChangePhase(Phases.PreBattle); } } } break; case Phases.PreBattle: gameCursor.lite.color = Color.white; // ChangePhase(Phases.Battle); break; case Phases.Battle: // ??? <-- ...?!?! battleTime += Time.deltaTime; // levelInfo.scenario.Check(battleTime); // bool test = true; if (creepCount > 0) { test = false; } else { foreach (Database.SpawnSequenceRunner Q in levelInfo.scenario.spawns) { if (!Q.terminated) { test = false; } } } if (test) { ChangePhase(Phases.Victory); } break; case Phases.Victory: if (phaseTime >= 5 * Helper.SECOND) { ChangePhase(Phases.PostBattle); } break; case Phases.Defeat: if (phaseTime >= 5 * Helper.SECOND) { ChangePhase(Phases.PostBattle); } break; case Phases.PostBattle: ChangePhase(Phases.Finish); break; case Phases.Finish: break; } }