Facebook
From xxx, 1 Week ago, written in Python.
Embed
Download Paste or View Raw
Hits: 195
  1. import pyglet
  2. from pyglet import shapes
  3. from pyglet.window import key, mouse
  4.  
  5. #https://pyglet.readthedocs.io/en/latest/programming_guide/keyboard.html
  6.  
  7.  
  8. width = 300
  9. height = 300
  10.  
  11. title = "PyGlet"
  12.  
  13. window = pyglet.window.Window(width, height, title)
  14. batch = pyglet.graphics.Batch()
  15.  
  16.  
  17. circle = shapes.Circle(x=100, y=100, radius=10, color=(50, 225, 30),batch=batch)
  18.  
  19.  
  20. @window.event
  21. def on_key_press(symbol, modifiers):
  22.     if symbol == key.LEFT:
  23.         circle.x -= 10
  24.     elif symbol == key.RIGHT:
  25.         circle.x += 10
  26.     elif symbol == key.UP:
  27.         circle.y += 10
  28.     elif symbol == key.DOWN:
  29.         circle.y -= 10
  30.     elif symbol == key.Y:
  31.         circle.color = (255,0,255)
  32.      
  33. @window.event
  34. def on_draw():
  35.  
  36.   window.clear()
  37.   batch.draw()
  38.  
  39.  
  40. pyglet.app.run()
  41.