ok. :)
this is a function of GameFloor class; the event handler. It puts the tile in the floor if it's in a valid position:
def handle_events(self, event):
if event.type == MOUSEBUTTONDOWN:
if self.dragging == True:
self.dragging = False
#tests if tile is on a free position
if self.free_position(self.d_tile.rect):
self.tiles.append(self.d_tile)
return True ##tile was succesfully inserted
else:
#tile can't be inserted in this position
self.display.remove(self.d_tile)
return False #tile didn't fit
return True
this is the code that remove the tile, in the main game class (GamePlay) event handling method:
if not self.floor.dragging: #floor is a GameFloor object
#remove a tile
for i in range(len(self.piso.tiles)):
if self.piso.tiles[i].hit_test():
self.piso.display.remove(self.piso.tiles[i])
self.piso.tiles.remove(self.piso.tiles[i])
else:
if self.floor.handle_events(event) == False:
self.tmp_tile.qt = 1
self.loja.player.add_tile(self.tmp_tile) #gives back to the player the tile that didn't fit
--
Thiago Henrique Petruccelli
On Tue, Nov 17, 2009 at 2:34 PM, Thiago Chaves <shundread@xxxxxxxxx> wrote:Sure, share the code.
-Thiago
On Tue, Nov 17, 2009 at 6:26 PM, Thiago Petruccelli
<thiagopetruccelli@xxxxxxxxx> wrote:
> Hi!
>
> I am making a game in wich the player has to fill an area with tiles. It's
> an educational game. But I got a problem with pygame events... Actually I
> think it's a simple problem, but I don't know how to solve.
>
> There are two functionalities for the left click of the mouse: the first is
> to put a tile in the area, when dragging one tile, and the other is to
> remove one tile of the area (when not dragging). The problem is that, when I
> put both codes together, the two things happen at the same time - it puts
> the tile and then removes it. I've tried to block the removal of the tile
> setting a variable, "placed", which blocks the action of removing the tile
> until the next event handling. But it didn't work.
>
> Can someone help me solve this?
>
> Thanks in advance,
> --
> Thiago Henrique Petruccelli
>