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

  • SEARCH
  • Home
  • 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 6802861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:16:28+00:00 2026-05-26T19:16:28+00:00

Edit: Totally forgot to mention I’m coding in Java I’m having a real hard

  • 0

Edit: Totally forgot to mention I’m coding in Java

I’m having a real hard time making some kind of detection system or some way to make my pacman sprite/character move smoothly through my board in the game. I did not make the board it’s a image.

I had tried colour detection first which worked the best yet was not smooth at all and pretty choppy.

I then tried to manual input coordinates of location not allowed to be entered. This also did not work out so well.

I’m currently trying now to have the program use colour detection and check a separate unseen board to see if I’m still on the path. This has failed by far the most. It seems like it would be the smartest but the corners are just alful and hard to fix by adjusting the images.

I’m wondering what method you guys would suggest for such a task.

  • 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-05-26T19:16:29+00:00Added an answer on May 26, 2026 at 7:16 pm

    A typical approach to storing “old school” game boards is to use a char or int multidimensional array. Using Matt’s excellent little graphic you can see there are 21 by 21 squares in the board:

    int board[21][21] = {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, 
                         {1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1},
                         {1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1},
                         /* ... and so on, for all 21 lines .. */                      }};
    

    It doesn’t really matter which numbers you pick for walls and pathways. The “pathway” positions initially contain a code for “contains a dot”. As paccy consumes the dots, store a new value into the board at the position to indicate that the dot has been consumed but it is still a pathway square. Matt recommended -1 for walls, 0 for no dot, and 1 for a dot — that’s a pretty plan, as it lets your “wall collision” routines simply look for

    if (board[pac.x][pac.y] > 0) {
        /* still in bounds */
    } else {
        /* collided against a wall */
    }
    

    The downside is the -1 is more awkward looking in your array initializer.

    If this were done in C, it’d be easy enough to “improve” this using char board[21][21] instead of int board[21][21] and store the game board as a C string:

    char board[21][21] = " XXXXXXXXXXXXXXXXXXX "
                         " X        X        X "
                         " X XX XXX X XXX XX X "
                         " X                 X "
                         " X XX X XXXXX X XX X "
                         " X    X   X   X    X "
                         " XXXX XXX X XXX XXXX "
                         "    X X       X X    "
                         "XXXXX X XXXXX X XXXXX"
                         "        X   X        "
                         "XXXXX X XXXXX X XXXXX"
                         "    X X       X X    "
                         " XXXX X XXXXX X XXXX "
                         " X        X        X "
                         " X XX XXX X XXX XX X "
                         " X  X           X  X "
                         " XX X X XXXXX X X XX "
                         " X    X   X   X    X "
                         " X XXXXXX X XXXXXX X "
                         " X                 X "
                         " XXXXXXXXXXXXXXXXXXX";
    

    This is far easier to read in the source code, takes less memory, and your wall-collision routines can look like this:

    if (board[pac.x][pac.y] == 'X') {
        /* collided with a wall */
    } else {
        /* still in bounds */
    }
    

    (Though the trailing NUL that the compiler will insert at the end of the string means that lower-right-hand square can never be used for pathway or wall — a little more effort can work around that, but it isn’t as beautiful.)

    I don’t remember enough Java to make this work in Java — but I’m sure you can figure out something if this looks compelling enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
I'm new to java so apologies if I've got totally the wrong end of
Alright totally new to jeditable, Say I have some <div> 's and <input type='hidden'
I encounter a totally strange behavior of the Java compiler. I can't cast a
I have to develop a real-time web application, where the server needs to inform
I need some information here. I am totally new at MVC therefore for you
I am totally confused right now. Edit: Okay, nevermind. The Python socket as well
I am going to totally re-ask this question. So this is one big edit
gcc 4.4.2 c89 I re-engineering some code in c89. However, I am totally confused
I am writing Java application, which is totally GUI-less. It runs in terminal through

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.