mirror of
https://github.com/pythonguis/pythonguis-examples.git
synced 2025-01-13 16:42:55 +08:00
solitaire: fix bouncing and animation.
This commit is contained in:
parent
655347985a
commit
7ca39a4623
@ -21,8 +21,7 @@ WORK_STACK_Y = 200
|
|||||||
SIDE_FACE = 0
|
SIDE_FACE = 0
|
||||||
SIDE_BACK = 1
|
SIDE_BACK = 1
|
||||||
|
|
||||||
SLIPPING_OFFSET = 20
|
BOUNCE_ENERGY = 0.8
|
||||||
DEAL_N = 3
|
|
||||||
|
|
||||||
# We store cards as numbers 1-13, since we only need
|
# We store cards as numbers 1-13, since we only need
|
||||||
# to know their order for solitaire.
|
# to know their order for solitaire.
|
||||||
@ -187,14 +186,6 @@ class StackBase(QGraphicsRectItem):
|
|||||||
card.stack = None
|
card.stack = None
|
||||||
self.cards = []
|
self.cards = []
|
||||||
|
|
||||||
def take_top_card(self):
|
|
||||||
try:
|
|
||||||
card = self.cards[-1]
|
|
||||||
self.remove_card(card)
|
|
||||||
return card
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def is_valid_drop(self, card):
|
def is_valid_drop(self, card):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -239,6 +230,14 @@ class DeckStack(StackBase):
|
|||||||
self.add_card(card)
|
self.add_card(card)
|
||||||
card.turn_back_up()
|
card.turn_back_up()
|
||||||
|
|
||||||
|
def take_top_card(self):
|
||||||
|
try:
|
||||||
|
card = self.cards[-1]
|
||||||
|
self.remove_card(card)
|
||||||
|
return card
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
def set_color(self, color):
|
def set_color(self, color):
|
||||||
color = QColor(color)
|
color = QColor(color)
|
||||||
color.setAlpha(50)
|
color.setAlpha(50)
|
||||||
@ -636,10 +635,11 @@ class MainWindow(QMainWindow):
|
|||||||
def win_animation(self):
|
def win_animation(self):
|
||||||
# Start off a new card
|
# Start off a new card
|
||||||
for drop in self.drops:
|
for drop in self.drops:
|
||||||
card = drop.take_top_card()
|
if drop.cards:
|
||||||
if card and card.vector is None:
|
card = drop.cards.pop()
|
||||||
card.vector = QPoint(-random.randint(1, 10), 0)
|
if card.vector is None:
|
||||||
break
|
card.vector = QPoint(-random.randint(1, 10), 0)
|
||||||
|
break
|
||||||
|
|
||||||
for card in self.deck:
|
for card in self.deck:
|
||||||
if card.vector is not None:
|
if card.vector is not None:
|
||||||
@ -647,7 +647,8 @@ class MainWindow(QMainWindow):
|
|||||||
card.vector += QPoint(0, 1) # Gravity
|
card.vector += QPoint(0, 1) # Gravity
|
||||||
|
|
||||||
if card.pos().y() > WINDOW_SIZE[1] - CARD_DIMENSIONS.height():
|
if card.pos().y() > WINDOW_SIZE[1] - CARD_DIMENSIONS.height():
|
||||||
card.vector = QPoint(card.vector.x(), -card.vector.y() )
|
# Bounce the card, losing some energy.
|
||||||
|
card.vector = QPoint(card.vector.x(), -int(card.vector.y() * BOUNCE_ENERGY) )
|
||||||
|
|
||||||
if card.pos().x() < - CARD_DIMENSIONS.width():
|
if card.pos().x() < - CARD_DIMENSIONS.width():
|
||||||
card.vector = None
|
card.vector = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user