OSDN Git Service

update
[yukkurioverwint/YukkuriOverwinter.git] / ctrl.js
diff --git a/ctrl.js b/ctrl.js
index 44afe8a..b63d752 100644 (file)
--- a/ctrl.js
+++ b/ctrl.js
@@ -5,7 +5,7 @@ var Ctrl = enchant.Class.create({
                this.currentCommand = ECommand.WORLD_CURSOR;
                this.backgroundMap = null;
                this.player = null;
-               this.objArray = [];
+               this.objArray = {};
                this.def = null;
                this.objSprite = null;
                this.mangTouch = null;
@@ -13,6 +13,16 @@ var Ctrl = enchant.Class.create({
                this.min = 0;
                this.hour = 0;
                this.day = 0;
+               // this.popup = new GWindow(game.rootScene,0,0,100,100);
+               this.popup = new GPopup(game.rootScene,0,0,100,100);
+               // this.popup = new GWindow(this, {
+               //      x: 0,
+               //      y: 0,
+               //      width: 100,
+               //      height: 40,
+               //      color: "#ff0000",
+               // });
+               // this.popup.opacity = 0;
        },
        calcTime:function(){
                // var sec = ctl.time/BASE_FPS;
@@ -46,7 +56,6 @@ var Ctrl = enchant.Class.create({
                delete this.objArray[obj.id];
        },
        setMenuBg: function (menuBg){
-               console.log("setMenuBg");
                this.menuBg = menuBg;
        },
        setBackgroundMap: function(backgroundMap){
@@ -89,6 +98,7 @@ var CommandIcon = enchant.Class.create(enchant.Sprite,{
                enchant.Sprite.call(this, x, y);
                this.ecmd = ecmd;
                this.index = index;
+               this.text = "";
        },
        isCurrent: function(){
                return (this.index * 2)%2 !== 0;
@@ -100,19 +110,30 @@ var CommandIcon = enchant.Class.create(enchant.Sprite,{
                this.frame = (this.index * 2);
        }
 });
+var ICON_TEXT = [
+"クリックアイコンです。\nフィールドのスクロールや\n各オブジェクトのステータスが見れます。",
+"命令アイコンです。\nプレイヤーゆっくりに\n移動命令を出せます。",
+"食物アイコンです。\nゆっくりが食べる\n食べ物を設置できます。",
+"家アイコンです。\nゆっくりが住む事のできる\nプレイスを設置できます。",
+"ゴミ箱アイコンです。\n配置したオブジェクトを削除できます。",
+"しつけアイコンです。\nゆっくりに対してアクションが出来ます。",
+];
 var MangIcon = enchant.Class.create({
        initialize: function (ctl, menuBg){
                var self = this;
                this.ctl = ctl;
                this.cmdIcons = [];
                var index = 0;
+               var POS_NUMBER = 4;
+               var HEIGHT_TOP_MARGIN = 2;
                for (var key in ECommand) {
                        var value = ECommand[key];
                        this.cmdIcons[value] = new CommandIcon(ICON_WIDTH, ICON_HEIGHT, value, index);
                        this.cmdIcons[value].image = this.ctl.game.assets[EResPath.COMMAND];
-                       this.cmdIcons[value].x = ICON_WIDTH * index + 5;
-                       this.cmdIcons[value].y = ICON_HEIGHT + 2;
-
+                       this.cmdIcons[value].x = ICON_WIDTH * (index%POS_NUMBER) + 5;
+                       var yindex = parseInt(index/POS_NUMBER) + 1;
+                       this.cmdIcons[value].y = ICON_HEIGHT * yindex + HEIGHT_TOP_MARGIN;
+                       this.cmdIcons[value].text = ICON_TEXT[value];
                        // odd equals current. even equals not current.
                        this.cmdIcons[value].frame = (this.ctl.getCurrentCommand() == value)? index * 2 + 1: index * 2;
                        menuBg.addChild(this.cmdIcons[value]);
@@ -156,9 +177,11 @@ var WorldCursorTouchEvent = enchant.Class.create(ATouchEvent,{
                var tx = this.touchX;
                var ty = this.touchY;
                var nodes = this.ctl.getObjs();
-               nodes.sort(ctl.def.nodeSort);
+
+               // nodes.sort(ctl.def.nodeSort);
                for (var id in nodes) {
                        var node = nodes[id];
+                       if(node === null || node === undefined)continue;
                        var nx = node.getX();
                        var ny = node.getY();
                        if(node == null)continue;
@@ -180,6 +203,12 @@ var WorldCursorTouchEvent = enchant.Class.create(ATouchEvent,{
                                // 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);
                                box.drawBox();
+                               // var menuWindow = new MenuWindow(this.ctl, node, e.x, e.y, 300, 300);
+                               // menuWindow.draw();
+                               // new GWindow(game.rootScene,0,0,100,100);
+                               // ctl.popup.renew(game.rootScene,640,0,100,100);
+                               // ctl.popup.setText("aaaaaa");
+                               // ctl.popup.drawText();
                                break;
                        }
                }
@@ -274,6 +303,91 @@ var WorldPlaceTouchEvent = enchant.Class.create(ATouchEvent,{
        }
 });
 
+var WorldRemoveTouchEvent = enchant.Class.create(ATouchEvent,{
+       initialize: function (ctl){
+               this.ctl = ctl;
+               this.touchX = 0;
+               this.touchY = 0;
+       },
+       touchstart :function(e){
+               this.touchX = e.x - this.ctl.backgroundMap.x;
+               this.touchY = e.y - this.ctl.backgroundMap.y;
+               var tx = this.touchX;
+               var ty = this.touchY;
+               var nodes = this.ctl.getObjs();
+               // nodes.sort(ctl.def.nodeSort);
+               for (var id in nodes) {
+                       var node = nodes[id];
+                       var nx = node.getX();
+                       var ny = node.getY();
+                       if(node == null)continue;
+                       // if(node instanceof Box
+                       //      || node instanceof this.ctl.def.Food
+                       //      || node instanceof this.ctl.def.Unun
+                       //      ){
+                       //      continue;
+                       // }
+                       if(node instanceof this.ctl.def.Yukkuri){
+                               nx -= node.getWidth() / 2;
+                               ny -= node.getHeight() / 2;
+                       }
+                       if(     nx <= tx
+                               && (nx + node.getWidth()) >= tx
+                               && ny <= ty
+                               && (ny + node.getHeight()) >= ty
+                               ){
+                               if(node instanceof this.ctl.def.Yukkuri){
+                                       mangMsg.output(node, EMsg.REMOVE_YUKKURI);
+                                       node.setFaceImage(EFace.CRY1);
+                               }
+                               else if(node instanceof this.ctl.def.Place){
+                                       node.removeAll();
+                               }
+                               else{
+                                       node.removeAll();
+                                       node.undefineAll();
+                               }
+
+                               break;
+                       }
+               }
+       }
+});
+var WorldPicoPicoHummerTouchEvent = enchant.Class.create(ATouchEvent,{
+       initialize: function (ctl){
+               this.ctl = ctl;
+               this.touchX = 0;
+               this.touchY = 0;
+       },
+       touchstart :function(e){
+               this.touchX = e.x - this.ctl.backgroundMap.x;
+               this.touchY = e.y - this.ctl.backgroundMap.y;
+               var tx = this.touchX;
+               var ty = this.touchY;
+               var nodes = this.ctl.getObjs();
+               // nodes.sort(ctl.def.nodeSort);
+               for (var id in nodes) {
+                       var node = nodes[id];
+                       var nx = node.getX();
+                       var ny = node.getY();
+                       if(node == null)continue;
+                       if(!(node instanceof this.ctl.def.Yukkuri)){
+                               continue;
+                       }
+                       nx -= node.getWidth() / 2;
+                       ny -= node.getHeight() / 2;
+                       if(     nx <= tx
+                               && (nx + node.getWidth()) >= tx
+                               && ny <= ty
+                               && (ny + node.getHeight()) >= ty
+                               ){
+                               node.damage(EDamage.PICOHAN);
+
+                               break;
+                       }
+               }
+       }
+});
 
 var MangTouch = enchant.Class.create({
        initialize: function (ctl){
@@ -284,6 +398,8 @@ var MangTouch = enchant.Class.create({
                this.mang[ECommand.WORLD_TARGET] = new WorldTargetTouchEvent(ctl);
                this.mang[ECommand.WORLD_APPLE] = new WorldAppleTouchEvent(ctl);
                this.mang[ECommand.WORLD_PLACE] = new WorldPlaceTouchEvent(ctl);
+               this.mang[ECommand.WORLD_REMOVE] = new WorldRemoveTouchEvent(ctl);
+               this.mang[ECommand.WORLD_PICOPICO_HUMMER] = new WorldPicoPicoHummerTouchEvent(ctl);
                ctl.mangTouch = this;
        },
        get: function(ecmd){
@@ -549,6 +665,22 @@ var MangMsg = enchant.Class.create({
                        var num = 1;
                        yukkuri.tweet(M.get(myCode,mySize,"LEARN_NO_FOOD_IN_PLACE" + num));
                }
+               else if(emsg == EMsg.REMOVE_YUKKURI){
+                       var num = 1;
+                       yukkuri.tweet(M.get(myCode,mySize,"REMOVE_YUKKURI" + num));
+               }
+               else if(emsg == EMsg.LOST_HOUSE){
+                       var num = 1;
+                       yukkuri.tweet(M.get(myCode,mySize,"LOST_HOUSE" + num));
+               }
+               else if(emsg == EMsg.MOVE_TO_HUNTING){
+                       var num = 1;
+                       yukkuri.tweet(M.get(myCode,mySize,"MOVE_TO_HUNTING" + num));
+               }
+               else if(emsg == EMsg.DAMAGE){
+                       var num = rand(1) + 1;
+                       yukkuri.tweet(M.get(myCode,mySize,"DAMAGE" + num));
+               }
 
        }
 });