#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  GameCore.py
#  

import pygame, sys
from pygame.locals import *

pygame.init()
fpsClock = pygame.time.Clock()

windowSurfaceObj = pygame.display.set_mode((800,600))
pygame.display.set_caption('Pygame Core File')

blackColor = pygame.Color(0,0,0)
greenColor = pygame.Color(0,255,0)


class Ball:
    def __init__(self, ballx, bally, ballxv, ballyv, size):
        self.x = ballx
        self.y = bally
        self.dx = ballxv
        self.dy = ballyv
        self.size = size
    def getBallRectangle(self):
        return (self.x,self.y,self.size,self.size)
    def update(self):
        self.x += self.dx
        self.y += self.dy
    def collides(self, minx, maxx, miny, maxy):
        if self.x < minx or self.x > maxx:
            self.dx *= -1
        if self.y < miny or self.y > maxy:
            self.dy *= -1

balls = []
    
while True:
    windowSurfaceObj.fill(blackColor)

    for b in balls:
        b.update()
        b.collides(0,800,0,600)
        pygame.draw.rect(windowSurfaceObj, greenColor, b.getBallRectangle())
    
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == MOUSEMOTION:
            pass
        elif event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                pygame.event.post(pygame.event.Event(QUIT))
            elif event.key == K_UP:
                balls.append(Ball(400,400,4,4,10))
    pygame.display.update()
    fpsClock.tick(30)
