OSDN Git Service

update grow pattern
authornagoling <>
Sat, 12 Oct 2013 07:30:55 +0000 (16:30 +0900)
committernagomi <nagomi@192.168.1.23>
Sat, 12 Oct 2013 07:30:55 +0000 (16:30 +0900)
class.js
ctrl.js
data/okazari.png
main.js

index d51a906..896af24 100644 (file)
--- a/class.js
+++ b/class.js
@@ -236,6 +236,12 @@ var Box = enchant.Class.create(enchant.Sprite, {
        getY : function(){
                return this.y;
        },
+       getWidth: function(){
+               return this.width;
+       },
+       getHeight: function(){
+               return this.height;
+       },
        touchstart:function(self){
                return function(e){
                        if(typeof e === "undefined")return;
diff --git a/ctrl.js b/ctrl.js
index 4176de0..5d5afed 100644 (file)
--- a/ctrl.js
+++ b/ctrl.js
@@ -44,8 +44,8 @@ var Ctrl = enchant.Class.create({
        isCollision : function (e, node){
                var ex = e.x - ctl.backgroundMap.x;
                var ey = e.y - ctl.backgroundMap.y;
-               if(node.getX() <= ex && node.getX() + node.width >= ex
-                       && node.getY() <= ey && node.getY() + node.height >= ey){
+               if(node.getX() <= ex && node.getX() + node.getWidth() >= ex
+                       && node.getY() <= ey && node.getY() + node.getHeight() >= ey){
                        return true;
                }
                return false;
@@ -145,13 +145,13 @@ var WorldCursorTouchEvent = enchant.Class.create(ATouchEvent,{
                                continue;
                        }
                        if(node instanceof this.ctl.def.Yukkuri){
-                               nx -= node.width / 2;
-                               ny -= node.height / 2;
+                               nx -= node.getWidth() / 2;
+                               ny -= node.getHeight() / 2;
                        }
                        if(     nx <= tx
-                               && (nx + node.width) >= tx
+                               && (nx + node.getWidth()) >= tx
                                && ny <= ty
-                               && (ny + node.height) >= ty
+                               && (ny + node.getHeight()) >= ty
                                ){
                                // new BoxLabel(this.ctl,100, e.x, e.y);
                                var box = new Box(this.ctl, node, e.x - ctl.backgroundMap.x, e.y - ctl.backgroundMap.y, 200, 200);
index 8a774d6..53e5c82 100644 (file)
Binary files a/data/okazari.png and b/data/okazari.png differ
diff --git a/main.js b/main.js
index b1e3d28..c335aba 100644 (file)
--- a/main.js
+++ b/main.js
@@ -1,5 +1,20 @@
 enchant();
 //////////////////////////////////////
+/*
+    CanvasLayer初期化後にcanvasのコンテキストを操作する
+*/
+// var initCanvas = CanvasLayer.prototype.initialize;
+
+// CanvasLayer.prototype.initialize = function() {
+//     initCanvas.call(this);
+//     console.log("canvas");
+
+//     // 拡大時の処理をNearest Neighbor方式に切り替え
+//     // ただしChromeとFireFoxでのみ動作
+//     this.context.imageSmoothingEnabled = false;
+//     this.context.webkitImageSmoothingEnabled = false;
+//     this.context.mozImageSmoothingEnabled = false;
+// };
 //global
 var ctl = null;
 var mangIcon = null;
@@ -136,7 +151,12 @@ var EWalkAnimation = {
        START: 0,
        END: 1,
 };
-
+var EGrow = {
+       ADULT : 0,
+       SUBADULT : 1,
+       CHILD : 2,
+       BABY : 3,
+};
 
 var ObjSprite = enchant.Class.create(enchant.Sprite,{
        initialize: function (w, h){
@@ -160,6 +180,12 @@ var ObjSprite = enchant.Class.create(enchant.Sprite,{
        getY: function(){
                return this.y;
        },
+       getWidth: function(){
+               return this.width;
+       },
+       getHeight: function(){
+               return this.height;
+       },
        removeAll: function(){
                this.remove();
                ctl.removeObj(this);
@@ -186,6 +212,9 @@ enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunction
        }
        return this.tween(params);
 };
+function plusFrameScale(frame, scale){
+       return (frame/2) * (1 - scale)
+}
 
 
 
@@ -381,6 +410,7 @@ window.onload = function(){
                        }
                        if(this.yukkuri.imgGroup.tl.queue.length === 0){
                                var frame = 200;
+                               frame += plusFrameScale(frame, this.yukkuri.getMyScale());
                                if(this.isMoving){
                                        this.isMoving = false;
                                        this.status = EAction.THINK;
@@ -795,6 +825,7 @@ window.onload = function(){
                                yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
                                var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
                                var frame = distance + distance/5 + 1;
+                               frame += plusFrameScale(frame, this.yukkuri.getMyScale());
                                yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
                                yukkuri.reverse();
 
@@ -837,6 +868,8 @@ window.onload = function(){
                        yukkuri.vy = node.y - yukkuri.getY();
                        var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
                        var frame = distance + 1;
+                       frame += plusFrameScale(frame, this.yukkuri.getMyScale());
+
                        yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
                                "onactionstart": this.onactionstart(this),
                                "onactiontick": this.onactiontick(this),
@@ -951,6 +984,8 @@ window.onload = function(){
                        yukkuri.vy = node.y + node.height - yukkuri.getY() - 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());
+
                        yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
                        yukkuri.reverse();
 
@@ -1109,12 +1144,21 @@ window.onload = function(){
                // }
        });
        var Okazari = enchant.Class.create(enchant.Sprite,{
-               initialize: function(){
+               initialize: function(yukkuri){
                        this.classname = "Okazari";
                        enchant.Sprite.call(this, 64, 64);
                        this.image = game.assets[EResPath.OKAZARI];
+                       this.yukkuri = yukkuri;
                        this.x = -CHARA_WIDTH / 2;
-                       this.y = -12 - CHARA_HEIGHT / 2;
+                       this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
+               },
+               getWidth: function(){
+                       return this.width;
+                       // return this.width * this.yukkuri.myScaleX;
+               },
+               getHeight: function(){
+                       return this.height;
+                       // return this.height * this.yukkuri.myScaleY;
                }
        });
        var Address = enchant.Class.create({
@@ -1138,8 +1182,26 @@ window.onload = function(){
        });
 
        var Yukkuri = enchant.Class.create(ObjSprite,{
-               initialize: function(x, y){
+               initialize: function(x, y, grow){
                        ObjSprite.call(this, 64, 64);
+                       this.grow = grow;
+                       if(grow == EGrow.ADULT){
+                               this.myScaleX = 1;
+                               this.myScaleY = 1;
+                       }
+                       else if(grow == EGrow.SUBADULT){
+                               this.myScaleX = 0.8;
+                               this.myScaleY = 0.8;
+                       }
+                       else if(grow == EGrow.CHILD){
+                               this.myScaleX = 0.6;
+                               this.myScaleY = 0.6;
+                       }
+                       else if(grow == EGrow.BABY){
+                               this.myScaleX = 0.4;
+                               this.myScaleY = 0.4;
+                       }
+
                        // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
                        this.classname = "Yukkuri";
                        this.addressBook = {};
@@ -1161,8 +1223,6 @@ window.onload = function(){
                        this.place = null;
                },
                runEnterframe:function(){
-                       // this.imgGroup.x = 0;
-                       // return ;
                        try{
                                this.act();
                                if(this.isDead())return;
@@ -1216,14 +1276,19 @@ window.onload = function(){
                        this.action.act();
                },
                animation: function(){
+
+                       var frame = 10;
+                       frame += plusFrameScale(frame, this.getMyScale());
+                       var move = 5;
+                       move -= plusFrameScale(move, this.getMyScale());
                        if(this.walkAnimationStatus == EWalkAnimation.END){
                                this.imgBody.y = 0;
-                               this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING, {
+                               this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
                                        "onactionstart": function(e){
                                                this.walkAnimationStatus = EWalkAnimation.START;
                                        }
                                })
-                               .moveByEx(0, 5, 10, enchant.Easing.SWING,
+                               .moveByEx(0, move, frame, enchant.Easing.SWING,
                                {
                                        "onactionend": function(e){
                                                this.walkAnimationStatus = EWalkAnimation.END;
@@ -1234,11 +1299,14 @@ window.onload = function(){
                                this.imgBody.tl.loop();
                        }
                },
+               getMyScale: function(){
+                       return (this.myScaleX + this.myScaleY) / 2;
+               },
                getWidth: function(){
-                       return this.width;
+                       return this.width * this.myScaleX;
                },
                getHeight: function(){
-                       return this.height;
+                       return this.height * this.myScaleY;
                },
                getX: function(){
                        return this.imgGroup.x;
@@ -1439,8 +1507,8 @@ window.onload = function(){
                }
        });
        var Marisa = enchant.Class.create(Yukkuri,{
-               initialize: function(x, y){
-                       Yukkuri.call(this,x,y);
+               initialize: function(x, y, grow){
+                       Yukkuri.call(this,x,y, grow);
                        this.classname = "Marisa";
 
                        // var xml = this.loadParamsXML("./data/marisa/params.xml");
@@ -1449,7 +1517,7 @@ window.onload = function(){
                        this.shadow = new enchant.Sprite(64, 64);
                        this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
                        this.shadow.x = 0 + this.x;
-                       this.shadow.y = CHARA_HEIGHT / 16 + this.x;
+                       this.shadow.y = this.getWidth() / 16 + this.x;
                        this.shadow.image._element.style.zIndex = 2;
 
                        this._style.zIndex = 5;
@@ -1479,22 +1547,27 @@ window.onload = function(){
                        this.hear.y = -CHARA_HEIGHT / 2;
                        this.hear._style.zIndex = 0;
 
-                       this.okazari = new Okazari();
-                       this.okazari.image._element.style.zIndex = 1;
+                       this.okazari = new Okazari(this);
 
                        // this.imgGroup._style.zIndex = 1;
 
+
                        this.imgGroup.addChild(this.shadow);
                        this.imgBody.addChild(this);
                        this.imgBody.addChild(this.face);
                        this.imgBody.addChild(this.hear);
                        this.imgBody.addChild(this.okazari);
+                       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.width/2;
-                               this.budge.y -= this.height/2;
+                               this.budge.x -= this.getWidth()/2;
+                               this.budge.y -= this.getHeight()/2;
+                               this.budge.scale(this.myScaleX, this.myScaleX);
                        }
                        this.imgGroup.addChild(this.imgBody);
                        backgroundMap.addChild(this.imgGroup);
@@ -1503,9 +1576,22 @@ window.onload = function(){
                        this.imgGroup.addChild(this._tweet);
                        this.imgGroup.x = x;
                        this.imgGroup.y = y;
+
                        this.animation();
                        this.action = new Action(this);
                        ctl.addObj(this);
+                       // this.imgGroup.scale(_scaleX,_scaleX);
+                       // this.scale(scale,scale);
+               },
+               myScale: function(_scaleX, _scaleY){
+                       this.face.scale(_scaleX,_scaleY);
+                       this.okazari.x = -32;
+                       this.okazari.y = -32 - this.getWidth()/6;
+                       this.okazari.scale(_scaleX,_scaleY);
+                       this.hear.scale(_scaleX,_scaleY);
+                       this.scale(_scaleX,_scaleY);
+                       this.shadow.scale(_scaleX, _scaleY);
+
                },
                setFaceImage: function(eface){
                        var path = this.faceStatus[eface];
@@ -1516,7 +1602,7 @@ window.onload = function(){
                initialize: function(x, y){
                        // this.runEnterframe = function(){
                        // },
-                       Marisa.call(this, x, y);
+                       Marisa.call(this, x, y, EGrow.ADULT);
                        this.classname = "Player";
                        ctl.setPlayer(this);
                        // this.removeEventListener('enterframe',this.runEnterframe);
@@ -1616,12 +1702,17 @@ window.onload = function(){
                backgroundMap.addChild(foodGroup);
                // backgroundMap.addChild(placeGroup);
                var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
-               new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200);
-               new Marisa(PALYER_INIT_X + 800, PALYER_INIT_Y + 800);
-               new Unun(100, 100);
+               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 + 200, PALYER_INIT_Y + 200);
+               // new Marisa(PALYER_INIT_X + 800, PALYER_INIT_Y + 800);
+               // new Unun(100, 100);
                // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
                var touchX = 0;
 
+
                game.rootScene.addEventListener('touchstart', function (e) {
                        game.touched = true;
                        var mang = mangTouch.get(ctl.getCurrentCommand());