# Arup Guha
# 6/14/2024
# Put all generic functions for dot game here.

import dotconsts
import random

# This function removes all items that will never be visible again,
# and returns how many were removed.
def removeUseless(items):

    # For concurrency issues, I first go through and find the ones to remove.
    dellist = []
    for item in items:
        if item.y > dotconsts.SCREEN_H or item.y < 0:
            dellist.append(item)
        if item.x > dotconsts.SCREEN_W or item.x < 0:
            dellist.append(item)

    # Then I remove them.
    for item in dellist:
        items.remove(item)
        
# This function handles moving each item listed in items.
def move(items):
    for item in items:
        item.move()

# Draws text with font and color on surface at coordinate (x,y)
def draw(text, font, color, surface, x, y):
    
    # Draw text on a new Surface. Title, antialias and color are used.
    text = font.render(text, 1, color)

    # Returns a new rectangle covering the entire surface.
    # This rectangle will always start at (0, 0) with a width and height the same size as the image.
    textrect = text.get_rect()

    # Sets location of text.
    textrect.topleft = (x, y)

    # Draw one image onto another. Source and destination are passed. Source is textobj and it will be written onto textrect,
    surface.blit(text, textrect)
