Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 21 Aug 2004
Offline Last Active Mar 28 2015 09:16 AM

#5214346 Best way of handling Auto-tiling?

Posted by Roots on 03 March 2015 - 08:02 PM

We have had a little experience with it. Here's some old documentation on how we originally went about handling transition tiles in our title: [LINK].


While in theory this sounds nice, it was really a pain to implement and support it. We've pretty much thrown away all support for this sort of programmable transition tile. We achieve the same effect now by simply using multiple tile layers and having transparency in several of our tiles that do the blending. Adding support to our editor to automatically detect the proper transition tiles and enter it accordingly is not worth the effort for us (we are a very small team of unpaid hobbyists). Instead, we focused on making our editor easy to use in other areas and add in the extra tiles necessary into our tilesets to achieve nice looking transitions.


Here's a long-ish video I released recently of several major changes that I made to our editor. You can kind of get an idea of how we build maps using tilesets, layers, and a feature we call "map contexts". If you're not interested in watching the whole thing, I would skim around and take a look at the different things we can do with it.




My opinion is that custom support for transition tiles in your editor/game is "nice to have", but probably shouldn't be a high priority. There's likely much more important things you can invest your teams time in, and I don't think adding any fancy transition tiles will save you much time in map design (at least not for a game like ours). But take my opinion with a grain of salt, as I haven't worked extensively with this sort of technology myself.

#5210486 Very basic 2D RPG game

Posted by Roots on 13 February 2015 - 09:02 AM

Well typically 2D RPG maps are built using layers. A layer may contain either tiles or objects (sprites). Typically you don't want to have something like a house be an object, because such a large, static structure is better constructed using tiles (since you can change up the size and display of the house more easily that way). I'll give you a simplified explanation of the class modeling in my own RPG.


We have a class called MapMode which is the highest level class and implements the main loading, update and draw code. This class got really big in the past because there's so many different things it needs to do, so we decided to create some helper classes to it that are responsible for handling specific operations on the map. Two of these classes are called TileSupervisor, which manages everything having to do with tiles and tile layers, and the ObjectSupervisor, which manages all of the sprites and the map's collision grid. Naturally, our tile layers are managed by TileSupervisor while the object layers are managed by ObjectSupervisor. We can have any number of tile/object layers and their draw order can be arranged and re-arranged in any way we like, but for simplicity let's assume we'll always have 3 tile layers and 1 object layer.



Our map is built using several layers of tiles, where each layer is like a 2D array. The same tile image may be drawn in more than one location, so it's inefficient to store several copies of the images. The TileSupervisor class maintains a vector of tile images, and our layers are nothing more than integers that index into that vector to extract the desired image to draw. Now we could either create a 2D array for every tile, or we could create a single 2D array and store the layer information for all tiles in there. We went with the latter approach. The MapTile class is a very simple wrapper around a 1D vector. This vector contains the indexes into the tile images container for each tile layer. So if we wanted to draw a tile that was located at the X, Y position on the map for a layer Z, we would access the 2D array of MapTile objects, index the X, Y element of this array, extract the Zth element from the MapTile object, and use this integer to index into the tile images container to extract the image to draw.



Now let's talk about objects. We define a MapObject as an entity with an x, y position on the map that has a height and length property, indicating how large the object is. We also have other properties we can set for objects such as whether or not to draw the object if it is on the screen (visibility toggle). We have a base class called MapObject which is abstract and contains these common properties, as well as pure virtual functions for drawing and updating the object. We have a number of classes derive from MapObject to support different types of objects on a map.

  • PhysicalObject is a static object that does not move. A tree could be a physical object, for instance.
  • TreasureObject is derived from PhysicalObject and can be interacted with by the player to extract treasure contents.
  • VirtualSprite is a sprite (moving object) with no image. This serves both as a base class for other sprites, and can also be used as a map camera (our camera is always focused on a map object).
  • MapSprite implements NPCs and player-controlled sprites. They can have dialogs, be given movement commands, etc.
  • EnemySprite is derived from MapSprite and causes a battle to occur when it collides with the player controlled sprite.


The ObjectSupervisor maintains a vector of MapObjects for each object layer. When it's time to update the map, the code will go through and call the update function on every object to update their animations, change their position, perform collision detection, etc. To improve performance, we keep the objects in this container sorted based on their draw order (you want to draw objects on the screen from top to bottom). So when we call the draw function, we already have a draw-order sorted container of objects and can simply iterate through the container and draw each object that should be visible on the screen.




Hope that starts to get the gears moving in your head about how you can go about implementing tiles and objects and layers on a map. The map code for an RPG is probably the most complex piece of the game and it will take time and practice before things start to make sense. I didn't even get into other map aspects like dialogues, events, pathfinding, and so on. My project is reasonably well documented (certainly more so than most) and the code is open source, so you are welcome to study it and learn if you like.



Documents the design and structure of our map code. Somewhat incomplete, but covers the most important aspects.



Source code - main directory



Source code - map directory



You can also download it and run Doxygen on the source tree. This tool will build the API documentation and can also do things like construct class hierarchy diagrams to give you a better understanding of each piece of the code and how they all tie together. Again though, this is pretty complex and is definitely above the scope of what you're aiming to do with your project. Hope you find this information helpful.

#5210465 Very basic 2D RPG game

Posted by Roots on 13 February 2015 - 07:51 AM

FYI, even a simple 2D RPG is quite an ambitious project and not very suitable for a beginner IMO. I was in the same position as you ten years ago and went ahead anyway. I suggest making an extremely basic game first and build up from there. Start small and work your way up instead of trying to add everything you need all at once. For example, your milestones could be something like this.


  • A single map that you can walk around in.
  • Add NPCs that randomly walk around the map
  • Add dialogue to the NPCs
  • Add random enemy encounters (with a very simple battle system where all you can do is select "Attack")
  • Add a basic character management menu
  • Add a second map


And so on. I'll second KnolanCross that if you just want to make a RPG, use one of those tools he listed above. You may think that coding a simple 2D RPG isn't that difficult, but it is. My project is currently hovering around 250K lines of code that were written (and re-written) over many years. If you want to make an RPG from scratch, be prepared for the enormous amount of time and effort it will take.

#5210186 Modern game development/programming for a not-quite beginner?

Posted by Roots on 11 February 2015 - 09:47 PM

Maybe take a look at these courses:







They pretty much dive right in and you'll make simple clones of popular games like Asteroids. I think this would be a good way to both refresh yourself on the fundamentals of programming, get some experience making games again, and learn a popular new language in the process. I got about half of the first course a couple years ago to refresh myself on Python and I thought it was run very well.



C++ has evolved quite a bit, but as long as you still know how to do memory management and understand the basics of object oriented programming, it shouldn't be too difficult to pick up again. C# would more or less tie you to Windows. There's unofficial support to run the language on other systems, but I'm not sure about the effectiveness of writing C# applications for non-Windows systems.



If you're making a simple 2D clone to get some practice, using SDL or SMFL is a solid and reasonable choice. If you're planning to do anything really complex though, I would suggest using an existing game engine library instead of rolling your own.

#5209315 Should i use sdl or some higher level framework?

Posted by Roots on 07 February 2015 - 04:40 PM

Is your goal to make a game? Use an existing game engine. Is your goal to learn as much as possible? Use SDL and make your own (simple) engine.



It's not quite as simple as that, I'm afraid. But in a lot of cases that's what it boils down to. Ten years ago I, being incredibly ignorant, decided to use SDL and make my own engine. I learned a ton from the process, but I paid dearly because it took a long, long time (several years) until we had a useful and stable engine that could do what we needed it to. My project would be years forward ahead of where it is if we used an existing engine.

#5209313 Looking for critique on my new RPG forest theme...

Posted by Roots on 07 February 2015 - 04:12 PM

I pretty much second everything Elahrairah said. Thematically, I think you hit the nail on the head. But it does sound "too busy" as was said. I think maybe it could be improved if you added in some softer, less intense sections in the tune that perhaps focus on one or two instruments. That would also help feel like the song is going somewhere, instead of just making slight changes to the melody here and there. Overall though, I think this is pretty awesome work!

#5208090 SDL2 and Linux [RANT]

Posted by Roots on 01 February 2015 - 03:56 PM

I think it's a little silly to be angry about a product which was provided to you to use for free. I'd understand if you expressed disappointment instead of anger though.



Anyway, no SDL2 is not perfect. Neither is any other piece of software in the wild. Many people rave about it because it's one of the best solutions of it's kind. Since it is free/open source software, you have a few options. You can fix it yourself, wait for it to be fixed by someone else, or find another alternative that hopefully works out better for you. If it was commercial software, you would have fewer options than that (and less money). Just trying to bring some perspective to your situation. I use SDL as well and I have had issues with it similar to yours, but I stuck with it because it was the best alternative out there for us at the time and now it's so entrenched in our code now that to take it out would require a lot of work. I think you should take a look around and compare it with other solutions to see if you have any better luck with them.

#5206992 Use gimp instead of Photoshop

Posted by Roots on 27 January 2015 - 02:56 PM

Gimp's main weakness, IMO, is that it has a crappy user interface. Other than that, I've found it to be an immensely useful and powerful tool and haven't had a need to seek out any alternative image editor. I say stick with Gimp for it's features if you can tolerate it's cumbersome UI. You may find that later when you can afford Photoshop, you're already accustomed to Gimp and won't need or want to switch.

#5206012 What's a good way to play random environment sounds?

Posted by Roots on 22 January 2015 - 10:57 AM

I was going to suggest the same thing that samoth did. It doesn't make any sense to continually call random in a loop for this. Figure out a range of the minimum and maximum values you'd like to wait between playing this sound (say 5000ms min, 12000ms max), then set the play timer to 5000 + random(7000) after each playback of the sound.

#5205020 Problem with SDL

Posted by Roots on 17 January 2015 - 10:56 PM

First minor issue: You shouldn't start your variable names with an underscore. Variable names starting with underscores are reserved for the compiler.


This is the first time I've heard this after writing C++ code for 12 years. I think it's a pretty common practice to prefix private variable names with an underscore. We do it in my project (> 150k lines of code) and cross-compile it on multiple different systems and haven't run into any name conflicts yet...

#5203850 Writing for games, need help.

Posted by Roots on 13 January 2015 - 01:53 AM

I'm also working on a jRPG which started out as a short story, not a game. We kind of rolled with the idea of making a game based off of a book, so I write chapters of a novel that serves as a basis for the game's narrative. When I'm writing, I try to do so with no regard of the fact that a game is being based off of this story (I want the story to drive the game, not the game drive the story). Another writer makes adjustments and changes to each chapter as necessary to make the story flow well in the game.

#5203570 Algorithm for a "fill" tool in a 2D array?

Posted by Roots on 11 January 2015 - 05:51 PM

I'm working on implementing a feature in a 2D map editor that I'm sure there's a common algorithm for. It's a fill tool where if you click a certain tile, that tile and all identical tiles orthogonal and adjacent to it are set to a new value. The data structure I'm working with is a 2D array of integer values. Here's the function definition:


void FillArea(int x, int y, int value);


Is there a name for this type of algorithm? I've tried searching online but wasn't sure exactly how to describe it. Essentially, this is the same algorithm that a raster image editor like Photoshop or Gimp would use when you fill a selected area with a color. I've had a couple ideas so far, but both have flaws:



First Solution: Use a recursive call to check adjacent tiles


The solution starts at the x/y tile. It sets the new value, then looks at all adjacent tiles to see if it matches the value. And the calls continue until it finds the edges of the map.


The problem with this one is it doesn't seem very efficient with how many recursive calls it has to make. These maps can be fairly big, so the call stack can easily get to a size of 100s or even 1000s. Plus I'd have to keep track of which nodes I've already visited, since there's more than one path to a node from the start.



Second Solution: Set the tiles one row at a time


From the starting position, we only look to the left and right and find all tiles that match. Then we have a line with two end points. Using that line, we then look at the lines above and below it and see if those tiles match. We do this until we reach the boundaries of the data structure or there's no more tiles above or below.


The problem here is that for certain shapes, this just won't work. For example, imagine the following structure:

[o x x x x x o o o]
[x x o x X x x o o]
[x o o o o o o o o]

The capital X is the starting point, and all the small x's are locations that match the value of X. The o's are points that we do not want to set. With this algorithm, it would only set the segment of four x's with the big X in it. The two x's to the left of that line segment would never be set, and neither would the single x on the bottom line. An adjustment to this algorithm might work where you revisit each row and check again, but that seems kind of hackish.



I'm still thinking about alternative approaches, but really I think the best solution here would be to use an existing solution rather than coming up with one on my own. Any suggestions for how to solve this problem or pointers to existing solutions?

#5202747 Programming a Level Editor

Posted by Roots on 07 January 2015 - 11:12 PM

What type of game are you looking to make? Level editors take various forms depending on the type of game. I work on a 2D RPG and we've built a separate GUI application for constructing our maps using the QT framework. It works pretty awesome for our purposes. However, making a level editor can consume a lot of time and effort from you and your team, so if you can find an existing tool to do the job, I would urge you to go with that. For example, the Tiled Map Editor is a free an open source application much like our own editor. Both Tiled and our editor are free to use and open source, so you can study the code to figure out how to make a similar tool, or modify the code to add any special features that you need.



Another approach is to have your editor in-game. This is very useful if you are working on a platformer title, for instance, and can immediately test the location of jumps and other objects to make sure that they are reachable. One open source project that I am aware that uses this approach is Frogatto and Friends (website is down at the moment, so try searching for it on github). I watched a video a few years back about how their in-game editor works and I was really impressed at how easy it was to use.



EDIT: Found the video showing the Frogatto Editor:

#5202166 Looking for a good way to make games in C/C++ on linux for cross-platform

Posted by Roots on 06 January 2015 - 12:39 AM

I've been working on a cross-platform C++ game for several years. Below is a link to the list of libraries that our game uses. The code is also open source and well documented if you want to dig around and figure out how we put together a working title with these libraries.


Allacrost Libraries

#5200649 JRPG Combat System Concept

Posted by Roots on 29 December 2014 - 03:29 PM

I really like the idea. It seems like it would be a great tool to allow RPG battles to be more strategic. Instead of knowing "this enemy is weak to fire, so I will use fire-based attacks" you are essentially evaluating the enemy, the terrain, and the ability of your own party and creating a weakness on the enemy which best suits your circumstances. It's fantastic, but also sounds like this would be difficult to pull off well.


Questions I immediately began asking myself:

  • Does the active behavior remain on the enemy permanently until it is defeated, or is it a temporary state that requires the ability to be re-cast?
  • Can an enemy "cure" the behavior afflicting them, or change their own behavior to something different?
  • Can the ally characters also be afflicted with a behavior?
  • Are there varying degrees to the behavior that can be applied? (Example: a stronger version of gravity that slows down the target even more)


I think the best solution to experimental design questions like these is to code up a prototype and figure out how to make it work best. Sometimes ideas sound really fun on paper, then you code up your game and play it, and find that they aren't that exciting or just make the battle system more annoying or tedious.