class DamageArea {
 Point [] points;
 int timer;
 float power;
 
 DamageArea(Point [] points){
   this.points = points;
   timer = damageAreaTime;
   float area = max (triangleArea(points), minDamageArea);
   //power = area/
   //println(power);
   power = 1;
 }
  
 void render() {
   //if (timer % 2 == 0) {
     //float intensity = 1 - power / maxDamageArea;
     //fill(211,32,32, 255 * intensity);
     fill(211, 32, 32, 255 * (float(timer) / damageAreaTime));
     beginShape();
     for (int i = 0; i < points.length; i++) {
       vertex(points[i].x, points[i].y);
     }
     endShape(CLOSE);
   //}
 }
 
 void update() {
   timer--;
 }
 
}

class Point {
  float x, y;
  Point (float x, float y){
    this.x = x;
    this.y = y;
  }
}

float triangleArea(Point [] points){
  float a;
  a = abs (points[0].x * (points[1].y - points[2].y) + points[1].x * (points[2].y - points[0].y) + points[2].x * (points[0]. y - points[1].y)) / 2;
  return a;
}

boolean isInsideTriangle(float x, float y, float x1, float y1, float x2, float y2, float x3, float y3){
 Point p1 = new Point(x1, y1);
 Point p2 = new Point(x2, y2);
 Point p3 = new Point(x3, y3);
  
 Point p = new Point(x,y); // <-- You are checking if this point lies in the triangle.
 //Now, the barycentric coordinates, generally called alpha, beta, and gamma, are calculated as follows:
  
 float alpha = ((p2.y - p3.y)*(p.x - p3.x) + (p3.x - p2.x)*(p.y - p3.y)) /
  ((p2.y - p3.y)*(p1.x - p3.x) + (p3.x - p2.x)*(p1.y - p3.y));
 float beta = ((p3.y - p1.y)*(p.x - p3.x) + (p1.x - p3.x)*(p.y - p3.y)) /
  ((p2.y - p3.y)*(p1.x - p3.x) + (p3.x - p2.x)*(p1.y - p3.y));
 float gamma = 1.0f - alpha - beta;
 //If all of alpha, beta, and gamma are greater than 0, then the point p lies within the triangle made of points p1, p2, and p3.  
 //The explanation behind this is that a point inside a triangle can be described using the points of the triangle, and three coefficients (one for each point, in the range [0,1]):
  
 //p = (alpha)*p1 + (beta)*p2 + (gamma)*p3;
 
 boolean t = (alpha > 0 && beta > 0 && gamma > 0);
 //println(t);
 return t;
}