2019-04-04 16:32:45

Hello!
I am going to create a game, something for my own enjoyment but I am getting stuck as fuck. I don't know the abstract thing and it seems that I should know them.
How should I represent a map in C#? Do you recommend me using any game engine or wrte everything myself?

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2019-04-04 16:46:52 (edited by kianoosh 2019-04-04 16:49:43)

No need to use a game engine as far as you have BPC shared component and then Irr klan. If you want to generate maps that are similar to dreamland, or games like this, You have different choices. One is using dictionaries and defining each single tile as a dictionary entry. That way you have control over each single tile in your map. Another way is using the arrays. This one decreases your control over your tiles, but might increase performence. It did increase performence on bgt, and vice versa in python so you have to test it yourself. In this way, chunks of tiles are placed as the array's elements. I have to tell you that I used this way of map creation in C# and worked fine. Never tried dictionaries. A suggestion. Your game loop *should not* be called in a timer.tick event. even if you set their interval to 1 millisecond the performence won't be like what you expect. You have to use threading and run your game loop on a separate thread.
Edit: If we could get unity to operate with the screenreaders correctly, I never would say that you don't need to use a game engine. smile

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2019-04-04 17:30:53

Yeah, dictionaries seems more performent from what i have read, and that's why I iwll try and use them. Thanks for your response Kianoosh

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2019-04-04 18:37:31

You can use BPC, write your own game engine, or do whatever you like. I wouldn't use a dictionary for a map if your going to represent it as an (x, y) coordinate pair. Instead, either use a 2D array (int[,] varname) or use a 2D matrix.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-04-06 20:42:39

See, my issue is this.
Suppose I want to spawn 0 by 10000 x and y platform. While it will be stupidly huge, I can't spawn it in the first place. I'm using python dictionaries, and I get a memory error when trying to append so many keys and values to it. To be fair, it did contain 22 million keys before it crashed so...
I'm wondering about a good way to do maps  as well. Most things I've found are dictionaries that are pared with an x and a y coord and a tile type, and that seems to work, but then again, I'm limited on my map size, and that's the last thing I want to happen.
I considered using a list to load only small chunks of map data, but then I lose the fine control the dictionary allows with tiles, again, something I do not want to happen.
Tips?

2019-04-06 22:19:52

As I said, either use a package explicitly designed for large matrices, or create a 2D list, like so:

l=[]
for i in range (0, 10000):
  lst = []
  for j in range(0, 10000):
    lst.append(object)
  l.append(lst)

Then use it like so:

platform=l[x][y]
"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-04-06 23:16:24

I generally code maps and tiles as classes
The map is  a class, which has a container which contains the tiles, which are classes
so the map clas has an array storing the tile objects.

Paul

2019-04-06 23:29:36 (edited by amerikranian 2019-04-06 23:30:57)

@6: Interesting, I shall have to consider being forced to use something external if creating maps by hand won't work out.
@7: See, but then comes the problem of looping through the objects.
Let's go back to post 4's example, a 0 by 10k platform. That will require 100000000 objects in a list. Unless, your tile classes contain the minimum and maximum coordinates for x and y, but then how would you control the tile's surface? Would you have it in the tile class itself? Then there comes a problem of playing the tile sound. Would I go and loop through the list of tiles and see if my x and y are within the bounds of the tile object?

2019-04-07 01:00:20 (edited by magurp244 2019-04-07 01:08:42)

If your going to be using structured maps that size you should really be using lists, not dictionaries. There are a few tricks you can use for navigating maps that size and doing border collision checks, such as liberal use of the len() function, which can tell you how long a particular axis of an array is. For example:

maps = [[0,0,0,0,0],
        [0,0,0,0,0],
        [0,0,0,0,0],
        [0,0,0,0,0],
        [0,0,0,0,0]]

print(len(maps))
print(len(maps[0]))

This creates a 5 by 5 2D map, the first print statement prints the length of rows there are, which would be considered vertical, and the second tells you the length of each individual row, which would be horizontal. So a 2D array could be considered: array[y][x], though I suppose you could arrange it however you like. Keep in mind that len() will return the total number of items in the list from 1 to whatever, but that lists start at 0 and go to the end point, so if you plan on using len() for indexing arrays, always do len()-1. Now as for how to control the tiles surface, all you really need is the number value, so 0 could be empty space, but you could switch that to 1 to represent a wall, 2 for a stairwell, 5 for a pork-chop, etc. Similarly you could replace the number value with a class reference for the player or an enemy NPC, or any number of things. For playing sounds, what you could do is take the players x and y coordinates within the map, and iterate through a section of map to play sounds, for example:

#3 is a sound we want to play
if maps[player.y][player.x-1] == 3:
    sound.play()
elif maps[player.y][player.x+1] == 3:
    sound.play()
elif maps[player.y+1][player.x] == 3:
    sound.play()
elif maps[player.y-1][player.x] == 3:
    sound.play()

This would play a sound in four directions around the player, but another way to do it would be like this:

for a in range(self.player.y-3,self.player.y+3,1):
    for b in range(self.player.x-3,self.player.x+3,1):
        if a >= 0 and a <= len(maps)-1:
            if b >= 0 and b <= len(maps[0])-1:
                if maps[a][b] == 3:
                    sound.play()

This also checks to make sure the x and y values are still in bounds of the array, which could cause errors. You could also do the same thing for the player reaching the edge of the map, and wrap around the map to the other side, or link to another map array, etc. Then there's getting into things like slicing arrays and such, another library you might want to check out if you plan on doing heavy array lifting would be Numpy.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer