Prevent overlap of spawning objects around a player GPS, and

For discussions about game development that does not fit in any of the other topics.
Post Reply
Thaywood
Posts: 17
Joined: Fri May 01, 2015 8:36 pm

Prevent overlap of spawning objects around a player GPS, and

Post by Thaywood »

I am currently working to create a database to store the trees generated in a game like Clash Of Clans/Pokemon Go. I have created the following tables:

Trees (tree_id PK, type_id FK, loc_lat, loc_lng);

Tree_Types (tree_type_id PK, name);

Users (user_id PK, loc_lat, loc_lng, visability_radius)

I am using PHP as an API to service the game I am creating. I need to some randomly position trees around the players GPS location (latitude/longitude) within a set radius stored in the users table. I have created the following query to add the trees to the database:

INSERT INTO Trees (loc_lat, loc_lng, type_id) SELECT ? AS loc_lat, ? as loc_lng, type_id FROM Tree_Types ORDER BY RAND() LIMIT 1;

However, from thinking about this, as I will need to add further tree types later on during the game, I would need to respawn the trees in the area to add the newly added tree types. But I would rather a method that records where trees were spawned and if trees types have been added to spawn them also.

One method I thought of adding was storing lat, lngs and a radius to form a circle area where trees have been spawned. Here is an example of the table stuctures:

Circle (circle_id PK, loc_lat, loc_lng, radius)

Circle_Spawned_Trees (id PK, circle_id FK, tree_type_id FK)

This will allow spawning of newly added trees in the existing circles and also spawn all trees in non-circle locations. For this, I would need a way to check if a location is within a circle, then check which trees are needed to spawn within the pre-spawned circle and add to Trees table. Then spawn all other trees within the radius of the players current location excluding all other circle radiuses within the circle table.

So what I am looking for is a way to add these trees randomly around the players current location and store into the database, which doesnt overlap with any other pre-spawned areas. I need a way of storeing the circles when spawning of an area, spawn random trees within an players GPS and radius and not in any other circles stored in the database.
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Prevent overlap of spawning objects around a player GPS,

Post by hallsofvallhalla »

sounds like it will just be a check on current tree location to others in a radius. So new tree spawns at 50x 100y. You do a check to see if any other exists within lets say 10 of it. so 40x-60x and 90y-110y. Maybe I am not understanding what you need though.
Post Reply

Return to “General Development”