This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
4
Pygame + raw_input() using Threading
Post Body
quote: http://stackoverflow.com/a/17601393/341744
http://i.stack.imgur.com/vrpFs.png
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)
i = 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 to exit"
quit_game = True
pygame.event.poll()
screen.fill((0, 0, 0))
for 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()
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 11 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/pygame/comm...