import math
import config
from point import Point

class Shape:
    def __init__(self, position, rotation, color):
        self.position = position
        self.rotation = rotation
        self.color = color
        self.dx = 0
        self.dy = 0

    def paint(self, surface):
        raise NotImplementedError()

    def game_logic(self, keys, newkeys):
        raise NotImplementedError()

    def contains(self, point):
        raise NotImplementedError()

    def getPoints(self):
        raise NotImplementedError()

    def get_rotation(self):
        return self.rotation

    def is_active(self):
        return self.active

    def set_active(self):
        self.active = True

    def set_inactive(self):
        self.active = False

    def move(self):
        (x, y) = self.position.pair()
        if x > config.SCREEN_X:
            x = 0
        if x < 0:
            x = config.SCREEN_X 
        if y > config.SCREEN_Y:
            y = 0
        if y < 0:
            y = config.SCREEN_Y 
        self.position = Point(x+self.dx, y+self.dy)

    def intersect(self, other_polygon):
        points = self.getPoints()
        other_points = other_polygon.getPoints()
        for point in points:
            if other_polygon.contains(point):
                return True

        for other_point in other_points:
            if self.contains(other_point):
                return True
            else:
                return False
        
    def accelerate(self, acceleration):
        angleinradians = math.radians(self.rotation)
        self.dx = self.dx + acceleration * math.cos(angleinradians)
        self.dy = self.dy + acceleration * math.sin(angleinradians)

    def rotate(self, degrees):
        if self.rotation > 360.0:
            self.rotation = 0.0
        elif self.rotation < 0.0:
            self.rotation = 360.0
        else:
            self.rotation += degrees
