Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:09:48+00:00 2026-06-12T21:09:48+00:00

Considering a tiled based game, where each agents can move straight/diagonally (in 8-directions). Basically,

  • 0

Considering a tiled based game, where each agents can move straight/diagonally (in 8-directions).
Basically, a map like this can be represented as a regular 2D grid, where 0 would represent an walkable location and 1 unwalkable locations (I’m using Lua):

-- Example : 3x3 sized map
local map = {
 {0,0,0},
 {0,1,1},
 {0,0,0},
}

At this point, how can we represent tile walkability depending from the direction an agent comes from ?
I.e. cell [2][2] above, which is statically unwalkable, would now be walkable if coming from [1][2] (above) or [2][1] (left), but not, for instance, from [3][2] (down).

I have given to this some thoughts, but I couldn’t come up with something clean enough, to me.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:09:49+00:00Added an answer on June 12, 2026 at 9:09 pm

    I’d overlay another 2D grid with of single bytes. Each bit of the byte corresponds to a possible entrance direction with a 1 meaning it can be walked on from that direction and a 0 meaning not. You can then check for enterability using binary masking.

    If most of your cells can be entered from any direction, then you may consider using a map with the tile’s absolute ID (X*MaxY+Y, for instance) as a key and the byte scheme described above indicating enterability. This is slower to access, but takes less space.

    For instance, let the directions be laid out as so:

    Bit #      X offset  Y offset
    123        -1 0 1    -1 -1 -1
    4 5        -1 0 1     0  0  0
    678        -1 0 1     1  1  1
    

    If I go in the northeast direction, this corresponds to bit #3. I can perform masking by translating the above values into bit masks:

    1   2   4
    8      16
    32 64 128
    

    I can enter from a direction if the following returns true

    Enterability(CurrentX+Xoffset(Dir), CurrentY+Yoffset(Dir)) & BitMask(Dir)
    

    (Sorry, I’m afraid I don’t know Lua well enough to write this up in that language)

    Edit

    So, say my directions and such are as above and I want a square that can be entered only from the North. To do this, I set bit #2:

    Enterability(X)=2
    

    If I want a square that is enterable from both the north and the southwest, I would use:

    Enterability(X)=2 | 64
    

    where | is the bitwise OR operation.

    If I want a square to be enterable from any direction but west I use:

    Enterability(X)=(~8)
    

    where ~ is the not operation.

    If I need to close a door, say to the east, I could unset that bit:

    Enterability(X)=Enterability(X) & (~16)
    

    To open the door again, I use:

    Enterability(X)=Enterability(X) | 16
    

    or, more simply,

    Enterability(X)|=16
    

    The ~16 produces a bitfield which is all ones except for the bit referring to 16. Using this with the AND operator (&) leaves all the bits on, except the one referring to 16.

    Also note that hexadecimal addressing can be more convenient:

     Decimal          Hexadecimal
    1   2   4       0x1  0x2  0x4
    8      16   =   0x8       0x10
    32 64 128       0x20 0x40 0x80
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Considering that this prints something like [E] [F] [A] [C] [A] [B] [F] [B]
I'm creating a map editor for a little game project that I'm doing. Considering
Considering this code, can I be absolutely sure that the finally block always executes,
Considering this part of a Java class, private List<Object> components = new ArrayList<Object>(); private
Considering it's a common issue, what could be the source of this error if
Considering this code with 3 differents function call semantics: void f(void){ puts(OK); } int
Considering this basic code snippet: <? class mcClassington { var $mcProperty='default'; function mcDoSomething() {
I am implementing a browser based game with a small group of friends using
Considering this code: std::vector<myObject*> veryLargeArray; for (int i = 0; i < veryLargeArray.size(); ++i)
Considering the fact that openmp uses simd model i.e. each instruction is executed by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.