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 9129263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:42:21+00:00 2026-06-17T07:42:21+00:00

I have an array[15][15] with path for my object. 0 is wall, anything else

  • 0

I have an array[15][15] with path for my object. 0 is wall, anything else makes path (1->2->3->…->end). It’s a reflection of the game field of 450px x 450px(30px x 30px is one field).

For array[15][15] looking like this:

080000000000000
010111011101110
010101010101010
010101010101010
010101010101010
010101010101010
010101010101010
010101010101010
010101010101010
010101010101010
010101010101010
010101010101010
010101010101010
011101110111010
000000000000090

I get:
map2

My object moves with some velocity * speed:

void Enemy::move()
{
    this->get_dir();
    this->x += this->velX * this->speed; // velX = -1 is left, 1 is right
    this->y += this->velY * this->speed; // velY = -1 is up, 1 is down
}

get_dir() checks what direction (velocity) it should set, like this:

void Enemy::get_dir()
{  
    Point p; // {x, y} struct

    p = this->get_grid(); // it tries to calculate X, Y axis into an array number
    if (p.y < 14 && path_grid[p.y + 1][p.x] - 1 == path_grid[p.y][p.x])
    {
        this->velY = 1;
        this->velX = 0;
        return;
    }
    /* same goes for rest of directions */

    this->velX = this->velY = 0; // if none matched it stops (reached end)
    return;
}

Point Enemy::get_grid()
{
    int x, y;

    for(y = 0;y < 15;y++)
    {
        if (this -> y >= y * 30 && this->y < (y + 1) * 30) break;
    }

    for(x = 0;x < 15;x++)
    {
        if (this -> x >= x * 30 && this->x < (x + 1) * 30) break;
    }

    return make_point(x, y);
}

But as you may notice, this will lead for my object to follow path like this:
path

Because it checks top left corner, and if I move right it should change the origin point, but I can’t figure out how to do it. When I tried adding 30 (object bitmap size) if it goest right, it stops at the up -> right corner. What’s a solution in here?

  • 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-17T07:42:22+00:00Added an answer on June 17, 2026 at 7:42 am

    Have removed most of my answer, as it appears to misunderstand the question. But I will leave this part about your get_grid function being crazy. Just use maths (I assume that x and y are integers):

    Point Enemy::get_grid()
    {
        return make_point(x / 30, y / 30);
    }
    

    Furthermore, if you want to take your grid position and show it in the centre of a tile where each tile is 30 pixels square, then do this:

    int pixelX = gridX * 30 + 15;
    int pixelY = gridY * 30 + 15;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2D-array that defines points in one or more paths: Path#1 =
I have an array of file path components like this: [ ['some', 'dir', 'file.txt'],
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I have TYPO3 4.6, in tempvoila template i have typoscript object path lib.header and
I have the following PHP object but I'm struggling to get the array item
I have a problem with my Three.js Json-Loader. I have some object their path
I have an array I'm using as a stack to store a path through
I have an array of CGColors that I need to display across a path.
I have an array with polygon coordinates, which I'm drawing currently with the Path

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.