i am writing a game that when it is run, cards are dealt out of the deck one by one(that means you should be able to see a card flow out of the deck, takes another position then the next one also gets out of the deck until all the card are finished from the deck), now the one i have written cards flow out of the deck at once and they take up another position.
import pygame
import os
import test
import random
global card_dir = ""
deck_of_cards = []
final_deck = []
#location of cards images
main_file = os.path.dirname(__file__)
cards = os.path.join(main_file, "images/cards")
WIDTH = 500
HEIGHT = 800
background = pygame.transform.scale(pygame.image.load("images/background.png.jpg"), size=(WIDTH, HEIGHT))
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("MY CARD GAME IN SPRITES")
screen.blit(background, (0, 0))
#dictionary of cards
my_cards = test.cards_dict()
def fineCard():
global deck_of_cards
deck_of_cards = [i for i in my_cards.keys()]
random.shuffle(deck_of_cards)
#card object with class sprite attributes
for i in deck_of_cards:
i = Sprite(i)
final_deck.append(i)
class Sprite():
def __init__(self, card_name, x=200, y=50, dx=200, dy=50):
self.card_name = card_name
self.dx = dx
self.dy = dy
self.x = x
self.y = y
self.card_dir = card_dir
self.deck_img = pygame.transform.scale(pygame.image.load(os.path.join(cards, my_cards[self.card_name])), (100,133))
def display_card(self, window):
window.blit(self.deck_img, (self.x, self.y))
def move_sprite(self, vel, card_dir):
if card_dir == "out":
for i in final_deck:
if i.dx > i.x and i.dy > i.y:
i.y += vel
i.x += vel
elif i.dx != i.x:
i.x -= vel
elif i.dy != i.y:
i.y += vel
def draw_sprite():
global card_dir, final_deck
even_list = []
vel = 5
card_dir = "out"
for card in final_deck:
even_list.append(card)
even_list.pop(even_list.index(card))
card.dy = 410
card.dx = 50
def start():
run = True
FPS = 15
speed = 5
clock = pygame.time.Clock()
fineCard()
def redraw():
screen.blit(background, (0,0))
for j in final_deck:
j.display_card(screen)
j.move_sprite(speed, card_dir)
pygame.display.update()
while run:
redraw()
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.update()
key = pygame.key.get_pressed()
if key[pygame.K_SPACE]:
draw_sprite()
if __name__ == "__main__":
start()
type here
your text i expected the cards to get out of the deck one by one but the deck expands a bit and cards are still packed together while moving out of the deck
maxbet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.