using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RangePolygon : GamePolygon {

	private Color color;

	public RangePolygon(GameVertex origin, float range, Color color) : base(createSliced(origin, range)) {
		this.color = color;
		addToGame();
	}

	public override void addToGame() {
		base.addToGame();

		renderer.material = new Material(GameController.defaultMaterial); //TODO : optimize
		renderer.material.color = color;
	}

	private static SlicedPolygon createSliced(GameVertex origin, float range) {
		ContourBuilder builder = new ContourBuilder();
		for (int i = 0; i < Constants.SAMPLE_MISSILE_RANGE_DISPLAY; i++) {

			float angle = i * Mathf.PI * 2 / Constants.SAMPLE_MISSILE_RANGE_DISPLAY;
			builder.addVertex(new GameVertex(origin.x() + Mathf.Cos(angle) * range, origin.y() + Mathf.Sin(angle) * range));
		}

		return new SlicedPolygon(builder.build());
	}
}
