OSDN Git Service

init
authornagoling <nagoling@gmail.com>
Thu, 19 Sep 2013 16:53:23 +0000 (01:53 +0900)
committernagoling <nagoling@gmail.com>
Thu, 19 Sep 2013 16:53:23 +0000 (01:53 +0900)
class.js [new file with mode: 0644]
ctrl.js [new file with mode: 0644]
index.html [new file with mode: 0644]

diff --git a/class.js b/class.js
new file mode 100644 (file)
index 0000000..d4eb673
--- /dev/null
+++ b/class.js
@@ -0,0 +1,117 @@
+TTweet = enchant.Class.create(enchant.Sprite, {
+    initialize : function(w, h) {
+        this.lifetime = 0;
+        enchant.Sprite.call(this, w, h + TTweet.TAIL);
+        this.image = new Surface(w, h + TTweet.TAIL);
+        var t = TTweet.TAIL;
+        var s = TTweet.SIZE;
+        var c = TTweet.CURVE;
+        this.outCurve = {
+            lt : {x:  0, y:  t},
+            rt : {x:  w, y:  t},
+            rd : {x:  w, y:h+t},
+            ld : {x:  0, y:h+t}
+        };
+        this.inCurve = {
+            lt : {x:  0+s, y:  t+s},
+            rt : {x:  w-s, y:  t+s},
+            rd : {x:  w-s, y:h+t-s},
+            ld : {x:  0+s, y:h+t-s}
+        };
+        this.image.context.font = "12px 'Times New Roman'";
+        this.addEventListener('enterframe', function(){
+            if((this.age % 15) == 0){
+                this.lifetime--;
+            }
+            if(this.lifetime <= 0){
+                this.lifetime = 0;
+                this.opacity = 0;
+            }
+        });
+    },
+    reDraw : function() {
+        var c = TTweet.CURVE;
+        var o = this.outCurve;
+        with(this.image.context) {
+            fillStyle = 'black';
+            strokeStyle = 'black';
+            beginPath();
+            moveTo(o.lt.x, o.lt.y+c);
+            quadraticCurveTo(o.lt.x, o.lt.y, o.lt.x+c, o.lt.y);
+            lineTo(o.rt.x-c, o.rt.y);
+            quadraticCurveTo(o.rt.x, o.rt.y, o.rt.x, o.rt.y+c);
+            lineTo(o.rd.x, o.rd.y-c);
+            quadraticCurveTo(o.rd.x, o.rd.y, o.rd.x-c, o.rd.y);
+            lineTo(o.ld.x+c, o.ld.y);
+            quadraticCurveTo(o.ld.x, o.ld.y, o.ld.x, o.ld.y-c);
+            // しっぽ
+            // var _height = 100;
+            // lineTo(this.width/2-4,_height + TTweet.TAIL);
+            // lineTo(this.width/2,_height + 0);
+            // lineTo(this.width/2+4,_height + TTweet.TAIL);
+            closePath();
+            fill();
+            stroke();
+        };
+        this.clear();
+    },
+    clear : function() {
+        var c = TTweet.CURVE;
+        var o = this.outCurve;
+        var i = this.inCurve;
+        with(this.image.context) {
+            // 抜く
+               fillStyle = 'white';
+            beginPath();
+            moveTo(i.lt.x, o.lt.y+c);
+            quadraticCurveTo(i.lt.x, i.lt.y, o.lt.x+c, i.lt.y);
+            lineTo(o.rt.x-c, i.rt.y);
+            quadraticCurveTo(i.rt.x, i.rt.y, i.rt.x, o.rt.y+c);
+            lineTo(i.rd.x, o.rd.y-c);
+            quadraticCurveTo(i.rd.x, i.rd.y, o.rd.x-c, i.rd.y);
+            lineTo(o.ld.x+c, i.ld.y);
+            quadraticCurveTo(i.ld.x, i.ld.y, i.ld.x, o.ld.y-c);
+            closePath();
+            fill();
+        };
+    },
+    text : function(text, x, y) {
+        this.clear();
+        this.opacity = 1;
+
+        this.reDraw();
+        with(this.image.context) {
+            // var size = measureText(text);
+               fillStyle = 'black';
+            textAlign = 'center';
+            textBaseline = 'middle';
+            this.x = x;
+            this.y = y;
+            // fillText(text,this.width/2,this.height/2);
+            // console.log(size);
+            // this.width = size;
+            // console.log(this.width);
+            // this.reDraw();
+            this.fillTextLine(text,this.width/2,this.height/2);
+        }
+        this.lifetime = 7;
+
+    },
+    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);
+        });
+    },
+
+
+});
+TTweet.TAIL  =  8;
+TTweet.SIZE  =  2;
+TTweet.CURVE = 16;
+
+//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
new file mode 100644 (file)
index 0000000..b921859
--- /dev/null
+++ b/ctrl.js
@@ -0,0 +1,341 @@
+var Ctrl = enchant.Class.create({
+       initialize: function (){
+               this.game = null;
+               this.menuBg = null;
+               this.currentCommand = ECommand.WORLD_CURSOR;
+               this.backgroundMap = null;
+               this.player = null;
+       },
+       init : function (game){
+               this.game = game;
+       },
+       setMenuBg: function (menuBg){
+               console.log("setMenuBg");
+               this.menuBg = menuBg;
+       },
+       setBackgroundMap: function(backgroundMap){
+               this.backgroundMap = backgroundMap;
+       },
+       setPlayer: function(player){
+               this.player = player;
+       },
+       /**
+        * [setCurrentCommand description]
+        * @param {ECommand} cmd [description]
+        */
+       setCurrentCommand: function(cmd){
+               this.currentCommand = cmd;
+       },
+       getCurrentCommand: function(){
+               return this.currentCommand;
+       }
+});
+var CommandIcon = enchant.Class.create(enchant.Sprite,{
+       initialize: function (x, y, ecmd, index){
+               enchant.Sprite.call(this, x, y);
+               this.ecmd = ecmd;
+               this.index = index;
+       },
+       isCurrent: function(){
+               return (this.index * 2)%2 !== 0;
+       },
+       setCurrent: function(){
+               this.frame = (this.index * 2) + 1;
+       },
+       removeCurrent: function(){
+               this.frame = (this.index * 2);
+       }
+});
+var MangIcon = enchant.Class.create({
+       initialize: function (ctl, menuBg){
+               var self = this;
+               this.ctl = ctl;
+               this.cmdIcons = [];
+               var index = 0;
+               for (var key in ECommand) {
+                       var value = ECommand[key];
+                       this.cmdIcons[value] = new CommandIcon(40, 40, value, index);
+                       this.cmdIcons[value].image = this.ctl.game.assets[EResPath.COMMAND];
+                       this.cmdIcons[value].x = 40 * index;
+                       this.cmdIcons[value].y = 4;
+
+                       // 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]);
+                       this.cmdIcons[value].ontouchstart = function(obj){
+                               // change command icons
+                               var nowECmd = self.ctl.getCurrentCommand();
+                               self.cmdIcons[nowECmd].removeCurrent();
+                               if(!this.isCurrent()){
+                                       this.setCurrent();
+                               }
+                               self.ctl.setCurrentCommand(this.index);
+                       };
+                       index++;
+               }
+       },
+       get: function(commandIndex){
+               return this.cmdIcons[commandIndex];
+       }
+});
+var ATouchEvent = enchant.Class.create({
+       // initialize: function (ctl){
+       //      this.ctl = ctl;
+       // },
+       touchstart: function(e){
+       },
+       touchmove: function(e){
+       },
+       touchend: function(e){
+       }
+});
+
+var WorldCursorTouchEvent = 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;
+       },
+       touchmove : function(e){
+               var backgroundMap = this.ctl.backgroundMap;
+               var game = this.ctl.game;
+
+               if(game.touched){
+                       backgroundMap.x = e.x - this.touchX;
+                       if(backgroundMap.x < -EFieldPos.WIDTH)backgroundMap.x = -EFieldPos.WIDTH;
+                       if(backgroundMap.x > 0)backgroundMap.x = 0;
+
+                       backgroundMap.y = e.y - this.touchY;
+                       if(backgroundMap.y < -EFieldPos.HEIGHT)backgroundMap.y = -EFieldPos.HEIGHT;
+                       if(backgroundMap.y > 0)backgroundMap.y = 0;
+               }
+               if(e.x > EFieldPos.WIDTH)game.touched = false;
+               else if(e.x < 30)game.touched = false;
+       },
+       touchend : function(e){
+       }
+});
+var WorldTargetTouchEvent = enchant.Class.create(ATouchEvent,{
+       initialize: function (ctl){
+               this.ctl = ctl;
+               this.touchX = 0;
+               this.touchY = 0;
+       },
+       touchstart :function(e){
+               if(e.x >= 0 && e.x <= EFieldPos.WIDTH){
+                       var backgroundMap = this.ctl.backgroundMap;
+                       addEffect(this.ctl.backgroundMap, -backgroundMap.x + e.x, -backgroundMap.y + e.y);
+                       this.ctl.player.tweet("ゆっくりりかいしたよ!");
+                       // this.ctl.player.tweet("ゆー...いきたくないのぜ");
+               }
+       }
+});
+
+var MangTouch = enchant.Class.create({
+       initialize: function (ctl){
+               this.ctl = ctl;
+               var cursor = ECommand.WORLD_CURSOR;
+               this.mang = {};
+               this.mang[ECommand.WORLD_CURSOR] = new WorldCursorTouchEvent(ctl);
+               this.mang[ECommand.WORLD_TARGET] = new WorldTargetTouchEvent(ctl);
+       },
+       get: function(ecmd){
+               return this.mang[ecmd];
+       }
+});
+var MangLabel = enchant.Class.create({
+       initialize: function (ctl, menuBg){
+               this.ctl = ctl;
+               var labelGroup = new LabelGroup();
+               this.START_XPOS = 4;
+               this.START_YPOS = GAME_HEIGHT / 2;
+               this.GAUGE_XPOS = 80;
+               this.menuBg = menuBg;
+               this.widthArr = [];
+               this.WIDTH_MARGIN = 4;
+               this.GAUGE_HEIGHT = 16;
+               var FONT = "18px 'Times New Roman'";
+               var COLOR = "#ffffff";
+               menuBg.image.context.font = FONT;
+               var self = this;
+               // this.labels = {};
+               this.labelParams = {
+                       "yukkuri" : {
+                               label: null,
+                               init: function(){
+                                       var TEXT = "ゆっくり";
+                                       var label = new Label(TEXT);
+                                       label.color = COLOR;
+                                       label.font = FONT;
+                                       label.x = self.START_XPOS;
+                                       label.y = self.START_YPOS;
+                                       label.textWidth = menuBg.image.context.measureText(TEXT).width;
+                                       this.label = label;
+                               },
+                               draw: function(yukkuriObj){
+                                       //100/maxhp*hp
+                                       var gauge = 100 / yukkuriObj.param.maxYukkuri * yukkuriObj.param.yukkuri;
+                                       self.menuBg.image.context.fillStyle = "#ffffff";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
+                                       self.menuBg.image.context.fillStyle = "#ff0000";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
+                               }
+                       },
+                       "hungry" : {
+                               label: null,
+                               init: function(){
+                                       var TEXT = "空腹";
+                                       var label = new Label(TEXT);
+                                       label.color = COLOR;
+                                       label.font = FONT;
+                                       label.x = self.START_XPOS;
+                                       label.y = self.START_YPOS + 20;
+                                       label.textWidth = menuBg.image.context.measureText(TEXT).width;
+                                       this.label = label;
+                               },
+                               draw: function(yukkuriObj){
+                                       var gauge =yukkuriObj.param.hungry;
+                                       self.menuBg.image.context.fillStyle = "#ffffff";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
+                                       self.menuBg.image.context.fillStyle = "#bb7777";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
+                               }
+                       },
+                       "unun" : {
+                               label: null,
+                               init: function(){
+                                       var TEXT = "うんうん";
+                                       var label = new Label(TEXT);
+                                       label.color = COLOR;
+                                       label.font = FONT;
+                                       label.x = self.START_XPOS;
+                                       label.y = self.START_YPOS + 40;
+                                       label.textWidth = menuBg.image.context.measureText(TEXT).width;
+                                       this.label = label;
+                               },
+                               draw: function(yukkuriObj){
+                                       var gauge =yukkuriObj.param.unun;
+                                       self.menuBg.image.context.fillStyle = "#ffffff";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
+                                       self.menuBg.image.context.fillStyle = "#bb7777";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
+                               }
+                       },
+                       "sleep" : {
+                               label: null,
+                               init: function(){
+                                       var TEXT = "眠気";
+                                       var label = new Label(TEXT);
+                                       label.color = COLOR;
+                                       label.font = FONT;
+                                       label.x = self.START_XPOS;
+                                       label.y = self.START_YPOS + 60;
+                                       label.textWidth = menuBg.image.context.measureText(TEXT).width;
+                                       this.label = label;
+                               },
+                               draw: function(yukkuriObj){
+                                       var gauge =yukkuriObj.param.unun;
+                                       self.menuBg.image.context.fillStyle = "#ffffff";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
+                                       self.menuBg.image.context.fillStyle = "#bb7777";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
+                               }
+                       },
+                       "stress" : {
+                               label: null,
+                               init: function(){
+                                       var TEXT = "ストレス";
+                                       var label = new Label(TEXT);
+                                       label.color = COLOR;
+                                       label.font = FONT;
+                                       label.x = self.START_XPOS;
+                                       label.y = self.START_YPOS + 80;
+                                       label.textWidth = menuBg.image.context.measureText(TEXT).width;
+                                       this.label = label;
+                               },
+                               draw: function(yukkuriObj){
+                                       var gauge =yukkuriObj.param.stress;
+                                       self.menuBg.image.context.fillStyle = "#ffffff";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
+                                       self.menuBg.image.context.fillStyle = "#bb7777";
+                                       self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
+                               }
+                       },
+               };
+
+               this.menuBg.image.context.fillStyle = '#ff0000';
+               for(var key in this.labelParams){
+                       var labelObj = this.labelParams[key];
+                       labelObj.init();
+                       labelGroup.addChild(labelObj.label);
+               }
+               menuBg.addChild(labelGroup);
+       },
+       draw: function(yukkuriObj){
+               for(var key in this.labelParams){
+                       var labelObj = this.labelParams[key];
+                       labelObj.draw(yukkuriObj);
+               }
+
+       }
+});
+
+
+// var MangLabel = enchant.Class.create({
+//     initialize: function (ctl, menuBg){
+//             this.ctl = ctl;
+//             var labelGroup = new LabelGroup();
+//             this.START_XPOS = 4;
+//             this.START_YPOS = GAME_HEIGHT / 2;
+//             this.menuBg = menuBg;
+//             this.widthArr = [];
+//             this.WIDTH_MARGIN = 4;
+//             var FONT = "14px 'Times New Roman'";
+//             var COLOR = "#ffffff";
+//             menuBg.image.context.font = FONT;
+//             var self = this;
+//             this.labels = {
+//                     "yukkuri" : function(){
+//                             var TEXT = "ゆっくり";
+//                             var label = new Label(TEXT);
+//                             label.color = COLOR;
+//                             label.font = FONT;
+//                             label.x = self.START_XPOS;
+//                             label.y = self.START_YPOS;
+//                             label.textWidth = menuBg.image.context.measureText(TEXT).width;
+//                     },
+//                     "hungry" : function(){
+//                             var TEXT = "空腹";
+//                             var label = new Label(TEXT);
+//                             label.color = COLOR;
+//                             label.font = FONT;
+//                             label.x = self.START_XPOS;
+//                             label.y = self.START_YPOS + 20;
+//                             label.textWidth = menuBg.image.context.measureText(TEXT).width;
+//                             return label;
+//                     },
+//             };
+
+//             this.labels["yukkuri"]();
+//             console.log(this.labels["yukkuri"]().textWidth);
+//             // for(var key in this.labels){
+//             //      console.log(key);
+//             //      var label = this.labels[key]();
+//             //      // labelGroup.addChild(label);
+//             // }
+//             // var width = this.widthArr['yukkuri'];
+//             // this.menuBg.image.context.fillStyle = '#ff0000';
+//             // this.menuBg.image.context.fillRect(this.START_XPOS + width, this.START_YPOS, 100, 30);
+//             // menuBg.addChild(labelGroup);
+//     },
+//     draw: function(){
+//             label = this.labels[key]();
+//             this.menuBg.image.context.fillStyle = '#ff0000';
+//             this.menuBg.image.context.fillRect(label.x, label.y, 100, 14);
+//     }
+// });
+
diff --git a/index.html b/index.html
new file mode 100644 (file)
index 0000000..8de7368
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <meta http-equiv="x-ua-compatible" content="IE=Edge">
+        <meta name="viewport" content="width=device-width, user-scalable=no">
+        <meta name="apple-mobile-web-app-capable" content="yes"> 
+        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
+        <title>ゆっくり"えっとう"していってね!(仮</title>
+        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
+        <script type="text/javascript" src="net.js"></script>
+        <script>
+        </script>
+
+        <script type="text/javascript" src="jkl-parsexml.js"></script>
+        <script type="text/javascript" src="init.js"></script>
+        <script type="text/javascript" src="enchant.js"></script>
+        <script type="text/javascript" src="mixing.enchant.js"></script>
+        <script type="text/javascript" src="class.js"></script>
+        <script type="text/javascript" src="ctrl.js"></script>
+        <script type="text/javascript" src="main.js"></script>
+        <style type="text/css">
+            body {
+                margin: 0;
+            }
+        </style>
+    </head>
+    <body>
+    </body>
+</html>