# Arup Guha
# 5/31/2024
# This is the same as bounce circle, but when you use the new
# Token class, it shows squares bouncing around.

import random
import math
import time
import pygame, sys

from TokenFile import token
from pygame.locals import *

# Useful Constants
SCREEN_W = 1000
SCREEN_H = 600
BALL_D = 30
NUM_BALLS = 10

# Color Constants
WHITE = pygame.Color(255,255,255)
BLUE = pygame.Color(0,0,255)

# Returns a random integer in between low and high not equal to 0.
def myrand(low,high):
    res = 0
    while res == 0:
        res = random.randint(low, high)
    return res

def main():

    # Basic Set Up
    pygame.init()
    DISPLAYSURF = pygame.display.set_mode((SCREEN_W, SCREEN_H))
    pygame.display.set_caption("Object Oriented Bouncing")

    clock = pygame.time.Clock()

    # Make NUM_BALLS random tokens.
    mytokens = []
    for i in range(NUM_BALLS):

        # Somewhere on the screen.
        x = random.randint(1, SCREEN_W-BALL_D)
        y = random.randint(1, SCREEN_H-BALL_D)

        # Random non-zero movement in both directions.
        dx = myrand(-2,2)
        dy = myrand(-2,2)
        
        mytok = token(x,y,dx,dy,BALL_D,BLUE)
        mytokens.append(mytok)
        
    # Game loop.
    while True:

        # Look for events - we aren't using this right now.
        for event in pygame.event.get():
            
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        # White background.
        DISPLAYSURF.fill(WHITE)

        # Essentially update each ball.
        for item in mytokens:
            item.updateFrame(DISPLAYSURF)
            
        # Update what we put on the canvas.
        pygame.display.update()

        # Just testing collision code.
        for i in range(len(mytokens)):
            for j in range(i+1, len(mytokens)):
                #if mytokens[i].collide(mytokens[j]):
                    print("collide",i,j)
                    

        # Wait a bit!
        clock.tick(100)

# Run it
main()
