package scripts;

import com.stencyl.graphics.G;
import com.stencyl.graphics.BitmapWrapper;
import com.stencyl.graphics.ScaleMode;

import com.stencyl.behavior.Script;
import com.stencyl.behavior.Script.*;
import com.stencyl.behavior.ActorScript;
import com.stencyl.behavior.SceneScript;
import com.stencyl.behavior.TimedTask;

import com.stencyl.models.Actor;
import com.stencyl.models.GameModel;
import com.stencyl.models.actor.Animation;
import com.stencyl.models.actor.ActorType;
import com.stencyl.models.actor.Collision;
import com.stencyl.models.actor.Group;
import com.stencyl.models.Scene;
import com.stencyl.models.Sound;
import com.stencyl.models.Region;
import com.stencyl.models.Font;
import com.stencyl.models.Joystick;

import com.stencyl.Config;
import com.stencyl.Engine;
import com.stencyl.Input;
import com.stencyl.Key;
import com.stencyl.utils.motion.*;
import com.stencyl.utils.Utils;

import openfl.ui.Mouse;
import openfl.display.Graphics;
import openfl.display.BlendMode;
import openfl.display.BitmapData;
import openfl.display.Bitmap;
import openfl.events.Event;
import openfl.events.KeyboardEvent;
import openfl.events.TouchEvent;
import openfl.net.URLLoader;

import box2D.common.math.B2Vec2;
import box2D.dynamics.B2Body;
import box2D.dynamics.B2Fixture;
import box2D.dynamics.joints.B2Joint;
import box2D.collision.shapes.B2Shape;

import com.stencyl.graphics.shaders.BasicShader;
import com.stencyl.graphics.shaders.GrayscaleShader;
import com.stencyl.graphics.shaders.SepiaShader;
import com.stencyl.graphics.shaders.InvertShader;
import com.stencyl.graphics.shaders.GrainShader;
import com.stencyl.graphics.shaders.ExternalShader;
import com.stencyl.graphics.shaders.InlineShader;
import com.stencyl.graphics.shaders.BlurShader;
import com.stencyl.graphics.shaders.SharpenShader;
import com.stencyl.graphics.shaders.ScanlineShader;
import com.stencyl.graphics.shaders.CSBShader;
import com.stencyl.graphics.shaders.HueShader;
import com.stencyl.graphics.shaders.TintShader;
import com.stencyl.graphics.shaders.BloomShader;



class SceneEvents_0 extends SceneScript
{
	public var _mute:Bool;
	
	
	public function new(dummy:Int, dummy2:Engine)
	{
		super();
		nameMap.set("mute", "_mute");
		_mute = false;
		
	}
	
	override public function init()
	{
		
		/* ======================== When Creating ========================= */
		stopAllSounds();
		Joystick.addJoystick(1, 550, 220, 0, 0, 0, 0, 0, false);
		loopSound(getSound(75));
		
		/* ========================= Type & Type ========================== */
		addSceneCollisionListener(getActorType(7).ID, getActorType(9).ID, function(event:Collision, list:Array<Dynamic>):Void
		{
			if(wrapper.enabled)
			{
				recycleActor(getActor(2));
				switchScene(GameModel.get().scenes.get(1).getID(), createBubblesOut(1, Utils.getColorRGB(0,204,51)), createBubblesIn(1, Utils.getColorRGB(0,153,204)));
			}
		});
		
		/* ======================= Every N seconds ======================== */
		runPeriodically(1000 * 2, function(timeTask:TimedTask):Void
		{
			if(wrapper.enabled)
			{
				getActor(2).spinBy(360, 1, Easing.linear);
			}
		}, null);
		
		/* ========================= When Drawing ========================= */
		addWhenDrawingListener(null, function(g:G, x:Float, y:Float, list:Array<Dynamic>):Void
		{
			if(wrapper.enabled)
			{
				g.setFont(getFont(63));
				g.drawString("" + "Lvl.1", 40, 287);
			}
		});
		
		/* ======================== When Updating ========================= */
		addWhenUpdatedListener(null, function(elapsedTime:Float, list:Array<Dynamic>):Void
		{
			if(wrapper.enabled)
			{
				if(getActor(5).isMousePressed())
				{
					switchScene(GameModel.get().scenes.get(2).getID(), createCircleOut(1, Utils.getColorRGB(0,204,0)), createCircleIn(1, Utils.getColorRGB(0,0,0)));
				}
				if(getActor(3).isMousePressed())
				{
					switchScene(GameModel.get().scenes.get(0).getID(), createCircleOut(1, Utils.getColorRGB(51,204,0)), createCircleIn(1, Utils.getColorRGB(0,0,0)));
				}
				if(getActor(4).isMousePressed())
				{
					if(_mute)
					{
						_mute = false;
						loopSound(getSound(75));
						getActor(4).setAnimation("unmute");
					}
					else
					{
						_mute = true;
						stopAllSounds();
						getActor(4).setAnimation("mute");
					}
				}
			}
		});
		
	}
	
	override public function forwardMessage(msg:String)
	{
		
	}
}