def run(self): g = self.g tick = 30 clock = pygame.time.Clock() running = True level_key = sorted(self._levels.keys())[0] disp_w, disp_h = self.g.surface.get_size() board_surface = self.g.surface.subsurface( pygame.Rect((0,0), (disp_w/2, disp_h*7/8))) buttons_surface = self.g.surface.subsurface( pygame.Rect((0, disp_h*7/8), (disp_w, disp_h/8))) tao_surface = self.g.surface.subsurface( pygame.Rect((disp_w/2, 0), (disp_w/2, disp_h*7/8))) buttons = Buttons(self.g, buttons_surface) bg_colors = mk_color_set() frame_cnt = 0 while running: if True: # debug # Pulse the background to see what's being redrawn. self.g.surface.fill( bg_colors[frame_cnt%len(bg_colors)]) if g.android: if g.android.check_pause(): g.android.wait_for_resume() for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_q: running = False if event.type in (pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP): if buttons.collidepoint(event.pos): action = buttons.mouse_event(event, buttons_surface) if action is not None: if action.lower() == "abort": running = False elif action == "+": level.change_size(1) elif action == "-": level.change_size(-1) if level.collidepoint(event.pos, board_surface): action = level.mouse_event(event, board_surface) level = self._levels[level_key] level.draw(board_surface) buttons.draw() pygame.display.flip() frame_cnt += 1 clock.tick(tick)