Está en la página 1de 2

import random

import pygame
from pygame.locals import QUIT

NEGRO = (0, 0, 0)
ROJO = (255, 0, 0)
CAFE = (90, 50, 15)
AZULNOCHE = (9, 35, 67)
VERDEPASTO = (17, 99, 67)
VERDE = (10, 255, 10)
BLANCO = (222, 224, 200)
GRIS = (186, 186, 177)
GrisCastillo = (158, 158, 158)
NEGRO = (2, 3, 3)
ROJO = (255, 0, 0)
CAFE = (90, 50, 15)

Dimensiones = (700,500)

class CirculoRebota:
def __init__(self):

# Posición de la Pelota
self.x = Dimensiones[0] / 2
self.y = Dimensiones[1] / 2

self.dir_x = random.choice([-5,5])
self.dir_y = random.choice([-5,5])

self.radio = 50

def draw(self, surface):


pygame.draw.circle(surface, VERDE, (self.x, self.y), self.radio)

def Mover(self):
self.x += self.dir_x
self.y += self.dir_y

def Rebotar(self):

if self.x <= 0:
self.dir_x = -self.dir_x
if self.x >= Dimensiones[0]:
self.dir_x = -self.dir_x
if self.y <= 0:
self.dir_y = -self.dir_y
if self.y>= Dimensiones[1]:
self.dir_y = -self.dir_y

def main():
pygame.init()
Pantalla = pygame.display.set_mode(Dimensiones)
pygame.display.set_caption("Introducción a los Gráficos")

#Se define para poder gestionar cada cuando se ejecuta un fotograma


reloj = pygame.time.Clock()
circulo = CirculoRebota()
Terminar = False
while not Terminar:
circulo.Mover()
circulo.Rebotar()

for event in pygame.event.get():


if event.type == QUIT:
Terminar = True

Pantalla.fill(BLANCO)
circulo.draw(Pantalla)
pygame.display.flip()
reloj.tick(20) # Limitamos a 20 fotogramas por segundo
pygame.quit()

if __name__ == "__main__":
main()

También podría gustarte