Code: Alles auswählen
"C:\Spiele und Programme\Python\python.exe" "C:/Users/N4SONIC/Desktop/Python Projekte/Game/main.py"
Traceback (most recent call last):
File "C:/Users/N4SONIC/Desktop/Python Projekte/Game/main.py", line 3, in <module>
from hud_text import *
File "C:\Users\N4SONIC\Desktop\Python Projekte\Game\hud_text.py", line 3, in <module>
font = pygame.font.SysFont("arial", 20)
File "C:\Spiele und Programme\Python\lib\site-packages\pygame\sysfont.py", line 577, in SysFont
font = pygame.font.Font(fontname, size)
pygame.error: font not initialized
Process finished with exit code 1
Code: Alles auswählen
import pygame
from player import *
from hud_text import *
pygame.init()
window = pygame.display.set_mode((800,600))
pygame.display.set_caption("Window")
black = (0,0,0)
white = (255,255,255)
blue = (50,60,200)
green = (40,255,40)
yellow = (255,255,85)
red = (255,85,85)
orange = (255,170,0)
FPS = 60
clock=pygame.time.Clock()
player = Player(100,black,400,300,50,50)
health_text = Health_Text("Leben",player.health,red,5,5)
gameLoop=True
while gameLoop:
for event in pygame.event.get():
if (event.type==pygame.QUIT):
gameLoop=False
window.fill(blue)
player.render(window)
health_text.render(window)
clock.tick(FPS)
pygame.display.flip()
pygame.quit()
Code: Alles auswählen
import pygame
font = pygame.font.SysFont("arial", 20)
class Health_Text:
def __init__(self,text,variable,color,x,y):
self.text = text
self.variable = variable
self.color = color
self.x = x
self.y = y
def render(self,window):
str = font.render(self.text.format(self.variable),True,self.color)
window.blit(str, (self.x,self.y))