OSDN Git Service

Popupとピコハン機能を追加
authornagoling <>
Sat, 30 Nov 2013 12:30:59 +0000 (21:30 +0900)
committernagomi <nagomi@192.168.1.23>
Sat, 30 Nov 2013 12:30:59 +0000 (21:30 +0900)
class.js
ctrl.js
lang/ja.js
main.js

index 8a2db85..7f07cc5 100644 (file)
--- a/class.js
+++ b/class.js
@@ -169,6 +169,7 @@ var Box = enchant.Class.create(enchant.Sprite, {
                var o = this.outCurve;
                with(this.image.context) {
                        fillStyle = 'black';
+
                        strokeStyle = 'black';
                        beginPath();
                        moveTo(o.lt.x, o.lt.y+c);
@@ -266,6 +267,109 @@ var Box = enchant.Class.create(enchant.Sprite, {
 });
 
 
+GPopup = enchant.Class.create(enchant.Sprite, {
+       initialize : function(scene, x, y, w, h) {
+               enchant.Sprite.call(this, w, h);
+               this.image = new Surface(w, h);
+               this.x = x;
+               this.y = y;
+               scene.addChild(this);
+               this.scene = scene;
+               this.text = "";
+       },
+       clear : function() {
+               this.image.context.fillStyle = '#000099';
+               this.image.context.fillRect(0, 0, this.getWidth(), this.getHeight());
+       },
+       setText : function(text) {
+               this.image.context.fillStyle = 'black';
+               this.image.context.textAlign = 'left';
+               this.image.context.textBaseline = 'top';
+               this.image.context.font = "13px 'Times New Roman'";
+
+               var textWidth = Math.floor(this.image.context.measureText(text).width);
+               var lineHeight = this.image.context.measureText("あ").width;
+               var _textList = text.split("\n");
+               this.renew(this.scene, this.x, this.y, textWidth, (lineHeight) * _textList.length + 6);
+               this.text = text;
+       },
+       drawText : function (){
+               this.clear();
+               var x = 0;
+               var y = 0;
+               // var lineHeight = this.image.context.measureText("あ").width;
+               this.image.context.fillStyle = '#ffffff';
+               this.image.context.textAlign = 'left';
+               this.image.context.textBaseline = 'alphabetic';
+               this.image.context.font = "12px 'Times New Roman'";
+               this.fillTextLine(this.text ,x, y);
+       },
+       getWidth : function(){
+               return this.image.width;
+       },
+       getHeight : function(){
+               return this.image.height;
+       },
+       fillTextLine : function(text, x, y) {
+               var textList = text.split("\n");
+               var lineHeight = this.image.context.measureText("あ").width + 2;
+               var self = this;
+               textList.forEach(function(text, i) {
+                       self.image.context.fillText(text, x, y + lineHeight * (i+1));
+               });
+       },
+       renew : function(scene, x, y, w, h){
+               scene.removeChild(this);
+               enchant.Sprite.call(this, w, h);
+               this.image = new Surface(w, h);
+               this.x = x;
+               this.y = y;
+               scene.addChild(this);
+       }
+});
+
+
+GWindow = enchant.Class.create(enchant.Sprite, {
+       initialize : function(scene, x, y, w, h) {
+               enchant.Sprite.call(this, w, h);
+               this.image = new Surface(w, h);
+               this.x = x;
+               this.y = y;
+               scene.addChild(this);
+       },
+       clear : function() {
+               this.image.context.fillStyle = '#ffff00';
+               this.image.context.fillRect(0, 0, this.getWidth(), this.getHeight());
+       },
+       text : function(text, x, y) {
+               this.clear();
+               this.image.context.fillStyle = 'black';
+               this.image.context.textAlign = 'left';
+               this.image.context.textBaseline = 'middle';
+               this.image.context.font = "12px 'Times New Roman'";
+               var textWidth = Math.floor(this.image.context.measureText(text).width);
+
+               var lineHeight = this.image.context.measureText("あ").width;
+               this.image.context.fillText(text + ":" + textWidth,x, y + lineHeight);
+       },
+       getWidth : function(){
+               return this.image.width;
+       },
+       getHeight : function(){
+               return this.image.height;
+       },
+
+       renew : function(scene, x, y, w, h){
+               scene.removeChild(this);
+               enchant.Sprite.call(this, w, h);
+               this.image = new Surface(w, h);
+               this.x = x;
+               this.y = y;
+               scene.addChild(this);
+       }
+});
+
+
 //how to use
 //var tweet = new TTweet(128, 64);
 //tweet.text("ABCDEFG");
\ No newline at end of file
diff --git a/ctrl.js b/ctrl.js
index 428bae1..b63d752 100644 (file)
--- a/ctrl.js
+++ b/ctrl.js
@@ -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;
@@ -88,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;
@@ -99,6 +110,14 @@ 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;
@@ -114,7 +133,7 @@ var MangIcon = enchant.Class.create({
                        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]);
@@ -184,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;
                        }
                }
@@ -335,12 +360,32 @@ var WorldPicoPicoHummerTouchEvent = enchant.Class.create(ATouchEvent,{
                this.touchY = 0;
        },
        touchstart :function(e){
-               // if(e.x >= 0 && e.x <= EFieldPos.WIDTH){
-               //      var backgroundMap = this.ctl.backgroundMap;
-               //      var tx = -backgroundMap.x + e.x;
-               //      var ty = -backgroundMap.y + e.y;
-               //      new ctl.def.Place("tree", tx, ty);
-               // }
+               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;
+                       }
+               }
        }
 });
 
@@ -632,6 +677,10 @@ var MangMsg = enchant.Class.create({
                        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));
+               }
 
        }
 });
index f10050f..3b4a6c9 100644 (file)
@@ -50,10 +50,14 @@ M.BASE.L.HUNTING_MESSAGE4 = "ゆっくりごはんになってね!";
 M.BASE.L.HUNTING_MESSAGE5 = "ゆっくりたべものさん\nあつめるよ!";
 M.BASE.L.HUNTING_MESSAGE6 = "ゆっくりかりをするよ!!";
 M.BASE.L.HUNTING_MESSAGE7 = "たべものさん\nいっぱいかるよ!";
+M.BASE.L.HUNTING_MESSAGE8 = "ゆうっしゅうっ\nでごめんね!";
 M.BASE.L.LEARN_NO_FOOD_IN_PLACE1 = "ゆー、たべものさんがないよ";
 M.BASE.L.MOVE_TO_HUNTING1 = "ゆっくりかりにいくよ!";
 M.BASE.L.REMOVE_YUKKURI1 = "%name%はごみじゃないよ!";
 M.BASE.L.LOST_HOUSE1 = "おうちが\nなくなってるううぅぅ!!";
+M.BASE.L.DAMAGE1 = "いたいいたいをされたら\nゆっくりできないよ!";
+M.BASE.L.DAMAGE2 = "ゆ!?\nいたいよ!やめてよね!\nゆっくりできないよ!";
+
 
 M.MARISA = {};
 M.MARISA.L = {};
diff --git a/main.js b/main.js
index 0fa0ca9..3218c75 100644 (file)
--- a/main.js
+++ b/main.js
@@ -190,6 +190,7 @@ var EMsg = {
        REMOVE_YUKKURI:20,
        LOST_HOUSE:21,
        MOVE_TO_HUNTING:22,
+       DAMAGE:23,
 
 };
 var EWalkAnimation = {
@@ -228,6 +229,9 @@ var EExSkill = {
 var EMemory = {
        FOOD_IN_PLACE : 1,
 };
+var EDamage = {
+       PICOHAN : 1
+};
 var ObjSprite = enchant.Class.create(enchant.Sprite,{
        initialize: function (w, h){
                enchant.Sprite.call(this, w, h);
@@ -349,7 +353,7 @@ window.onload = function(){
        var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
        var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
        var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
-       var game = new Game(GAME_WIDTH, GAME_HEIGHT);
+       game = new Game(GAME_WIDTH, GAME_HEIGHT);
        game.fps = FPS;
        var _loadArr = [];
        var i=0;
@@ -2101,6 +2105,10 @@ window.onload = function(){
                        this.param.yukkuri = yukkuri;
                        if(this.param.yukkuri < 0)this.param.yukkuri = 0;
                },
+               addYukkuri: function(yukkuri){
+                       this.param.yukkuri += yukkuri;
+                       if(this.param.yukkuri < 0)this.param.yukkuri = 0;
+               },
                getHungry: function(){
                        return this.param.hungry;
                },
@@ -2289,6 +2297,14 @@ window.onload = function(){
                getMemory: function(ememory){
                        return this.memoryHash[ememory];
                },
+               damage: function(edamage){
+                       if(edamage == EDamage.PICOHAN){
+                               mangMsg.output(this, EMsg.DAMAGE);
+                               this.setFaceImage(EFace.CRY1);
+                               this.addYukkuri(-1);
+                               //現在の行動パターンから躾対象かセレクトする
+                       }
+               },
                destruct: function(){
 
                }
@@ -2559,7 +2575,6 @@ window.onload = function(){
                windowSurface.context.fillStyle = '#000';
                windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
 
-
                menuSurface.context.fillStyle = '#000';
                menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
                menuBg.image = menuSurface;
@@ -2569,7 +2584,9 @@ window.onload = function(){
                mangIcon = new MangIcon(ctl, menuBg);
 
                game.rootScene.addChild(backgroundMap);
-               game.rootScene.addChild(windowFront);
+               // game.rootScene.addChild(windowFront);
+               // game.rootScene.addChild(gwindow);
+               // var gwindow = new GWindow(ctl, {}, 0, 0, 80, 80);
                game.rootScene.addChild(menuBg);
 
                // var labelGroup = new LabelGroup();
@@ -2590,14 +2607,74 @@ window.onload = function(){
                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 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);
                // new Reimu(PALYER_INIT_X + 250, PALYER_INIT_Y + 400, EGrow.BABY);
                // new Unun(100, 100);
                // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
                var touchX = 0;
+               // var input = new Label("<form name='hoge' style='background-color:#ff0000;'>" +
+               //              "<input type='text' name='text'>" +
+               //              // "<select name='input_item' id='input_item'><option name='none'>りんご</option></select>" +
+               //              "</from>");
+               // input.y = 0;
+               // input.element.innerHTML = "<form name='hoge' style='background-color:#ff0000;'>" +
+               //              "<input type='text' name='text'>" +
+               //              // "<select name='input_item' id='input_item'><option name='none'>りんご</option></select>" +
+               //              "</from>";
+               // menuBg.addChild(input);
+               // game.rootScene.addChild(input);
+               // var inputEvent = new Label('');
+               // output.y = 64;
+               // game.rootScene.addChild(output);
+               // output.onenterframe = function(e) {
+               //              output.text = document.hoge.text.value;
+               //      };
+               // };
+               // enchant.Node.GAddEvent = function(){
+               // }
+               var popupStatus = null;
+               var testFlg = false;
+               var iconText = [];
+               game._element.addEventListener('mousemove', function (e) {
+                       var mang = mangTouch.get(ctl.getCurrentCommand());
+                       if(EMenuPos.X < e.layerX){
+                               var ex = e.layerX - EMenuPos.X;
+                               var ey = e.layerY;
+                               var hitFlg = false;
+                               // console.log("ex:" + ex);
+                               for(var i=0;i<mangIcon.cmdIcons.length;i++){
+                                       var icon = mangIcon.cmdIcons[i];
+                                       if(icon.x <= ex && ex <= (icon.x + ICON_WIDTH)
+                                               && icon.y <= ey && ey <= (icon.y + ICON_HEIGHT)
+                                               ){
+                                               hitFlg = true;
+                                               if(popupStatus !== i){
+                                                       ctl.popup.renew(game.rootScene, EMenuPos.X + 5, e.layerY + ICON_HEIGHT / 2, 80, 80);
+                                                       ctl.popup.setText(icon.text);
+                                                       popupStatus = i;
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                               if(hitFlg){
+                                       ctl.popup.opacity = 0.9;
+                                       ctl.popup.drawText();
+                               }
+                               else {
+                                       ctl.popup.opacity = 0;
+                               }
+                               // console.log(e.layerX + ":" + e.layerY);
+                       }
+               });
+               // enchant.Core.instance._element.addEventListener('mousemove', function(e) {
+
+               // game.rootScene.addEventListener('mousemove', function (e) {
+               //      console.log("mmmmmmmmm");
+               // });
 
 
                game.rootScene.addEventListener('touchstart', function (e) {
@@ -2616,7 +2693,7 @@ window.onload = function(){
                });
 
 
-               game.rootScene.addEventListener('enterframe', function(){
+               game.rootScene.addEventListener('enterframe', function(e){
                        //main frame
                        mangLabel.draw(player);
                        if(this.age%BASE_FPS == 0 ){