Making walls in tile-based games: what am I missing?

norien
  • Making walls in tile-based games: what am I missing? norien

    After spending time today to jot down some notes regarding the implementation of walls into my tile-based game, I've suddenly realized it's not going to be as simple as I imagined before. While the current stage of my work is not even close to actually making the wall-related code, I've come up with three different ways to do it. Right now I'm unsure which one of my ideas will work best, and whether I missed something or not.

    Important: a character CAN stand on a tile that has walls, regardless of their form.

    The common thing for all the three variants: the tilemap will be "kept" in an single-dimension std::vector (or similar) based container. The reasons for that are (awesomely) explained in answers to a different question.

    Container classes in tile-based games.

    Back to walls.

    A) The simple approach.

    Nothing fancy here. Each tile-container can hold not only characters, but one or several Wall objects, which are attached to the edge inside the tile.

    First approach

    Pros: easy to implement, nothing to change in the engine. Cons: Two things. One - it might be just in my head, but some combinations just look ugly. Second - this approach allows to make a double-wall from two adjacent tiles. Building will be an important part of the game, and double-walls allow the builders to possibly forego upgrading the material of the walls through game means, and just achieve increased durability with doubling the existing wall. That's not desirable. Sure, I could include a procedure that forbids double-walling, but it will have a bad feel to it.

    B)The smart(?) approach.

    Instead of letting the players double-wall the whole map, I'm going to beat them to it. Every wall has two halves that are attached to the edge of the tile from inside. So, to make a single "Wall unit" I'll have to create two Half-Wall objects in two adjacent tiles.

    Second approach

    Pros: It's symmetrical!!! Also, no significant change of current engine specs is needed. Cons: More hassle, more objects, and, of course, the "caps". As you can see in the picture, a corner will basically cry for a "cap" object. I'm actually cool with it, it's not so hard to add. Hey, I already have a plan for thin columns made out of four connected caps. Sweet. Still, I have some worries regarding possible Field of View and Line of Sight issues.

    C) The total overhaul variant.

    Or, I could just create borders and corners as separate containers for game objects. Just like that.

    Third approach

    Pros: Not even sure. Well, it's straightforward. Definitely. Cons: It will require an overhaul. Not of code, thankfully, but of the current game mechanic mentality - that's for sure. The benefits are not so obvious. Also, this aprroach requires much more containers than the two previous ones. The indexing math will also be a bit of pain.

    So here we have it - three distinct ways of making walls between tiles. If there are any alternatives out there - I'll be happy to check them out. If there are any benefits/downfalls to any of the approaches that I didn't see - please point them out.

  • Sorry to say but the third way is really the way to think, well, you already have the ability to do that so lets move on and think about the other two!

    The thing is that a wall is a zero width, two dimentional (height*length, in a 3D world) square partitioning two Boxes. You should consider them as such but you might use a simpler solution as when to build your dungeon (especially if other people might build parts).

    It seems it is a Top-Down 2D game where walls have "a width" so they need that corner (your 'cap' object). This is exclusively 'graphics' though so I'd go with some sort of:

    A 2D map with the tiles (ie. type of tile and such).

    A 2D map with 2 walls, ex. bottom and right (the left wall will be the 'right wall' in the tile left from this one).

    + a Logic that draws all the walls and 'caps' etc.

    Thus separating logic and graphics. You might do an "interface" taking care of things like SetWall(ThisTile, LEFT, NOWALL) -> setting the right wall of the tile left of ThisTile to "NOWALL"...

    Maybe this seems blurry but the thing is that you should always try to have at one side the logic (the actual data, without redundancy) and on the other side the 'drawing of the data' which calculates if there is need for a 'cap' etc.

    ++

  • I'd use your method 'B'.

    To avoid needing 'caps', just extend each wall "1/2 wall thickness" in both directions. This will create overlapping walls where they meet, but your diagrams already suggests this is not a problem.

    So, in Method 'B', Pic #3, the horizontal wall would extend to the left a bit, and the vertical wall would extend up a bit.

    [I'm new here, just registered. Am I missing something, as I can't see an 'Add Comment' button to your original post. Is that a privilege of people with higher reputations? Or am I overlooking the obvious? Sorry for adding this as an 'answer'.]

  • You noted that a character can stand on a tile containing a wall but have you considered treating each tile as wall itself? Even half a tile as a wall in a horizontal or Vertical fashion?

    Pros: Calculations and placements are trivial, collision is trivial where all calculations and collisions are just based on the coordinates of the walls placement.

    Cons: It could impact your entire implementation, code and graphics. You don't want to totally abandon your method either, you still want special cases where only part of a tile is wall (Link to the Past with cliffs).

    This is how I would I have based my implementation, going forward, knowing that I can always reference a tile and perform a calculation on it depending on my characters location and what kind of tile it is.

    A castle wall I could just perform a calculation from the center drawing a box that I could not pass through or if its a round rock I could do the same calculation from the center but as a circle so my character can move around in like it was rounded.

Tags
c++ tiles level-design
Related questions and answers
  • that make really hard to work with when coding some functions that use them. I was thinking of making ie. SimpleMesh and HierarchyMesh objects, which will also require that the renderer can deal with different types of objects in the same scene. I was also thinking about making a MeshNode class and then make a Mesh object that contains them, but then I have some conflict on where to store some data... them to be attached to the node in most cases, even if I allow setting global lights to the scene. @Nicol: Yes that's what I'm trying to figure out. You can see the code doesn't rely on any hardware

  • this summer and I have a good grounding on the web side of things. I've also done some very basic c++ (what i would consider basic). My c++ skills basically comes down to different tutorials on things... I take and the language that I base my first decade of programming on. This is important to me so please do not dismiss it as another student who likes games and wants to code them. I'm a hungry young.... Not my brightest moment. So we've gone from students making lazy decisions to lecturers just crapping out projects handing us a fork and saying eat it...... but i digress. If I wasn't up to the task

  • have updated my code with a new algorithm that checks where the ball was previously before collision. Corner cases work on that single platform correctly now, but when I have a wall of objects, I keep... the platform. I have tried many different ways of doing this, such as trying to find the penetration depth and repositioning the player backwards by the penetration depth. Sadly, nothing I've tried seems...I am trying to create a 2D platformer (Mario-type) game and I am some having some issues with handling collisions properly. I am writing this game in C++, using SDL for input, image loading, font

  • Alright so i'm making a vertical side scroller where you are an '8' character traveling downward while avoiding my randomly generated walls (the "generation" function) on the left and right sides... until you pop out into an open space, known as a ' ' (space) character. You lose one life for each INITIAL collision with the X wall, and do not lose another until you have popped out and been freed from it. As an added touch i have made it so after you collide while traveling down the randomly generated map (or rather as the walls move uppward while your character stays put) the X chars you've

  • I am quite new to OpenGL, I have managed after long trial and error to integrate Nehe's Cel-Shading rendering with my Model loaders, and have them drawn using the Toon shade and outline AND their original texture at the same time. The result is actually a very nice Cel Shading effect of the model texture, but it is havling the speed of the program, it's quite very slow even with just 3 models on screen... Since the result was kind of hacked together, I am thinking that maybe I am performing some extra steps or extra rendering tasks that maybe are not needed, and are slowing down the game

  • . And I could see a case there for using arrays rather than linked lists, because you would have to make your own (which while simple enough to do, could potentially lead to many more errors). I also... that. All this seems well and good, except I have one question, why not linked lists rather than arrays? Sure, if you had to make your own linked list class, I would be on board, but in c++ anyway, assuming... critical place in the code. He gave the example of loading data from a wad file in doom, which while fast, still took that naive approach (at least according to the talk, I haven't looked

  • # bindings get dropped repeatedly. I'm not an engine enthusiast, I just want to make a game. I don't see this happening with Irrlicht. Ogre3D. Way too much work, it's just a graphics engine. Also no multiple... don't need 3D, and it is quite ...a lot of work to learn. I also don't like that it is so expensive to use for different platforms and that I can only code for it through scripting. You have to buy each... etc. are far worse in Flash, than they are in XNA/WPF.) Now, I'm aware that I could make my own engine that supports each of those platforms, but quite frankly, that would be too much work plowing

  • my classes and still have them do what I want. Here's a few examples of a dependency chain: I have a status effect class. The class has a number of methods (Apply/Unapply, Tick, etc.) to apply... related to the graphics library I'm using, but is more of a conceptual thing. In C#, I coupled graphics in with alot of my classes which i know is a terrible idea. Wanting to do it decoupled... sort of designs other people used to overcome them, or would use. For a little background, I started working on it in my free time last summer. I was initially making the game in C#, but about 3 months

  • I'm a beginner both in game developping and programming. I'm trying to learn some principle in the building of a game engine. I want to create a simple game, I'm at the point where I'm trying to implement the game engine. So I thought my game engine should control this things: - Moving the objects in the scene - Checking the collisions - Adjusting movements based on collisions - Passing...; //this method is unique to the class player void generate_mesh(); } Now in the game engine I want to have a general object list where I can check for example for collision, move objects, and so

Data information