OSDN Git Service

update
[yukkurioverwint/YukkuriOverwinter.git] / lib / FormSprite.js
index cb6a276..968fe3b 100644 (file)
@@ -1,8 +1,10 @@
 var FormSprite = enchant.Class.create({
        initialize: function (){
                this.spriteArray = [];
+               this.formSpriteArray = [];
                this.id = guid();
                this.mainIndex = 0;
+               this.shadowIndex = 0;
        },
        addChild:function(sprite, index, attr){
                this.add(sprite, index, attr);
@@ -12,6 +14,16 @@ var FormSprite = enchant.Class.create({
                sprite.id = guid();
                App.backgroundMap.addChild(sprite);
        },
+       addYukkuri: function(formSprite){
+               var addIndex = function (){
+                       var i = 0;
+                       return function(){
+                               return i++;
+                       };
+               }();
+               var index = addIndex();
+               this.formSpriteArray[index] = formSprite;
+       },
        // addChildAll:function(){
        //      for(var i=0;i<this.spriteArray.length;i++){
        //              if(this.spriteArray[i] === undefined)continue;
@@ -24,17 +36,23 @@ var FormSprite = enchant.Class.create({
        // },
        /**
        attr: 
-               mainIndex:true/false
+               mainIndexFlg:true/false
+               shadowIndexFlg:true/false
                type:body/tweet
+
        */
        add : function(sprite, index, attr){
                if(attr === undefined)attr = {};
                this.spriteArray[index] = sprite;
                this.spriteArray[index].type = attr.type;
                this.spriteArray[index].scaleValue = attr.scaleValue;
+               this.spriteArray[index].spname = attr.spname;
                if(attr.mainIndexFlg){
                        this.mainIndex = index;
                }
+               if(attr.shadowIndexFlg){
+                       this.shadowIndex = index;
+               }
                // this.spriteArray.push(sprite);
        },
        remove: function (sprite){
@@ -54,6 +72,73 @@ var FormSprite = enchant.Class.create({
                        spr.y += y;
                }
        },
+       /**
+       x
+       attr: targetTypes 許可するtypeを配列で指定する
+       */
+       addXAttr: function(x, attr){
+               for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
+                       var spr = this.spriteArray[i];
+                       if(!attr || attr.targetTypes.indexOf(spr.type) >= 0){
+                               spr.x += x;
+                       }
+               }
+       },
+       addYAttr: function(y, attr){
+               for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
+                       var spr = this.spriteArray[i];
+                       if(!attr || attr.targetTypes.indexOf(spr.type) >= 0){
+                               spr.y += y;
+                       }
+               }
+       },
+       setXAttr: function(x, attr){
+               for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
+                       var spr = this.spriteArray[i];
+                       if(!attr || attr.targetTypes.indexOf(spr.type) >= 0){
+                               spr.x = x;
+                       }
+               }
+       },
+       setYAttr: function(y, attr){
+               for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
+                       var spr = this.spriteArray[i];
+                       if(!attr || attr.targetTypes.indexOf(spr.type) >= 0){
+                               spr.y = y;
+                       }
+               }
+       },
+       calcField: function(field, value, attr){
+               for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
+                       var spr = this.spriteArray[i];
+                       if(!attr || attr.types.indexOf(spr.type) >= 0){
+                               if(attr.calc == "equal"){
+                                       spr[field] = value;
+                               }
+                               else if(attr.calc == "add"){
+                                       spr[field] -= value;
+                               }
+                               else{
+                                       spr[field] = value;
+                               }
+                       }
+               }
+       },
+       getMainSprite: function(){
+               return this.spriteArray[this.mainIndex];
+       },
+       getShadowSprite: function(){
+               return this.spriteArray[this.shadowIndex];
+       },
+       getMainShadowMarginY: function(){
+               if(!this.getShadowSprite())return 0;
+               return Math.round(this.getMainSprite().y - this.getShadowSprite().y);
+       },
        getX: function(){
                return Math.round(this.spriteArray[this.mainIndex].x,2) - this.spriteArray[this.mainIndex].baseX;
        },
@@ -74,6 +159,15 @@ var FormSprite = enchant.Class.create({
                        spr.y = y + spr.baseY;
                }
        },
+       addBodyY: function(y){
+               for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
+                       var spr = this.spriteArray[i];
+                       if(spr.type == "body" || spr.type == "budge"){
+                               this.spriteArray[i].y += y;
+                       }
+               }
+       },
        setFixBudgeLeft: function (index){
                this.spriteArray[index].x = this.spriteArray[this.mainIndex].x + this.spriteArray[this.mainIndex].width / 3 * 2;
                this.spriteArray[index].scaleX = 1;
@@ -81,6 +175,12 @@ var FormSprite = enchant.Class.create({
        setFixBudgeRight: function (index){
                this.spriteArray[index].x = this.spriteArray[this.mainIndex].x;
        },
+       setFixKukiLeft: function (){
+               this.calcField("x", this.getMainSprite().x - 30, {types:["kuki"],calc:"equal"});
+       },
+       setFixKukiRight: function (){
+               this.calcField("x", this.getMainSprite().x + 30, {types:["kuki"],calc:"equal"});
+       },
        formScaleX: function(x){
                for(var i=0;i<this.spriteArray.length;i++){
                        if(this.spriteArray[i] === undefined)continue;
@@ -143,12 +243,37 @@ var FormSprite = enchant.Class.create({
        tlQueueLength:function(){
                return this.spriteArray[this.mainIndex].tl.queue.length;
        },
-       animation: function(){
+       formRunAnimation: function(){
+               //影とボディの差異が強くなったら修正する
+               if(this.getMainShadowMarginY() < -8)this.addBodyY(+1);
+               else if(this.getMainShadowMarginY() > 0)this.addBodyY(-1);
+               
                for(var i=0;i<this.spriteArray.length;i++){
                        if(this.spriteArray[i] === undefined)continue;
                        var spr = this.spriteArray[i];
-                       if(spr.type == "body" || spr.type == "budge"){
-                               spr.anim.animrun();
+                       if(spr.type == "body" 
+                               || spr.type == "budge"
+                               || spr.type == "kuki"
+                               ){
+                               spr.anim.runAnim();
+                       }
+               }
+       },
+       formStartAnimation: function(){
+               for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
+                       var spr = this.spriteArray[i];
+                       if(spr.type == "body" || spr.type == "budge" || spr.type == "kuki"){
+                               spr.anim.startAnim();
+                       }
+               }
+       },
+       formStopAnimation: function(){
+               for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
+                       var spr = this.spriteArray[i];
+                       if(spr.type == "body" || spr.type == "budge" || spr.type == "kuki"){
+                               spr.anim.stopAnim();
                        }
                }
        },