This is more of a DevLog than a tutorial.
I've developed a system to do a Procedurally generated Map, but you could say that it's more or less a controlled Random Map Generation.
Before this could have been done I needed to import the JSON and convert it to Elixir Maps. Unfortunately detailing every little step seems to take too much so I'll refrainto the bare basics.
Although we won't use it too much in this tutorial , we will download the JSON database form cataclysm.
It's included in the download at the end of the post.
Our game world consists of multiple maps.
The current map is the one the user is located at.
Each map location or tile consists of a tinymap.
Each tinymap consists of 24x24 tiles.
Each tinymap tile is 0.5m by 0.5m.
Meaning that a tinymap is 24x0.5 = 12 meters in width and height.
The total size in square meters is 24x24 x (0.5*0.5) = 144 m2 which equates to quite a considerable size.
The user can see up to 5 tiles in each direction on a map
And the user can see most of the 24x24 tiles on a tinymap.
We will randomly generate a map for eachtime the user plays so it seems different with each game.
I';ve experimented a little bit with the map generation and have 4 different ways of doing it.
However only one of them works as expected (detail more)
PUtting it all together
When the user starts the game we'll generate a random map.
For the moment seeing all the code' we;ve just implemented by now there there will only be roads and houses..
but we will soon add more:)
cli.ex
def main(_args) do IO.puts(@tag) name = read_text("What is your name dear adventurer?") IO.puts "Welcome to LifeBeyondApocalypse #{name}!" User.start(name) GamePam.start_map() read_command(IO.ANSI.format([:italic,"To find out more about a topic type", :magenta, " help <topic>"])) end
game_map.ex
def start_map(name \\\\ "Zombie City") doDataStorage.start(:game_map, DataStorage, :new, MapGenerator.generate_new_map(name, 48,24)) end def get_map() do DataStorage.get_struct(:game_map) end def move(location) do IO.puts "Move to #{location}" user = User.get_struct() where_to = move_to(location,user) case verify_bounds(where_to,get_map()) do def show_map() do\t%User{x: x, y: y} = User.get_struct()\tmap = get_map()\ttext = IO.ANSI.format_fragment([:bright, :green, get(map.map, y - 1, x - 1), :reset, :white])\tIO.write IO.ANSI.format([:white, set(map.map, y - 1,x - 1, text )]) end
Verifybounds signature needs to change
def verify_bounds({x,y}, %{max_x: max_x, max_y: max_y}) when x>=1 and y>=1 and max_x >= x and max_y >= y do
We need to change the places where the generate_map() function is used.
You can take a look at the full sourcecode and review the modifications of what has actually occured.
You can download the source for 0x07 from the Life Beyond Apocalypse Fossil Repo.
I've recieved a message of why I don't put it on GitHub. i will, however the official repo will ALWAYS be Fossil.