i wondering if there way, in python, while graphical piece inside games.screen.mainloop() running, if can user input through raw_input() console.
yes, have @ following example:
import pygame import threading import queue pygame.init() screen = pygame.display.set_mode((300, 300)) quit_game = false commands = queue.queue() pos = 10, 10 m = {'w': (0, -10), 'a': (-10, 0), 's': (0, 10), 'd': (10, 0)} class input(threading.thread): def run(self): while not quit_game: command = raw_input() commands.put(command) = input() i.start() old_pos = [] while not quit_game: try: command = commands.get(false) except queue.empty: command = none if command in m: old_pos.append(pos) pos = map(sum, zip(pos, m[command])) if pygame.event.get(pygame.quit): print "press enter exit" quit_game = true pygame.event.poll() screen.fill((0, 0, 0)) p in old_pos: pygame.draw.circle(screen, (50, 0, 0), p, 10, 2) pygame.draw.circle(screen, (200, 0, 0), pos, 10, 2) pygame.display.flip() i.join()
it creates little red circle. can move around entering w, a, s or d console.
Comments
Post a Comment