Dlaczego nie moge wyświetlic pygame

0

Tule in not callable??
chciałem wyświetlić jednocześnie 2 napisy, ale dostaje komunikat jak wyżej, nie rozumiem dlaczego, i co robie żle. Chodzi o to że 2 napis nie che się wypisać,

import pygame
import time

pygame.init()

disp_width = 800
disp_height = 600
player_width = 96

black = (0,0,0)
white = (255,255,255)
red = (255,0,0)

display = pygame.display.set_mode((disp_width,disp_height))
pygame.display.set_caption('A RaGe!')
clock = pygame.time.Clock()

gamerImg = pygame.image.load('data\\img\\pajac.png')

def gamer(x,y):
   display.blit(gamerImg, (x,y))
   
def Game():
   x = (disp_width *0.45)
   y = (disp_height * 0.8)
      

   end = False
   while not end:
      for event in pygame.event.get():
         if event.type == pygame.QUIT:
            end = True

      pressed = pygame.key.get_pressed()
      if pressed[pygame.K_SPACE]: end = True
      if pressed[pygame.K_DOWN]: y += 5
      if pressed[pygame.K_UP]: y -= 5
      if pressed[pygame.K_LEFT]: x -= 5
      if pressed[pygame.K_RIGHT]: x += 5
      
      if x > disp_width - player_width or x < 0: suicide()
         
      display.fill(white)
      gamer(x,y)
      pygame.display.update()
      clock.tick(60)

def suicide():
   message_display('You have done with yourself')
   message_display('Good',-1)
   
def message_display(text, var=0):
   text_rage = pygame.font.Font('data\\fonts\\Unchained-RegularShadow.ttf',40)
   TextSurf, TextRect = text_objects(text, text_rage)
   if var == -1:
      TextRect.center((700),(500)) ###########blad
   else:
      TextRect.center = ((disp_width/2),(disp_height/2))
   display.blit(TextSurf, TextRect)
   pygame.display.update()
   
   time.sleep(3)
  # Game()
def text_objects(text, font):
   textSurface = font.render(text, True, black)
   return textSurface, textSurface.get_rect()
   
Game()
pygame.quit()
quit()


1

Przyjrzyj się dokładnie linijce z TextRect działającej i niedziałającej, czym się różnią?

Poza tym Twoje rozwiązanie jest bardzo nieoptymalne, bo generujesz czcionkę w każdej klatce! (funkcja message_display)
Powinieneś pewne ciężkie rzeczy przygotować sobie przed pętlą.

0

odnośnie tego, co trzeba przygotować przed pętlą to co? dokładnie
Za chwile zaaktaualiwuzje

0

cos takiego?

import pygame
import time

pygame.init()

disp_width = 800
disp_height = 600
player_width = 96

black = (0,0,0)
white = (255,255,255)
red = (255,0,0)

display = pygame.display.set_mode((disp_width,disp_height))
pygame.display.set_caption('A RaGe!')
clock = pygame.time.Clock()

gamerImg = pygame.image.load('data\\img\\pajac.png')


def gamer(x,y):
   display.blit(gamerImg, (x,y))
   
def Game(TextSurf, TextRect):
   x = (disp_width *0.45)
   y = (disp_height * 0.8)   

   end = False
   while not end:
      for event in pygame.event.get():
         if event.type == pygame.QUIT:
            end = True

      pressed = pygame.key.get_pressed()
      if pressed[pygame.K_SPACE]: end = True
      if pressed[pygame.K_DOWN]: y += 5
      if pressed[pygame.K_UP]: y -= 5
      if pressed[pygame.K_LEFT]: x -= 5
      if pressed[pygame.K_RIGHT]: x += 5
      
      if x > disp_width - player_width or x < 0: suicide(TextSurf, TextRect)
         
      display.fill(white)
      gamer(x,y)
      pygame.display.update()
      clock.tick(60)

def suicide(TextSurf, TextRect):
   display.blit(TextSurf, TextRect)
   pygame.display.update()
   time.sleep(3)
   Game(TextSurf, TextRect)
   
def message_prepare(text):
   text_rage = pygame.font.Font('data\\fonts\\Unchained-RegularShadow.ttf',40)
   TextSurf, TextRect = text_objects(text, text_rage)
   TextRect.center = ((disp_width/2),(disp_height/2))
   return TextSurf, TextRect
  
def text_objects(text, font):
   textSurface = font.render(text, True, black)
   return textSurface, textSurface.get_rect()

TextSurf, TextRect = message_prepare('You have done with yourself')  
Game(TextSurf, TextRect)
pygame.quit()
quit()


1 użytkowników online, w tym zalogowanych: 0, gości: 1