/// <summary> /// Returns true if hero can move to the target point. /// </summary> private bool _heroWalkCheck(string direction) { int xOff = 0, yOff = 0; switch (direction) { case "Right": xOff = 1; yOff = 0; break; case "Left": xOff = -1; yOff = 0; break; case "Up": xOff = 0; yOff = 1; break; case "Down": xOff = 0; yOff = -1; break; } int xLoc = hero.posX + xOff, yLoc = hero.posY + yOff; if (!O_GetUnit.I._pointHasUnit(xLoc, yLoc)) { return(true); } O_ClassUnit obstacle = O_GetUnit.I._getUnitFromPoint(xLoc, yLoc); string moveType = hero.moveType, obsType = obstacle.obstacleType; // Checks if (moveType == "land" && (obsType == "boulder")) { return(false); } return(true); }
public O_ClassUnit _getUnitFromPoint(int posX, int posY) { O_ClassUnit retUnit = O_Globals.I.units [0]; foreach (O_ClassUnit unit in O_Globals.I.units) { if (unit.posX == posX && unit.posY == posY) { retUnit = unit; break; } } return(retUnit); }
// Includes // - _polarizeHeroPosition - Switch hero position when switching maps // - (10, 0) becomes (-10, 0) #region "Misc" /// <summary> /// Switch hero position when switching maps, i.e. (10, 0) becomes (-10, 0). /// Only use this when the player reaches the edge of an overworld map. /// </summary> private void _polarizeHeroPosition(string facing) { int profile = ZPlayerPrefs.GetInt("Profile"); O_ClassUnit hero = O_ControlHero.I.hero; if (facing == "Up" || facing == "Down") { PlayerPrefs.SetInt("O_LastX_" + profile.ToString(), hero.posX); PlayerPrefs.SetInt("O_LastY_" + profile.ToString(), hero.posY * -1); } else if (facing == "Left" || facing == "Right") { PlayerPrefs.SetInt("O_LastX_" + profile.ToString(), hero.posX * -1); PlayerPrefs.SetInt("O_LastY_" + profile.ToString(), hero.posY); } }
public void _start() { int prof = O_Globals.I.prof; int posX = PlayerPrefs.GetInt("O_LastX_" + prof.ToString()), posY = PlayerPrefs.GetInt("O_LastY_" + prof.ToString()); string facing = PlayerPrefs.GetString("O_LastFacing_" + prof.ToString()); // Spawns the hero O_ControlUnit.I._createUnit("testYou", posX, posY); hero = O_GetUnit.I._getLastCreatedUnit(); hero.facing = facing; O_ControlCamera.I._reposition(hero.sprite.transform.position.x, hero.sprite.transform.position.y); // Hero stats hero.moveType = "land"; /////// Misc //////// // Set the hero's gameobject name to MainHero hero.sprite.name = "MainHero"; }
//Returns true if hero is entering a region private bool _heroEnterRegionCheck(O_ClassUnit hero) { int prof = PlayerPrefs.GetInt("CurProfile"); foreach (O_ClassUnit cL in O_Globals.I.units) { if (cL.nature == "location") { if (cL.posX == hero.posX && cL.posY == hero.posY) { O_ControlScene.I._setNextArea(cL.nextScene, cL.location, hero.facing); O_ControlScene.I._switchScene(); //Pause controls and moves the curtain isPaused = true; //O_ControlUI_Move.I._moveUI(1); return(true); } } } return(false); }
void Update() { if (!editorMode) { return; } try{ Vector3 gamePoint = O_ControlCamera.I._getGamePoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y)); int actPosX = (int)gamePoint.x, actPosY = (int)gamePoint.y; // Doodad and tail rotation float zRotation = 0; if (rotateDood) { float.TryParse(doodRotation, out zRotation); } #region "Mouse Click" if (Input.GetMouseButton(0)) { #region "Terrain Brush" if (brushMode == "Terrain") { O_ClassTerrain targetTile = O_GetTerrain.I._getTerrain(actPosX, actPosY); targetTile._changeTerrain(O_DB_Terrain.I._getSprite(terType), terType); targetTile.sprite.name = targetTile.sprite.name.Replace("(Clone)", ""); targetTile.sprite.transform.SetParent(GameObject.Find("_O_TERRAIN").transform); } #endregion #region "Unit Brush" else if (brushMode == "Unit") { // Remove existing unit if present bool hasUnit = O_GetUnit.I._pointHasUnit(actPosX, actPosY); if (hasUnit) { O_ControlUnit.I._addToDestroyList(O_GetUnit.I._getUnitFromPoint(actPosX, actPosY)); } // Create Unit O_ControlUnit.I._createUnit(unitType, actPosX, actPosY); // Specials O_ClassUnit createdUnit = O_GetUnit.I._getLastCreatedUnit(); switch (createdUnit.type) { case "pathBlocker": // Switch pathBlocker sprite createdUnit._changeSprite("pathBlocker_Editor"); createdUnit.sprite.transform.SetParent(GameObject.Find("_O_UNITS").transform); break; } // Finalize creation createdUnit.sprite.name = createdUnit.sprite.name.Replace("(Clone)", ""); createdUnit.sprite.transform.SetParent(GameObject.Find("_O_UNITS").transform); } #endregion #region "Doodad Brush (Per Tile)" else if (brushMode == "Doodad") { // Remove existing doodad if present bool hasDood = O_GetDoodad.I._pointHasDood(actPosX, actPosY); if (hasDood) { O_ControlDoodad.I._addToDestroyList(O_GetDoodad.I._getDoodFromPoint(actPosX, actPosY)); } // Create Doodad if (rotateDood) { O_ControlDoodad.I._createDoodad(doodType, actPosX, actPosY, zRotation); } else { O_ControlDoodad.I._createDoodad(doodType, actPosX, actPosY); } // Specials O_ClassDoodad createdDood = O_GetDoodad.I._getLastCreatedDood(); /*Create tail*/ if (createTail) { O_ControlDoodad.I._createTails(createdDood, isTailTree, zRotation); } // Finalize creation createdDood.sprite.name = createdDood.sprite.name.Replace("(Clone)", ""); createdDood.sprite.transform.SetParent(GameObject.Find("_O_DOODADS").transform); } #endregion #region "Corner Brush" else if (brushMode == "Corner") { // Remove existing corner if present bool hasDood = O_GetDoodad.I._pointHasDood(actPosX, actPosY, "Corner"); if (hasDood) { O_ControlDoodad.I._addToDestroyList(O_GetDoodad.I._getDoodFromPoint(actPosX, actPosY, "Corner")); } // Create Doodad string cornerType_orig = cornerType; if (cornerBase == "Line") { } else { if (cornerBase == "Outward") { cornerType += "Corner3"; } else if (cornerBase == "Inward") { cornerType += "Corner2"; } float zRot = 0; float.TryParse(cornerLine, out zRot); O_ControlDoodad.I._createDoodad(cornerType, actPosX, actPosY, zRot); } // Specials O_ClassDoodad createdDood = O_GetDoodad.I._getLastCreatedDood(); /*Return original cornerBase*/ cornerType = cornerType_orig; // Finalize creation createdDood.sprite.name = createdDood.sprite.name.Replace("(Clone)", ""); createdDood.sprite.transform.SetParent(GameObject.Find("_O_DOODADS").transform); } #endregion #region "Unit Eraser" else if (brushMode == "Unit Eraser") { // Remove existing unit if present bool hasUnit = O_GetUnit.I._pointHasUnit(actPosX, actPosY); if (hasUnit) { O_ControlUnit.I._addToDestroyList(O_GetUnit.I._getUnitFromPoint(actPosX, actPosY)); Debug.Log("Unit erased!"); } } #endregion #region "Doodad Eraser" else if (brushMode == "Doodad Eraser") { // Remove existing unit if present bool hasDood = O_GetDoodad.I._pointHasDood(actPosX, actPosY); if (hasDood) { O_ControlDoodad.I._addToDestroyList(O_GetDoodad.I._getDoodFromPoint(actPosX, actPosY)); Debug.Log("Doodad erased!"); // Remove tails for (float x = -0.5f; x < 1; x += 0.25f) { for (float y = -0.5f; y < 1; y += 0.25f) { hasDood = O_GetDoodad.I._pointHasDood(actPosX + x, actPosY + y); if (hasDood) { O_ControlDoodad.I._addToDestroyList(O_GetDoodad.I._getDoodFromPoint(actPosX + x, actPosY + y)); } } } } } #endregion } #endregion #region "Keyboard Keys" if (Input.GetKey(KeyCode.E) && !telePressed) { O_ControlHero.I._instantMove(actPosX, actPosY); Debug.Log("Teleported to " + actPosX + ", " + actPosY + ", " + telePressed); telePressed = true; } else if (!Input.GetKey(KeyCode.E) && telePressed) { telePressed = false; } #endregion #region "Bursh control" brush.transform.position = new Vector3(actPosX, actPosY, 0); #endregion }catch (Exception ex) { Debug.Log("Turning off editor mode. Reason: " + ex.Message); _turnOffEditor(true); } }
public void _addToDestroyList(O_ClassUnit targetUnit) { toDestroy.Add(targetUnit.id); }