Browse Source

Full HD Default , Multi line (\n separated) Column labeling

pull/1/head
kresse 1 year ago
parent
commit
f69819445a
2 changed files with 54 additions and 44 deletions
  1. +47
    -43
      hacKNerdy.py
  2. +7
    -1
      pygame_input.py

+ 47
- 43
hacKNerdy.py View File

@ -1,9 +1,10 @@
#!/usr/bin/env python3
#-.-coding=UTF8 -.-
# Mal ein kompletter Rewrite
# A more or less rewrite of the original pygame version
# by james Turk in 2007
#
# Alle Fehler gehen auf mich
# Greetings
#
# kresse 2020
@ -27,7 +28,11 @@ BLUE = (0,0,200)
# Dimension of the display Window
x_dim =1200
y_dim =768
#
# Dimension of the display Window
x_dim =1920
y_dim =1080
# Folder for sound effects
sfx="sfx//"
@ -109,18 +114,15 @@ class Spieler():
self.punkte=0
self.nr =nummer %spieler_anzahl
self.color=Farbliste[self.nr]
#print ("Spieler_Name = ",self.name)
#print ("spieler_Nr = ",self.nr)
#print ("Spielerfarbe = ",self.color)
def buzz():
pygame.mixer.Sound(sfx+'game-fx-1.wav').play()
def percent_tile(x1,y1,x2,y2):
return pygame.Rect(int(x_dim*x1/100),int(y_dim*y1/100),int(x_dim*x2/100),int(y_dim*y2/100))
def main():
# ich bin echt genervt, das das hier so definiert werden muss,
@ -176,6 +178,12 @@ def main():
def wandAnzeigen(screen):
global fragen
BG_COLOR = BLUE
FG_COLOR = WHITE
wall_font_name="None"
big_font_size=90
small_font_size=48
screen.blit(background, (0, 0))
if modus =="aussuchen":
@ -185,32 +193,33 @@ def main():
xStep = int(xEnd/6)
yStep = int(yEnd/6)
# Gitter zeichnen
for x in range(xStart, xEnd+1, xStep):
pygame.draw.line(screen, BLACK, (x,yStart), (x,yEnd), 5)
for y in range(yStart, yEnd+1, yStep):
pygame.draw.line(screen, BLACK, (xStart,y), (xEnd,y), 5)
# Beschriftung
for x in range(0, 6):
ausgabe=(fragen.fragenfeld[x*5].kategorie)
ausgabe=" "+(fragen.fragenfeld[x*5].kategorie)
ausgabe=ausgabe.replace('\\n' , '\n ')
# print (ausgabe)
#
# textCentered(ausgabe)
text = smallFont.render(ausgabe, 1, WHITE)
screen.blit(text, (x*xStep+10,25))
#text = smallFont.render(ausgabe, 1, WHITE)
#screen.blit(text, (x*xStep+10,25))
pgi.text_output (screen,percent_tile(x*16.6,0,18,20),ausgabe,BG_COLOR,FG_COLOR,wall_font_name,small_font_size)
for y in range(0, 5):
jetztfrage=fragen.fragenfeld[x*5+y]
if jetztfrage.farbe== BLUE:
text = bigFont.render(str(fragen.fragenfeld[x*5+y].punkte), 1, WHITE)
screen.blit(text, (x*xStep+7,(y+1)*yStep+10))
pgi.text_output (screen,percent_tile(x*16.7,(y+1)*90*(yStep/yEnd),18,20)," "+ str(fragen.fragenfeld[x*5+y].punkte),BG_COLOR,FG_COLOR,wall_font_name,big_font_size)
else:
hoehe=yStep-9
pygame.draw.line(screen, jetztfrage.farbe, (x*xStep+5,(y+1)*yStep+int(hoehe/2)+5), ((x+1)*xStep-4,(y+1)*yStep+int(hoehe/2)+5), int(hoehe))
text = bigFont.render(str(fragen.fragenfeld[x*5+y].punkte), 1, BLACK)
screen.blit(text, (x*xStep+7,(y+1)*yStep+10))
pgi.text_output (screen,percent_tile(x*16.7,(y+1)*90*(yStep/yEnd),18,20),"",jetztfrage.farbe,BLACK,wall_font_name,big_font_size)
# Gitter zeichnen
for x in range(xStart, xEnd+1, xStep):
pygame.draw.line(screen, FG_COLOR, (x,yStart), (x,yEnd), 5)
for y in range(yStart, yEnd+1, yStep):
pygame.draw.line(screen, FG_COLOR, (xStart,y), (xEnd,y), 5)
# Spieler
for _ in spieler:
linie_beginn= int(xEnd/(len(spieler)))*_.nr
@ -252,12 +261,15 @@ def main():
#
if druecker == -99:
drueckertext="WIR WARTEN...."
pgi.text_output (screen,percent_tile(40,85,24,15),drueckertext,BLUE,BLACK,font_name="arial",font_size=40)
else:
zeichneFarbe(druecker.color)
drueckertext=druecker.name
#zeichneFarbe(druecker.color)
#drueckertext=druecker.name
pgi.text_output (screen,percent_tile(40,85,24,15)," "+druecker.name,(druecker.color),BLACK,font_name="arial",font_size=40)
#
#
textunten(drueckertext)
#textunten(drueckertext)
else:
Anzeigetext=" Die FRAGE HATTEN WIR SCHON !!!"
textCentered(Anzeigetext)
@ -320,16 +332,12 @@ def main():
pygame.mixer.music.play(0)
#Fragenpaket auswählen
#fragenpaket= input('Welches Fragenpaket')
# Use Surface at Rect to print Text, with BGColor, TextColor in Font With Size
field_question= pygame.Rect(int(x_dim*0.05),int(y_dim*0.85),int(x_dim*0.4),int(y_dim*0.15))
pgi.text_output (screen,field_question,"Welches Fragenpaket?",BLACK,GREEN,font_name="ocra",font_size=40)
pgi.text_output (screen,percent_tile(5,85,40,15),"Welches Fragenpaket?",BLACK,GREEN,font_name="ocra",font_size=40)
# Use Surface at Rect to input Text, with BGColor, TextColor in Font With Size
field_answer= pygame.Rect(int(x_dim*0.45),int(y_dim*0.85),int(x_dim*0.4),int(y_dim*0.15))
fragenpaket= pgi.text_input (screen,field_answer,BLACK,GREEN,font_name="ocra",font_size=40)
fragenpaket= pgi.text_input (screen,percent_tile(45,85,40,15),BLACK,GREEN,font_name="ocra",font_size=40)
if fragenpaket =="":
fragenpaket="1"
@ -355,18 +363,14 @@ def main():
# initialize Spieler
for spieler_nr in range(spieler_anzahl):
#spieler.append (Spieler((input("Name des "+ str(spieler_nr+1) +". Spielers > ")+" ")[0:11],spieler_nr))
# Use Surface at Rect to print Text, with BGColor, TextColor in Font With Size
question="Name des "+ str(spieler_nr+1) +". Spielers? "
field_question= pygame.Rect(int(x_dim*0.05),int(y_dim*0.85),int(x_dim*0.4),int(y_dim*0.15))
pgi.text_output (screen,field_question,question,BLACK,GREEN,font_name="ocra",font_size=35)
pgi.text_output (screen,percent_tile(5,85,40,15),question,BLACK,GREEN,font_name="ocra",font_size=40)
# Use Surface at Rect to input Text, with BGColor, TextColor in Font With Size
field_answer= pygame.Rect(int(x_dim*0.45),int(y_dim*0.85),int(x_dim*0.4),int(y_dim*0.15))
player_name= pgi.text_input (screen,field_answer,BLACK,GREEN,font_name="ocra",font_size=35)
player_name=pgi.text_input (screen,percent_tile(45,85,40,15),BLACK,GREEN,font_name="ocra",font_size=40)
spieler.append(Spieler(player_name[0:11],spieler_nr))
@ -381,7 +385,7 @@ def main():
# Hauptschleife
while not quit:
clock.tick(60)
clock.tick(30)
for event in pygame.event.get():
if event.type == QUIT:
quit = True


+ 7
- 1
pygame_input.py View File

@ -134,11 +134,13 @@ def draw_text_in (text,area, color_rect=(0,0,255), color_text=(255,255,255),font
y_pos = x_pos = 2
area_out=pygame.Surface(area.get_size())
area_out.fill(color_rect)
#
for line in text.splitlines():
#
out_text = font.render(line, 1, color_text)
area_out.blit(out_text, (x_pos, y_pos))
y_pos += font_size
x_pos = 0
return area_out
@ -170,7 +172,7 @@ def text_output (surf,text_rect, text_to_display, color_rect=(0,0,255), color_te
area_for_text = pygame.Surface((text_rect.w,text_rect.h))
area_out= draw_text_in ( text_to_display,area_for_text,color_rect , color_text,font_name,font_size)
surf.blit(area_out,(text_rect.x,text_rect.y))
pygame.display.update()
#pygame.display.update()
def main():
@ -201,6 +203,10 @@ def main():
# Test of text_input() and text_output()
#
text_output (screen,pygame.Rect(0,180,400,70),"text_output\nexample",BLUE,YELLOW,font_name="ocra",font_size=30)
# Use Surface at Rect to print Text, with BGColor, TextColor in Font With Size
text_output (screen,pygame.Rect(160,30,400,60),"WAS ist die Antwort?",BLUE,YELLOW,font_name="ocra",font_size=30)


Loading…
Cancel
Save