Advertisement
richigarza

puddi

Nov 8th, 2012
2,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys  
  3. import math
  4. import random
  5. import time
  6. import serial
  7. import pygame, pygame.font, pygame.event, pygame.draw, string
  8. from pygame.locals import *
  9.  
  10.  
  11.  
  12. black = (   0,   0,   0)
  13. white = ( 255, 255, 255)
  14. blue = ( 36, 162, 202)
  15.  
  16. def figure(screen,x,y):
  17.  
  18.     # Figure
  19.     # pygame.draw.ellipse(screen,black,[1+x,1+y,150,150],2)
  20.  
  21.     pygame.font.init()
  22.    
  23. size=width, height = 700,550
  24. pared=ancho, alto = 50, 100
  25. screen=pygame.display.set_mode(size)
  26. speed=[50,10]
  27. lol=pygame.image.load("puddi.jpeg")
  28. lolrect=lol.get_rect()
  29.  
  30.  
  31. pygame.display.set_caption("Lawl")
  32.  
  33.  
  34. done=False
  35. clock=pygame.time.Clock()
  36. #pygame.mouse.set_visible(0)
  37.  
  38. try:
  39.     ser = serial.Serial( '/dev/ttyACM0', 9600 )
  40. except:
  41.     print "port /dev/ttyACM0 is not open"
  42.  
  43. while done==False:
  44.     for event in pygame.event.get():
  45.         if event.type == pygame.QUIT:
  46.             done=True
  47.    
  48.    
  49.     lolrect=lolrect.move(speed)
  50.     if lolrect.left < 0:
  51.         speed[0] = -speed[0]
  52.         ser.write("L")
  53.  
  54.     if lolrect.right > width:
  55.         speed[0] = -speed[0]
  56.         ser.write("R")    
  57.  
  58.     if lolrect.top < 0:
  59.         speed[1] = -speed[1]
  60.         ser.write("U")
  61.  
  62.     if lolrect.bottom > height:
  63.         speed[1] = -speed[1]
  64.         ser.write("D")
  65.    
  66.     screen.fill(blue)
  67.     screen.blit(lol, lolrect)
  68.     pygame.display.flip()
  69.     clock.tick(20)
  70.      
  71. pygame.quit ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement