Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''Programa los procedimientos y funciones necesarios para manipular la posicion de la figura
- con las flechas del teclado.
- Tendras que manipular los eventos pertinentes y mantener un
- estado de la figura que contenga la posicioon (x,y) donde dibujar la figura.
- Sugerencia: cada vez que accione una tecla de flecha,
- modifica las coordenadas agregando o restando un
- valor constante (ejemplo, si toca derecha suma 10 a la coordenada x).'''
- import pygame
- import sys
- BLANCO = (255, 255, 255)
- ROJO = (255, 0, 0)
- MEDIDA_PANTALLA = (640, 480)
- def Pelota(pantalla, posicion):
- pygame.draw.circle(pantalla, ROJO, posicion, 239, 2)
- def Ejecutar():
- pygame.init()
- coordenadaX = 320
- coordenadaY = 240
- posicion = [coordenadaX , coordenadaY]
- pantalla = pygame.display.set_mode( MEDIDA_PANTALLA )
- reloj = pygame.time.Clock()
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
- pygame.quit()
- sys.exit()
- if event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
- coordenadaX=coordenadaX+10
- posicion = [coordenadaX, coordenadaY]
- print posicion[0]
- if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
- coordenadaX=coordenadaX-10
- posicion = [coordenadaX, coordenadaY]
- print posicion[0]
- pantalla.fill(BLANCO)
- Pelota(pantalla, posicion)
- pygame.display.flip()
- tick = reloj.tick(60)
- if __name__ == "__main__":
- Ejecutar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement