Gridless map in Visual Studio Express 2013

Started by
4 comments, last by DingusKhan 9 years, 2 months ago

Hello,

A few months ago I decided to build a simulation game engine that would be able top be used in multiple games for scaleability. I havetossed around the idea of making a multi-dimensional array with and x and y axxis to represent a grid, make each point on the grid one meter in size, and then render the "tiles" as the map. This would require storing things like the material (IE grass, asphalt, contrete etc) located at each location and the agent type located at the cordinate.

I have a working understanding of how agent based simulations work, as well as how to define objects via a class and assign them values such as hunger and thirst. What I am struggleing with is how to define the map. I have spent many nights and days looking foran example or a book that could explain how I am trying to do this. and the best resource I could find is this aritcal on hexagonal maps (link here http://www.redblobgames.com/grids/hexagons/ ) it explains how to do a hexagonal grid as well as determining a line in any 360 degree direction as well as line of sight, and to some degree, pathfinding. It does not show how to make the map so it does not have a predetermined size.

I do not know where to look so Iwould like to know if there are any resources, (code examples, youtube guides, books, or classes) that can be suggested for doing this in visual studio express 2013? I do have the XNA game studio extension installed.

Thank you

-Krulas-

Advertisement

I havetossed around the idea of making a multi-dimensional array with and x and y axxis to represent a grid, make each point on the grid one meter in size, and then render the "tiles" as the map.


Sounds good to me. Define a class or struct to represent one tile, and then make an array of that type.

This would require storing things like the material (IE grass, asphalt, contrete etc) located at each location and the agent type located at the cordinate.


The material part sounds fine. I'm not sure about agents. Do you have exactly one agent for every location? Can a location be empty? Can it have multiple agents at the same time?

If you can have a varying number of agents for any location, or agents that frequently move to other locations, then I would store agents in a separate list, and give the Agent class fields to hold its map coordinate - x and y, for example.


The material part sounds fine. I'm not sure about agents. Do you have exactly one agent for every location? Can a location be empty? Can it have multiple agents at the same time?

If you can have a varying number of agents for any location, or agents that frequently move to other locations, then I would store agents in a separate list, and give the Agent class fields to hold its map coordinate - x and y, for example.

Thank you for the reply.

as far as the map goes I want there to be a default value for dirt (dirt being empty). I got ahead of myself when I mentioned that it would be storing agents as that isnt within the scope of what im having a problem with,

As far as the map decleration goes I have

Public Class Map
Dim map As Array
End Class

Am I missing somthing? or is this all I need to do if I do not want the map to have a predetermined size?

Is it a requirement to declare the X, and Y axis? Do I need to declare those in the array decleration or is simply declaring the array a I have done enough to make it work?

Do I need to declare a default value? or is prefilled with "0"?

Again I want want to reiterate, I am looking for a resource or information on how this is, or can be done. I realize I may be asking somthing that is fundamentally simple, another reason i would be happy with a response of "go look at book A".

thank you

I'm not familiar with VB, but here's what I found with a google search for "visual basic 2d array":

https://msdn.microsoft.com/en-us/library/02e7z943.aspx

https://msdn.microsoft.com/en-us/library/d2de1t93(v=vs.90).aspx


It does not show how to make the map so it does not have a predetermined size.

Are you talking about allowing a map to have a predetermined size that's unbounded (e.g. a statically-sized array, where the size is determined at runtime, perhaps as a function of the map file), or allowing a map to have an "infinite" map, a'la Minecraft?

My approach to any large map (and I'd consider 'large' to be 512x512), static or "infine", would be to break the map up into chunks. Each chunk would be a fixed size (lets say 32x32 tiles), and the whole map is made up of a grid of chunks (or perhaps a graph, if you want to be fancy). The chunks can be streamed into and out of memory as the player gets nearer or farther from them, which keeps the working set of the map to a reasonable size. There are other fringe benefits, for example you can sometimes share chunks when they are the same (a large expanse of ocean, for instance, could use the same tile data for every map chunk that was just water).

But, yes, otherwise you have the right intuition generally -- create an array of some size, and assign each element an index that corresponds to a particular tile, which has a particular appearance and other properties like collision. It might be convenient that the default value of 0 happens to allign with the default tile that you want, but in practice you're probably going to load the map indices from a file anyways, so there's not a pressing need.

throw table_exception("(? ???)? ? ???");

Hi.

If we're thinking about the same thing, I worked on small project a while ago that had a gridless map system. It was basically a 1D array (later a std::vector, since it was done in C++ and I wanted it to be dynamically sized), and instead of storing the tiles in an array, it wrote the properties of a tile to a text file. I developed this system to read a line of numbers, each one in specific places representing a different value. The values were x position of tile, y position of tile, rotation, x size of tile, y size of tile and single number for whether it was collidable or not. At run time or when the function was called from the game menu, the file was parsed and values processed, setting up a new tile based on the parsed description. The new tile was pushed back into the vector and the next one was loaded. Since the tile was placed with an X and Y position in pixels, it ignored whether the tile was on screen or not and did not require a pre-determined size, since the tile could be placed outside of the level and seen when the viewport moved.

The whole thing was surprisingly fast, as the lines of numbers were short enough to go in a standard int, and were difficult enough to read to discourage tampering. I ended up building a small level editor for it that could save and load the maps and such, but it was messy as I was only just starting games development at the time. The idea was really easy to work with, since it was literally just a text file (I ended up using a custom encryption algorithm to further discourage tampering). It was easy to implement once I had worked out what values I needed and how I'd use them when generating the level. Levels could have permanent changes made to them if necessary, allowing for some persistence (not used, since it was a single player game). Finally, it also made it relatively easy to build the level editor, allowing the users to make their own levels.

There were a few limitations. Huge levels took a while to load, which wasn't a problem for the project I was working on at the time since it had small levels, and occasionally the file size could get large, but even then an entire level would be less than a few KB max, since it was just numbers. You're also still bound to tiles, albeit freely placed and rotated to fit the need.

It was made using C++ and SFML, but I don't have the code anymore. The idea is also pretty simple, so it should be easy to adapt it to any other language/library.

I hope I helped.

This topic is closed to new replies.

Advertisement