| | |
pygame.font.Font
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
How do you render a font so that it changes when the variable changes?
This is my code:
Any help would be appreciated
This is my code:
python Syntax (Toggle Plain Text)
############################## # Copyright lololol (c) 2009 # ############################## import pygame from pygame.locals import * pygame.init() GRAVITY = 0.07 FRICTION = None def getNumKeysPressed(): temp = 0 for item in pygame.key.get_pressed(): if item: temp += 1 return temp class Player: def __init__(self, speed, image, health): self.move_speed = speed self.x = 0 self.y = 0 self.screen_width = 0 self.screen_height = 0 self.speed = [0, 0] self.image = pygame.image.load(image + '.png') self.image_alt = pygame.image.load(image + '_alt.png') self.blit_image = self.image self.health = health def update(self): self.x += self.speed[0] self.speed[1] += GRAVITY self.y += self.speed[1] if self.x > self.screen_width: self.x = self.screen_width if self.x < 0: self.x = 0 if self.y > self.screen_height: self.y = self.screen_height if self.y < 0: self.y = 0 def switch_image(self): temp = [self.image, self.image_alt] if self.blit_image == temp[1]: self.blit_image = temp[0] else: self.blit_image = temp[1] def walk_left(self): self.speed[0] = -self.move_speed def walk_right(self): self.speed[0] = self.move_speed def walk_up(self): self.speed[1] = -self.move_speed def walk_down(self): self.speed[1] = self.move_speed def main(): clock = pygame.time.Clock() p = Player(2, "rifleman_blu", 100) screen = pygame.display.set_mode((640,480)) pygame.display.set_caption("TF2 - 16 Bit - Demake") background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((250, 250, 250)) p.screen_width = (screen.get_width() - p.image.get_width()) p.screen_height = (screen.get_height() - p.image.get_height()) font = pygame.font.Font(None, 70) while True: clock.tick(60) FRICTION = p.speed[0] / 2 for event in pygame.event.get(): if event.type == QUIT: pygame.quit() return if event.type == KEYDOWN: if event.key == K_ESCAPE: g_exit() key = pygame.key.get_pressed() if key[K_LEFT]: p.switch_image() p.walk_left() if p.speed[0] != 0: p.speed[0] -= FRICTION elif key[K_RIGHT]: p.switch_image() p.walk_right() if p.speed[0] != 0: p.speed[0] -= FRICTION elif key[K_UP]: p.walk_up() elif key[K_DOWN]: p.walk_down() p.update() print p.speed[0] background.fill((250, 250, 250)) background.blit(p.blit_image, (p.x, p.y)) background.blit(pygame.image.load("health_bar.png"), (0,0)) text = font.render(str(p.health), 1, (255, 255, 255)) #this didnt work background.blit(text, (0,0)) screen.blit(background, (0,0)) pygame.display.flip() if __name__ == '__main__': main()
Any help would be appreciated
...
![]() |
Similar Threads
- Change Web Page Font Size on the Fly (Windows tips 'n' tweaks)
- Windows freeze in pygame- Windows (Python)
- Font widths question (Visual Basic 4 / 5 / 6)
- IE 6 all pages white background, font sizes erratic (Web Browsers)
- Change Font Size... c++ (C++)
- I've tried everything...setting font of selected text (Java)
- setting font of selected text (Java)
- I can't figure out how to change my jbutton font and color ( heres the code ) (Java)
- Turn on ClearType Font-Rendering Technology (Windows tips 'n' tweaks)
- Install or Remove a Font in Windows XP (Windows tips 'n' tweaks)
Other Threads in the Python Forum
- Previous Thread: Comma delimited file
- Next Thread: Can someone please a Tkinter program for this code?
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied apache application argv beginner book change code color converter dictionary dynamic edit editing enter examples excel file filename float format ftp function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql newb number numbers numeric output parameters parsing path phonebook port prime program programming projects py2exe pygame pyopengl pyqt python random recursion recursive redirect remote reverse scrolledtext server session simple smtp software sprite ssh statictext string strings syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






