OSDN Git Service

HorizonalStageからmanagerがうまく読めていないようだ
authorttwilb <ttwilb@users.sourceforge.jp>
Sun, 4 Aug 2013 16:07:13 +0000 (01:07 +0900)
committerttwilb <ttwilb@users.sourceforge.jp>
Sun, 4 Aug 2013 16:07:13 +0000 (01:07 +0900)
new GameStage を new HorizonalScrollStageClassにするとばぐる

その他いろいろ

documents/ClassTree.txt
www/corelib/classes/GameStageClass.js
www/corelib/classes/HorizonalScrollStageClass.js
www/corelib/classes/StageObjectClass.js
www/corelib/core.js
www/index_local_debug.html

index e69de29..9971a0a 100644 (file)
@@ -0,0 +1,8 @@
+GameStage
+       HorizonalScrollStageClass
+StageObject
+       MovableStageObjectClass
+               CharacterClass
+                       OperatedCharacterClass
+       BlockStageObjectClass
+       
\ No newline at end of file
index fbbba70..d998917 100644 (file)
@@ -45,16 +45,52 @@ GameStage.prototype = {
                this.tickCount++;
                drawText(this.debugContext, "tick:" + this.tickCount, 0, 20);
                
+               //\91S\82Ä\82Ì\83I\83u\83W\83F\83N\83g\82ð\8cv\8eZ
+               for(var sp in this.stageObjectList)
+               {
+                       var tickAllObjects = true;
+                       
+                       //\82Ü\82¸ \83N\83\89\83X\92è\8b`.tick() (\97á\82¦\82ÎBlockStageObjectClass.tick = function(){};) \82ª\92è\8b`\82³\82ê\82Ä\82½\82ç\8eÀ\8ds
+                       if(sp.tick)
+                       {
+                               tickAllObjects = sp.tick(this.stageObjectList[sp]);
+                       }
+                       
+                       //\8e\9f\82É\8ae\8eíStageObject\82Ìtick\82ð\8eÀ\8ds
+                       if(tickAllObjects)
+                       {
+                               for(i = 0; i < this.stageObjectList[sp].length; i++){
+                                       
+                                       this.stageObjectList[sp][i].tick();
+                                       
+                               }
+                       }
+               }
+               
+               //\97á\82¦\82Î\8f\88\97\9d\82Ì\92x\89\84\82Å\96\9e\91«\82Édraw\82Å\82«\82È\82¢\82Æ\82«\82É\82Í\82µ\82å\82ê\82é\82æ\82¤draw\82Í\95Ê\8f\88\97\9d\82É\82µ\82½
+               
+       },
+       draw: function(){
+               this.drawBackground();
+               this.drawAsPoint(0, 0);
+       },
+       drawAsPoint: function(x, y){
+               //\82·\82×\82Ä\83I\83u\83W\83F\83N\83g\8dÄ\95`\89æ
+               for(var sp in this.stageObjectList)
+               {
+                       //\8e\9f\82É\8ae\8eíStageObject\82Ìdraw\82ð\8eÀ\8ds
+                       for(i = 0; i < this.stageObjectList[sp].length; i++){
+                               
+                               var stgobj = this.stageObjectList[sp][i];
+                               stgobj.draw(stgobj.origin.x - x, stgobj.origin.y - y);
+                               
+                       }
+               }
+       },
+       drawBackground: function(){
                //\83L\83\83\83\93\83o\83X\82ð\91S\8fÁ\8b\8e
                this.mainContext.clearRect(0, 0, this.mainCanvas.width, this.mainCanvas.height);
                this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width * 8, this.collisionMapCanvas.height * 8);
-               //\91S\82Ä\82Ì\83I\83u\83W\83F\83N\83g\82ð\8dÄ\95`\89æ
-               
-               for(i = 0; i < this.stageObjectList.length; i++){
-                       //console.log(this.stageObjectList[i]);
-                       this.stageObjectList[i].tick();
-                       
-               }
        },
        runStage: function(){
                //\83X\83e\81[\83W\8f\89\8aú\89»\8f\88\97\9d
@@ -74,12 +110,24 @@ GameStage.prototype = {
                this.stageObjectList = null;
        },
        addStageObject: function(aStageObject){
-               //StageObject\92Ç\89Á\8f\88\97\9d
-               this.stageObjectList.push(aStageObject);
+       
+               var sp = aStageObject.constructor;
+               if(!this.stageObjectList[sp])
+               {
+                       this.stageObjectList[sp] = [];
+               }
+               this.stageObjectList[sp].push(aStageObject);
        },
        removeStageObject: function(aStageObject){
-               //StageObject\8dí\8f\9c\8f\88\97\9d
-               removeObjectFromArray(this.stageObjectList, aStageObject);
+               var sp = aStageObject.constructor;
+               if(this.stageObjectList[sp])
+               {
+                       removeObjectFromArray(this.stageObjectList[sp], aStageObject);
+                       if(this.stageObjectList[sp].length == 0)
+                       {
+                               removeObjectFromArray(this.stageObjectList, sp);
+                       }
+               }
        }
 };
 
index 2e9a4dc..d732335 100644 (file)
@@ -1,9 +1,40 @@
 
-var HorizonalScrollStageClass = function()
+var HorizonalScrollStageClass = function(opCharacter)
 {
        HorizonalScrollStageClass.base.apply(this, []);
+       
+       console.log(this.manager);
+       
        //\8c»\8dÝ\91\80\8dì\91Î\8fÛ\82É\82È\82Á\82Ä\82¢\82é\83L\83\83\83\89\83N\83^\81[\81B
-       var /* OperatedCaracterClass */ OperatingCharacter;
+       var /* OperatedCaracterClass */ OperatingCharacter = opCharacter;
+       
+       //\94w\8ci\82Ì\89æ\91\9c
+       var background = null;
+       
+       var scrollX = 0;
+       var scrollMaxX =1280 - 640;     //\83X\83e\81[\83W\82Ì\89¡\82Ì\92·\82³-640
        
-}.extend(GameStage);
+}.extend(GameStage, {
+       timerTick: function(){
+               this.constructor.base.timerTick.call(this);
+               this.scrollX = opCharacter.origin.x;
+               if(this.scrollX > this.scrollMaxX) this.scrollX = this.scrollMaxX;
+       },
+       draw: function()
+       {
+               this.drawBackground();
+               this.drawAsPoint(scrollX, 0);
+       },
+       drawBackground: function(){
+               if(this.background)
+               {
+                       this.mainContext.drawImage(background, 0, 0, 640, 480);
+               }else
+               {
+                       //\83L\83\83\83\93\83o\83X\82ð\91S\8fÁ\8b\8e
+                       this.mainContext.clearRect(0, 0, this.mainCanvas.width, this.mainCanvas.height);
+                       this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width * 8, this.collisionMapCanvas.height * 8);
+               }
+       }
+});
 
index 12793d9..eb7298a 100644 (file)
@@ -14,10 +14,9 @@ function StageObject(ownerStage){
 StageObject.prototype = {
        tick: function(){
                //\8dÄ\95`\89æ\82Ì\83^\83C\83~\83\93\83O\82²\82Æ\82É\8cÄ\82Î\82ê\82é\81B
-               this.display();
        },
        
-       display: function(){
+       draw: function(){
                //\8eÀ\8dÛ\82Ì\95`\89æ\82Ì\82Ý\82ð\8ds\82¤\81B\8cv\8eZ\82Ítick\82Å\8ds\82¤\81B
                
        }
index c7c8dc6..19d7e27 100755 (executable)
@@ -263,7 +263,6 @@ GameManager.prototype = {
        },
        loadStageFromLocal: function(code, onLoaded){
                var stage = eval(code);
-               console.log(code);
                mainManager.runStage(stage);
        },
        loadStageFromNetwork: function(name, onLoaded){
index 7b8de2f..14906dc 100644 (file)
@@ -8,6 +8,15 @@
 <script type="text/javascript" src="./corelib/header.js" charset="UTF-8"></script>
 <script type="text/javascript">
 
+onload = function()
+{
+       var val = localStorage.getItem("savedat");
+       if(val)
+       {
+               document.getElementById("stageCode").value = val;
+       }
+};
+
 var mainManager = null;
 var run = function() {
        
@@ -25,6 +34,11 @@ function reset(){
        }
 }
 
+function save()
+{
+       localStorage.setItem('savedat', document.getElementById('stageCode').value);
+}
+
 </script>
 </head>
 <body>
@@ -93,7 +107,8 @@ stage;
 
                
                </textarea>
-               <input type="button" onclick="run(); return false;" value="run"><input type="button" onclick="reset(); return false;" value="reset">
+               <input type="button" onclick="run(); return false;" value="run"><!--<input type="button" onclick="reset(); return false;" value="reset">--><input type="button" onclick="save(); return false;" value="save"><br>
+               ※すべてのコードを消したうえでセーブし更新すると最初のコードに戻ります。
                </form>
        </div>
 </body>