OSDN Git Service

バッチの修正
authornagoling <>
Mon, 16 Dec 2013 22:05:18 +0000 (07:05 +0900)
committernagomi <nagomi@192.168.1.23>
Mon, 16 Dec 2013 22:05:18 +0000 (07:05 +0900)
lib/FormSprite.js
main.js

index 0f289c6..cb6a276 100644 (file)
@@ -4,15 +4,24 @@ var FormSprite = enchant.Class.create({
                this.id = guid();
                this.mainIndex = 0;
        },
-       addChildAll:function(){
-               for(var i=0;i<this.spriteArray.length;i++){
-                       this.spriteArray[i].baseX = this.spriteArray[i].x;
-                       this.spriteArray[i].baseY = this.spriteArray[i].y;
-                       this.spriteArray[i].anim = new Animation(this.spriteArray[i]);
-                       this.spriteArray[i].id = guid();
-                       App.backgroundMap.addChild(this.spriteArray[i]);
-               }
-       },
+       addChild:function(sprite, index, attr){
+               this.add(sprite, index, attr);
+               sprite.baseX = sprite.x;
+               sprite.baseY = sprite.y;
+               sprite.anim = new Animation(sprite);
+               sprite.id = guid();
+               App.backgroundMap.addChild(sprite);
+       },
+       // addChildAll:function(){
+       //      for(var i=0;i<this.spriteArray.length;i++){
+       //              if(this.spriteArray[i] === undefined)continue;
+       //              this.spriteArray[i].baseX = this.spriteArray[i].x;
+       //              this.spriteArray[i].baseY = this.spriteArray[i].y;
+       //              this.spriteArray[i].anim = new Animation(this.spriteArray[i]);
+       //              this.spriteArray[i].id = guid();
+       //              App.backgroundMap.addChild(this.spriteArray[i]);
+       //      }
+       // },
        /**
        attr: 
                mainIndex:true/false
@@ -33,12 +42,14 @@ var FormSprite = enchant.Class.create({
        },
        addX: function(x){
                for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
                        var spr = this.spriteArray[i];
                        spr.x += x;
                }
        },
        addY: function(y){
                for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
                        var spr = this.spriteArray[i];
                        spr.y += y;
                }
@@ -51,18 +62,28 @@ var FormSprite = enchant.Class.create({
        },
        setX: function(x){
                for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
                        var spr = this.spriteArray[i];
                        spr.x = x + spr.baseX;
                }
        },
        setY: function(y){
                for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
                        var spr = this.spriteArray[i];
                        spr.y = y + spr.baseY;
                }
        },
+       setFixBudgeLeft: function (index){
+               this.spriteArray[index].x = this.spriteArray[this.mainIndex].x + this.spriteArray[this.mainIndex].width / 3 * 2;
+               this.spriteArray[index].scaleX = 1;
+       },
+       setFixBudgeRight: function (index){
+               this.spriteArray[index].x = this.spriteArray[this.mainIndex].x;
+       },
        formScaleX: function(x){
                for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
                        var spr = this.spriteArray[i];
                        if(spr.type == "tweet")continue;
                        spr.scaleX = x;
@@ -70,6 +91,7 @@ var FormSprite = enchant.Class.create({
        },
        formScaleY: 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 == "tweet")continue;
                        spr.scaleY = y;
@@ -85,14 +107,12 @@ var FormSprite = enchant.Class.create({
        tlMoveBy:function(x, y, time, eventFunctions){
                var self = this;
                for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
                        var spr = this.spriteArray[i];
                        if(spr.type == "tweet")continue;
 
-                       // var addX = x + spr.baseX;
-                       // var addY = y + spr.baseX;
                        var addX = x;
                        var addY = y;
-                       // console.log(i+":spry:" + spr.y);
                        var params = {
                                x: this.paramX(spr.x, addX),
                                y: this.paramY(spr.y, addY),
@@ -109,15 +129,13 @@ var FormSprite = enchant.Class.create({
        },
        paramX : function(x, addX){
                return x  + addX;
-               // return function(){
-               //      return x  + addX;
-               // }
        },
        paramY : function(y, addY){
                return y + addY;
        },
        tlMoveTo:function(x, y, time, easing ){
                for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
                        var spr = this.spriteArray[i];
                        spr.tl.moveTo(x, y, time, easing);
                }
@@ -127,14 +145,16 @@ var FormSprite = enchant.Class.create({
        },
        animation: 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"){
+                       if(spr.type == "body" || spr.type == "budge"){
                                spr.anim.animrun();
                        }
                }
        },
        scale: function(_scaleX,_scaleY){
                for(var i=0;i<this.spriteArray.length;i++){
+                       if(this.spriteArray[i] === undefined)continue;
                        var spr = this.spriteArray[i];
                        if(spr.type == "tweet")continue;
                        spr.scale(_scaleX, _scaleY);
diff --git a/main.js b/main.js
index 96bf118..eeb810d 100644 (file)
--- a/main.js
+++ b/main.js
@@ -33,7 +33,7 @@ var CHARA_WIDTH = 64;
 var CHARA_HEIGHT = 64;
 var GAME_WIDTH = 800;
 var GAME_HEIGHT = 600;
-var FPS = 40;
+var FPS = 20;
 var BASE_FPS = 20;
 var HUNGRY_MAX = 100;
 var TIME_SPEED = 4;
@@ -337,31 +337,47 @@ window.onload = function(){
                if(b instanceof Box){
                        return -1;
                }
+               var budgeValue = 10 + 28;
+               var shadowValue = -28;
+               //okazariは他のbodyと比べて11低い
+               var okazariValue = 37 + 11;
+               var bodyValue = 37;
+               var tweetValue = 148;
+
                if(a.type == "shadow"){
-                       ay += -28 * a.scaleValue;
+                       ay += shadowValue * a.scaleValue;
                }
-               if(b.type == "shadow"){
-                       by += -28 * b.scaleValue;
+               else if(a.type == "body" && a.classname == "Okazari"){
+                       ay += okazariValue * a.scaleValue - a.anim.cnt;
                }
-               if(a.classname == "Okazari"){
-                       ay += 11 * a.scaleValue;
+               else if(a.type == "body"){
+                       ay += bodyValue * a.scaleValue - a.anim.cnt;
                }
-               if(b.classname == "Okazari"){
-                       by += 11 * b.scaleValue;
+               else if(a.type == "tweet"){
+                       ay += tweetValue * a.scaleValue;
                }
-               if(a.type == "body"){
-                       ay += 32 * a.scaleValue;
+               else if(a.type == "budge"){
+                       ay += budgeValue * a.scaleValue - a.anim.cnt;
                }
-               else if(a.type == "tweet"){
-                       ay += 148 * a.scaleValue;
+
+               if(b.type == "shadow"){
+                       by += shadowValue * b.scaleValue;
                }
-               if(b.type == "body"){
-                       by += 32 * b.scaleValue;
+
+               else if(b.type == "body" && b.classname == "Okazari"){
+                       by += okazariValue * b.scaleValue - b.anim.cnt;
+               }
+               else if(b.type == "body"){
+                       by += bodyValue * b.scaleValue - b.anim.cnt;
                }
                else if(b.type == "tweet"){
-                       by += 148 * b.scaleValue;
+                       by += tweetValue * b.scaleValue;
+               }
+               else if(b.type == "budge"){
+                       by += budgeValue * b.scaleValue - b.anim.cnt;
                }
 
+
                if(a instanceof SpriteGroup){
                        ay = a.y;
                        ay += a.height/2;
@@ -377,15 +393,15 @@ window.onload = function(){
                if(b instanceof Place){
                        by += Math.round(b.height * 0.7);
                }
-               if(a.flgMiYukkuri){
-                       ay += CHARA_HEIGHT;
-               }
-               if(b.flgMiYukkuri){
-                       by += CHARA_HEIGHT;
-               }
+               // if(a.flgMiYukkuri){
+               //      ay += CHARA_HEIGHT;
+               // }
+               // if(b.flgMiYukkuri){
+               //      by += CHARA_HEIGHT;
+               // }
 
-               if(ay < by)return -1;
-               else if(ay > by)return 1;
+               if(Math.round(ay) < Math.round(by))return -1;
+               else if(Math.round(ay) > Math.round(by))return 1;
                if(a.id < b.id)return -1;
                else if(a.id > b.id)return 1;
                return 0;
@@ -1197,8 +1213,8 @@ window.onload = function(){
                        //food distance
                        if(this.data.type == "food"){
                                this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
-                               yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
-                               yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
+                               yukkuri.vx = node.x - yukkuri.getX() + node.width / 2 + yukkuri.getWidth() / 2;
+                               yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2 + yukkuri.getHeight() / 2;
                                var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
                                var frame = distance + distance/5 + 1;
                                frame += plusFrameScale(frame, this.yukkuri.getMyScale());
@@ -1241,8 +1257,8 @@ window.onload = function(){
                        //food distance
                        if(this.data.type == "food"){
                                this.action.setStatus(EAction.WAIT);
-                               yukkuri.vx = nodeX - yukkuri.getX();
-                               yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2;
+                               yukkuri.vx = nodeX - yukkuri.getX() + yukkuri.getWidth() / 2;
+                               yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2 + yukkuri.getHeight() / 2;
                                var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
                                var frame = distance + distance/5 + 1;
                                frame += plusFrameScale(frame, this.yukkuri.getMyScale());
@@ -2015,7 +2031,7 @@ window.onload = function(){
                                                // this.kukis[0].miYukkuris[0].animY(-_y);
                                        }
                                        // console.log(this.getX() + ":" + this.getY());
-                                       this.act();
+                                       // this.act();
                                        if(this.isDead())return;
                                        this.runYukkuri();
                                        this.runHungry();
@@ -2032,12 +2048,18 @@ window.onload = function(){
                reverse:function(){
                        if(this.direction == EDirection.RIGHT){
                                this.formSprite.formScaleX(this.myScaleX);
+                               if(this instanceof Player){
+                                       this.formSprite.setFixBudgeRight(5);
+                               }
                                // this.formSprite.formScaleY(this.myScale);
 
                                // this.imgBody.scaleX = 1;
                        }
                        else if(this.direction == EDirection.LEFT){
                                this.formSprite.formScaleX(-this.myScaleX);
+                               if(this instanceof Player){
+                                       this.formSprite.setFixBudgeLeft(5);
+                               }
                                // this.formSprite.formScaleY(this.myScale);
                                // this.imgBody.scaleX = -1;
                        }
@@ -2592,19 +2614,23 @@ window.onload = function(){
                        this.kukis[3] = new Kuki(this, -5, 5);
                        this._tweet = new TTweet(this, 148, 64);
 
-                       this.formSprite.add(this.shadow,0,{type:"shadow",scaleValue:this.myScaleY});
-                       this.formSprite.add(this, 1, {
+                       this.formSprite.addChild(this.shadow,0,{type:"shadow",scaleValue:this.myScaleY});
+                       this.formSprite.addChild(this, 1, {
                                mainIndexFlg:true,
                                type : "body",
                                scaleValue:this.myScaleY
                        });
-                       this.formSprite.add(this.face,2,{type:"body",scaleValue:this.myScaleY});
-                       this.formSprite.add(this.hear,3,{type:"body",scaleValue:this.myScaleY});
-                       this.formSprite.add(this.okazari,4,{type:"body",scaleValue:this.myScaleY});
-                       this.formSprite.add(this._tweet,5,{type:"tweet",scaleValue:this.myScaleY});
-                       this.formSprite.addChildAll();
-                       this.formSprite.setX(x);
-                       this.formSprite.setY(y);
+                       // this.formSprite.add(this.face,2,{type:"body",scaleValue:this.myScaleY});
+                       // this.formSprite.add(this.hear,3,{type:"body",scaleValue:this.myScaleY});
+                       // this.formSprite.add(this.okazari,4,{type:"body",scaleValue:this.myScaleY});
+                       // this.formSprite.add(this._tweet,6,{type:"tweet",scaleValue:this.myScaleY});
+                       // this.formSprite.addChildAll();
+                       this.formSprite.addChild(this.face,2,{type:"body",scaleValue:this.myScaleY});
+                       this.formSprite.addChild(this.hear,3,{type:"body",scaleValue:this.myScaleY});
+                       this.formSprite.addChild(this.okazari,4,{type:"body",scaleValue:this.myScaleY});
+                       this.formSprite.addChild(this._tweet,6,{type:"tweet",scaleValue:this.myScaleY});
+                       // this.formSprite.addChildAll();
+
                        // App.backgroundMap.addChild(this._tweet);
                        // this.imgGroup.addChild(this.shadow);
                        // this.imgBody.addChild(this);
@@ -2619,15 +2645,14 @@ window.onload = function(){
                        // this.imgBody.addChild(new Kuki(this));
                        this.myScale(this.myScaleX, this.myScaleY)
                        if(this instanceof Player){
-                               // this.myScaleX = 0.5;
-                               // this.myScaleY = 0.5;
-
                                this.budge = new enchant.Sprite(16, 16);
                                this.budge.image = game.assets[EResPath.PLAYER_BADGE];
-                               // this.imgBody.addChild(this.budge);
-                               this.budge.x -= this.getWidth()/2;
-                               this.budge.y -= this.getHeight()/2;
-                               this.budge.scale(this.myScaleX, this.myScaleX);
+                               this.budge.x = -this.getWidth()/2;
+                               this.budge.y = -this.getHeight()/2;
+                               this.budge.scale(this.myScaleX, this.myScaleY);
+                               this.formSprite.addChild(this.budge,5, {type:"budge",scaleValue:this.myScaleY});
+                               this.formSprite.setX(x);
+                               this.formSprite.setY(y);
                        }
                        // this.imgGroup.width = this.getWidth();
                        // this.imgGroup.height = this.getHeight();
@@ -2852,15 +2877,15 @@ window.onload = function(){
                // var food = new def.Food("apple", 200, 250);
                backgroundMap.addChild(foodGroup);
                // backgroundMap.addChild(placeGroup);
-               var player = new Player(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
+               var player = new Player(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.ADULT);
                // var player = new Player(0, 0);
                // console.log(player.getX());
                // player.addKuki();
                // player.createKuki();
-               new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
-               new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
-               new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
-               new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
+               // new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
+               // new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
+               // new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
+               // new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
                // // new Reimu(PALYER_INIT_X + 400, PALYER_INIT_Y + 400, EGrow.ADULT);
                // new Reimu(PALYER_INIT_X + 350, PALYER_INIT_Y + 400, EGrow.SUBADULT);
                // new Reimu(PALYER_INIT_X + 300, PALYER_INIT_Y + 400, EGrow.CHILD);