Distance, positioning, need help please

Blitz3D Forums/Blitz3D Programming/Distance, positioning, need help please

Rrtaya_Tsamsiyu(Posted 2015) [#1]
i've been working on 2d RTS game. Uses all ASCII characters. Right now i'm trying to implement AI. The objects i have so far are Factories, Ammo Dumps, Tanks, and Supply Piles that randomly spawn in the world at the beginning of the game.

-----------------------------------------
Some details: Ammo Dumps collect money from supply piles, and must be within 2 squares of a pile. Ammo Dumps and Factories can only be built up to 3 squares away from a Factory.

For testing, the only supply pile that spawns is just close enough to the South East start position for an ammo dump. To get the AI to spawn there set your spawn point to NW at the beginning of the game.

The problem is this; i want the AI to, if a factory is not close enough to build an ammo dump, build a factory toward the closest supply pile. Right now the AI's factories spawn, well, nowhere near where they need to.
These calculations are made more difficult by the fact that when you move around the map, it is actually the map that is moving, and therefore the coordinates of all objects.

Map is 80 pixels wide per square + 8, 13 pixels tall per square +13.
Any help is appreciated, i'm sorry if my code is weird lol.
Problem code is between lines 749 and 762



H&K(Posted 2015) [#2]
These calculations are made more difficult by the fact that when you move around the map, it is actually the map that is moving, and therefore the coordinates of all objects.

No they aren't.

Result = (X1-x2)*(y1-y2)


a) It doesn't matter if these are on a moving or rotating map, its their relative difference that's important.
b)The distance = (Sqr result), but again you only need relative, so don't bother Sqring it.


Rrtaya_Tsamsiyu(Posted 2015) [#3]
Thank you for the input, i'll keep looking into it.