Hi,
I'm trying to use Gummworld2 for some basic tile collision, and I'm running into some problems. I modified your make_tiles to give me a random map with two colors, with a boolean "solid" to be tested. Code is below, but basically I wanted to use Intersect_Indices to get the cells that the player's new position falls into, test to see whether they're solid, and reject the move if any are. It seems to sort of work, except that all the solid tiles have a buffer around them, which I'm pretty sure is because of the fact that get_cell returns more than one sprite, which is not what I'd expected.
Any suggestions? I tried to find a simple way to do this, but nothing popped out at me. Adding a separate object for every wall seemed like it would be unnecessarily slow.
Below is the update method for my player class, which was based on the Thing class from example 24.
Thanks for your help.
Kenny
==================================================
def update(self, dt, move_x, move_y):
clearx, cleary = True, True
new_pos_x = self.position + Vec2d((move_x,0))
for c in State.world.intersect_indices(pygame.Rect(new_pos_x[0], new_pos_x[1], self.width, self.height)):
for s in State.map.layers[0].objects.get_cell(c):
if s.solid:
clearx = False
break
new_pos_y = self.position + Vec2d((move_x if clearx else 0,move_y))
for c in State.world.intersect_indices(pygame.Rect(new_pos_y[0], new_pos_y[1], self.width, self.height)):
for s in State.map.layers[0].objects.get_cell(c):
if s.solid:
cleary = False
break
self.position = self.position + ((move_x if clearx else 0, move_y if cleary else 0))