I’m using rayCast() to check if different points are occupied. the reason I’m using rayCast() is because it doesn’t require extra objects(empties usually) to test the existence of objects with the near/collision sensor. I’m using a modified flood-fill algorithm to fill an area with squares, each of which needs to check up, down, left, and right to see if there is anything there. I need to do this test for every square. That means anywhere from 4 to 4000 rayCast’s need to take place. This takes too much time. I don’t want the player waiting 1-10 seconds every time this event occurs, which is often.
should I use empties and near sensors? something else?
[SOLVED]
instead of using raycast, I should use a matrix(list) to keep track of what areas on my grid are occupied.
maybe using a sphere sensor is more fast(not sure)
place a sphere in each ceil, then do a loop to see if collide with something, each sphere rapresent a ceil free/no free
(require 2 frame)
maybe using a sphere sensor is more fast(not sure)
place a sphere in each ceil, then do a loop to see if collide with something, each sphere rapresent a ceil free/no free
(require 2 frame)
PS: anyway if understand well need 1000 sphere that here a lot
It sounds like you should be keeping track of any objects you put in the area yourself instead of using ray casts. You can represent the state of the area with a simple 2D list of boolean values. Any time you add a square, mark its position in the list as occupied. When you remove a square, mark its position as open.
I agree with Mobius, Modularize. Seperate the logic behind your game from what is displayed.
I would think to store all the information internally in python, and make the objects fit what is stored.
that does sound better. would I use a matrix? how would I store this grid of information? the points couldn’t be boolean. I would probably need 4-6 different designations.
# sample variables
N = 5
M = 5
x = 2
y = 3
# To initialize and NxM area
points = []
for i in range(N):
points.append([False] * M)
# To set point (x, y)
points[x][y] = True
# To access point (x, y)
testPoint = points[x][y]
If you need six states for each point, then just use the integers 0-5 instead of True/False.