# Arup Guha
# Version as of 6/5/2024
# Token class for SI@UCF
# Stores attributes for a basic object in pyGame.
# Since there aren't abstract classes, we use a circle for our object.

import random
import math
import time
import pygame, sys
from pygame.locals import *

# Token Class we'll use for drawing objects in pyGame
class token:

    # Constructor.
    def __init__(self,myx,myy,mydx,mydy,myr,mycolor):
        self.x = myx
        self.y = myy
        self.dx = mydx
        self.dy = mydy
        self.r = myr
        self.color = mycolor

    # Call each frame.
    def move(self):
        self.x += self.dx
        self.y += self.dy

    # Executes updating dx as necessary for bouncing off the left wall.
    def bounceLeft(self):
        if self.x + self.dx < self.r:
            self.dx = -self.dx

    # Executes updating dx as necessary for bouncing off the right wall.
    def bounceRight(self, SCREEN_W):
        if self.x + self.dx > SCREEN_W-self.r:
            self.dx = -self.dx

    # Executes updating y as necessary for bouncing off the top wall.
    def bounceUp(self):
        if self.y + self.dy < self.r:
            self.dy = -self.dy

    # Executes updating y as necessary for bouncing off the bottom wall.
    def bounceDown(self, SCREEN_H):
        if self.y + self.dy > SCREEN_H-self.r:
            self.dy = -self.dy

    # Adds addDX to the the change in x per frame, and adds addDY to
    # the change in y per frame.
    def changeVelocity(self,addDX,addDY):
        self.dx += addDX
        self.dy += addDY

    # Directly set the velocity to newDX, newDY.
    def setVelocity(self,newDX,newDY):
        self.dx = newDX
        self.dy = newDY

    # Change the color of this token to newcolor.
    def changeColor(self,newcolor):
        self.color = newcolor

    # Draws this object on the display surface as a circle.
    # Likely to be overridden most of the time.
    def draw(self, DISPLAYSURF):
        pygame.draw.circle(DISPLAYSURF, self.color, (self.x, self.y), self.r, 0)
        
    # Returns true iff the two circles represented by self and other intersect.
    # Should be overridden for different objects.
    def collide(self, other):

        # I know these aren't the centers, but this difference is the same as the
        # difference of the x and y coordinates of the centers.
        center_dx = self.x - other.x
        center_dy = self.y - other.y
        dist_sq = center_dx*center_dx + center_dy*center_dy
        dist_sq_radii = (self.r + other.r)*(self.r + other.r)
        return dist_sq <= dist_sq_radii
