diff --git a/Map.js b/Map.js index 94d3bde..a920e82 100644 --- a/Map.js +++ b/Map.js @@ -30,16 +30,34 @@ function Map() self.width = mapObj.width; self.tileSize = mapObj.tileSize; system.log("Loading Map: " + self.name); - mapObj.loadBackgroundAndForegroundAssets(self); - mapObj.loadCheckpoints(self); - mapObj.loadEvents(self); - mapObj.loadProps(self); - mapObj.loadLights(self); - mapObj.loadMapBGM(self); - mapObj.loadNavis(self); - mapObj.loadNPCs(self); - mapObj.loadPhysics(self); - mapObj.loadParticleEmitters(self); + self.loadBackgroundAndForegroundAssets(mapObj); + mapObj.initialize(self); + physics.addEntity(world.player); + var i = world.entity.length; + while(i--){ + if(world.entity[i].applyPhysics){ + physics.addEntity(world.entity[i]); + } + } + } + + this.loadBackgroundAndForegroundAssets = function(mapObj) + { + for(var x = 0; x < mapObj.width; x++) + { + self.background[x] = []; + self.foreground[x] = []; + for(var y = 0; y < mapObj.height; y++) + { + self.background[x][y] = new Image(); + self.foreground[x][y] = new Image(); + self.background[x][y].src = ('res/map/' + mapObj.name + '/image/' + x + '-' + y + 'bg.png'); + self.foreground[x][y].src = ('res/map/' + mapObj.name + '/image/' + x + '-' + y + 'fg.png'); + self.background[x][y].addEventListener('load', self.loadedAsset, false); + self.foreground[x][y].addEventListener('load', self.loadedAsset, false); + self.numAssets += 2; + } + } } this.loadedAsset = function() diff --git a/Map_Designer.js b/Map_Designer.js index 1a7dad0..1475ff8 100644 --- a/Map_Designer.js +++ b/Map_Designer.js @@ -326,9 +326,7 @@ function Map_Designer() break; } case'prop':{ - ani = select.animationBase; - world.addEntity(new Prop(select.name, input.screenX, input.screenY, select.height, select.width, select.foreground, - new Animation(ani.name,ani.texture,ani.start,ani.end,ani.tpt,ani.size,ani.sheetSize, ani.repeat), select.specialtyFunction)); + PROPS.get(select.basePropObject)(input.screenX, input.screenY); break; } case'collision':{ @@ -412,6 +410,61 @@ function Map_Designer() } } + this.checkSaveMap = function() + { //This function merely logs the rendered map file. JS can't write files like I need it to. + //Eventually, integrate with this: http://www.html5rocks.com/en/tutorials/file/filesystem/ + if(select == false && input.key["escape"] == 2){ + var d = new Date(); + var mapSave = "\n\n\n//************************************************************************\n"; + mapSave += "//*** MAP START - Copy the below into your map file. *********************\n"; + mapSave += "//************************************************************************\n" + mapSave += "\t\t//Map "+map.name+" Generated on "+d.getMonth()+"/"+d.getDate()+"/"+d.getFullYear()+"\n"; + $.each(map.bgm, function(k,v){ + mapSave += "\t\tmap.bgm['"+k+"'] = "+v+";\n" + }); + $.each(fx.getEffects(), function(k,v){ + if(this.type == 'emitter'){ + mapSave += "\t\tfx.addFXEmitter('"+this.name+"', "+this.x+", "+this.y+", "+this.life+", "+this.size+", "+this.al + +", '"+this.asset_or_color+"', '"+this.baseEmitterFuncName+"');\n" + } + }); + $.each(physics.collisionArea, function(k,v){ + mapSave += "\t\tphysics.addCollisionArea('"+this.name+"', "+this.x+", "+this.y+", "+this.h+", "+this.w+");\n" + }); + $.each(world.entity, function(){ + switch(this.type){ + case 'npc':{ + mapSave += "\t\tworld.addEntity(new Entity_NPC('"+this.name+"', "+this.x+", "+this.y+", "+this.speed + +", "+this.stepSize+", "+this.width+", "+this.height+", "+this.foreground+", '"+this.startAI+"', '"+this.secondAI+"'));\n" + break; + } + case 'prop':{ + mapSave += "\t\tPROPS.get('"+this.basePropObject+"')("+this.x+", "+this.y+");\n"; + break; + } + } + }); + $.each(map.navi.node, function(k,v){ + mapSave += "\t\tmap.navi.addNode('"+k+"', "+v.x+", "+v.y+", "+v.height+", "+v.width+", "+v.num+");\n"; + }); + $.each(map.lights, function(k,v){ + mapSave += "\t\tmap.lights.push(new Light('"+v.name+"', "+v.worldX+", "+v.worldY+", "+v.r+", "+v.g+", "+v.b + +", "+v.brightness+", "+v.baseRadius+", "+v.shader+", "+v.baseSpecFactor+", "+v.interact+"));\n"; + }); + $.each(map.em.events, function(k,v){ + mapSave += "\t\tmap.em.addEvent('"+k+"', "+v.x+", "+v.y+", "+v.height+", "+v.width+", "+v.active + +", '"+v.onEnterBase+"', '"+v.onActionBase+"', '"+v.onExitBase+"');\n"; + }); + $.each(map.checkpoint.checkpoint, function(k,v){ + mapSave += "\t\tmap.checkpoint.addCheckpoint('"+k+"', "+v.x+", "+v.y+", "+v.height+", "+v.width+", "+v.active+");\n"; + }); + mapSave += "//************************************************************************\n"; + mapSave += "//*** MAP END - Copy the above into your map file. ***********************\n"; + mapSave += "//************************************************************************"; + system.log(mapSave); + } + } + this.update = function() { x = input.screenX; @@ -432,5 +485,6 @@ function Map_Designer() } } } + self.checkSaveMap(); } } \ No newline at end of file diff --git a/Prop.js b/Prop.js index 7c19b92..b394bf8 100644 --- a/Prop.js +++ b/Prop.js @@ -1,4 +1,4 @@ -function Prop(NAME, X, Y, H, W, FOREGROUND, ANIMATION, SPECIALTY_FUNCTION) +function Prop(NAME, X, Y, H, W, FOREGROUND, ANIMATION, SPECIALTY_FUNCTION, BASE_PROP_OBJECT) { system.log("Constructing Prop: " + NAME); var self = this; @@ -13,6 +13,7 @@ function Prop(NAME, X, Y, H, W, FOREGROUND, ANIMATION, SPECIALTY_FUNCTION) self.animationBase = ANIMATION; animate.addPreMadeAnimation(self.animationBase.name, self.animationBase); self.specialtyFunction = SPECIALTY_FUNCTION; + self.basePropObject = BASE_PROP_OBJECT; this.update = function() { diff --git a/res/map/javabomb/javabomb.js b/res/map/javabomb/javabomb.js index 99e19ad..01ec758 100644 --- a/res/map/javabomb/javabomb.js +++ b/res/map/javabomb/javabomb.js @@ -6,26 +6,11 @@ function map_javabomb() self.width = 2; self.tileSize = 1024; - this.loadMapBGM = function(theMap) + this.initialize = function(map) { - theMap.bgm["chords"] = true; - } - - this.loadParticleEmitters = function(theMap) - { - //fx.addFXEmitter('explosion1', 500, 150, -1/*emitter*/, 50, true, 'rgb(255,0,0)', 'explosion-emitter'); - fx.addFXEmitter('explosion1', 500, 150, -1/*emitter*/, 50, true, 'muteOn', 'explosion-emitter'); - } - - this.loadPhysics = function(theMap) - { - physics.addEntity(world.player); - var i = world.entity.length; - while(i--){ - if(world.entity[i].applyPhysics){ - physics.addEntity(world.entity[i]); - } - } + //Map javabomb Generated on 3/27/2013 + map.bgm['chords'] = true; + fx.addFXEmitter('explosion1', 500, 150, -1, 50, true, 'muteOn', 'explosion-emitter'); physics.addCollisionArea('col1', 450, 290, 15, 900); physics.addCollisionArea('col2', 867, 302, 10, 100); physics.addCollisionArea('col3', 887, 312, 10, 100); @@ -37,71 +22,27 @@ function map_javabomb() physics.addCollisionArea('col9', 1450, 382, 15, 1050); physics.addCollisionArea('col10', 1970, 288, 200, 15); physics.addCollisionArea('col11', 1108, 130, 200, 25); - } - - this.loadNPCs = function(theMap) - { - world.addEntity( new Entity_NPC('test1', 1425/*X*/, 150/*Y*/, 300/*speed*/, 0.25/*step size*/, 48/*W*/, 128/*H*/, false/*Foreground*/, 'base_idle'/*Script*/, 'base_secondary_update') ); - } - - this.loadNavis = function(theMap) - { - theMap.navi.addNode('start', 250, 219, 32, 32, 0); - theMap.navi.addNode('node2', 500, 219, 32, 32, 1); - theMap.navi.addNode('node3', 800, 219, 32, 32, 2); - theMap.navi.addNode('node4', 1200, 300, 32, 32, 3); - theMap.navi.addNode('node5', 1450, 350, 32, 32, 4); - } - - this.loadLights = function(theMap) - { - system.log("Initializing World Lights..."); - theMap.lights.push(new Light('Light1', 1000/*x*/, 400/*Y*/, 0/*R*/, 0/*G*/, 0/*B*/, 90/*brightness*/, 300/*radius*/, 0/*shader*/, 0.0/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light2', 76/*x*/, 165/*Y*/, 150/*R*/, 10/*G*/, 0/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light3', 210/*x*/, 165/*Y*/, 150/*R*/, 150/*G*/, 10/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light4', 366/*x*/, 165/*Y*/, 10/*R*/, 150/*G*/, 150/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light5', 518/*x*/, 165/*Y*/, 150/*R*/, 10/*G*/, 150/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light6', 670/*x*/, 165/*Y*/, 10/*R*/, 150/*G*/, 150/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light7', 820/*x*/, 165/*Y*/, 10/*R*/, 150/*G*/, 10/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light8', 1220/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light9', 1425/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light10', 1627/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light11', 1825/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - } - - this.loadProps = function(theMap) - { + world.addEntity(new Entity_NPC('test1', 1425, 310.5, 300, 0.25, 48, 128, false, 'base_idle', 'base_secondary_update')); PROPS.get('testprop1')(500, 180); - } - - this.loadEvents = function(theMap) - { - theMap.em.addEvent('endOfLevel', 1500, 340, 64, 100, true, 'endOfLevel1', 'null', 'null'); - } - - this.loadCheckpoints = function(theMap) - { - theMap.checkpoint.addCheckpoint('spot2', 700, 219, 32, 32, false); - theMap.checkpoint.addCheckpoint('start', 400, 219, 32, 32, true); - } - - this.loadBackgroundAndForegroundAssets = function(theMap) - { - for(var x = 0; x < self.width; x++) - { - theMap.background[x] = []; - theMap.foreground[x] = []; - for(var y = 0; y < self.height; y++) - { - theMap.background[x][y] = new Image(); - theMap.foreground[x][y] = new Image(); - theMap.background[x][y].src = ('res/map/' + self.name + '/image/' + x + '-' + y + 'bg.png'); - theMap.foreground[x][y].src = ('res/map/' + self.name + '/image/' + x + '-' + y + 'fg.png'); - theMap.background[x][y].addEventListener('load', theMap.loadedAsset, false); - theMap.foreground[x][y].addEventListener('load', theMap.loadedAsset, false); - theMap.numAssets += 2; - } - } + map.navi.addNode('start', 250, 219, 32, 32, 0); + map.navi.addNode('node2', 500, 219, 32, 32, 1); + map.navi.addNode('node3', 800, 219, 32, 32, 2); + map.navi.addNode('node4', 1200, 300, 32, 32, 3); + map.navi.addNode('node5', 1450, 350, 32, 32, 4); + map.lights.push(new Light('Light1', 1000, 400, 0, 0, 0, 90, 300, 0, 0, true)); + map.lights.push(new Light('Light2', 76, 165, 150, 10, 0, 50, 250, 1, 0.5, true)); + map.lights.push(new Light('Light3', 210, 165, 150, 150, 10, 50, 250, 1, 0.5, true)); + map.lights.push(new Light('Light4', 366, 165, 10, 150, 150, 50, 250, 1, 0.5, true)); + map.lights.push(new Light('Light5', 518, 165, 150, 10, 150, 50, 250, 1, 0.5, true)); + map.lights.push(new Light('Light6', 670, 165, 10, 150, 150, 50, 250, 1, 0.5, true)); + map.lights.push(new Light('Light7', 820, 165, 10, 150, 10, 50, 250, 1, 0.5, true)); + map.lights.push(new Light('Light8', 1220, 335, 10, 10, 250, 60, 250, 1, 0.5, true)); + map.lights.push(new Light('Light9', 1425, 335, 10, 10, 250, 60, 250, 1, 0.5, true)); + map.lights.push(new Light('Light10', 1627, 335, 10, 10, 250, 60, 250, 1, 0.5, true)); + map.lights.push(new Light('Light11', 1825, 335, 10, 10, 250, 60, 250, 1, 0.5, true)); + map.em.addEvent('endOfLevel', 1500, 340, 64, 100, true, 'endOfLevel1', 'null', 'null'); + map.checkpoint.addCheckpoint('spot2', 700, 219, 32, 32, false); + map.checkpoint.addCheckpoint('start', 400, 219, 32, 32, true); } } MAP_STORE.add('javabomb', new map_javabomb()); \ No newline at end of file diff --git a/res/map/javabomb2/javabomb2.js b/res/map/javabomb2/javabomb2.js index cc2e146..12f4687 100644 --- a/res/map/javabomb2/javabomb2.js +++ b/res/map/javabomb2/javabomb2.js @@ -6,25 +6,11 @@ function map_javabomb2() self.width = 2; self.tileSize = 1024; - this.loadMapBGM = function(theMap) - { - theMap.bgm["chords"] = true; - } - - this.loadParticleEmitters = function(theMap) + this.initialize = function(map) { + map.bgm["chords"] = true; + fx.addFXEmitter('explosion1', 500, 150, -1/*emitter*/, 50, true, 'rgb(255,0,0)', 'explosion-emitter'); fx.addFXEmitter('explosion1', 500, 150, -1/*emitter*/, 50, true, 'rgb(255,0,0)', 'explosion-emitter'); - } - - this.loadPhysics = function(theMap) - { - physics.addEntity(world.player); - var i = world.entity.length; - while(i--){ - if(world.entity[i].applyPhysics){ - physics.addEntity(world.entity[i]); - } - } physics.addCollisionArea('col1', 390, 290, 15, 900); physics.addCollisionArea('col2', 797, 302, 10, 100); physics.addCollisionArea('col3', 817, 312, 10, 100); @@ -36,67 +22,23 @@ function map_javabomb2() physics.addCollisionArea('col9', 1450, 382, 15, 1050); physics.addCollisionArea('col10', 1970, 288, 200, 15); physics.addCollisionArea('col11', 1108, 130, 200, 25); - } - - this.loadNPCs = function(theMap) - { world.addEntity( new Entity_NPC('test1', 1425/*X*/, 150/*Y*/, 300/*speed*/, 0.25/*step size*/, 48/*W*/, 128/*H*/, false/*Foreground*/, 'base_idle'/*Script*/, 'base_secondary_update') ); - } - - this.loadNavis = function(theMap) - { - theMap.navi.addNode('start', 250, 219, 32, 32, 0); - theMap.navi.addNode('node2', 500, 219, 32, 32, 1); - theMap.navi.addNode('node3', 800, 219, 32, 32, 2); - theMap.navi.addNode('node4', 1200, 300, 32, 32, 3); - theMap.navi.addNode('node5', 1450, 350, 32, 32, 4); - } - - this.loadLights = function(theMap) - { - system.log("Initializing World Lights..."); - theMap.lights.push(new Light('Light1', 1000/*x*/, 400/*Y*/, 0/*R*/, 0/*G*/, 0/*B*/, 90/*brightness*/, 300/*radius*/, 0/*shader*/, 0.0/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light3', 210/*x*/, 165/*Y*/, 150/*R*/, 150/*G*/, 10/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light5', 518/*x*/, 165/*Y*/, 150/*R*/, 10/*G*/, 150/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light7', 820/*x*/, 165/*Y*/, 10/*R*/, 150/*G*/, 10/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light8', 1220/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light10', 1627/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - theMap.lights.push(new Light('Light11', 1825/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); - } - - this.loadProps = function(theMap) - { + map.navi.addNode('start', 250, 219, 32, 32, 0); + map.navi.addNode('node2', 500, 219, 32, 32, 1); + map.navi.addNode('node3', 800, 219, 32, 32, 2); + map.navi.addNode('node4', 1200, 300, 32, 32, 3); + map.navi.addNode('node5', 1450, 350, 32, 32, 4); + map.lights.push(new Light('Light1', 1000/*x*/, 400/*Y*/, 0/*R*/, 0/*G*/, 0/*B*/, 90/*brightness*/, 300/*radius*/, 0/*shader*/, 0.0/*specFactor*/, true/*interraction*/)); + map.lights.push(new Light('Light3', 210/*x*/, 165/*Y*/, 150/*R*/, 150/*G*/, 10/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); + map.lights.push(new Light('Light5', 518/*x*/, 165/*Y*/, 150/*R*/, 10/*G*/, 150/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); + map.lights.push(new Light('Light7', 820/*x*/, 165/*Y*/, 10/*R*/, 150/*G*/, 10/*B*/, 50/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); + map.lights.push(new Light('Light8', 1220/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); + map.lights.push(new Light('Light10', 1627/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); + map.lights.push(new Light('Light11', 1825/*x*/, 335/*Y*/, 10/*R*/, 10/*G*/, 250/*B*/, 60/*brightness*/, 250/*radius*/, 1/*shader*/, 0.5/*specFactor*/, true/*interraction*/)); PROPS.get('testprop1')(500, 180); - } - - this.loadEvents = function(theMap) - { - theMap.em.addEvent('endOfLevel', 1500, 340, 64, 100, true, 'endOfLevel2', 'null', 'null'); - } - - this.loadCheckpoints = function(theMap) - { - theMap.checkpoint.addCheckpoint('spot2', 700, 219, 32, 32, false); - theMap.checkpoint.addCheckpoint('start', 400, 219, 32, 32, true); - } - - this.loadBackgroundAndForegroundAssets = function(theMap) - { - for(var x = 0; x < self.width; x++) - { - theMap.background[x] = []; - theMap.foreground[x] = []; - for(var y = 0; y < self.height; y++) - { - theMap.background[x][y] = new Image(); - theMap.foreground[x][y] = new Image(); - theMap.background[x][y].src = ('res/map/' + self.name + '/image/' + x + '-' + y + 'bg.png'); - theMap.foreground[x][y].src = ('res/map/' + self.name + '/image/' + x + '-' + y + 'fg.png'); - theMap.background[x][y].addEventListener('load', theMap.loadedAsset, false); - theMap.foreground[x][y].addEventListener('load', theMap.loadedAsset, false); - theMap.numAssets += 2; - } - } + map.em.addEvent('endOfLevel', 1500, 340, 64, 100, true, 'endOfLevel2', 'null', 'null'); + map.checkpoint.addCheckpoint('spot2', 700, 219, 32, 32, false); + map.checkpoint.addCheckpoint('start', 400, 219, 32, 32, true); } } MAP_STORE.add('javabomb2', new map_javabomb2()); \ No newline at end of file diff --git a/scripts/prop/props/Chapter_1.js b/scripts/prop/props/Chapter_1.js index df04720..c7208a2 100644 --- a/scripts/prop/props/Chapter_1.js +++ b/scripts/prop/props/Chapter_1.js @@ -4,5 +4,5 @@ PROPS.add('testprop1', function(X, Y){ function(){ //example prop //this.x += 20 * clock.delta; - })); + }, "testprop1")); }); \ No newline at end of file