Trade-Winds/Oversimplified.js

3 lines
39 KiB
JavaScript

function IsInternetExplorer(){var e=window.navigator.userAgent,i=e.indexOf("MSIE ");return!!(i>0||navigator.userAgent.match(/Trident.*rv\:11\./))}var Oversimplified={},OS=Oversimplified;Oversimplified.canvas=null,Oversimplified.context=null,Oversimplified.nextID=0,Oversimplified.loadingScripts=[],Oversimplified.loadedScripts=[],Oversimplified.emptyImage=new Image,Oversimplified.emptyImage.src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=",Oversimplified.emptyImage.width=1,Oversimplified.emptyImage.height=1,Oversimplified.Settings={defaultStep:1/30,numberOfScriptsToLoad:0,soundVolume:.75,musicVolume:.75,preventRightClick:!0},Oversimplified.S=Oversimplified.Settings,Oversimplified.timestamp=function(){return window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},Oversimplified.now=null,Oversimplified.dateTime=0,Oversimplified.lastFrame=Oversimplified.timestamp(),Oversimplified.step=Oversimplified.Settings.defaultStep,Oversimplified.camera={x:0,y:0,width:640,height:480,hBorder:64,vBorder:64,following:"",Follow:function(e){this.following=e.name}},Oversimplified.SetCamera=function(e){Oversimplified.camera.width="undefined"!=typeof e.width?e.width:Oversimplified.camera.width,Oversimplified.camera.height="undefined"!=typeof e.height?e.height:Oversimplified.camera.height,Oversimplified.SetCanvasToCameraSize(),Oversimplified.camera.x="undefined"!=typeof e.x?e.x:Oversimplified.camera.x,Oversimplified.camera.y="undefined"!=typeof e.y?e.y:Oversimplified.camera.y,"undefined"!=typeof e.objectToFollow&&(e.objectToFollow.name?Oversimplified.camera.Follow(e.objectToFollow):Oversimplified.DEBUG.showMessages&&console.log("Oversimplified.Settings.SetCamera()'s objectToFollow argument must be a Oversimplified.GameObject.")),Oversimplified.camera.hBorder="undefined"!=typeof e.hBorder?e.hBorder:Oversimplified.camera.hBorder,Oversimplified.camera.vBorder="undefined"!=typeof e.vBorder?e.vBorder:Oversimplified.camera.vBorder},Oversimplified.mouse={x:0,y:0,leftCode:IsInternetExplorer()?1:0,middleCode:IsInternetExplorer()?4:1,rightCode:2,leftDown:!1,left:!1,leftUp:!1,middleDown:!1,middle:!1,middleUp:!1,rightDown:!1,right:!1,rightUp:!1,wheel:0},Oversimplified.heldKeys=[],Oversimplified.pressedKeys=[],Oversimplified.releasedKeys=[],Oversimplified.Key={37:"left arrow",38:"up arrow",39:"right arrow",40:"down arrow",45:"insert",46:"delete",8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps lock",27:"escape",32:"space",33:"page up",34:"page down",35:"end",91:"left win/special key",92:"right win/special key",93:"select key",96:"numpad 0",97:"numpad 1",98:"numpad 2",99:"numpad 3",100:"numpad 4",101:"numpad 5",102:"numpad 6",103:"numpad 7",104:"numpad 8",105:"numpad 9",106:"numpad asterisk",107:"numpad plus",109:"numpad dash",110:"numpad period",111:"numpad slash",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num lock",145:"scroll lock",186:"semicolon",187:"equal",188:"comma",189:"dash",190:"period",191:"slash",192:"grave accent",219:"open bracket",220:"backslash",221:"close bracket",222:"quote"},Oversimplified.Keycode={backspace:8,tab:9,enter:13,shift:16,ctrl:17,alt:18,pausebreak:19,capslock:20,escape:27,space:32,pageup:33,pagedown:34,end:35,home:36,left:37,up:38,right:39,down:40,insert:45,del:46,zero:48,one:49,two:50,three:51,four:52,five:53,six:54,seven:55,eight:56,nine:57,a:65,b:66,c:67,d:68,e:69,f:70,g:71,h:72,i:73,j:74,k:75,l:76,m:77,n:78,o:79,p:80,q:81,r:82,s:83,t:84,u:85,v:86,w:87,x:88,y:89,z:90,leftwinkey:91,rightwinkey:92,selectkey:93,numpad_0:96,numpad_1:97,numpad_2:98,numpad_3:99,numpad_4:100,numpad_5:101,numpad_6:102,numpad_7:103,numpad_8:104,numpad_9:105,numpad_asterisk:106,numpad_plus:107,numpad_dash:109,numpad_period:110,numpad_slash:111,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,numlock:144,scrolllock:145,semicolon:186,equal:187,comma:188,dash:189,period:190,slash:191,grave:192,openbracket:219,backslash:220,closebraket:221,quote:222},Oversimplified.Controls={},Oversimplified.Controls.Add=function(e,i,s){return"undefined"!=typeof s?Oversimplified.Controls[e]=new Oversimplified.Axis(i,s):Oversimplified.Controls[e]=new Oversimplified.Control(i),Oversimplified.Controls[e]},Oversimplified.Controls.New=Oversimplified.Controls.Add,Oversimplified.Controls.CheckAll=function(){for(var e in Oversimplified.Controls)"undefined"!=typeof Oversimplified.Controls[e].Check&&Oversimplified.Controls[e].Check()},Oversimplified.C=Oversimplified.Controls,Oversimplified.Control=function(e){this.keyCode=e,this.keyName=Oversimplified.Key[e],this.down=this.pressed=!1,this.held=!1,this.up=this.released=!1},Oversimplified.Control.prototype.type="Control",Oversimplified.Control.prototype.Check=function(){-1!=Oversimplified.heldKeys.indexOf(this.keyCode)?this.held=!0:this.held=!1,-1!=Oversimplified.pressedKeys.indexOf(this.keyCode)?this.down=this.pressed=!0:this.down=this.pressed=!1,-1!=Oversimplified.releasedKeys.indexOf(this.keyCode)?this.up=this.released=!0:this.up=this.released=!1},Oversimplified.Axis=function(e,i){this.positiveKeycode=e,this.positiveKeyName=Oversimplified.Key[e],this.negativeKeycode=i,this.negativeKeyName=Oversimplified.Key[i],this.direction=0},Oversimplified.Axis.prototype.type="Axis",Oversimplified.Axis.prototype.Check=function(){-1!=Oversimplified.heldKeys.indexOf(this.positiveKeycode)&&-1==Oversimplified.heldKeys.indexOf(this.negativeKeycode)&&(this.direction=1),-1!=Oversimplified.heldKeys.indexOf(this.negativeKeycode)&&-1==Oversimplified.heldKeys.indexOf(this.positiveKeycode)&&(this.direction=-1),(-1==Oversimplified.heldKeys.indexOf(this.negativeKeycode)&&-1==Oversimplified.heldKeys.indexOf(this.positiveKeycode)||-1!=Oversimplified.heldKeys.indexOf(this.negativeKeycode)&&-1!=Oversimplified.heldKeys.indexOf(this.positiveKeycode))&&(this.direction=0)},Oversimplified.Rooms={currentRoom:"Default",AllBeforeDo:function(){},AllDo:function(){},AllAfterDo:function(){}},Oversimplified.Rooms.Add=function(e,i){return"undefined"==typeof Oversimplified.Rooms[e]?(Oversimplified.Rooms[e]=new Oversimplified.Room(e,i),Oversimplified.Rooms[e]):(Oversimplified.DEBUG.showMessages&&console.log('A Room with the name "'+e+'" already exists!'),!1)},Oversimplified.Rooms.New=Oversimplified.Rooms.Add,Oversimplified.R=Oversimplified.Rooms,Oversimplified.O=null,Oversimplified.Room=function(e,i){this.id=Oversimplified.nextID++;var s=this;this.name=e,this.hasRunStart=!1,i="undefined"!=typeof i?i:{},i.width="undefined"!=typeof i.width&&i.width>=Oversimplified.camera.width?i.width:Oversimplified.camera.width,i.height="undefined"!=typeof i.height&&i.height>=Oversimplified.camera.height?i.height:Oversimplified.camera.height,i.stepSpeed="undefined"!=typeof i.stepSpeed&&i.stepSpeed>0?i.stepSpeed:Oversimplified.Settings.defaultStep,this.width=i.width,this.height=i.height,"undefined"!=typeof i.backgroundSrc&&""!=i.backgroundSrc?(this.bg=new Image,this.bg.src=i.backgroundSrc):this.bg=Oversimplified.emptyImage,this.background={},this.background.loaded=!1,this.bg!=Oversimplified.emptyImage&&(this.bg.onload=function(){s.background.loaded=!0,s.background.width=this.width,s.background.height=this.height,1==i.backgroundSize&&(s.width=this.width,s.height=this.height)}),this.stepSpeed=i.stepSpeed,this.objects={},this.O=this.objects,"undefined"!=typeof i.backgroundColor&&(this.background.color=i.backgroundColor),"undefined"!=typeof i.foreground&&(this.foreground=new Image,this.foreground.loaded=!1,this.foreground.src=i.foreground,this.foreground.onload=function(){this.loaded=!0});for(var t in i)"undefined"==typeof this[t]&&(this[t]=i[t]);this.drawOrder=[],this.DoFirst=function(){},this.BeforeDo=function(){},this.Do=function(){},this.AfterDo=function(){},this.DoLast=function(){},this.DrawBelow=function(){},this.DrawAbove=function(){}},Oversimplified.Room.prototype.type="Room",Oversimplified.Room.prototype.Start=function(){if(this.DoFirst(),this.name===Oversimplified.Rooms.currentRoom)for(var e in this.objects)this.objects[e].Start();this.hasRunStart=!0},Oversimplified.Room.prototype.Update=function(){Oversimplified.step!=this.stepSpeed&&(Oversimplified.step=this.stepSpeed),this.drawOrder=[];for(var e in this.objects)if("GameObject"==this.objects[e].type){if(this.drawOrder.length<=0){this.drawOrder=[e];continue}for(var i=this.objects[e].depth,s=0;s<this.drawOrder.length;s++)if(i<this.objects[this.drawOrder[s]].depth){this.drawOrder.splice(s,0,e);break}this.drawOrder.indexOf(e)<0&&this.drawOrder.push(e)}if(this.hasRunStart||this.Start(),this.BeforeDo(),this.Do(),this.name===Oversimplified.Rooms.currentRoom)for(var e in this.objects)this.objects[e].Update();this.AfterDo()},Oversimplified.Room.prototype.End=function(){this.DoLast(),this&&(this.hasRunStart=!1)},Oversimplified.Room.prototype.Draw=function(){var e=this;if("undefined"!=typeof this.background.color){var i=Oversimplified.context.fillStyle;Oversimplified.context.fillStyle=this.background.color,Oversimplified.context.fillRect(0,0,Oversimplified.camera.width,Oversimplified.camera.height),Oversimplified.context.fillStyle=i}this.background.loaded&&Oversimplified.context.drawImage(e.bg,Oversimplified.camera.x,Oversimplified.camera.y,Oversimplified.camera.width<=e.background.width?Oversimplified.camera.width:e.background.width,Oversimplified.camera.height<=e.background.height?Oversimplified.camera.height:e.background.height,0,0,e.background.width,e.background.height),this.DrawBelow();for(var s=0;s<this.drawOrder.length;s++)"undefined"!=typeof this.objects[this.drawOrder[s]]&&this.objects[this.drawOrder[s]].Draw();"undefined"!=typeof this.foreground&&this.foreground.loaded&&Oversimplified.context.drawImage(e.foreground,Oversimplified.camera.x,Oversimplified.camera.y,Oversimplified.camera.width,Oversimplified.camera.height,0,0,e.foreground.width,e.foreground.height),this.DrawAbove()},Oversimplified.Room.prototype.AddObject=function(e,i){i="undefined"!=typeof i?i:{};var s=this;return"GameObject"==e.type?(i.id=Oversimplified.nextID++,i.name=e.name+i.id.toString(),s.objects[i.name]=Oversimplified.CopyObject(e,i),s.objects[i.name]):s.objects[e]?(Oversimplified.DEBUG.showMessages&&console.log('Object with name "'+e+'" already exists in current room!'),!1):(s.objects[e]=new Oversimplified.GameObject(e,i),s.objects[e])},Oversimplified.Room.prototype.SetAsCurrentRoom=function(){Oversimplified.SetRoom(this)},Oversimplified.Create=function(e,i){return Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].AddObject(e,i)},Oversimplified.SetRoom=function(e){"undefined"!=typeof Oversimplified.Rooms[Oversimplified.Rooms.currentRoom]&&Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].End(),Oversimplified.Rooms.currentRoom=e.name,Oversimplified.O=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects,Oversimplified.camera.following="",Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].Start(),Oversimplified.DEBUG.showMessages&&console.log('The current room is "'+Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].name+'".')},Oversimplified.PremadeObjects={},Oversimplified.PremadeObjects.Add=function(e,i){return"undefined"==typeof Oversimplified.PremadeObjects[e]?(Oversimplified.PremadeObjects[e]=new Oversimplified.GameObject(e,i),Oversimplified.PremadeObjects[e]):(Oversimplified.DEBUG.showMessages&&console.log('A Premade Object with the name "'+e+'" already exists!'),!1)},Oversimplified.PremadeObjects.New=Oversimplified.PremadeObjects.Add,Oversimplified.Prefabs=Oversimplified.PremadeObjects,Oversimplified.P=Oversimplified.PremadeObjects,Oversimplified.GameObject=function(e,i){this.id=Oversimplified.nextID++;var s=this;if(this.self=s,this.hasRunStart=!1,this.name=e,this.depth="undefined"!=typeof i.depth?i.depth:0,this.solid="undefined"!=typeof i.solid?i.solid:!1,this.persistent="undefined"!=typeof i.persistent?i.persistent:!1,this.x="undefined"!=typeof i.x?i.x:-1,this.y="undefined"!=typeof i.y?i.y:-1,this.xPrevious=this.x,this.yPrevious=this.y,this.screenX=this.x-Oversimplified.camera.x,this.screenY=this.y-Oversimplified.camera.y,this.image=i.imageSrc?i.imageSrc.src?i.imageSrc:new Image:Oversimplified.emptyImage,this.image.src=this.image.src?this.imageSrc.src:i.imageSrc,this.sprite={},this.sprite.xScale="undefined"!=typeof i.xScale?i.xScale:1,this.sprite.yScale="undefined"!=typeof i.yScale?i.yScale:this.sprite.xScale,this.sprite.rotation="undefined"!=typeof i.rotation?Math.clampAngle(i.rotation):0,this.sprite.animations={},this.sprite.frameColumn=0,this.sprite.frameRow=0,"undefined"!=typeof i.animations)for(var t=0;t<i.animations.length;t++)0==t&&"Default"!=i.animations[t].name&&(this.sprite.animations.Default=i.animations[t]),this.sprite.animations[i.animations[t].name]=i.animations[t];else this.image!=Oversimplified.emptyImage?this.image.onload=function(){s.sprite.animations.Default=new Oversimplified.Animation("newAnimation",{width:this.width,height:this.height})}:this.sprite.animations.Default=new Oversimplified.Animation("newAnimation",{width:this.image.width,height:this.image.height});this.sprite.currentAnimation="Default",this.mask=i.maskImageSrc?new Image:{},this.mask.src=i.maskImageSrc?i.maskImageSrc:"",""==this.mask.src&&(this.mask.width=this.sprite.animations.Default.width,this.mask.height=this.sprite.animations.Default.height),""!=this.mask.src?this.mask.onload=function(){s.xBound=this.width/2*s.sprite.xScale,s.yBound=this.height/2*s.sprite.yScale}:(s.xBound=this.mask.width/2*s.sprite.xScale,s.yBound=this.mask.height/2*s.sprite.yScale);for(var r in i)"undefined"==typeof this[r]&&(this[r]=i[r]);this.DoFirst=function(){},this.BeforeDo=function(){},this.Do=function(){},this.AfterDo=function(){},this.DoLast=function(){},this.DrawBelow=function(){},this.DrawAbove=function(){}},Oversimplified.GameObject.prototype.type="GameObject",Oversimplified.GameObject.prototype.AddAnimation=function(e,i,s,t){"undefined"!=typeof e.name?this.sprite.animations[t.name]=e:("undefined"==typeof Oversimplified.Animations[e]&&Oversimplified.Animations.Add(e,i,s,t),this.sprite.animations[Oversimplified.Animations[e].name]=Oversimplified.Animations[e])},Oversimplified.GameObject.prototype.Draw=function(){this.DrawBelow();var e=this,i=e.sprite.currentAnimation;if(e.sprite.animations[i]){var s=e.sprite.animations[i].width,t=e.sprite.animations[i].height,r=e.sprite.animations[i].width*e.sprite.xScale,o=e.sprite.animations[i].height*e.sprite.yScale,d=e.sprite.animations[i].columns,n=e.sprite.animations[i].rows,m=e.sprite.animations[i].xOffset,l=e.sprite.animations[i].yOffset,f=e.sprite.animations[i].speed;if(e.sprite.frameColumn<d&&(e.sprite.frameColumn+=f),e.sprite.frameColumn>=d&&(e.sprite.frameColumn=0,e.sprite.frameRow++),e.sprite.frameRow>n-1&&(e.sprite.frameRow=0),Oversimplified.IsOnCamera(e)){var a=Math.floor(e.sprite.frameColumn),p=Math.floor(e.sprite.frameRow);Oversimplified.context.translate(e.x-Oversimplified.camera.x,e.y-Oversimplified.camera.y);var v=e.sprite.rotation*(Math.PI/180);Oversimplified.context.rotate(v),Oversimplified.context.drawImage(e.image,s*a+m,t*p+l,s,t,-(r/2),-(o/2),r,o),Oversimplified.context.rotate(-v),Oversimplified.context.translate(-(e.x-Oversimplified.camera.x),-(e.y-Oversimplified.camera.y)),Oversimplified.DEBUG.objectsOnScreen++}}else Oversimplified.DEBUG.showMessages&&console.log("No animation at "+i);this.DrawAbove()},Oversimplified.GameObject.prototype.SetScale=function(e,i){this.sprite.xScale=e,this.sprite.yScale="undefined"!=typeof i?i:e,this.xBound=this.mask.width/2*this.sprite.xScale,this.yBound=this.mask.height/2*this.sprite.yScale},Oversimplified.GameObject.prototype.SetImageRotation=function(e){this.sprite.rotation=Math.clampAngle(e)},Oversimplified.GameObject.prototype.RotateImage=function(e){this.sprite.rotation+=Math.clampAngle(e)},Oversimplified.GameObject.prototype.SetAnimation=function(e){e.name&&(e=e.name),this.sprite.currentAnimation=e,this.sprite.frameColumn=0,this.sprite.frameRow=0},Oversimplified.GameObject.prototype.Start=function(){this.DoFirst(),this.hasRunStart=!0},Oversimplified.GameObject.prototype.Update=function(){this.screenX=this.x-Oversimplified.camera.x,this.screenY=this.y-Oversimplified.camera.y,this.xPrevious=this.x,this.yPrevious=this.y,this.hasRunStart||this.Start(),this.BeforeDo(),this.Do(),this.AfterDo(),this.sprite.rotation=Math.clampAngle(this.sprite.rotation)},Oversimplified.GameObject.prototype.End=function(){this.DoLast(),this&&(this.hasRunStart=!1)},Oversimplified.GameObject.prototype.MoveTo=function(e,i,s){s="undefined"!=typeof s?s:1,this.x<e&&(this.x+=s),this.x>e&&(this.x-=s),this.y<i&&(this.y+=s),this.y>i&&(this.y-=s)},Oversimplified.GameObject.prototype.PointOverlaps=function(e,i){return e>this.x-this.xBound&&e<this.x+this.xBound&&i>this.y-this.yBound&&i<this.y+this.yBound},Oversimplified.GameObject.prototype.IsOverlapping=function(e){e="undefined"!=typeof e?e:!1;for(var i in Oversimplified.O){var s=Oversimplified.O[i];if(s!=this)if(e){if(s.PointOverlaps(this.x-this.xBound,this.y-this.yBound)||s.PointOverlaps(this.x+this.xBound,this.y-this.yBound)||s.PointOverlaps(this.x-this.xBound,this.y+this.yBound)||s.PointOverlaps(this.x+this.xBound,this.y+this.yBound)||s.PointOverlaps(this.x-this.xBound,this.y)||s.PointOverlaps(this.x+this.xBound,this.y)||s.PointOverlaps(this.x,this.y-this.yBound)||s.PointOverlaps(this.x,this.y+this.yBound))return s}else for(var t=0;t<2*s.xBound;t++)for(var r=0;r<2*s.yBound;r++){var o=s.x-s.xBound+t,d=s.y-s.yBound+r;if(o>this.x-this.xBound&&o<this.x+this.xBound&&d>this.y-this.yBound&&d<this.y+this.yBound)return s}}return!1},Oversimplified.GameObject.prototype.IfOverlappingThenMove=function(e){var i=this.IsOverlapping(e);return 0!=i?(this.x<i.x&&this.x--,this.x>=i.x&&this.x++,this.y<i.y&&this.y--,this.y>=i.y&&this.y++,!0):!1},Oversimplified.GameObject.prototype.KeepInsideRoom=function(){var e=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom];(this.x<this.xBound||this.x>e.width-this.xBound)&&(this.x=this.xPrevious),(this.y<this.yBound||this.y>e.height-this.yBound)&&(this.y=this.yPrevious)},Oversimplified.GameObject.prototype.MouseIsOver=function(){return!!this.PointOverlaps(Oversimplified.mouse.x,Oversimplified.mouse.y)},Oversimplified.GameObject.prototype.Clicked=function(e){return e="undefined"!=typeof e?e:Oversimplified.mouse.leftDown,!(!this.MouseIsOver()||!e)},Oversimplified.GameObject.prototype.SimpleMove=function(e,i,s,t){t="undefined"!=typeof t?t:2;var r=!1,o=!1,d=!1,n=!1;if(s){for(var m=0;m<2*this.yBound;m+=t){var l=this.y-this.yBound+m;r||(r=0>e&&Oversimplified.CollisionAtPoint(this.x-this.xBound+e,l)),o||(o=e>0&&Oversimplified.CollisionAtPoint(this.x+this.xBound+e,l))}for(var f=0;f<2*this.xBound;f+=t){var a=this.x-this.xBound+f;d||(d=0>i&&Oversimplified.CollisionAtPoint(a,this.y-this.yBound+i)),n||(n=i>0&&Oversimplified.CollisionAtPoint(a,this.y+this.yBound+i))}}return s&&(r||o||d||n)?!1:(this.x+=e,this.y+=i,!0)},Oversimplified.GameObject.prototype.Destroy=function(){this.End(),delete Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[this.name]},Oversimplified.GameObjectsAtPoint=function(e,i){var s=[];for(var t in Oversimplified.O){var r=Oversimplified.O[t];e<=r.x+r.xBound&&e>=r.x-r.xBound&&i<=r.y+r.yBound&&i>=r.y-r.yBound&&s.push(r)}return s.length>0?s:!1},Oversimplified.CollisionAtPoint=function(e,i){for(var s=Oversimplified.GameObjectsAtPoint(e,i),t=0;t<s.length;t++)if(1==s[t].solid)return!0;return!1},Oversimplified.Animations={},Oversimplified.Animations.Add=function(e,i,s,t){return"undefined"==typeof Oversimplified.Animations[e]?(Oversimplified.Animations[e]=new Oversimplified.Animation(e,i,s,t),Oversimplified.Animations[e]):(Oversimplified.DEBUG.showMessages&&console.log('An animation with the name "'+e+'" already exists!'),!1)},Oversimplified.Animations.New=Oversimplified.Animations.Add,Oversimplified.A=Oversimplified.Animations,Oversimplified.Animation=function(e,i,s,t){this.id=Oversimplified.nextID++,this.name=e,this.width=i,this.height=s,this.columns="undefined"!=typeof t.columns?t.columns:1,this.rows="undefined"!=typeof t.rows?t.rows:1,this.speed="undefined"!=typeof t.speed?Math.clamp01(t.speed):1,this.xOffset="undefined"!=typeof t.xOffset?t.xOffset:0,this.yOffset="undefined"!=typeof t.yOffset?t.yOffset:0},Oversimplified.Animation.prototype.type="Animation",Oversimplified.Effects={Sounds:{},Tunes:{}},Oversimplified.Effects.S=Oversimplified.Effects.Sounds,Oversimplified.Effects.T=Oversimplified.Effects.Music=Oversimplified.Effects.M=Oversimplified.Effects.Tunes,Oversimplified.E=Oversimplified.Effects,Oversimplified.Effects.AddSound=function(e,i){return"undefined"==typeof Oversimplified.Effects.Sounds[e]?(Oversimplified.Effects.Sounds[e]=new Oversimplified.Sound(e,i),Oversimplified.Effects.Sounds[e]):(Oversimplified.DEBUG.showMessages&&console.log('A Sound with the name "'+e+'" already exists!'),!1)},Oversimplified.Effects.NewSound=Oversimplified.Effects.AddSound,Oversimplified.Effects.AddTune=function(e,i){return"undefined"==typeof Oversimplified.Effects.Tunes[e]?(Oversimplified.Effects.Tunes[e]=new Oversimplified.Sound(e,i),Oversimplified.Effects.Tunes[e]):(Oversimplified.DEBUG.showMessages&&console.log('A Tune with the name "'+e+'" already exists!'),!1)},Oversimplified.Effects.AddMusic=Oversimplified.Effects.NewTune=Oversimplified.Effects.NewMusic=Oversimplified.Effects.AddTune,Oversimplified.Effects.Tunes.CheckLoops=function(){for(var e in Oversimplified.Effects.Tunes)"Tune"==Oversimplified.Effects.Tunes[e].type&&Oversimplified.Effects.Tunes[e].IsPlaying()&&Oversimplified.Effects.Tunes[e].CheckLoop()},Oversimplified.Sound=function(e,i){this.id=Oversimplified.nextID++,i="undefined"!=typeof i?i:{},this.name=e,this.source={mp3:"undefined"!=typeof i.mp3&&i.mp3.length>0?i.mp3:!1,wav:"undefined"!=typeof i.wav&&i.wav.length>0?i.wav:!1,ogg:"undefined"!=typeof i.ogg&&i.ogg.length>0?i.ogg:!1},this.audioElement=document.createElement("audio"),this.audioElement.id=this.name+this.id.toString(),this.element=this.audioElement;for(var s in this.source)if(s!==!1){var t=document.createElement("source");t.src=this.source[s],this.audioElement.appendChild(t)}document.getElementById("audio").appendChild(this.audioElement),this.audioElement.load()},Oversimplified.Sound.prototype.type="Sound",Oversimplified.Sound.prototype.Play=function(){this.element.currentTime=0,this.element.volume=Oversimplified.Settings.soundVolume,this.element.play()},Oversimplified.Sound.prototype.Stop=function(){this.element.pause(),this.element.currentTime=0},Oversimplified.Sound.prototype.IsPlaying=function(){return!this.element.paused&&!this.element.ended&&0<this.element.currentTime},Oversimplified.Tune=function(e,i){this.id=Oversimplified.nextID++,i="undefined"!=typeof i?i:{},this.name=e,this.source={mp3:"undefined"!=typeof i.mp3&&i.mp3.length>0?i.mp3:!1,wav:"undefined"!=typeof i.wav&&i.wav.length>0?i.wav:!1,ogg:"undefined"!=typeof i.ogg&&i.ogg.length>0?i.ogg:!1},this.duration="undefined"!=typeof i.duration?i.duration:!1,this.audioElement=document.createElement("audio"),this.audioElement.id=this.name+this.id.toString(),this.element=this.audioElement;for(var s in this.source)if(s!==!1){var t=document.createElement("source");t.src=this.source[s],this.audioElement.appendChild(t)}document.getElementById("audio").appendChild(this.audioElement),this.audioElement.load()},Oversimplified.Tune.prototype.type="Tune",Oversimplified.Tune.prototype.Play=function(){this.element.currentTime=0,this.element.volume=Oversimplified.Settings.musicVolume,this.element.loop=!0,this.element.play()},Oversimplified.Tune.prototype.Stop=function(){this.element.pause(),this.element.currentTime=0},Oversimplified.Tune.prototype.CheckLoop=function(){this.duration<this.element.duration&&this.element.currentTime>this.duration&&(this.element.currentTime=0)},Oversimplified.Tune.prototype.IsPlaying=function(){return!this.element.paused&&!this.element.ended&&0<this.element.currentTime},Oversimplified.CopyObject=function(e,i){var s={};"GameObject"==e.type&&(s.self=s,s.image=new Image,s.image.src=e.image.src,s.sprite={},s.sprite.xScale=e.sprite.xScale,s.sprite.yScale=e.sprite.yScale,s.sprite.rotation=e.sprite.rotation,s.sprite.frameColumn=0,s.sprite.frameRow=0,s.sprite.animations=e.sprite.animations,s.sprite.currentAnimation=e.sprite.currentAnimation,s.mask=new Image,s.mask.src=e.mask.src,""==s.mask.src&&(s.mask.width=s.sprite.animations.Default.width,s.mask.height=s.sprite.animations.Default.height),s.mask.onload=function(){s.xBound=this.width/2,s.yBound=this.height/2});for(var t in e)"undefined"==typeof s[t]&&(e[t].slice?s[t]=e[t].slice():s[t]=e[t]);for(var r in i)i[r].slice?s[r]=i[r].slice():s[r]=i[r];return"undefined"==typeof s.id&&(s.id=Oversimplified.nextID++),"undefined"==typeof s.name&&(s.name=e.name+s.id.toString()),s},Oversimplified.Save=function(e,i){if("undefined"!=typeof Storage){if(localStorage.setItem(e,i),localStorage.getItem(e)==i)return Oversimplified.DEBUG.showMessages&&console.log("Successfully saved "+i+' to localStorage["'+e+'"].'),!0;Oversimplified.DEBUG.showMessages&&console.log("Could not save "+i+' to localStorage["'+e+'"].')}else Oversimplified.DEBUG.showMessages&&console.log("This browser does not support saving to localStorage.");return!1},Oversimplified.Load=function(e){if("undefined"!=typeof Storage){if(localStorage.getItem(e))return Oversimplified.DEBUG.showMessages&&console.log('Successfully loaded from localStorage["'+e+'"].'),localStorage.getItem(e);Oversimplified.DEBUG.showMessages&&console.log('No data saved in localStorage["'+e+'"].')}else Oversimplified.DEBUG.showMessages&&console.log("This browser does not support loading from localStorage.");return!1},Oversimplified.Erase=function(e){if("undefined"!=typeof Storage)if(localStorage.getItem(e)){if(localStorage.removeItem(e),!localStorage.getItem(e))return Oversimplified.DEBUG.showMessages&&console.log('Successfully erased localStorage["'+e+'"].'),!0;Oversimplified.DEBUG.showMessages&&console.log('Could not erase localStorage["'+e+'"].')}else Oversimplified.DEBUG.showMessages&&console.log('There is no data to remove from localStorage["'+e+'"].');else Oversimplified.DEBUG.showMessages&&console.log("This browser does not support manipulating localStorage.");return!1},Oversimplified.DEBUG={showMessages:!0,DrawBoundingBox:function(e){var i=Oversimplified.context.fillStyle;Oversimplified.context.fillStyle="rgba(255, 0, 255, 0.5)",Oversimplified.context.fillRect(e.x-e.xBound-Oversimplified.camera.x,e.y-e.yBound-Oversimplified.camera.y,2*e.xBound,2*e.yBound),Oversimplified.context.fillStyle=i},CountObjectsInRoom:function(e){var i,s=0;i="undefined"!=typeof e?e.name?e:Oversimplified.Rooms[e]:Oversimplified.Rooms[Oversimplified.Rooms.currentRoom];for(var t in i.objects)s++;return s},objectsOnScreen:0,CountObjectsOnScreen:function(){return Oversimplified.DEBUG.objectsOnScreen},ListControls:function(){var e=0,i=0,s=0;for(var t in Oversimplified.Controls)if("undefined"!=typeof Oversimplified.Controls[t].Check){s++;var r='Oversimplified.C["'+t+'"] ';"Control"==Oversimplified.Controls[t].type&&(r+="(Control): "+Oversimplified.C[t].keyName,e++),"Axis"==Oversimplified.Controls[t].type&&(r+="(Axis) Positive: "+Oversimplified.C[t].positiveKeyName+", Negative: "+Oversimplified.C[t].negativeKeyName,i++),console.log(r)}console.log(e+" Controls and "+i+" Axes.\n"+s+" in all")}},window.onload=function(){Oversimplified.Initialize()},Oversimplified.Initialize=function(){Oversimplified.SetupCanvas(),Oversimplified.SetupControls(),Oversimplified.AddScript("start.js",function(){start(),Oversimplified.SetCanvasToCameraSize(),Oversimplified.Frame()})},Oversimplified.SetupCanvas=function(){Oversimplified.canvas=document.getElementById("game"),Oversimplified.canvas.getContext?Oversimplified.context=Oversimplified.canvas.getContext("2d"):alert("No 2D Canvas Context for game."),Oversimplified.Settings.preventRightClick&&(Oversimplified.canvas.oncontextmenu=function(){return!1})},Oversimplified.SetupControls=function(){Oversimplified.SetupMouseListeners(),Oversimplified.SetupKeyboardListeners()},Oversimplified.SetupMouseListeners=function(){Oversimplified.canvas.addEventListener("mousemove",function(e){var i=Oversimplified.canvas.getBoundingClientRect();Oversimplified.mouse.x=e.clientX-i.left+Oversimplified.camera.x,Oversimplified.mouse.y=e.clientY-i.top+Oversimplified.camera.y},!1),Oversimplified.canvas.addEventListener("mousedown",function(e){e.button===Oversimplified.mouse.leftCode?(Oversimplified.mouse.left||(Oversimplified.mouse.leftDown=!0),Oversimplified.mouse.left=!0):e.button===Oversimplified.mouse.middleCode?(e.preventDefault(),Oversimplified.mouse.middle||(Oversimplified.mouse.middleDown=!0),Oversimplified.mouse.middle=!0):e.button===Oversimplified.mouse.rightCode&&(Oversimplified.mouse.right||(Oversimplified.mouse.rightDown=!0),Oversimplified.mouse.right=!0)},!1),Oversimplified.canvas.addEventListener("mouseup",function(e){e.button===Oversimplified.mouse.leftCode?(Oversimplified.mouse.left=!1,Oversimplified.mouse.leftUp=!0):e.button===Oversimplified.mouse.middleCode?(Oversimplified.mouse.middle=!1,Oversimplified.mouse.middleUp=!0):e.button===Oversimplified.mouse.rightCode&&(Oversimplified.mouse.right=!1,Oversimplified.mouse.rightUp=!0)},!1),Oversimplified.canvas.addEventListener("mouseout",function(){Oversimplified.mouse.left=Oversimplified.mouse.middle=Oversimplified.mouse.right=!1},!1),Oversimplified.canvas.addEventListener("mousewheel",Oversimplified.MouseWheelHandler,!1),Oversimplified.canvas.addEventListener("DOMMouseScroll",Oversimplified.MouseWheelHandler,!1),Oversimplified.canvas.addEventListener("touchstart",function(e){switch(e.preventDefault(),e.targetTouches.length){case 1:Oversimplified.mouse.right=!1,Oversimplified.mouse.middle=!1,Oversimplified.mouse.left||(Oversimplified.mouse.leftDown=!0),Oversimplified.mouse.left=!0;break;case 2:Oversimplified.mouse.left=!1,Oversimplified.mouse.middle=!1,Oversimplified.mouse.right||(Oversimplified.mouse.rightDown=!0),Oversimplified.mouse.right=!0;break;case 3:Oversimplified.mouse.left=!1,Oversimplified.mouse.right=!1,Oversimplified.mouse.middle||(Oversimplified.mouse.middleDown=!0),Oversimplified.mouse.middle=!0}var i=Oversimplified.canvas.getBoundingClientRect();Oversimplified.mouse.x=e.targetTouches[0].clientX-i.left+Oversimplified.camera.x,Oversimplified.mouse.y=e.targetTouches[0].clientY-i.top+Oversimplified.camera.y},!1),Oversimplified.canvas.addEventListener("touchmove",function(e){e.preventDefault();var i=Oversimplified.canvas.getBoundingClientRect();Oversimplified.mouse.x=e.targetTouches[0].clientX-i.left+Oversimplified.camera.x,Oversimplified.mouse.y=e.targetTouches[0].clientY-i.top+Oversimplified.camera.y},!1),window.addEventListener("touchend",function(e){e.targetTouches.length<1?(Oversimplified.mouse.left&&(Oversimplified.mouse.leftUp=!0),Oversimplified.mouse.left=!1,Oversimplified.mouse.right=!1,Oversimplified.mouse.middle=!1):e.targetTouches.length<2?(Oversimplified.mouse.right&&(Oversimplified.mouse.rightUp=!0),Oversimplified.mouse.right=!1,Oversimplified.mouse.middle=!1):e.targetTouches.length<3&&(Oversimplified.mouse.middle&&(Oversimplified.mouse.middleUp=!0),Oversimplified.mouse.middle=!1)},!1)},Oversimplified.SetupKeyboardListeners=function(){window.addEventListener("keydown",function(e){[Oversimplified.Keycode.left,Oversimplified.Keycode.right,Oversimplified.Keycode.up,Oversimplified.Keycode.down,Oversimplified.Keycode.space,Oversimplified.Keycode.tab].indexOf(e.keyCode)>-1&&e.preventDefault()},!1),document.addEventListener("keydown",function(e){var i=e.which;-1==Oversimplified.pressedKeys.indexOf(i)&&-1==Oversimplified.heldKeys.indexOf(i)&&Oversimplified.pressedKeys.push(i),-1==Oversimplified.heldKeys.indexOf(i)&&Oversimplified.heldKeys.push(i)},!1),document.addEventListener("keyup",function(e){var i=e.which;Oversimplified.heldKeys.splice(Oversimplified.heldKeys.indexOf(i),1),-1==Oversimplified.releasedKeys.indexOf(i)&&Oversimplified.releasedKeys.push(i);
},!1)},Oversimplified.SetCanvasToCameraSize=function(){Oversimplified.canvas.width!=Oversimplified.camera.width&&(Oversimplified.DEBUG.showMessages&&console.log("Adjusting Camera Width from "+Oversimplified.canvas.width+" to "+Oversimplified.camera.width),Oversimplified.canvas.width=Oversimplified.camera.width),Oversimplified.canvas.height!=Oversimplified.camera.height&&(Oversimplified.DEBUG.showMessages&&console.log("Adjusting Camera Height from "+Oversimplified.canvas.height+" to "+Oversimplified.camera.height),Oversimplified.canvas.height=Oversimplified.camera.height)},Oversimplified.Frame=function(){if(Oversimplified.Settings.numberOfScriptsToLoad>0&&Oversimplified.loadedScripts.length==Oversimplified.Settings.numberOfScriptsToLoad||Oversimplified.Settings.numberOfScriptsToLoad<=0&&0==Oversimplified.loadingScripts.length){for(Oversimplified.now=Oversimplified.timestamp(),Oversimplified.dateTime=Oversimplified.dateTime+Math.min(1,(Oversimplified.now-Oversimplified.lastFrame)/1e3);Oversimplified.dateTime>Oversimplified.step;)Oversimplified.dateTime=Oversimplified.dateTime-Oversimplified.step,Oversimplified.Update(),Oversimplified.Draw(),Oversimplified.EndFrame();Oversimplified.lastFrame=Oversimplified.now}else{if(Oversimplified.DEBUG.showMessages){var e="Loaded "+Oversimplified.loadedScripts.length.toString();e+=Oversimplified.Settings.numberOfScriptsToLoad>0?" of "+Oversimplified.Settings.numberOfScriptsToLoad.toString():"",e+=" scripts:\n"+Oversimplified.loadedScripts.toString()+".\nWaiting for:\n"+Oversimplified.loadingScripts.toString(),console.log(e)}if(Oversimplified.Settings.numberOfScriptsToLoad>0){var i=Oversimplified.loadedScripts.length/Oversimplified.Settings.numberOfScriptsToLoad,s=32,t=Math.round(.6*Oversimplified.camera.width),r=Math.round(t*i),o=Math.round(.2*Oversimplified.camera.width),d=Math.round(.5*Oversimplified.camera.height)-Math.round(s/2),n=OS.context.fillStyle,m=OS.context.strokeStyle;OS.context.fillStyle="#DD5511",OS.context.fillRect(o,d,r,s),OS.context.strokeStyle="#882200",OS.context.lineWidth=5,OS.context.strokeRect(o,d,t,s),OS.context.fillStyle=n,OS.context.strokeStyle=m}}requestAnimationFrame(Oversimplified.Frame)},Oversimplified.Update=function(){Oversimplified.Controls.CheckAll(),Oversimplified.Rooms.AllBeforeDo(),Oversimplified.Rooms.AllDo(),"undefined"!=typeof Oversimplified.Rooms[Oversimplified.Rooms.currentRoom]?Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].Update():Oversimplified.DEBUG.showMessages&&console.log("There is no current room. Please add one or make sure you are referencing the correct room with Oversimplified.Rooms.SetRoom()."),Oversimplified.Rooms.AllAfterDo(),""!=Oversimplified.camera.following&&(Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].x-Oversimplified.camera.x>Oversimplified.camera.width-Oversimplified.camera.hBorder&&(Oversimplified.camera.x=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].x-(Oversimplified.camera.width-Oversimplified.camera.hBorder)),Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].x-Oversimplified.camera.x<Oversimplified.camera.hBorder&&(Oversimplified.camera.x=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].x-Oversimplified.camera.hBorder),Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].y-Oversimplified.camera.y>Oversimplified.camera.height-Oversimplified.camera.vBorder&&(Oversimplified.camera.y=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].y-(Oversimplified.camera.height-Oversimplified.camera.vBorder)),Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].y-Oversimplified.camera.y<Oversimplified.camera.vBorder&&(Oversimplified.camera.y=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].objects[Oversimplified.camera.following].y-Oversimplified.camera.vBorder)),Oversimplified.camera.x<0&&(Oversimplified.camera.x=0),Oversimplified.camera.x+Oversimplified.camera.width>Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].width&&(Oversimplified.camera.x=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].width-Oversimplified.camera.width),Oversimplified.camera.y<0&&(Oversimplified.camera.y=0),Oversimplified.camera.y+Oversimplified.camera.height>Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].height&&(Oversimplified.camera.y=Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].height-Oversimplified.camera.height)},Oversimplified.Draw=function(){Oversimplified.context.clearRect(0,0,Oversimplified.canvas.width,Oversimplified.canvas.height),Oversimplified.DEBUG.objectsOnScreen=0,"undefined"!=typeof Oversimplified.Rooms[Oversimplified.Rooms.currentRoom]?Oversimplified.Rooms[Oversimplified.Rooms.currentRoom].Draw():Oversimplified.DEBUG.showMessages&&console.log("There is no current room. Please add one or make sure you are referencing the correct room with Oversimplified.Rooms.SetRoom().")},Oversimplified.EndFrame=function(){Oversimplified.mouse.wheel=0,Oversimplified.mouse.leftDown=!1,Oversimplified.mouse.middleDown=!1,Oversimplified.mouse.rightDown=!1,Oversimplified.mouse.leftUp=!1,Oversimplified.mouse.middleUp=!1,Oversimplified.mouse.rightUp=!1,Oversimplified.pressedKeys=[],Oversimplified.releasedKeys=[]},Oversimplified.MouseWheelHandler=function(e){e.preventDefault(),Oversimplified.mouse.wheel=Math.max(-1,Math.min(1,e.wheelDelta||-e.detail))},Oversimplified.IsOnCamera=function(e,i){if("undefined"!=typeof i)return e>Oversimplified.camera.x&&e<Oversimplified.camera.x+Oversimplified.camera.width&&i>Oversimplified.camera.y&&i<Oversimplified.camera.y+Oversimplified.camera.height;var s=e;return s.x+s.xBound>Oversimplified.camera.x&&s.x-s.xBound<Oversimplified.camera.x+Oversimplified.camera.width&&s.y+s.yBound>Oversimplified.camera.y&&s.y-s.yBound<Oversimplified.camera.y+Oversimplified.camera.height},Oversimplified.AddScript=function(e,i){i="undefined"!=typeof i?i:e.slice(e.lastIndexOf("/")>-1?e.lastIndexOf("/")+1:0,e.indexOf(".")),Oversimplified.loadingScripts.push(e);var s=document.createElement("script");s.src=e,s.onload=function(){"string"!=typeof i?Oversimplified.WaitForScriptsToLoad(function(){i()}):"function"==typeof window[i]?Oversimplified.WaitForScriptsToLoad(function(){window[i]()}):Oversimplified.DEBUG.showMessages&&console.log(i+" is not a function!"),Oversimplified.loadedScripts.push(e),Oversimplified.loadingScripts.splice(Oversimplified.loadingScripts.indexOf(e),1)},document.body.appendChild(s)},Oversimplified.WaitForScriptsToLoad=function(e){Oversimplified.DEBUG.showMessages&&Oversimplified.Settings.numberOfScriptsToLoad>0&&console.log("Waiting for "+(Oversimplified.Settings.numberOfScriptsToLoad-Oversimplified.loadedScripts.length).toString()+" scripts to load"),Oversimplified.loadingScripts.length>0?setTimeout(function(){Oversimplified.WaitForScriptsToLoad(e)},.1):e()},Math.clamp=function(e,i,s){return i==s?(Oversimplified.DEBUG.showMessages&&console.log("Min and Max cannot be the same number!"),!1):i>s?(Oversimplified.DEBUG.showMessages&&console.log("Min must be less than Max!"),!1):(i>e&&(e=i),e>s&&(e=s),e)},Math.clamp01=function(e){return 0>e&&(e=0),e>1&&(e=1),e},Math.clampAngle=function(e,i,s){for(;e>=360;)e-=360;for(;0>e;)e+=360;if("undefined"!=typeof i&&"undefined"!=typeof s){for(;i>=360;)i-=360;for(;0>i;)i+=360;for(;s>=360;)s-=360;for(;0>s;)s+=360;if(i==s)return Oversimplified.DEBUG.showMessages&&console.log("Min and Max cannot be the same number!"),!1;if(i>s)return Oversimplified.DEBUG.showMessages&&console.log("Min must be less than Max!"),!1;i>e&&(e=i),e>s&&(e=s)}return e},Math.radToDeg=function(e){return e/(Math.PI/180)},Math.degToRad=function(e){return e*(Math.PI/180)},Math.getCos=function(e){return Math.cos(Math.degToRad(e))},Math.getSin=function(e){return Math.sin(Math.degToRad(e))},Math.coinFlip=function(){return Math.random()>=.5},Math.randomRange=function(e,i){return Math.random()*(i-e)+e};