Creating random tile map world generation - c#

so after searching I've found only Java and C++, and I'm fond of and only know .net enough to complete my project. We're creating a random tile generating map (think terraria/flat minecraft kinda thing) and after creating almost all of the materials and a bunch of other code in Unity I've realized I can't quite figure this out (and know next to nothing about perlin and can't figure it out, so examples would be appreciated.)
I started in .net (MS VS) splitting the screen space into pieces I called parcels that are 32x32 and created a loop to fill it. But we're using Unity as it's already a game engine and aren't sure how to accomplish this.
First there's the different sprites the map must be made of, I already created classes and coded lists of what must go into what height but I don't know how to generate all random terrain out of nothing, since the world would need to be random and created before the player sees anything.
I tried a mesh but it uses too much memory looping the way it does; I also tried a plane and filling it with textures, but couldn't get the randomization right and then of course it's a flat object with images and not blocks that can be interacted with.
My direct question: How do we generate a world made of thousands of intractable tiles (we have a limit in mind already for both X & Y) out of random tiles that is in 2D space in C#? (Either strict C# or something that can be imported into Unity, similar to the games I mentioned already.)
Thanks in advance for any advice, hope I gave enough information. I know this is all about procedural generation and probably perlin noise algorithms, but neither of us know about those nor know where to start.
Edit: I was asked to give more information, so far I've been using for loops to create both single and chunks of random tiles. Using an IList to store what's gone where so as it's generating nothing overlaps. (I don't know a better way to do this.)
Both methods work great until I star passing about 150 blocks, then it simply locks up and has to be crashed. I've tried it without the list system thinking that data was the cause, it's not. I've tried using Tidy Tile Mapper in Unity, but the same problem exists once you pass about 200 tiles. I can't find the correct way to create objects the player can interact with without clogging memory.

Maybe you could show us a bit of code of what you've tried already. With these kind of things you will always have to manage memory to pull it off, so maybe you're trying the right thing with the wrong methods. This is not an easy question to answer and it would take more than a post here to do it right, besides being different for each different purpose.

Related

What's the fastest way to validate if a GeoJson Polygon contains a certain section, using .net

I have a Polygon (a sequence of 2D-points) loaded (I can parse from GPX, Google polyline and GeoJson) in my C# program. And I have around 1000 of 'segments' that also are GeoJson Linestrings.
Some of these segments are 'far away' off the track, while others could perfectly intersect with the track. My question is what the fastest way (ideally using an existing in memory library) would be to detect which segments are part of the overall track. (The points obviously don't have to match 100%, but can be a few meters off the track)
Consider the situation where I have a recorded GPS-track (of a car for example) and I want to check against a library of streets if that track has been driving through those streets. (ideally in the specified direction, if possible)
So, my main questions:
Is there an out of the box open source library available that has implemented this?
If not, I'm happy to contribute it, but then I'm looking for a good description of such an algorithm.
Further clarification
I have indeed found several options to work out if a point is inside , or on a polygon. (see here).
But the main challenge is to find out if someone has done this before in .net and to understand if there are out of the box possibilities for this.
Any help is appreciated.

Coloring areas of map in unity 2D

I am new to unity, but I know C# very well.
I am working on a game similar to eu4.
When area is conquered, it should change color.
I have no idea how to do it, or what to search in the internet for a solution.
Here is the map:
(The borders separate the areas)
Any help please?
It's very simple, you just have sprites for each "country".
(So, in the dark color.)
Simply turn them on or off as you wish. That's all there is to it.
Another approach is you could learn how to make and use a typical "flood fill algorithm". But that is far beyond the scope of this question and is a general computer science issue. (You might look on, say, gamedev for starter tips on this. Additionally you'll have to become expert at generating textures dynamically in Unity.)
Check EU4 and CK2 map files. It might give you many ideas how to handle grand strategy maps.
You got some work to do to achieve this. But basically, there is a .bmp file in game files which every province is painted with a unique color. Here is an example of small portion which consist Italy:
Once you've done that, you will need some sort of data file (.csv in eu4's case) that includes which color includes which province, which provinces are neighboring, etc... In EU4, color info and adjadency info are in seperate files, but of course you're free to approach however you want.
Once you are done with "Data" part, you will need an algorithm that scans these files and distinguish each province in seperate game objects. Mainly, you must write a method that removes every color in an image except a certain one, instantiate it to the map and repeat process for each province. And you're done.
Edit: You can, of course, do these manually. But automated process is always better especially when you a lot of povinces to sepearate. Also making tweaks in map will be much easier that way, or you'll have a hard time recreating every single sprite for even small changes.
Another advantage is, you can easily add different mapmodes like heightmap, rivermap or such...
As your question doesn't give much in terms of your structure it's hard to give you examples.
The most straightforward for you probably is to separate your map into nodes (your bordered areas) and display them all as unique gameObjects. You can then access things like their Renderer to give them different colour.
We can give much better answers if you give us more information on how your data/graphics are structured.

grid based world for ant simulation

I've got to create an ant simulation for a a piece of coursework.
I've got to use a "2D discrete (grid based) world" to put the ants on. the problem is that I don't know how/what that is.
I just need someone to explain and show me what that is. Thanks a lot in advance!
yea its supposed to be really basic, like the ants are supposed to move around and find food and a nest. – D Goble
Decided to post a reply to the above in a comment, like I said you wont get the exact code you need without posting some of your own but what you need to do (and research) is.
Simulate your world. (There are better ways of doing this but for a simple world look at a 2D array with int values representing the tile e.g. 0 = empty, 1 = ant, 2 = food, 3 = nest, 4 = obstacle)
Store your objects in some sort of structure with properties. (e.g. you will want an Ant object with various actions like move, eat, ect. But if this is one of your first C# projects feel free to ignore this until you are a little more comfortable)
A game tick to progress your game, look up game state management or game loop. (Again this depends on experience, if you want something simple a basic loop will do).
A basic AI for your ants, are they just going to randomly move around (unless they try to hit an obstacle) or will they seek out the nearest source of food and then return to their nest? (If so there are plenty of pathfinding examples out there)
Draw your game, for this just use the console no need for anything fancy. There are loads of examples of C# console games out there that will show you how to do this.
If you do a bit of Googling around each of these terms that should get you most of the way there.

Artificial intelligence (or at least path generation) of entities in a 2-dimensional plane

TL;DR
Given a 2-dimensional plane (say, 800x600 pixels or even 4000x4000) that can contain obstacles (static objects) or entities (like tanks, or vehicles), how can computer-controlled tanks navigate the map without colliding with static objects while pursuing other tanks? Please note that every static object or entity has the ability to freely rotate at 360 degrees and has an arbitrary size.
Context
What I am really trying to do is to develop a game with tanks. It initially started as a modern alternative to an old arcade game called "Battle City". At first, it might have been easy to develop an AI, considering the 13x13 grid, fixed sizes and no rotation. But now, with free rotation and arbitrary sizes, I am unable to find a way of replicating such behavior in these circumstances.
The computer-controlled tanks must be able to navigate a map full of obstacles and pursue the player. I think that the main problem is generating all the possibilities for a tank to go to; the collision system is already implemented and awaiting to be used. For example, tanks might be able to fit through tight spaces (which can be diagonal, for instance) just by adjusting its angle of rotation.
Although I have quite some experience in programming, this is way beyond my reach. Even though I would prefer a broader answer regarding the implementationn of tank's artificial intelligence, a method for generating the said paths might suffice.
I initially though about using graphs, but I do not know how to apply them considering different tanks have different sizes and the rotation thing gives me a headache. Then again, if I would be using graphs, what will a node represent? A pixel? 16,000,000 nodes would be quite a large number.
What I am using
C# as the main programming language;
MonoGame (XNA Framework alternative) for rendering;
RotatedRectangle class (http://www.xnadevelopment.com/tutorials/rotatedrectanglecollisions/rotatedrectanglecollisions.shtml).
I am looking forward for your guidelines. Thank you for your time!
I've been working on a project of crowd simulation that included path finding and obstacles/other people avoidance.
We've used the Recast Navigation, a all-in-one library which implements state-of-the-art navigation mesh algorithms.
You can get more info here : https://github.com/memononen/recastnavigation
In our project, it has proven to be reliable and very configurable. Even if it's written in C++, you can easily find/make a wrapper (in our case, we've been using it wrapped in Javascript on a Nodejs server!)
If you don't want to use this library, you can still take a look at Navigation Meshes, which is the underlying theory behind Recast.
I hope it will help!
Navigation Mesh, that's what ur looking for. To explain a bit, it's in theory really easy. U build ur World (2D/3D) and after creation u generate a new mesh, that tells entities where they are allowed to move, without colliding with the surroundings. They then move on this mesh. Next is the path generation algorithm which is basically nothing else then checking in any mathematically form how to get on this mesh to it's target. On an actual navigation mesh, this get's rather complicated but easy if u think of a grid where u check which fields to move to get the shortest way.
So short answered, u need any type of additional layer of ur world, that tells the AI where it is allowed to move, and any kind of algorithm that fits ur type of layer to calculate the path.
As a hint, for unity as an example, there are many free good build solutions. Also u will find a bunch of good libraries to achieve this without a game engine like unity.

Good ways to map a 2D side shooter (somewhat like liero, or soldat)

I'm wondering what way would be best to render a 2D map for a shooter (these will be static maps) similar to Soldat. Multiple options I've considered are a tile based map (stored in txt files), or just creating different classes for the different terrains I plan to use and creating a data structure to read/store them in a file. (I want to also be able to include things like jumping/running on walls, sliding down walls/slopes ect)
I feel like there must be a better way than either of these, but haven't been able to find definitive information :/
Thanks :)
Soldat used a polygon based format to render and represent it's levels. The editor would have allowed the user to plot points and connections between them to make walls and structures when were then given textures and properties (such as collide = death). Items and images where then overlayed over this.
The soldat rendering engine would then use these structures to perform collision detection and to build up the polygon (triangles that are drawn) representation of the world.
I was going to go with the "just use a tile map," but then I looked at Soldat and it's a bit more complex.
I don't know what they're using, but I suspect they're using polygons and probably colliding against polygons as well. The levels are likely generated with the same sort of primitives you'd see in 3D games, but all in a plane. E.g. texture mapped triangles and collision against the edges of the surfaces rather than against the surface itself.
In my experience, "terrain" is usually an object in itself and the collision and visual representations are data inside that object (aggregated into that object, typically). The different pieces of terrain don't necessarily need to be different types of thing, indeed in all of the games I've made the entire world was generally a single object of type "Terrain" or "World" or something and it managed the doings of the various visible pieces coming into and out of view.
This doesn't feel like a great answer, but I thought I'd try to give you something.
Examples of platform games doing what you want are Braid and Aquaria. You can get Aquaria for 2 pennies litteraly, with the Humble Indie Bundle.
Here's the Aquaria's editor in action. I could not find a decent video of the Braid editor.
I found this other video about IndieLib, and a level editor that they have created which is similar to Aquaria's (Disclaimer: I haven't tried it myself).
Appart from that, googling for "Braid and Aquaria platform engine" should give you more results.
I would recommend reading the book Building XNA 2.0 Games: A Practical Guide for Independent Game Development. It walks you through the development of a 2D side-scoller game named Zombie Smashers (based on the author's award-winning The Dishwasher: Dead Samurai).
Chapter 4: The Map Editor is what you are looking for.
It will help you even if you don't plan on developing in XNA.

Categories