• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
suliman

Best way to check tile-distance (building placement)

4 posts in this topic

Hi

When placing buildings in my game (think dune 2 or warcraft 2) they must be placed with no more than 2 empty tiles spacing from an existing building. What is the best way to perform such a check? Buildings are X*Y tiles in size (and X and Y may not be the same for some building types).

 

Thanks!
Erik

Edited by suliman
0

Share this post


Link to post
Share on other sites

Hmm … "best way" is ever a fruitless question, because what is the measure for "best"?

 

Let a tile index be [x ; y]. Let the tiles covered by building n be from [xl,n ; yb,n] to [ xr,n; yt,n ], e.g. read it as from left / bottom corner to right / up corner. Then the separate distances between 2 buildings 1 and 2 for the both dimensions are

   dx = min( | xl,1 - xr,2 | , | xr,1 - xl,2 | )

   dy = min( | yb,1 - yt,2 | , | yt,1 - yb,2 | )

 
Both of the separate distances need to be 1 for directly adjacent buildings. A value of 2 means that 1 free tile is in-between them. Hence, if no more than 2 free tiles is allowed, both separate distances must be less than 4. (Notice that you may need to use a slightly more complex condition if diagonal distances need to be considered.)
 
Above solution requires AFAIS that the building do not overlap, or else false positives may occur if one building is really big compared to the other, so checking whether the tiles under the placeable building are free should be done already simply by checking each tile in  [xl,2 ; yb,2] to [ xr,2; yt,2 ] for coverage.
 
You can restrict the search over all already placed buildings (if needed) by e.g. using a spatial partitioning scheme.
Edited by haegarr
0

Share this post


Link to post
Share on other sites

Best in this case in easy to understand/code and not too slow (its c++)

 

Yes I already check for overlap. How would you do that check actually? Loop though each tile of the proposed building-position and check how far other buildings are?

0

Share this post


Link to post
Share on other sites

It depends a lot on what your game looks like.

 

If the map is "reasonably sized" (few thousand tiles in each direction), the easiest way may be to draw into a bitmap of "occupied" tiles whenever a house is placed. Placing a new house then just makes it necessary to do a few samples into neighboring bitmap pixels. If they're zero, there is no house.

 

Another solution would be to do a hierarchical collision detection as suggested by haegarr. For example:

  • First, a spatial partitioning scheme like an octree or a regular grid (hashed if you will). Depending on the world size, a hashed/virtualized regular grid will likely be best.
  • Next, a radius-radius collision. For that, calculate for each house type (offline preprocessing!) the squared radius of from the house center to the most distant occupied tile, plus 3. If squared distance of the to-be-placed house and another one isn't less than the sum of these two radii, there is no point in pursuing that pair any further.
  • Last, if the radius test passed, do an exact tile-by-tile collision for this pair.
0

Share this post


Link to post
Share on other sites


Yes I already check for overlap. How would you do that check actually? Loop though each tile of the proposed building-position and check how far other buildings are?

Do you mean the overlap check? It depends on how the ground data is available. However, looping over all tiles of the desired coverage is not needed if the bordering tiles are compared.

 

* Is there an array where each tile occurrence is memorized, then setting a flag for coverage is a simple extension with which direct indexed checking can be done.

 

* If you have a kind of sparse array for coverage then a separated indexing is to be done.

 

* If you have no explicit coverage but the building instances store the covered tile indices (as is used in my post above for distance calculations), then an overlap test would look like

    xl,2 <= xr,1 && xr,2 >= xl,1 && yb,2 <= yt,1 && yt,2 >= yb,1 then overlapping

Whether this is worth being accelerated depends on the amount of building. As said, some kind of spatial partitioning may be an option.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0