Giter Club home page Giter Club logo

Comments (9)

Yonaba avatar Yonaba commented on May 21, 2024

Hi,
The problem seems to occur with this line:

local path, length = pather:getPath(employee.x, employee.y, map_tile_x, map_tile_y)

The method is prototyped as follows:

pather:getPath(startX,startY,endX,endY)

startX and startY should be the coordinates of the starting point on the tile map, and endX and endY the coordinates for the goal point (still on the tile map). Therefore, are you sure that employee.x and employee.y are valid coordinates on the tile map and not screen pixels/world coordinates ?

Maybe you can try this:

local start_tick = love.timer.getMicroTime()*1000
print(employee.x, employee.y, pather.grid:getNodeAt(employee.x,employee.y)
local path, length = pather:getPath(employee.x, employee.y, map_tile_x, map_tile_y)
local time = (love.timer.getMicroTime()*1000 - start_tick)

from jumper.

tbergeron avatar tbergeron commented on May 21, 2024

Hi and thanks for your support. It prints "128 128 nil". The coordinates are right but getNodeAt always returns nil :-/

from jumper.

Yonaba avatar Yonaba commented on May 21, 2024

Well, that is strange.
I am assuming here that you already have your 2D grid map in a 2-dimensional array.
When you inits a pather, (passing a map and optional search parameters to Jumper), it actually keeps track of the map passed to init Jumper and is accessible through pather.grid.map (actually it isn't internally used, I just set it for future plans).
Anyway, you might want to check if, in the meanwhile, you didn't accidentally set some values to nil.

Just for debugging purposes, try to add these extra lines, run this, so you can workout what's possibly going on :

print('Start Node Tile Coordinates',employee.x, employee.y)
print('Map passed to Jumper',pather.grid.map[employee.y], pather.grid.map[employee.y][employee.x])
print('Internal Matching Node',pather.grid:getNodeAt(employee.x,employee.y))
local path, length = pather:getPath(employee.x, employee.y, map_tile_x, map_tile_y)

Alternatively, so can provide your souce (a *.love file, as it seems you're using Lรถve2D).

from jumper.

tbergeron avatar tbergeron commented on May 21, 2024

Thanks again for helping me, it's very appreciated.

The second print goes crashing because of a nil value. I've joined a *.love file this time hehe. https://dl.dropbox.com/u/199126/test.love The debug code you just told me is located in Game.lua:85

from jumper.

Yonaba avatar Yonaba commented on May 21, 2024

Hi,
Actually I can't run the game, after cloking the continue button, it crashes. See the traceback.
Anyway, I think I saw what the problem was.
The map defined inside office is a 33 (width) x 25 (height) map. Therefore it means that when you are making a pathfinding request, startX, startY and endX, endY shouldn't be values higher than 33 (on X) or 25 (on Y), as they refer to specifics tiles. These values should represent the grid position (not the world position) of your entities.

Looking at your employee class, it appears to x and y attributes stand for their position on the screen. You will have to calculate and keep updated their grid position. In pseudocode, that would be

employee.grid_x = math.floor(employee.x/tileWidth)+1
employee.grid_y = math.floor(employee.y/tileHeight)+1

I am adding +1 here because your map starts indexing at 1,1.

Then you can use these new attributes to make path request:

pather:getPath(employee.grid_x, employee.grid_y, map_tile_x, map_tile_y)

from jumper.

tbergeron avatar tbergeron commented on May 21, 2024

Nevermind that, I had a typo. So far so good, it almost work! I'll keep you updated on my progress :-) Thanks for the help!

from jumper.

tbergeron avatar tbergeron commented on May 21, 2024

Wow it works!!! Thanks a lot, and very good job on the library!

from jumper.

Yonaba avatar Yonaba commented on May 21, 2024

You are welcome!
Good luck on this project, though. I like the gameplay, reminds me GameDev Story that I played like hell on Android.

from jumper.

tbergeron avatar tbergeron commented on May 21, 2024

Haha! GameDev Story is my #1 inspiration for this game. It'll be very different though, more interactive, but still the same vision. I'm glad you like it :-)

from jumper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.