# Complete

from vector import *

class mass():
    def __init__(self,position):
        self.position = position
        self.velocity = vector(0,0)
        self.mass = 1 # kg
        self.forces = []
    
    def move(self):
        self.position.shift_by(self.velocity)

        if self.position.x > 20 :
            self.position.x = 20.0
            self.velocity.x = -abs(self.velocity.x)
        elif self.position.x < 0:
            self.position.x = 0.0
            self.velocity.x = abs(self.velocity.x)

        if self.position.y > 20 :
            self.position.y = 20.0
            self.velocity.y = -abs(self.velocity.y)
        elif self.position.y < 0:
            self.position.y = 0.0
            self.velocity.y = abs(self.velocity.y)

    def receive_force(self):
        sum_forces = add_all(self.forces)
        self.velocity.shift_by(mult(sum_forces,1/self.mass))
        self.forces = []


    
    

class thruster(mass):
    def __init__(self,position):
        super().__init__(position)
        self.power = 5
        self.reference = []

    def set_reference(self, mass0, mass1):
        self.reference = []
        self.reference.append(mass0)
        self.reference.append(mass1)

    def fire(self):
        REFERENCE = vector(self.reference[0].position.x-self.reference[1].position.x, self.reference[0].position.y-self.reference[1].position.y)
        THRUST = mult(REFERENCE.unit(),self.power)
        self.forces.append(THRUST)

    def fire_backward(self):
        REFERENCE = vector(self.reference[0].position.x-self.reference[1].position.x, self.reference[0].position.y-self.reference[1].position.y)
        THRUST = mult(REFERENCE.unit(),-self.power)
        self.forces.append(THRUST)


class head(mass):
    def __init__(self,position,*meters):
        super().__init__(position)
        self.mass = 2 # kg
        self.meters = []

    