• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

HELP!!! RTS Quadtree nearest opponent

E

ezravitto

Guest
Hi! I need help implementing quadtree to my rts game, but the "insertion" part of Quadtree doesn't make sense to me, gml is the only programming language i use.

so here's my insertion code:
GML:
if instance_exists(oQuadPointTest)
{
var _check;

_check = instance_find(oQuadPointTest,instance_number(oQuadPointTest)-1)
if !scrContain(_check){return 0;}//this will return the object id if it is true

if ds_list_size(_objects)<capacity
{ds_list_add(_objects,_check);}
else
{if !_divided {scrSubdivide();}}
}
Thankyou for giving time!
 
E

ezravitto

Guest
1587909238473.png

this is the result.
the leaf of quadtree only detects the newest object. i know it was inside the code check for "instance_number",
but what i wanted to happen is for every leaf to check if they contain objects in their region.. i hope that make sense?
and also how can a quadtree count the objects inside it?
 

vdweller

Member
A rather incomplete and unoptimized quadtree implementation with find k-nearest neighbors capability:

 
Top