Python Forum
[PyGame] csrss.exe using 50% of my gpu
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] csrss.exe using 50% of my gpu
#1
Hello !
I'm pretty new in Python and pygame.
I don't know why a csrss.exe is using 50% of my gpu each time i'm running it.
I juste draw 5 rectangles for now.

here is my code:

# Création d'un jeu de carte

import random
import pygame

# definition des objets

class carte:
    def __init__(self, nom, attribut, attaque, defense, effet):
        self.nom = nom
        self.attribut = attribut
        self.attaque = attaque
        self.defense = defense
        self.effet = effet
        self.position = ""

    def __str__(self):
        return f"{self.nom} d'attribut {self.attribut}, atk: {self.attaque}, def: {self.defense}, a pour effet: {self.effet}."
    
class deck:
    def __init__(self):
        self.cartes = []
        self.nb_cartes = len(self.cartes)

    def creer_deck(self, nom):
        self.nom = nom

    def melanger(self):
        random.shuffle(self.cartes)

    def ajouter(self, carte):
        self.cartes.append(carte)

    def pioche(self):
        return self.cartes.pop() if self.cartes else None

# initialisation des variables globales

list_attributs = ["Feu", "Eau", "Vent", "Terre", "Lumiere", "Tenebre"]
deck_feu = deck()
deck_eau = deck()
deck_vent = deck()
deck_terre = deck()
deck_lumiere = deck()
deck_tenebre = deck()

# definition des fonctions

def atk_def_alea():
    attaque = random.randint(0, 50)
    ajoute_50 = random.randint(0,1)
    attaque *= 100
    if ajoute_50 and attaque != 5000:
        attaque +=50
    return attaque

def nom_alea():
    list_noms_masc = ["Maxime", "Benoit", "Valentin", "Loevan", "mael"]
    list_noms_fem = ["Crystale", "Emma", "Tessa", "Lola", "illona"]
    list_titres_masc = ["Le Magicien", "Le Démon", "Le Dieu", "Le Roi", "Le Valet", "Le Chevalier", "Le Dragon", "Le Slime", "L'Entité", "Le Bouffon", "Le Ver"]
    list_titres_fem = ["La Magicienne", "La Démone", "La Deesse", "La Reine", "La Bonne", "La Chevalier", "La Dragonne", "La Slime", "L'Entitée", "La Bouffonne", "La Ver"]
    list_lieux = ["des Tenebres", "des Enfers", "de La Montagne", "de La Prairie", "de La Foret", "des Oceans", "du Monde Souterain", "des Cieux", "des Rivieres", "des Egouts"]
    masc_fem = random.randint(0,1)
    if masc_fem:
        nom_de_carte_alea = list_noms_fem[random.randint(0, len(list_noms_fem) - 1)] + " " + list_titres_fem[random.randint(0, len(list_titres_fem) - 1)] + " " + list_lieux[random.randint(0, len(list_lieux)-1)]
    else:
        nom_de_carte_alea = nom_de_carte_alea = list_noms_masc[random.randint(0, len(list_noms_masc) - 1)] + " " + list_titres_masc[random.randint(0, len(list_titres_masc) - 1)] + " " + list_lieux[random.randint(0, len(list_lieux) - 1)]
    return nom_de_carte_alea

# création d'un deck de 20 cartes pour chaques attributs

for attribut in list_attributs:
    temp_deck = deck()
    for i in range(20):
        ma_carte = carte(nom_alea(), attribut, atk_def_alea(), atk_def_alea(), "gagne 500 d'attaque")
        temp_deck.ajouter(ma_carte)

    match attribut:
        case "Feu":
            deck_feu = temp_deck
        case "Eau":
            deck_eau = temp_deck
        case "Vent":
            deck_vent = temp_deck
        case "Terre":
            deck_terre = temp_deck
        case "Lumiere":
            deck_lumiere = temp_deck
        case "Tenebre":
            deck_tenebre = temp_deck

for carte in deck_feu.cartes:
    print(carte)
print(len(deck_feu.cartes))

WIDTH = 800
HEIGHT = 600
ROUGE = 255,0,0
CARTE_WIDTH = 140
CARTE_HEIGHT = 202

pygame.init()

screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Mon Jeu de Carte !")

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    for i in range(5):
        pygame.draw.rect(screen, ROUGE, rect=(i * (CARTE_WIDTH + 18) + 14, 10, CARTE_WIDTH, CARTE_HEIGHT))

    pygame.display.flip()


pygame.quit()
Reply
#2
Normally in pygame you create a clock object to control how often the event loop runs. Otherwise the event/redraw loop is running continuously. One rect or one million makes no difference if there is no pause in the loop.
Darcia likes this post
Reply
#3
oh thanks i just did it and now i only using 2%
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020