private IEnumerator Move(Coord dest) { // Remove branches entering the stages not chosen in the next column and grey them out for (int i = 0; i < _currMap[dest.col].Length; i++) { StageNode stage = _currMap[dest.col][i]; // Ignore null stages and the current stage if (stage == null || i == dest.row) { continue; } stage.SetInaccessible(); stage.DestroyEntryBranch(); } // Readjust length of vertical path leading to next column PositionVerticalPath(GetCurrStage().GetVerticalPath(), GetCurrStage(), _currMap[dest.col][dest.row]); SetPlayerCoord(dest); _canMove = false; // TODO: move animation? yield return(new WaitForSeconds(1f)); GetCurrStage().EnterStage(); _mapDisplay.SetActive(false); }
private void InitializeStage(ZoneProperties properties, int stageCol, StageNode stage, StageCategory category) { switch (category) { case StageCategory.BATTLE: BattleType battleType = (BattleType)Random.Range(0, System.Enum.GetValues(typeof(BattleType)).Length - 1); stage.SetStage(battleType); InitializeCombatStage(properties, stageCol, stage, battleType); break; case StageCategory.BOSS: stage.SetStage(BattleType.BOSS); InitializeCombatStage(properties, stageCol, stage, BattleType.BOSS); break; case StageCategory.EVENT: EventType eventType = (EventType)Random.Range(0, System.Enum.GetValues(typeof(EventType)).Length); stage.SetStage(eventType); break; default: Debug.LogWarning("No category found when initializing stage."); break; } }
private void DrawIcon(StageNode.StageType type, Vector2 pos) { GameObject newIcon = Instantiate(myIcon, transform); activeIcons.Add(newIcon); newIcon.GetComponent <SpriteRenderer>().sprite = icons[StageNode.GetStageTypeNum(type)]; newIcon.transform.localPosition = new Vector3(pos.x, pos.y, newIcon.transform.position.z); }
// Update is called once per frame void Update() { if (IsFreeze) { return; } if (Input.GetButtonDown("Attack")) { if (_targetStage != FirstNode && State != StageSelectState.Title) { MoveScene(); } } var p = Mathf.MoveTowards(Position, _playerPositionTarget, MoveSpeed * _moveSpeedMag * Time.deltaTime); MovePlayer(p); var forward = p >= Position; var low = forward ? Position : p; var high = forward ? p : Position; foreach (var e in _eventList) { var c = e.GetPosition(); if (low <= c && c <= high) { e.OnExecute(this, forward, false); } } if (Input.GetKeyDown(KeyCode.P) && !_isSceneMoving) { _isSceneMoving = true; _lastSelectedStageIndex = 0; GameData.Instance.DeleteDataAll(); GameData.Instance.Save(); SceneChanger.Instance.MoveScene("StageSelect", 0.2f, 0.2f, SceneChangeType.BlackFade); } if (p == Position) { _currentSelectedStage = _targetStage; _currentSelectedStage.IsSelected = true; } else { if (_currentSelectedStage) { _currentSelectedStage.IsSelected = false; } _currentSelectedStage = null; } Position = p; }
// Use this for initialization void Start() { _playerBody = PlayerModel.Find("Body").Find("StarWithBone"); // イベント読み込み _eventList = GetComponentsInChildren <MonoBehaviour>() .Select(x => x as IStageMoveEvent) .Where(x => x != null) .OrderBy(x => x.GetPosition()) .ToList(); GameData.Instance.Load(); // 進行度読み込み var clearedStages = new HashSet <string>(); GameData.Instance.GetData(StageProgressKey, ref clearedStages); var stageProgress = clearedStages.Count; var followerCount = 0; // ステージノードのセットアップ(+1はタイトル分) FirstNode.SetUpNode(null, stageProgress + 1, ref followerCount); _targetStage = _currentSelectedStage = GetStageNode(_lastSelectedStageIndex); if (_currentSelectedStage != FirstNode) { State = StageSelectState.Select; } _playerPositionTarget = GetLength(_targetStage); // イベントを実行 foreach (var item in _eventList) { if (_playerPositionTarget > item.GetPosition()) { Debug.Log(_playerPositionTarget + " " + item.GetPosition()); item.OnExecute(this, true, true); } } // プレイヤーを移動 MovePlayer(_playerPositionTarget); Position = _playerPositionTarget; // BGMを鳴らす AudioManager.FadeIn(1.0f, "vigilante"); // ステージ選択用 StartCoroutine(SelectionInput()); }
public void Start() { myPlayer = player.GetComponent <PlayerController>(); currentLevelStartStage = GenerateLevelStartStage(); Assert.AreEqual(stageTypeFrequencies.Length, StageNode.NUM_STAGE_TYPES); waitingForDeathClick = false; deathScreen.enabled = false; currentStage = currentLevelStartStage; currentLevel = 0; myCurrentStageText = currentStageText.GetComponent <Text>(); GenerateMap(); }
private int RoomDepth(StageNode room, int d) { if (room.nextStages.Count == 0) { return(d); } int maxd = d; for (int i = 0; i < room.nextStages.Count; i++) { maxd = System.Math.Max(maxd, RoomDepth(room.nextStages[i], d + 1)); } return(maxd); }
// Creates a path segment going into or out of the given transform (isEntryBranch specifies which) private void CreateBranch(StageNode stage, bool isEntryBranch) { float branchWidth = _horizontalPadding / 2; RectTransform branch = Instantiate(_pathPrefab, stage.transform).GetComponent <RectTransform>(); branch.sizeDelta = new Vector2(branchWidth + branch.rect.height, branch.rect.height); if (isEntryBranch) { branch.anchoredPosition -= new Vector2(branchWidth / 2, 0); stage.SetEntryBranch(branch.gameObject); } else { branch.anchoredPosition += new Vector2(branchWidth / 2, 0); } }
public void EnterNextStage() { if (currentStage.nextStages.Count == 0) { // final thingy, move on. currentLevel += 1; currentLevelStartStage = GenerateLevelStartStage(); currentStage = currentLevelStartStage; } else { print("moving into next stage, going through way down num " + GetCurrentRoom().wayDownNum); currentStage = currentStage.nextStages[GetCurrentRoom().wayDownNum]; } GenerateMap(); }
private float GetLength(StageNode to) { var length = 0.0f; var current = FirstNode; while (current != to) { if (!current.NextStage) { break; } length += current.Length; current = current.NextStage; } return(length); }
void makeMove(CreateNodeAction createNodeAction) { if (createNodeAction == null) { return; } StageNode stageNode = new StageNode(createNodeAction.Position, createNodeAction.Width); if (createNodeAction.IndexInList != GlobalConst.INVALID_ID) { Nodes.Insert(createNodeAction.IndexInList, stageNode); } else { Nodes.Add(stageNode); } }
void undoMove(DeleteNodeAction deleteNodeAction) { if (deleteNodeAction == null) { return; } StageNode stageNode = new StageNode(deleteNodeAction.Position, deleteNodeAction.Width); if (deleteNodeAction.IndexInList != GlobalConst.INVALID_ID) { nodes.Insert(deleteNodeAction.IndexInList, stageNode); } else { nodes.Add(stageNode); } }
void undoMove(CreateNodeAction createNodeAction) { if (createNodeAction == null) { return; } StageNode stageNode = new StageNode(createNodeAction.Position, createNodeAction.Width); if (createNodeAction.IndexInList != GlobalConst.INVALID_ID) { nodes.RemoveAt(createNodeAction.IndexInList); } else { nodes.RemoveAt(Nodes.Count - 1); } }
// Change given path's height so that it extends from stageA to stageB private void PositionVerticalPath(RectTransform path, StageNode stageA, StageNode stageB) { if (stageA == null || stageB == null) { Debug.LogWarning("Cannot position vertical path between null StageNodes"); return; } RectTransform rectA = stageA.GetComponent <RectTransform>(); RectTransform rectB = stageB.GetComponent <RectTransform>(); path.sizeDelta = new Vector2(path.rect.width, Mathf.Abs(rectA.anchoredPosition.y - rectB.anchoredPosition.y) + path.rect.width); // Set absolute y of the path float pathY = (rectA.anchoredPosition.y + rectB.anchoredPosition.y) / 2; Transform originalParent = path.parent; path.SetParent(path.parent.parent); path.anchoredPosition = new Vector2(path.anchoredPosition.x, pathY); path.SetParent(originalParent); }
public StageNode[][] GenerateZoneMap(ZoneProperties properties) { StageNode[][] map = new StageNode[properties.columns.Length + 1][]; // Initialize columns for (int col = 0; col < properties.columns.Length + 1; col++) { // Create column of nodes map[col] = new StageNode[properties.mapRows]; for (int row = 0; row < properties.mapRows; row++) { map[col][row] = null; } } int middleRow = properties.mapRows / 2; _mapContainer.anchoredPosition = Vector3.zero; // Create starting column StageNode firstStage = InstantiateStageNode(properties, map, 0, middleRow); // Create end column (boss) StageNode finalStage = InstantiateStageNode(properties, map, properties.columns.Length, middleRow); InitializeStage(properties, properties.columns.Length, finalStage, StageCategory.BOSS); // Set first and last stage positions as scrolling bounds _mapScroller.SetBounds(firstStage.transform.position.x, finalStage.transform.position.x); // Create nodes in between for (int col = 1; col < properties.columns.Length; col++) { for (int row = 0; row < properties.mapRows; row++) { StageNode stage = InstantiateStageNode(properties, map, col, row).GetComponent <StageNode>(); InitializeStage(properties, col, stage, properties.columns[col - 1].stageType); } } return(map); }
private int GetStageIndex(StageNode stage) { if (!stage) { return(0); } var current = FirstNode; var count = 0; while (current != stage) { if (!current.NextStage) { break; } current = current.NextStage; count++; } return(count); }
public bool Load(string filename) { try { FileStream file = new FileStream(filename, FileMode.Open); BinaryReader br = new BinaryReader(file); int version = br.ReadInt32(); if (version != VERSION) { Debug.LogError(string.Format("StageData.Load, invalid stage data version({0}, {1} expected)!", version, VERSION)); return(false); } _max_xcount = br.ReadInt32(); _max_ycount = br.ReadInt32(); int len = br.ReadInt32(); for (int i = 0; i < len; i++) { int key = br.ReadInt32(); uint mask = br.ReadUInt32(); StageNode node = new StageNode(); node.mask = mask; _data.Add(key, node); } br.Close(); file.Close(); } catch (IOException e) { Debug.LogError(e); return(false); } return(true); }
private StageNode.StageType MakeRandomStageType(int risk, int reward) { // todo: this ignores risk, reward for now. float valTotal = 0; foreach (var freq in stageTypeFrequencies) { valTotal += freq; } float random = Random.Range(0, valTotal); for (var num = 0; num < StageNode.NUM_STAGE_TYPES; num++) { random -= stageTypeFrequencies[num]; if (random <= 0) { return(StageNode.GetStageTypeFromNum(num)); } } return(StageNode.GetStageTypeFromNum(StageNode.NUM_STAGE_TYPES - 1)); }
public void Respawn(StageNode node) { StageNode = node; _renderer.sprite = Manager.Instance.GameCfg.BubbSprites[(int)node.BubbType]; }
private void SetTarget(StageNode node) { _targetStage = node; _playerPositionTarget = GetLength(_targetStage); _moveSpeedMag = 1 + Mathf.Abs(Position - _playerPositionTarget) * 0.8f; }
private void EnableNextPaths() { _mapDisplay.SetActive(true); if (_currCoord == null) { return; } if (_currCoord.col + 1 >= _currMap.Length) { NextMap(); return; } _canMove = true; // Create branch leaving current node CreateBranch(GetCurrStage(), false); // Go through next column and find the topmost and bottommost stages that can be reached // Also, grey out unreachable stages int topBranchIndex = -1; int bottomBranchIndex = -1; for (int i = 0; i < _currMap[_currCoord.col + 1].Length; i++) { StageNode stage = _currMap[_currCoord.col + 1][i]; if (stage == null) { continue; } if (i < _currCoord.row - _moveRange || i > _currCoord.row + _moveRange) { stage.SetInaccessible(); } else { if (topBranchIndex == -1) { topBranchIndex = i; } if (bottomBranchIndex == -1 || i > bottomBranchIndex) { bottomBranchIndex = i; } } } // Create branches entering each of the next nodes for (int i = topBranchIndex; i <= bottomBranchIndex; i++) { StageNode stage = _currMap[_currCoord.col + 1][i]; if (stage != null) { CreateBranch(stage, true); } } // Connect all the branches with one vertical path StageNode stageA = _currMap[_currCoord.col + 1][topBranchIndex]; StageNode stageB = _currMap[_currCoord.col + 1][bottomBranchIndex]; if (_currCoord.row < topBranchIndex) { stageA = GetCurrStage(); } else if (_currCoord.row > bottomBranchIndex) { stageB = GetCurrStage(); } RectTransform verticalPath = Instantiate(_pathPrefab, GetCurrStage().transform).GetComponent <RectTransform>(); verticalPath.anchoredPosition += new Vector2(_horizontalPadding / 2, 0); GetCurrStage().SetVerticalPath(verticalPath); PositionVerticalPath(verticalPath, stageA, stageB); }
// Use this for initialization public void SetUpNode(StageNode prevStage, int clearedCount, ref int followerCount) { if (GateRenderers.Length > 1) { _gateMaterial = GateRenderers[0].material; foreach (var item in GateRenderers) { item.sharedMaterial = _gateMaterial; } } _gateAnimator = GetComponentInChildren <Animator>(); if (_gateAnimator) { _gateAnimator.SetFloat("DoorSpeed", -1 * _animSpeed); } OnIsSelectedChanged += e => { if (_gateAnimator) { var t = _gateAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime; t = Mathf.Clamp(t, 0, 1); _gateAnimator.Play("gate", 0, t); _gateAnimator.SetFloat("DoorSpeed", (IsSelected ? 1 : -1) * _animSpeed); } }; IsCleared = clearedCount > 0; PrevStage = prevStage; // クリア状態を表示 if (_gateMaterial) { _gateMaterial.EnableKeyword("EMISSION"); var c = IsCleared ? new Color(2, 2, 0) : new Color(2, 0, 0); _gateMaterial.SetColor("_EmissionColor", c); } // 助けた数を表示 FollowerFindData followerData = new FollowerFindData(); GameData.Instance.GetData(TargetStageName + StageController.StageFollowerDataTarget, ref followerData); var count = followerData.FindedIndexList.Count; followerCount += count; for (int i = 0; i < FindedFollowerPositions.Count; i++) { var t = FindedFollowerPositions[i]; GameObject f; if (i >= count) { f = Instantiate(FollowerModelPrefab, t.position, t.rotation); // 助けてなければ黒色にする var rs = f.GetComponentsInChildren <Renderer>(); foreach (var item in rs) { item.material.EnableKeyword("EMISSION"); item.material.SetColor("_EmissionColor", new Color(.25f, .25f, .25f)); } } else { f = Instantiate(FollowerChipPrefab, t.position, t.rotation); } f.transform.localScale = Vector3.one * 0.75f; } if (NextStage) { NextStage.SetUpNode(this, --clearedCount, ref followerCount); } }
public void SetData(StageNode node) { Data = node.Data; }
private void InitializeCombatStage(ZoneProperties properties, int stageCol, StageNode stage, BattleType battleType) { StageInfoContainer stageInfo = new StageInfoContainer(properties.columns[stageCol - 1], battleType); stage.SetStageInfoContainer(stageInfo); }
private StageNode GenerateLevelStartStage() { int totalDepth = levelStageDepth; int targetWidth = levelTargetStageWidths[currentLevel]; int maxWidthDiff = 2; Debug.Log("Making stages:"); List <StageNode> prevStages = new List <StageNode>(); StageNode start = new StageNode(this, 0, 0, firstStageType, 0, 0); prevStages.Add(start); for (var depth = 1; depth < totalDepth; depth++) { Debug.Log("Depth=" + depth); int prevWidth = prevStages.Count; int newWidth = Math.Max(RandomTowardsTarget(prevWidth, targetWidth, maxWidthDiff), 2); if (currentLevel == 0 && depth == 1) { newWidth = 1; // initial room only has one way down. } Debug.Log("Will make" + newWidth + " new"); List <StageNode> newStages = new List <StageNode>(); int connectedPrevUntil = 0; for (var newStageNum = 0; newStageNum < newWidth; newStageNum++) { // if we have an equal mapping, every prev has to point to newWidth / prevWidth. int connectToLeft = prevWidth - connectedPrevUntil - 1; Debug.Log("Make new " + newStageNum + ", with connectToLeft=" + connectToLeft); bool connectAgain = Random.Range(0, 2) == 0; connectAgain |= newStageNum == 0; // have to connect to first. connectAgain |= connectToLeft == 0; // have to connect if nothing else left int willConnectTo = (int)((connectToLeft * 1f / (newWidth - newStageNum))); willConnectTo = Random.Range(willConnectTo - 1, willConnectTo + 1); // add some noise willConnectTo = Math.Min(Math.Max(willConnectTo, 1), connectToLeft); Debug.Log("Decided to connect again=" + connectAgain + " and to news=" + willConnectTo + " from the" + connectToLeft + " that are left"); var connectToPrevStages = new List <StageNode>(); var startAtOldStageNum = connectedPrevUntil + (connectAgain ? 0 : 1); var newConnectPrevUntil = connectedPrevUntil + willConnectTo; Debug.Log("Thus will connect to prev nodes from " + startAtOldStageNum + " to " + (connectedPrevUntil + 1 + willConnectTo)); int riskSum = 0; int rewardSum = 0; for (var oldStageNum = startAtOldStageNum; oldStageNum <= newConnectPrevUntil; oldStageNum++) { connectToPrevStages.Add(prevStages[oldStageNum]); riskSum += prevStages[oldStageNum].pathRisk; rewardSum += prevStages[oldStageNum].pathReward; } int risk = riskSum / connectToPrevStages.Count; int reward = rewardSum / connectToPrevStages.Count; var nextStageType = MakeRandomStageType(risk, reward); var newStage = new StageNode(this, depth, newStageNum, nextStageType, risk + GetTypeRisk(nextStageType), reward + GetTypeReward(nextStageType)); foreach (var oldStage in connectToPrevStages) { oldStage.nextStages.Add(newStage); } newStages.Add(newStage); connectedPrevUntil = newConnectPrevUntil; } prevStages = newStages; } Debug.Log("start stage is:"); Debug.Log(start); return(start); }
public void RerenderMap() { ClearMap(); StageNode startNode = myManager.currentLevelStartStage; int depthLayers = RoomDepth(startNode, 1); // create depth linspace List <float> linspaceD = new List <float>(); for (int i = 0; i < (int)depthLayers; i++) { linspaceD.Add(bound.max.y + (bound.min.y - bound.max.y) * (float)i / (float)((int)depthLayers)); } List <float> lastLinspace = new List <float>(); Dictionary <int, List <int> > nodeToParents = new Dictionary <int, List <int> >(); List <StageNode> currLayer = new List <StageNode> { startNode }; while (currLayer.Count != 0) { // Draw the Rooms from the previous layer ... List <float> currLayerDrawPosX = new List <float>(); float offset = Mathf.Min(spacing, (float)(bound.max.x - bound.min.x) / currLayer.Count); float middle = bound.center.x - offset * currLayer.Count / 2f; for (int horizontalPos = 0; horizontalPos < currLayer.Count; horizontalPos++) { currLayerDrawPosX.Add(middle + offset * (float)horizontalPos); } for (int horizontalPos = 0; horizontalPos < currLayer.Count; horizontalPos++) { DrawIcon(currLayer[horizontalPos].type, new Vector2(currLayerDrawPosX[horizontalPos], linspaceD[currLayer[horizontalPos].stageDepth])); if (SameRoom(currLayer[horizontalPos], myManager.currentStage)) { DrawPlayer(new Vector2(currLayerDrawPosX[horizontalPos], linspaceD[currLayer[horizontalPos].stageDepth])); } } // Draw the lines foreach (StageNode node in currLayer) { if (node.stageDepth > 0) { var parents = nodeToParents[node.horizontalNum]; foreach (int parent in parents) { Vector2 p0 = new Vector2(lastLinspace[parent], linspaceD[node.stageDepth - 1]); Vector2 p1 = new Vector2(currLayerDrawPosX[node.horizontalNum], linspaceD[node.stageDepth]); Color col = new Color(194, 194, 209); int wayDownNum = myManager.GetCurrentRoom().wayDownNum; if (myManager.currentStage.stageDepth == node.stageDepth - 1 && myManager.currentStage.horizontalNum == parent && wayDownNum >= 0 && node.horizontalNum == myManager.currentStage.nextStages[wayDownNum].horizontalNum) { DrawLine(p0, p1, true, thickness); } else { DrawLine(p0, p1, false, thickness); } } } } // Prepare next stage nodeToParents.Clear(); List <StageNode> tmp = new List <StageNode>(); foreach (StageNode node in currLayer) { foreach (StageNode child in node.nextStages) { if (!nodeToParents.ContainsKey(child.horizontalNum)) { nodeToParents.Add(child.horizontalNum, new List <int>()); } nodeToParents[child.horizontalNum].Add(node.horizontalNum); if (tmp.Count == 0 || !SameRoom(tmp[tmp.Count - 1], child)) { tmp.Add(child); } } } lastLinspace = currLayerDrawPosX; currLayer = tmp; } }
private bool SameRoom(StageNode a, StageNode b) { return(a.horizontalNum == b.horizontalNum && a.stageDepth == b.stageDepth); }