如果要想自己设计一个roguelike游戏,那么需要你有一个随机地图生成,我在indienova上看到一篇文章,描述了一个roguelike算法,然后自己用unity实现了一个下。
原文有这个算法的各种讲解,还有动态的演示图,不理解算法原理的可以去看一下。
根据这个算法的代码:
using System.Collections; using System.Collections.Generic; using UnityEngine; public enum Tile { Floor,//地板 Wall//墙 } public class createMap : MonoBehaviour { public int row = 30; public int col = 30; private Tile[,] mapArray; public GameObject wall, floor,player; private GameObject map; private Transform maps; private int forTimes=0;//SmoothMapArray循环次数 // Use this for initialization void Start () { mapArray = new Tile[row,col]; maps = GameObject.FindGameObjectWithTag ("map").transform; map = new GameObject (); map.transform.SetParent (maps); //CreateMap (); GenerateMap (); } // Update is called once per frame void Update () { if (Input.GetKeyDown (KeyCode.Q)) { Destroy (map); GenerateMap (); } if (Input.GetKeyDown (KeyCode.W)) { InitMap (); } //下一步 if (Input.GetKeyDown (KeyCode.E)) { CreateMap (); }