# BlueSin

Members

14

142 Neutral

• Rank
Member
1. ## 2D Sorting map tiles into map chunks

Thanks so much for your tips Postie, I really appreciate it!  Before checking this though I actually was able to get it resolved by modifying the Create Tiles code to this: // Create map tiles private static Map CreateTiles(Map map) { // The current X position of the map float mapX = 0; // The current Y position of the map float mapY = 0; // Traverse chunk rows for (int chunkX = 0; chunkX < map.Chunks.Length; chunkX++) { // Traverse chunk columns for (int chunkY = 0; chunkY < map.Chunks[chunkX].Length; chunkY++) { // Initialize tile rows map.Chunks[chunkX][chunkY].Tiles = new MapTile[MAP_CHUNK_WIDTH][]; // Traverse tile rows for (int tileX = 0; tileX < map.Chunks[chunkX][chunkY].Tiles.Length; tileX++) { // Initialize tile columns map.Chunks[chunkX][chunkY].Tiles[tileX] = new MapTile[MAP_CHUNK_HEIGHT]; // Traverse tile columns for (int tileY = 0; tileY < map.Chunks[chunkX][chunkY].Tiles[tileX].Length; tileY++) { int chunkStartX = (int)chunkX * (map.GetTileWidth * MAP_CHUNK_WIDTH); int chunkStartY = (int)chunkY * (map.GetTileHeight * MAP_CHUNK_HEIGHT); // initialize this tile map.Chunks[chunkX][chunkY].Tiles[tileX][tileY] = new MapTile( 0, null, new Rectangle( (int)(chunkStartX + (mapX * map.GetTileWidth)), (int)(chunkStartY + (mapY * map.GetTileHeight)), map.GetTileWidth, map.GetTileHeight ), Noise.GetNoise(mapX * 0.1f, mapY * 0.1f, map.GetSeed)); // Increase mapY mapY++; } // Increase mapX mapX++; // Reset mapY mapY = 0f; } // Reset mapY mapX = 0f; } } // Return map return map; } I just need to optimize it in this case.  But I fully agree with your advice on using .Length.  However, the map is generated once and once generated it is static.  The map size and chunk size can never be changed, nor will this code block ever run again (unless a new map is created).  Thanks again!
2. ## 2D Sorting map tiles into map chunks

So I am having a ridiculous problem I cannot seem to wrap my head around.  I have been working at it for days, and I know the solution is simple I just cannot see it, so I need an outside opinion.  I am working on procedural map generator.  When I generate the map, the first thing I am doing is initializing map chunks.  These chunks will contain several tiles each and will be used to only draw the chunks that are currently on the screen.  All other chunks will not be drawn.   So I begin by creating chunks: // Creates map chunks private static Map CreateChunks(Map map) { // Initialize map chunk rows map.Chunks = new MapChunk[map.GetMapWidth / MAP_CHUNK_WIDTH][]; // Traverse chunk rows for (int chunkX = 0; chunkX < map.Chunks.Length; chunkX++) { // Initialize chunk column map.Chunks[chunkX] = new MapChunk[map.GetMapHeight / MAP_CHUNK_HEIGHT]; // Traverse chunk columns for (int chunkY = 0; chunkY < map.Chunks[chunkX].Length; chunkY++) { // Initialize chunk map.Chunks[chunkX][chunkY] = new MapChunk(MAP_CHUNK_WIDTH, MAP_CHUNK_HEIGHT); } } // Return map return map; } Then I create tiles within those chunks: // Create map tiles private static Map CreateTiles(Map map) { // The current X position of the map float mapX = 0; // The current Y position of the map float mapY = 0; // Traverse chunk rows for (int chunkX = 0; chunkX < map.Chunks.Length; chunkX++) { // Traverse chunk columns for (int chunkY = 0; chunkY < map.Chunks[chunkX].Length; chunkY++) { // Initialize tile rows map.Chunks[chunkX][chunkY].Tiles = new MapTile[MAP_CHUNK_WIDTH][]; // Traverse chunk rows for (int tileX = 0; tileX < map.Chunks[chunkX][chunkY].Tiles.Length; tileX++) { // Initialize tile columns map.Chunks[chunkX][chunkY].Tiles[tileX] = new MapTile[MAP_CHUNK_HEIGHT]; // Traverse tile columns for (int tileY = 0; tileY < map.Chunks[chunkX][chunkY].Tiles[tileX].Length; tileY++) { // initialize this tile map.Chunks[chunkX][chunkY].Tiles[tileX][tileY] = new MapTile( 0, null, new Rectangle( (int)mapX * map.GetTileWidth, (int)mapY * map.GetTileHeight, map.GetTileWidth, map.GetTileHeight ), Noise.GetNoise(mapX * 0.1f, mapY * 0.1f, map.GetSeed)); // Increase mapY mapY++; } // Increase mapX mapX++; // Reset map Y mapY = 0f; } } } // Return map return map; } So, in theory Chunk[0][0].Tile[0][0] should be positioned at Vector (0,0).  Which it is.  And in theory the second tile in the row Chunk[0][0].Tile[1][0] should be positioned at Vector (24, 0) (tiles are 24 x 24).  Which it is. The first tile in the second row Chunk[0][0].Tile[0][1] should be at Vector (0, 24).  Which it is.  All of that works fine.     The problem comes when we move on to the next chunk.  Chunk [1][0] is to the right of Chunk[0][0].  Chunk [0][1] should be below Chunk[0][0].  However the vector of Chunk[1][0].Tile[0][0] is  (18432, 0).  Chunk[0][1].Tile[0][0] has a Vector (0, 2304).  Which means they are reversed, in theory Chunk[1][0] should be Vector (2328, 0) (I need to increase mapX/mapY between chunk changes.  But given the way it stands now Chunk[0][1] is where Chunk[1][0] should be.  Chunk[1][0] current vector is just messed up.  I know I need to play around with the increase of mapX/mapY and reset of mapX/mapY to change it.  But I have tried every imaginable combination and it just isn't working.  Any help?
3. ## Generic Class Questions

Thanks that helped me understand it a bit better.  Appreciate the help!
4. ## Generic Class Questions

So I am reading the check marked reply on this post: http://gamedev.stackexchange.com/questions/30296/loading-class-instance-from-xml-with-texture2d   I have never used generic classes before and am absolutely confused on what he is talking about.  I read up on them and understand how they should be used, but the respondent's answer doesn't sound like it makes sense in a generic class.   What exactly is he saying I should be passing into the generic class' constructor?  Is he saying pass the Weapon instance into it, or the Texture instance?  Because if I pass a Weapon instance into it as T t, I cannot call t.TextureId because the Type is unknown.
5. ## Map Editor Help

That is helpful too, but it is lacking on features for what I want to do in the long run.  I think I am going to go with Andy's idea here and create my game project in XNA then create an XNA library for my map editor so that I can trigger that mode as I see fit.  Thanks all!
6. ## Map Editor Help

That is true, there is no REAL reason not to make the whole thing in XNA.  Albeit would be a little more work as an editor would require *some* controls at the very least to be partly functional.  The GUI just helps it feel more professional and clean I guess.
7. ## Map Editor Help

So I am preparing to create my own map editor for an XNA game I will be working on.  The map editor will need the ability to import graphic sprite sheets, allow me to pick various tiles on those sprite sheets and plot them on a virtual game map.  It will also need auto tiling and perhaps even other features later on.  Upon saving the map the editor will transform the tile ID's, map layer ID's and sprite sheet file data into a single .map file.   I don't want to embed XNA in a forms project, but I do want to be able to run my map in XNA by use of a play button on the editor interface, to test the map in XNA.   Herein lies the problem, I am not sure where to start.  Should I go with WPF? Or maybe forms and create a series of custom controls?  Or perhaps a forms project where I go batty with GDI+?  Or perhaps some other route for the editor.  I need an outside the box opinion here.   P.S. - I know these types of editors already exist, some for free and others to purchase.  However, I want to create a proprietary one that will be used for games created by my studio going forward.  Thus I am not interested in trying or buying any pre-made editors.   Thanks in advance!
8. ## Map Editor Help

So I am preparing to create my own map editor for an XNA game I will be working on.  The map editor will need the ability to import graphic sprite sheets, allow me to pick various tiles on those sprite sheets and plot them on a virtual game map.  It will also need auto tiling and perhaps even other features later on.  Upon saving the map the editor will transform the tile ID's, map layer ID's and sprite sheet file data into a single .map file.   I don't want to embed XNA in a forms project, but I do want to be able to run my map in XNA by use of a play button on the editor interface, to test the map in XNA.   Herein lies the problem, I am not sure where to start.  Should I go with WPF? Or maybe forms and create a series of custom controls?  Or perhaps a forms project where I go batty with GDI+?  Or perhaps some other route for the editor.  I need an outside the box opinion here.   P.S. - I know these types of editors already exist, some for free and others to purchase.  However, I want to create a proprietary one that will be used for games created by my studio going forward.  Thus I am not interested in trying or buying any pre-made editors.   Thanks in advance!
9. ## How to Use Perlin Simplex Noise?

I am incredibly new to noise, so please bear with me here.  So I used the code from http://cabbynode.net/2012/06/10/perlin-simplex-noise-for-c-and-xna/ to create my noise.  I simply filled a jagged float array with these values and used a white 16x16 texture colored on draw based on value to represent the result visually.  Here is that result:     So, it appears to be interpolating nicely enough.  But the question is how do I use this?  I can think of a couple of possibilities:   Each value is a block, and the material (i.e. - stone, dirt, etc.) of the block is based on that value.   OR   Each value is a chunk of the map, and the material (i.e. - stone, dirt, etc.) that the chunk is made of.   OR   I have completely no idea what I am doing and need the answer given to me lol.   On a side note, I changed the way I was looking at it so that if the value was >= 0.5 it was land, if not open space.  The result is what appears to be a pretty natural looking cave network.  So I guess I could use it that way as well, to tell me if there are caves.
10. ## Is my Game Engine right?

So I know there are alot of game engines out there, but still for educational purposes I want to try my hand at making my own.  Truth be told, I have been remaking virtual the same one for quite some time now and they work fabulously but I always quit out of fear that I am maybe doing something wrong.  I don't want to build my game on corrupted framework, but I want to actually move forward in creating a game!  So if you could please just read this over, and I know it is somewhat lengthy, but your patience and input is appreciated.   For my engine, what is the difference between a State and a Screen?  A State tells us where we are in the game. (i.e.- main menu, credits, etc.) Only one state can be active at a time.  A State can contain one or more active screens.  (i.e.- background screen, foreground screen, etc.) Each screen is made up of Components.  A Component is anything interacting with it's parent screen or being drawn to the screen. (i.e.- player, enemies, fps count, etc.)   Static GameEngine Class Static StateManager Class Static ScreenManager Class   Abstract State Class Abstract Screen Class Abstract Component Class   Game Class calls GameEngine.Update().  GameEngine.Update() calls StateManager.Update().  StateManager.Update() calls CurrentState.Update().  CurrentState.Update() calls ScreenManager.Update().  ScreenManager.Update() calls Screen.Update() on all active screens.  Screen.Update() calls Component.Update() on all components in it's component list.   Game Class calls GameEngine.Draw().  GameEngine.Draw() calls StateManager.Draw().  StateManager.Draw() calls CurrentState.Draw().  CurrentState.Draw() calls ScreenManager.Draw().  ScreenManager.Draw() calls Screen.Draw() on all active screens.  Screen.Draw() calls Component.Draw() on all components in it's component list.   My fear is that there are unnecessary steps in there, but at the same time isn't the object of the OOM to define objects?  Each of these classes plays a unique role within the structure, and are organized in an obvious hierarchy.  Once the GameEngine has been initialized and loaded, other than to call Update & Draw, the GameClass has no other interaction with the game other than to exit.  It is very streamlined, and the process can quite literally play itself.   From here, Screens can make requests to their parent State for a state change.  The state then requests an active state change from the state manager.  The state manager will call for an unload down the hiearchy, then change the active state and call a Load() down the hierarchy.  Then the Update/Draw cycles continue.   Components can remove themselves from a screen's component list by calling their parent screen's RemoveComponent() method.   StateManager keeps a list of all the states passed to it during game initialization.  Likewise, the screen manager keeps a copy of the list of screens for the active state, so that the active state doesn't manage them, the ScreenManager does.
11. ## Isometric Mapping Issues

Been reading around various articles for several weeks now. Been trying to get isometic mapping to work for months, but no matter how it is explained to me, I just cannot grasp it. But, I think I am getting close. I put up my Map.cs class which contains my isometric algorithm in my constructor. Also put up the Tile class for a reference. Default tile texture & map results are below the code. What is really weird is that if I use a flat tile...like grass, it shows up fine...although it does look a little squashed. But my game will be using isometric cube based/shaped textures. So I need it to work with the cubes, but as you can see from the screenshot...its all staggered. I am not very good at math, and it seems like no matter what I change, I just cannot get it. Also, since I am very bad with math, I might have my Height & Depth might be mixed up. For my code reference...depth refers to stacking cubes on top of each other (terrain height), whereas height refers to how deep the cubes go (on the Y) plane. Right now I am just testing with a depth of 1, so 1 map layer to create a nice flat diamond. Height of 10 and Width of 10. Even still I don't think that is what is wrong with it, I have no idea and would like an outside perspective, thanks. [b]Map.cs Class[/b] [CODE] using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace IsometricMapping { public class Map { // Width, height and depth of the map (X, Y, Z) private int width, height, depth; // Accessor for width public int GetWidth { get { return this.width; } } // Accessor for height public int GetHeight { get { return this.height; } } // Accessor for depth public int GetDepth { get { return this.depth; } } // Array of arrays of tiles used by this map [depth][width,height] private Tile[][,] tiles; // Accessor for the tile array public Tile[][,] GetTiles { get { return this.tiles; } } // The default texture assigned to tiles private Texture2D defaultTexture; // Accessor for the default texture public Texture2D GetDefaultTexture { get { return this.defaultTexture; } } // Default constructor for the Map class public Map(Texture2D defaultTexture, int width, int height, int depth) { // Assign values to fields this.defaultTexture = defaultTexture; this.width = width; this.height = height; this.depth = depth; // Initialize the Tile array this.tiles = new Tile[this.depth][,]; // Set up tile positions for (int z = 0; z < this.depth; z++) { // Initialize tile array by Z-layer this.tiles[z] = new Tile[this.width, this.height]; for (int y = 0; y < this.height; y++) { for (int x = this.width - 1; x >= 0; x--) { // Initialize tile at the specified position this.tiles[z][x, y] = new Tile(this.defaultTexture, new Vector2( (x * this.defaultTexture.Width / 2) + (y * this.defaultTexture.Width / 2), (y * this.defaultTexture.Height / 2) - (x * this.defaultTexture.Height / 2))); } } } } // Draws the map public void Render(SpriteBatch spriteBatch) { for (int z = 0; z < this.depth; z++) { for (int y = 0; y < this.height; y++) { for (int x = this.width - 1; x >= 0; x--) { spriteBatch.Draw( this.tiles[z][x, y].GetTexture, this.tiles[z][x, y].GetPosition, Color.White); } } } } } } [/CODE] [b]Tile.cs Class[/b] [CODE] using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace IsometricMapping { public class Tile { private Texture2D texture; public Texture2D GetTexture { get { return this.texture; } } public Texture2D SetTexture { set { if (value != null) this.texture = value; } } public int GetWidth { get { return this.texture.Width; } } public int GetHeight { get { return this.texture.Height; } } private Vector2 position; public Vector2 GetPosition { get { return this.position; } } public Tile(Texture2D texture, Vector2 position) { this.texture = texture; this.position = position; } } } [/CODE] [b]Default Tile Texture:[/b] [img]http://i806.photobucket.com/albums/yy341/BlueSin2009/XNA%20Development/sampleblock.png[/img] [b]Map Result:[/b] [b][img]http://i806.photobucket.com/albums/yy341/BlueSin2009/XNA%20Development/IsoIssues.png[/img][/b] By the way, I have gotten isometric mapping to work from the guides I have read. However, they are really just a jumping off point, and don't help me write the code the way I want it, similar to the way the code is written above. Also, they usually miss an important step such as terrain height, or are jagged as opposed to diamond, etc.
12. ## From start to finish (Questions)

Okay well, where do I go to learn about programming a very simple tetris type of game or something to start? I mean like I said I am not an uber programmer, but I do have an associates degree in computer programming. Most of the guides I find to program things like a tetris game, wind up losing me on the first couple steps. I guess I could always look around gamedev.net more and find out for myself, was just wondering if you guys had any suggestions. P.S. - Thanks for the kind words, they will help =P
13. ## From start to finish (Questions)

So this morning I woke up with a realization that my dreams to design a game that has laid in the back of my mind for years will never be accomplished just sitting around playing video games. So now I have questions about how to start. Right now there is just me, I have a pretty sturdy storyline in the back of my head, characters, etc, for a game that I plan to make MMORPG. I do not know any uber programmers, industry professionals or graphics designers, its literally just me at this point. So the next question is where to start? I look over some previous posts and saw that you could get business-start-up grants or media grants but you must be a professional and whatnot. Also I saw some methods to self fund your own demo's and what not, however, you still need to be an industry professional to even be considered by a big gaming corp to fund your game. So to me it sounds like I must go it alone...but a game like an MMORPG would take years and millions of dollars to make. I highly doubt my \$11/hour job will pay for that in time...which means I at least need some kind of investor or something. But I doubt an investor is going to bring millions to the table with me just having an idea. So can somebody maybe help me out on some resource links or guides or tips or something?