private void GenerateLevel() { LevelGenerator levelGenerator = new LevelGenerator(); LevelTemplate levelTemplate = levelGenerator.GenerateLevelTemplate(); CreateLevelFromTemplate(levelTemplate, transform); }
private void LoadLevel(LevelTemplate level, Vector2 at) { Save(); KeyboardState keys = Keyboard.GetState(); Session session = keys.IsKeyDown(Keys.LeftControl) || keys.IsKeyDown(Keys.RightControl) ? null : CurrentSession; if (session == null) { if (AreaData.GetCheckpoint(area, level.Name) != null) { session = new Session(area, level.Name) { StartCheckpoint = null }; } else { session = new Session(area); } } session.FirstLevel = false; session.StartedFromBeginning = false; session.Level = level.Name; session.RespawnPoint = keys.IsKeyDown(Keys.LeftShift) || keys.IsKeyDown(Keys.RightShift) ? at : (Vector2?)null; Engine.Scene = new LevelLoader(session, at); }
private void LoadLevel(int levelIndex) { CurrentLevelIndex = levelIndex; //ResetPlayerPosition(); LevelTemplate level = Levels[levelIndex]; Board.Instance.SetGrid(level.Height, level.Width); CurrentLevel = new BlockInstance[level.Height, level.Width, 3]; //3 layers, passables, solids, player SolutionBlockPositions = new List <Vector3Int>(); foreach (LevelTemplate.BlockDefinition blockDefinition in level.Blocklist) { LoadBlock(blockDefinition); //GameObject instance = Instantiate(blockDefinition.block.Prefab, transform); //Vector3 localPosition = blockDefinition.block.Prefab.gameObject.transform.localPosition + new Vector3(blockDefinition.position.x, 0.0f, blockDefinition.position.y); //instance.transform.localPosition = localPosition; //CurrentLevel[(int)blockDefinition.position.x, (int)blockDefinition.position.y] = new BlockInstance //{ // block = blockDefinition.block, // gameObject = instance, //}; } Invoke("LoadPlayerLate", 0.2f); //purge undo of level make undoInstructions.Pop(); undoInstructions.Push(new Queue <Action>()); }
/// <summary> /// Сохранение визуальных уровней и панелей в шаблон currentTemplate /// </summary> private void SaveTemplateView() { this.currentTemplate = new ViewWindowTemplate(); this.currentTemplate.Skin = new SkinManager().GetCurrentSkin(); foreach (var child in spMain.Children) { if (child.GetType() == typeof(Level)) { Level level = (Level)child; LevelTemplate lTemplate = new LevelTemplate(); lTemplate.Height = level.Height; //Перебираем все файловые панели foreach (var c in level.spMain.Children) { if (c.GetType() == typeof(FilePanel)) { FilePanel filePanel = (FilePanel)c; FilePanelTemplate fpTemplate = new FilePanelTemplate(); fpTemplate.FilePanelSettings = filePanel.FilePanelSettings; //fpTemplate.Width = filePanel.Width; //fpTemplate.Path = filePanel.Path; lTemplate.FilePanels.Add(fpTemplate); } } currentTemplate.Levels.Add(lTemplate); } } }
private static void SetSettings(LevelTemplate _data) { // Player Level Variables Settings.s_nPlayerInitialHealth = _data.nPlayerInitialHealth; Settings.s_nPlayerInitialResourceCount = _data.nPlayerInitialResourceCount; Settings.s_nPlayerNutrientPerBlock = _data.nPlayerNutrientPerBlock; Settings.s_fPlayerNutrientChance = _data.fPlayerNutrientChance; Settings.s_nPlayerChildSpawnCost = _data.nPlayerChildSpawnCost; Settings.s_nPlayerSqaudCaptainChildCost = _data.nPlayerSqaudCaptainChildCost; Settings.s_nPlayerActionBurstShotChildCost = _data.nPlayerActionBurstShotChildCost; Settings.s_nPlayerActionSwarmTargetChildCost = _data.nPlayerActionSwarmTargetChildCost; Settings.s_nPlayerActionScatterShotChildCost = _data.nPlayerActionScatterShotChildCost; // Squad Captain Level Variables Settings.s_fAggressiveToDefensive = _data.fAggressiveToDefensive; Settings.s_fMinimumCooldown = _data.fMinimumCooldown; Settings.s_fMaximumCooldown = _data.fMaximumCooldown; Settings.s_fThinkCooldown = _data.fThinkCooldown; // Enemy Main Level Variables Settings.s_nEnemyMainInitialHealth = _data.nEnemyMainInitialHealth; Settings.s_nEnemyMainInitialNutrientNum = _data.nEnemyMainInitialNutrientNum; Settings.s_nEnemyMainInitialChildCellNum = _data.nEnemyMainInitialChildCellNum; Settings.s_nEnemyMainInitialAggressiveness = _data.nEnemyMainInitialAggressiveness; Settings.s_fEnemyMainInitialVertSpeed = _data.fEnemyMainInitialVertSpeed; Settings.s_fEnemyMainMinHiriSpeed = _data.fEnemyMainMinHiriSpeed; Settings.s_fDefaultStunTime = _data.fDefaultStunTime; Settings.s_fDefaultStunTolerance = _data.fDefaultStunTolerance; // Enemy Child Level Variables Settings.s_nEnemyChildCountCap = _data.nEnemyChildCountCap; Settings.s_fEnemyTargetLeftNodeRequirement = _data.fEnemyTargetLeftNodeRequirement; Settings.s_fEnemyTargetRightNodeRequirement = _data.fEnemyTargetRightNodeRequirement; Settings.s_fEnemyTargetSquadCaptRequirement = _data.fEnemyTargetSquadCaptRequirement; Settings.s_fEnemyAttackChargeRequirement = _data.fEnemyAttackChargeRequirement; Settings.s_fEnemyAttackLandmineRequirement = _data.fEnemyAttackLandmineRequirement; Settings.s_fEnemyAttackTrickAttackRequirement = _data.fEnemyAttackTrickAttackRequirement; Settings.s_fEnemyDefendBurstSignificancy = _data.fEnemyDefendBurstSignificancy; Settings.s_fEnemyDefendSwarmSignificancy = _data.fEnemyDefendSwarmSignificancy; Settings.s_fEnemyDefendScatterSignificancy = _data.fEnemyDefendScatterSignificancy; Settings.s_fEnemyDefendQCWeight = _data.fEnemyDefendQCWeight; Settings.s_fEnemyDefendRCWeight = _data.fEnemyDefendRCWeight; Settings.s_fEnemyDefendTurtleWeight = _data.fEnemyDefendTurtleWeight; Settings.s_fEnemyDefendLadderWeight = _data.fEnemyDefendLadderWeight; // Aesthetics Level Variables Settings.s_EnvironmentColor = _data.EnvironmentColor; Settings.s_fSideWallSpeed = _data.fSideWallSpeed; Settings.s_fBackgroundSpeed = _data.fBackgroundSpeed; Settings.s_fParticleStartSpeedMultiplier = _data.fParticleStartSpeedMultiplier; }
//Constuctor public Level(LevelTemplate levelTemplate) { GameController.CurrentLevel = this; // zet zich zelf als het huidige level worldRoot = GameObject.FindWithTag("WorldRoot"); // neemt de worldroot om mee te geven aan de objecten die hij gaat genereren template = levelTemplate; // onthoud het template in ene klasse variable BuildLevel(); // bouwt heel het level en instantiate een hoop dingen en maakt een hoob objecten SetCameraPosition(); // zet de camera juist }
}//einde methode // zal enkel door devs gebruikt worden // het opslaan van een nieuw level template public static void SaveLevelTemplate(string levelName, LevelTemplate levelTemplate) { BinaryFormatter bf = new BinaryFormatter(); FileStream stream = File.Create(Application.streamingAssetsPath + slash + levelDirectory + levelName + levelExtention); bf.Serialize(stream, levelTemplate); stream.Close(); }//einde methode
// Use this for initialization public void Init(LevelTemplate template) { m_level = template; m_SelectableLayerMask = LayerMask.GetMask("Selectable"); HealthUpdate(); }
public static void LoadLevel(int _level) { s_nLevelID = _level; string path = "Levels/LEVEL_" + _level.ToString(); LevelTemplate levelData = Resources.Load(path) as LevelTemplate; SetSettings(levelData); }
public static void LoadTutorial() { s_nLevelID = 0; string path = "Levels/LEVEL_TUTORIAL"; LevelTemplate tutorialData = Resources.Load(path) as LevelTemplate; SetSettings(tutorialData); }
private void LoadLevel(LevelTemplate level, Vector2 at) { Save(); KeyboardState kbState = Keyboard.GetState(); bool createSession = kbState.IsKeyDown(Keys.LeftControl) || kbState.IsKeyDown(Keys.RightControl); bool customRespawnPoint = kbState.IsKeyDown(Keys.LeftShift) || kbState.IsKeyDown(Keys.RightShift); Session session; if (createSession || CurrentSession == null) { if (AreaData.GetCheckpoint(area, level.Name) != null) { session = new Session(area, level.Name) { StartCheckpoint = null }; } else { session = new Session(area); } } else { session = CurrentSession; } session.Level = level.Name; session.RespawnPoint = customRespawnPoint ? at : null; session.FirstLevel = false; session.StartedFromBeginning = false; if (createSession && !customRespawnPoint) { bool firstLevel = level.Name == session.MapData.StartLevel().Name; session.FirstLevel = firstLevel; if (firstLevel) { Vector2 defaultSpawnPoint; if (session.Area.GetLevelSet() == "Celeste") { Rectangle bounds = session.LevelData.Bounds; defaultSpawnPoint = session.GetSpawnPoint(new Vector2(bounds.Left, bounds.Bottom)); } else { defaultSpawnPoint = session.LevelData.Spawns[0]; } session.StartedFromBeginning = session.GetSpawnPoint(at) == defaultSpawnPoint; } } Engine.Scene = new LevelLoader(session, at); }
void Start() { Location.text = BeautifyLevelName(Application.loadedLevelName); level = FindObjectOfType<LevelTemplate>(); GameController = FindObjectOfType<GameController>(); PopulateScoreBoard(); InitialScoreBoardDisplayTime = ScoreBoardDisplayTime; }
public LevelTemplate(int[,] a, LevelTemplate temp) { levelPart = a; upperLeftBound = temp.upperLeftBound; upperRightBound = temp.upperRightBound; lowerLeftBound = temp.lowerLeftBound; lowerRightBound = temp.lowerRightBound; downBound = temp.downBound; upBound = temp.upBound; }
private void MakeMapEditorBetter() { // press cancel button to return game if ((Input.ESC.Pressed || Input.MenuCancel.Pressed) && CurrentSession != null) { Input.ESC.ConsumePress(); Input.MenuCancel.ConsumePress(); Engine.Scene = new LevelLoader(CurrentSession); } // press confirm button to teleport to selected room if (Input.MenuConfirm.Pressed) { Input.MenuConfirm.ConsumePress(); LevelTemplate level = TestCheck(mousePosition); if (level != null) { if (level.Type == LevelTemplateType.Filler) { return; } LoadLevel(level, mousePosition * 8f); } } // speed up camera when zoom out if (Camera != null && Camera.Zoom < 6f) { Camera.Position += new Vector2(Input.MoveX.Value, Input.MoveY.Value) * 300f * Engine.DeltaTime * ((float)Math.Pow(1.3, 6 - Camera.Zoom) - 1); } // controller right stick zoom the map GamePadState currentState = MInput.GamePads[Input.Gamepad].CurrentState; if (zoomWaitFrames <= 0 && Camera != null) { float newZoom = 0f; if (Math.Abs(currentState.ThumbSticks.Right.X) >= 0.5f) { newZoom = Camera.Zoom + Math.Sign(currentState.ThumbSticks.Right.X) * 1f; } else if (Math.Abs(currentState.ThumbSticks.Right.Y) >= 0.5f) { newZoom = Camera.Zoom + Math.Sign(currentState.ThumbSticks.Right.Y) * 1f; } if (newZoom >= 1f) { Camera.Zoom = newZoom; zoomWaitFrames = ZoomIntervalFrames; } } }
// Use this for initialization public void Init(LevelTemplate template) { m_GridRows = template.GridRows; //5; m_GridColumns = template.GridColumns; //5; GenerateBoard(); float averageSize = (m_GridRows + m_GridColumns) * 0.5f; Camera.main.transform.position = new Vector3(0, averageSize, -(averageSize * 0.1f)); Camera.main.transform.LookAt(Vector3.zero); }
protected override void LoadContent() { TowerTemplate = new LevelTemplate(ChunkSet.FromTexture(Content.Load <Texture2D>("Levels/tower"), 1), 1, 1, false, "bg_entrance", null, null); VillageTemplate = new LevelTemplate(ChunkSet.FromTexture(Content.Load <Texture2D>("Levels/village"), 15), 12, 3, false, "bg_entrance", TowerTemplate, null); FountainTemplate = new LevelTemplate(ChunkSet.FromTexture(Content.Load <Texture2D>("Levels/fountain"), 2), 2, 1, false, "bg_fountain", VillageTemplate, "Sounds/fountain"); JungleTemplate = new LevelTemplate(ChunkSet.FromTexture(Content.Load <Texture2D>("Levels/jungle2"), 15), 8, 3, false, "bg_jungle", FountainTemplate, "Sounds/jungle"); TunnelTemplate = new LevelTemplate(ChunkSet.FromTexture(Content.Load <Texture2D>("Levels/tunnel"), 2), 2, 1, false, "bg_tunnel", JungleTemplate, null); EntranceTemplate = new LevelTemplate(ChunkSet.FromTexture(Content.Load <Texture2D>("Levels/entrance"), 2), 2, 1, true, "bg_entrance", TunnelTemplate, null); _screens.Push(new StartScreen(this)); }
private void RenderHighlightCurrentRoom() { Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Camera.Matrix * Engine.ScreenMatrix); if (CurrentSession != null) { LevelTemplate currentTemplate = levels.Find(template => template.Name == CurrentSession.Level); currentTemplate?.RenderHighlight(Camera, false, true); } Draw.SpriteBatch.End(); }
private List <int[]> GetSurroundingTypeCoords(LevelTemplate levelTemplate, int[] coords, RoomTemplate.RoomType roomType) { List <int[]> surroundingAvailableCoords = new List <int[]>(); int[][] surroundingCoords = GetSurroundingCoords(coords); foreach (int[] surroundingCoord in surroundingCoords) { if (levelTemplate.IsInside(surroundingCoord) && levelTemplate.GetMap(surroundingCoord).GetRoomType() == roomType) { surroundingAvailableCoords.Add(surroundingCoord); } } return(surroundingAvailableCoords); }
private List <int[]> GetSurroundingAvailableCoords(LevelTemplate levelTemplate, int[] coords) { List <int[]> surroundingAvailableCoords = new List <int[]>(); int[][] surroundingCoords = GetSurroundingCoords(coords); foreach (int[] surroundingCoord in surroundingCoords) { if (levelTemplate.IsAvailable(surroundingCoord)) { surroundingAvailableCoords.Add(surroundingCoord); } } return(surroundingAvailableCoords); }
void Start() { for (int i = 0; i < LevelManager.levelTemplates.Count; i++) { LevelTemplate levelTemplate = LevelManager.levelTemplates[i]; int row = i / levelButtonsPerRow; int col = i % levelButtonsPerRow; GameObject levelButton = Instantiate(resources.levelButton, CalculatePosition(row, col), Quaternion.identity); levelButton.transform.SetParent(gameObject.transform, false); AddListener(levelButton.GetComponent <Button>(), i); levelButton.GetComponentInChildren <TextMeshProUGUI>().text = "" + (i + 1); levelButtons.Add(levelButton); } AdjustBackButtonPosition(); UpdateLevelButtonsStates(); }
private List <int[]> GetNextMainCoords(LevelTemplate levelTemplate, int[] mainHeadCoords) { List <int[]> availableCoords = new List <int[]>(); // the potential coordinate has to have at least 3 available squares next to it // or else it can get stuck in a loop int[][] surroundingCoords = GetSurroundingCoords(mainHeadCoords); foreach (int[] coords in surroundingCoords) { if (levelTemplate.IsAvailable(coords) && GetSurroundingTypeCoords(levelTemplate, coords, RoomTemplate.RoomType.MAIN).Count < 2) { availableCoords.Add(coords); } } return(availableCoords); }
/// <summary> /// First method that is called in the game state /// used to initialise values /// </summary> /// <returns>WaitingToStart state</returns> E_GameState Beginning() { m_GameTime = 0.0f; m_GameOver = false; m_GameStarted = false; m_Level = GameManager.Instance.LevelSet.Level(GameManager.Instance.m_LevelIndex); UIManager.Instance.Init(m_Level); //initialise the Gameboard Gameboard.Instance.Init(m_Level); PlayerController.Instance.Init(m_Level); return(E_GameState.WAITING_TO_START); }
// Load the template from the given path (usually from drag and drop). private void LoadTemplate(string path) { string json = File.ReadAllText(path); try { template = JsonUtility.FromJson <LevelTemplate>(json); } catch (System.Exception) { Debug.LogWarning("Cannot open that file in the tile editor."); return; } templateName = Path.GetFileNameWithoutExtension(path); titleContent = new GUIContent(templateName); }
private void ProceedMain(LevelTemplate levelTemplate) { int[] lastHeadCoords = levelTemplate.GetMainHead(); List <int[]> availableCoords = GetNextMainCoords(levelTemplate, lastHeadCoords); if (availableCoords.Count == 0) { return; } int[] nextMainCoords = availableCoords[rand.Next(availableCoords.Count)]; RoomTemplate lastHead = levelTemplate.GetMap(lastHeadCoords); levelTemplate.SetMain(nextMainCoords); // connect the door from the previous ConnectRooms(lastHead, levelTemplate.GetMap(nextMainCoords)); }
private Level LoadLevelFromTemplate(int number) { LevelTemplate levelTemplate = levelTemplates[number]; List <Vertex> vertices = new List <Vertex>(); foreach (float[] vertex in levelTemplate.GetVertices()) { vertices.Add(new Vertex(InstantiateVertex(vertex[0], vertex[1]))); } foreach (int[] edge in levelTemplate.GetEdges()) { CreateEdge(vertices[edge[0]], vertices[edge[1]]); } Graph graph = new Graph(vertices); return(new Level(number, graph, calculateBorder(levelTemplate.GetVertices()))); }
private void CreateLevelFromTemplate(LevelTemplate levelTemplate, Transform mapTransform) { for (int col = 0; col < levelTemplate.GetCols(); ++col) { for (int row = 0; row < levelTemplate.GetRows(); ++row) { RoomTemplate roomTemplate = levelTemplate.GetMap(new int[] { col, row }); if (roomTemplate.GetRoomType() != RoomTemplate.RoomType.EMPTY) { Room room = GenerateRoom(roomTemplate, col, row, mapTransform); if (roomTemplate.GetRoomType() == RoomTemplate.RoomType.SPAWN) { spawnPoint = room.GetSpawnPoint(); } } } } }
public static Puzzle CreateFromLevelTemplate(LevelTemplate levelTemplate, PuzzleCreationContext context) { var shapes = new List <Shape>(); foreach (var shapeData in levelTemplate.Shapes) { var shape = Shape.Create(shapeData.TilePositions, new Vector2(shapeData.OffsetX, shapeData.OffsetY), context.Storyboard, context.TileModel, context.Palette, -100); shapes.Add(shape); } AdjustInitialPositionsToCentreShape(shapes); AssignExplodedPositions(shapes, context.LayoutSize); var numberOfMoves = Math.Min(shapes.Count + (int)Math.Ceiling(context.Hardness * shapes.Count) - 1, 2 * shapes.Count); var deformations = GetDeformationSequence(shapes).Take(numberOfMoves).ToList(); return(new Puzzle(context.Storyboard, shapes, deformations)); }
private List <RoomTemplate> GetPotentialConnectRooms(LevelTemplate levelTemplate, int[] coords, int[] previousCoords) { List <RoomTemplate> potentialRooms = new List <RoomTemplate>(); int[][] surroundingCoords = GetSurroundingCoords(coords); foreach (int[] surroundingCoord in surroundingCoords) { if (surroundingCoord != previousCoords && levelTemplate.IsInside(surroundingCoord)) { RoomTemplate surroundingRoom = levelTemplate.GetMap(surroundingCoord); if (surroundingRoom.GetRoomType() == RoomTemplate.RoomType.MAIN || surroundingRoom.GetRoomType() == RoomTemplate.RoomType.OFFSHOOT) { potentialRooms.Add(surroundingRoom); } } } return(potentialRooms); }
public override void OnInspectorGUI() { if (GUILayout.Button("Add")) { levels.Add(new Level()); } foreach (var item in levels.list) { GUILayout.BeginHorizontal(); GUI.color = Color.white; if (GUILayout.Button(item.name + "- Edit")) { LevelTemplate.Init(item); } GUI.color = Color.red; if (GUILayout.Button("Remove")) { levels.Remove(item); break; } GUILayout.EndHorizontal(); } }
public void Init(LevelTemplate level) { LevelTemplate m_Level = level; GameObject m_BuildMenu = GameObject.Find("Build Menu"); //loop through each board piece in the level loadout and create a button for them for (int i = 0; i < m_Level.LevelLoadout.BoardPieces.Length; i++) { //instantiate the button Button temp = Instantiate(m_BuildButtonPrefab).GetComponent <Button>(); //assign the parent temp.transform.SetParent(m_BuildMenuContent, false); //give it an appropriate name temp.name = m_Level.LevelLoadout.BoardPieces[i].DisplayName + " Button"; //set up the on click event int index = i; temp.onClick.AddListener(() => BuildObject(index)); //set the properties of the button temp.transform.Find("Name").GetComponent <Text>().text = m_Level.LevelLoadout.BoardPieces[i].DisplayName; temp.transform.Find("Cost").GetComponent <Text>().text = m_Level.LevelLoadout.BoardPieces[i].BuildCost.ToString(); temp.transform.Find("Image").GetComponent <Image>().sprite = m_Level.LevelLoadout.BoardPieces[i].BuildUISprite; } }
// Use this for initialization void Awake() { S = this; updateTutorialObj(); }