
# animBall-1.py
# Animate a single ball

import pygame, random
from pygame.locals import *

# some colors
BLACK = (   0,   0,   0)
WHITE = ( 255, 255, 255)


# -------------- main --------------

pygame.init()

screen = pygame.display.set_mode((400, 400))
pygame.display.set_caption("Ball Animation")


# load ball as image
ballIm = pygame.image.load('smallBall.png').convert_alpha()

# store dimensions for later
scrWidth, scrHeight = screen.get_size()
imWidth, imHeight = ballIm.get_size()

# initialize ball's position
x = random.randrange(0, scrWidth-1 - imWidth)
y = 0
screen.blit(ballIm, [x,y])

# initialize ball's step done in each loop
xStep = 0; yStep = 8


clock = pygame.time.Clock()

running = True
while running:
    clock.tick(30)

    # handle events
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False

    # update game state
    # Move ball down
    y += yStep
    print("Pos: ", x, y)

    # redraw
    screen.fill(BLACK)
    screen.blit(ballIm, [x,y])
    pygame.display.update()

pygame.quit()
