[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Help - Events
Oh, I see. In this case, I would use a variable 'held' to indicate the
tile that is picked up. 'held' would be None if the no tile is held.
When a mouse down event is received, if there is a piece in 'held'
(held is not None), place it. If 'held' is None, then remove the tile
at the mouse location.
On Tue, Nov 17, 2009 at 14:53, Thiago Petruccelli
<thiagopetruccelli@xxxxxxxxx> wrote:
> Henrique, the pŕoblem is that when dragging, the mouse button down don't
> need to be held all the time; it's one click to pick the tile and another
> one to put it in the area.
>
> --
> Thiago Henrique Petruccelli
>
>
> On Tue, Nov 17, 2009 at 2:51 PM, Thiago Petruccelli
> <thiagopetruccelli@xxxxxxxxx> wrote:
>>
>> 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
>>> >
>>
>
>