# Arup Guha
# Version of Token Class
# 6/6/2024

# Edited this version to get the Fruit Game to work with inheritance.
# I put both a width and a height as instance variables so that I could
# inherit those characteristics in the pictoken class.

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,width,height,mycolor):
        self.dx = mydx
        self.dy = mydy
        self.rec = pygame.Rect(myx, myy, width, height)
        self.color = mycolor

    # Call each frame.
    def move(self):
        self.rec.x += self.dx
        self.rec.y += self.dy

    # Returns true iff the grid coordinate mypos is within the picture
    # box of self. Pygame does this for us, so call Pygame's method!
    def hit(self, mypos):
        return self.rec.collidepoint(mypos)

    # Executes updating dx as necessary for bouncing off the left wall.
    def bounceLeft(self):
        if self.rec.x + self.dx < 0:
            self.dx = -self.dx

    # Executes updating dx as necessary for bouncing off the right wall.
    def bounceRight(self, SCREEN_W):
        if self.rec.x + self.dx > SCREEN_W-self.rec.width:
            self.dx = -self.dx

    # Executes updating y as necessary for bouncing off the top wall.
    def bounceUp(self):
        if self.rec.y + self.dy < 0:
            self.dy = -self.dy

    # Executes updating y as necessary for bouncing off the bottom wall.
    def bounceDown(self, SCREEN_H):
        if self.rec.y + self.dy > SCREEN_H-self.rec.width:
            self.dy = -self.dy

    # Update for a single frame. Maybe this will typically be overridden.
    def updateFrame(self, DISPLAYSURF):
        self.move()
        self.bounceLeft()
        self.bounceRight(DISPLAYSURF.get_width())
        self.bounceUp()
        self.bounceDown(DISPLAYSURF.get_height())
        self.draw(DISPLAYSURF)

    # Draws this object on the display surface as a circle.
    # Likely to be overridden most of the time.
    def draw(self, DISPLAYSURF):
        pygame.draw.rect(DISPLAYSURF, self.color, self.rec, 0)
