using System;
using PlanetExpress.Tools;
using System.Drawing;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;

namespace PlanetExpress.items.effects	
{
	public class BoomEffect : CustomEffect {
		public static void Show(float x, float y) {
			CustomEffect eff = new BoomEffect();
			eff.X = x;
			eff.Y = y;
			MissionScreenClass.Area.AddObject(eff);
		}
		
		TexClass Boom;
		int frameWidth;
		int frameHeght;
		public BoomEffect () : base() {
			Boom = TexMan.LoadTexture(GameApp.GameFileName("data", "items", "boom.png"));
			frameWidth = Boom.Width / 8;
			frameHeght = Boom.Height / 7;
		}
		
		float LifeTime = 0;
		public override bool Action (double time) {
			base.Action (time);
			LifeTime += 100 * (float)time;
			return LifeTime < 7 * 8;
		}
		
		public override void Draw () {
			int c = (int) LifeTime % 8;
			int r = (int) LifeTime / 8;
			GL.PushMatrix(); {
				GL.Translate(X - frameWidth/2, Y-frameHeght/2, 0);
				GL.Color3(new float[]{1f, 1f, 1f});
				Boom.Render(0, 0,
				            new RectangleF(
				                           c*frameWidth, r*frameHeght,
				                           frameWidth, frameHeght
				                           ));
			} GL.PopMatrix();
		}
	}
}

