Okay, i searched the forums and didn’t find much help on this. I am creating a puzzle game and i need eveything to exist in grids. All moving enemies need to move in grid patterns, the main character needs to move in grids, and all objects need to take up one grid space. what is the easiest way to do this?
-how would i make all my objects the same size? (example: i need several boxes same size with very different functions)
-i need one of the boxes movable, when pushed i need it to move one grid space.
if there was a way that objects would snap to a grid space when i edit levels, that would be awesome.
How about something like this, applied to everything?
import GameLogic as g
cont = g.getCurrentController()
own = cont.getOwner()
pos = own.getPosition()
own.setPosition([int(pos[0]),int(pos[0]),int(pos[0])])
if own.prop == "player":
#stuff goes here
elif own.prop == "enemy":
#stuff goes here
Create your level and objects based off the blender units. Then, when you edit your level, hold down control when you do basic functions (g,s,r) to ‘snap’ to the grid. I did my lego peices this way (see my sig)
For ingame movement, just use Dloc in your motion actuator, with 1 or however many ‘grid peices’ you want your object to move for every logic tic.
“for every logic tic” is the bad part, it means that your objects will probably move too fast. You need a way of slowing it down - changing the pulse buttons should work but I tried and couldnt get them to.
for the game itself:
I would go with anoncompboy’s suggestion… once you have all your level designed in grids… use dLoc under the movement actuator to move your objects x units at a time…
Although, with some scripting, you could set up code that would move your objects gradually from “grid spot” to “grid spot” diving a sort of more realistic movement but still keeping the essence of what you want… BUT the problem is that this could get OVERLY complicated…
So first try using dLoc… and then jump onto harder stuff…
In order to manage the interaction, however, you’ll need something more complex. You’ll need to store object and score data in a grid list:
row = col = grid_size = 13
grid_list = [[] for r in range(row)]
for r in grid_list:
for c in range(col):
r.append(None)
Ideally, you'll create a GamePiece class, which will be stored in the grid_list:
class GamePiece:
def __init__(self, ge_obj, posn = [0,0]):
self.obj = ge_obj
self.posn = posn
...
and a GameBoard class that manages the grid_list. Ya, this can get extremely complex.