Help with drawing integers. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: Help with drawing integers. (/thread-20605.html) |
Help with drawing integers. - ghost0fkarma - Aug-21-2019 import pygame, sys class Scene: def __init__(self): self.team1 = 0 self.team2 = 0 self.font = pygame.font.SysFont('Cosmic Sans MS', 900) self.team1txt = self.font.render(str(self.team1), True, (24, 14, 89,)) self.team2txt = self.font.render(str(self.team2), True, (31, 200, 32,)) self.scoreboard = pygame.image.load("scoreboard.jpg") def draw(self, screen): screen.blit(self.scoreboard, (0, 0)) screen.blit(self.team1txt, (500, 500)) class main: def __init__(self, winx, winy, caption): self.screen = pygame.display.set_mode((winx, winy)) self.caption = pygame.display.set_caption(caption) self.clock = pygame.time.Clock() self.scene = Scene() self.black = (200, 0, 0) def loop(self): self.notDead = True while self.notDead: for event in pygame.event.get(): if event.type == pygame.QUIT: self.notDead = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.scene.team1 += 1 print(str(self.scene.team1)) if event.key == pygame.K_RIGHT: self.scene.team2 += 1 print(str(self.scene.team2)) self.scene.draw(self.screen) pygame.display.update() self.clock.tick(60) if __name__ == '__main__': pygame.init() pygame.font.init() game = main(1920, 1080, 'Scoreboard') game.loop()I can't seem to get the team1 and team2 score to show on the display. Any help is appreciated :) RE: Help with drawing integers. - metulburr - Aug-21-2019 Quote:You are only drawing one number here text1text. Duplicate that line under it and change team1txt to team2text and change the blit position tuple to something else and you wlll see both.def draw(self, screen): screen.blit(self.scoreboard, (0, 0)) screen.blit(self.team1txt, (500, 500)) like: def draw(self, screen): screen.blit(self.scoreboard, (0, 0)) screen.blit(self.team1txt, (500, 500)) screen.blit(self.team2txt, (900, 500)) RE: Help with drawing integers. - ghost0fkarma - Aug-21-2019 (Aug-21-2019, 03:43 PM)metulburr Wrote:Quote:You are only drawing one number here text1text. Duplicate that line under it and change team1txt to team2text and change the blit position tuple to something else and you wlll see both.def draw(self, screen): screen.blit(self.scoreboard, (0, 0)) screen.blit(self.team1txt, (500, 500)) Totally forgot to blit teamtxt2 derp, thank you for the help. Also, is there any way I could let the 2 teams type their desired team name? I have this but it requires the names to be typed in the shell. import pygame class Scene: def __init__(self): self.team1 = 0 self.team2 = 0 self.font = pygame.font.SysFont('Cosmic Sans MS', 60) self.background = pygame.image.load("background.jpg") self.test = [] def names(self): self.teamname1 = input() self.teamname2 = input() def update(self): self.team1txt = self.font.render(str(self.team1), True, (24, 14, 89,)) self.team2txt = self.font.render(str(self.team2), True, (31, 200, 32,)) self.team1nametxt = self.font.render(self.teamname1, True, (31, 200, 32,)) self.team2nametxt = self.font.render(self.teamname2, True, (31, 200, 32,)) def draw(self, screen): screen.blit(self.background, (0,0)) screen.blit(self.team1txt, (250,550)) screen.blit(self.team2txt, (800,550)) screen.blit(self.team1nametxt, (900, 200)) screen.blit(self.team2nametxt, (231, 900)) class main: def __init__(self, winx, winy, caption): self.screen = pygame.display.set_mode((winx, winy)) self.caption = pygame.display.set_caption(caption) self.clock = pygame.time.Clock() self.scene = Scene() self.playernames = True def loop(self): self.notDead = True while self.notDead: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() self.notDead = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.scene.team1 += 1 pygame.mixer.music.load("dading.mp3") pygame.mixer.music.play(0) if event.key == pygame.K_RIGHT: self.scene.team2 += 1 pygame.mixer.music.load("dading.mp3") pygame.mixer.music.play(0) if event.key == pygame.K_p: pygame.quit() exit() if self.playernames == True: self.scene.names() self.playernames = False self.scene.update() self.scene.draw(self.screen) pygame.display.update() self.clock.tick(60) if __name__ == '__main__': pygame.init() pygame.font.init() game = main(1920, 1080, 'Scoreboard') game.loop() RE: Help with drawing integers. - metulburr - Aug-22-2019 you would need to create a prompt. Pygame does not come with a default one, so you would have to create your own or use someone else's already made. Check out this tutorial https://python-forum.io/Thread-PyGame-User-Interface RE: Help with drawing integers. - Windspar - Aug-22-2019 Here my example. |