Apr-14-2019, 10:47 PM
Don't make new post. For same code that been alter a little.
You going the wrong direction here. Let remove python time and threading modules. That another learning curve.
You need to rewrite code. Do not copy and paste code. Type it out.
Examples of clean code.
Basic pygame setup.
You going the wrong direction here. Let remove python time and threading modules. That another learning curve.
You need to rewrite code. Do not copy and paste code. Type it out.
Examples of clean code.
Basic pygame setup.
class Game: info = None def __init__(self, caption, width, height): # Basic pygame setup pygame.display.set_caption(caption) self.surface = pygame.display.set_mode((width, height)) self.rect = self.surface.get_rect() self.clock = pygame.time.Clock() self.fps = 30 # Class global variable Game.info = self def mainloop(self): self.running = True while self.running: for event in pygame.event.get(): if event.type == pygame.QUIT: self.running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.running = False self.surface.fill(pygame.Color('Navy')) # Draw code here pygame.display.flip() self.clock.tick(self.fps) def main(): pygame.init() game = Game("Example", 800, 600) game.mainloop() pygame.quit() main()Button draft. Turning button into an object.
class Button: def __init__(self, caption, font, rect, color, text_color): self.image = font.render(caption, 1, text_color) self.rect = rect self.text_rect = self.image.get_rect() self.text_rect.center = rect.center self.color = color def draw(self, surface): # button draw code here def onbuttonup(self, event): # click eventChallange. Let see you add on mouse over method and finish button class.
99 percent of computer problems exists between chair and keyboard.