Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/src/js/jgame.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9 by tsugehara, Sat Jan 19 02:50:53 2013 UTC revision 10 by tsugehara, Mon Jan 21 06:20:41 2013 UTC
# Line 31  window.createCanvas = function (width, h Line 31  window.createCanvas = function (width, h
31      canvas.height = height;      canvas.height = height;
32      return canvas;      return canvas;
33  };  };
34    var Angle;
35    (function (Angle) {
36        Angle._map = [];
37        Angle._map[0] = "left";
38        Angle.left = 0;
39        Angle._map[1] = "right";
40        Angle.right = 1;
41        Angle._map[2] = "up";
42        Angle.up = 2;
43        Angle._map[3] = "down";
44        Angle.down = 3;
45    })(Angle || (Angle = {}));
46  var Area = (function () {  var Area = (function () {
47      function Area(x, y, width, height) {      function Area(x, y, width, height) {
48          this.x = x;          this.x = x;
# Line 553  var E = (function () { Line 565  var E = (function () {
565              };              };
566          }          }
567      };      };
568      E.prototype.getEntityByPoint = function (point) {      E.prototype.getEntityByPoint = function (point, force) {
569          if(this.entities) {          if(this.entities) {
570              for(var i = this.entities.length - 1; i >= 0; i--) {              for(var i = this.entities.length - 1; i >= 0; i--) {
571                  if(this.entities[i].pointCapture) {                  if(force || this.entities[i].pointCapture) {
572                      var p = this.entities[i].getEntityByPoint(point);                      var p = this.entities[i].getEntityByPoint(point);
573                      if(p) {                      if(p) {
574                          return p;                          return p;
# Line 564  var E = (function () { Line 576  var E = (function () {
576                  }                  }
577              }              }
578          }          }
579          if(this.pointCapture && this.hitTest(point)) {          if((force || this.pointCapture) && this.hitTest(point)) {
580              return this;              return this;
581          }          }
582          return null;          return null;
# Line 645  var Shape = (function (_super) { Line 657  var Shape = (function (_super) {
657    
658              }              }
659              case ShapeType.arc: {              case ShapeType.arc: {
660                  context.arc(this.width, this.width, this.width, 0, Math.PI * 2, false);                  var w2 = this.width / 2;
661                    context.arc(w2, w2, w2, 0, Math.PI * 2, false);
662                  break;                  break;
663    
664              }              }
# Line 743  var Resource = (function () { Line 756  var Resource = (function () {
756          this.loaded = new Trigger();          this.loaded = new Trigger();
757          this.images = {          this.images = {
758          };          };
759            this.scripts = {
760            };
761      }      }
762      Resource.instance = null;      Resource.instance = null;
763      Resource.getInstance = function getInstance() {      Resource.getInstance = function getInstance() {
# Line 756  var Resource = (function () { Line 771  var Resource = (function () {
771      Resource.prototype.get = function (name) {      Resource.prototype.get = function (name) {
772          return this.images[name];          return this.images[name];
773      };      };
774        Resource.prototype.loadScript = function (url, identifier, caller, callback) {
775            var script = document.createElement("script");
776            var heads = document.getElementsByTagName("head");
777            if(heads.length == 0) {
778                throw "can not find head tag";
779            }
780            script.src = url + "?" + (new Date()).getTime();
781            script.onload = function () {
782                callback.call(caller, identifier, script, true);
783            };
784            script.onerror = function () {
785                callback.call(caller, identifier, script, false);
786            };
787            heads[0].appendChild(script);
788        };
789        Resource.prototype.loadScriptComplete = function (name, script, is_success) {
790            if(!is_success) {
791                console.log("error: " + name);
792            } else {
793                this.scripts[name] = script;
794            }
795            for(var i = 0; i < this.requests.length; i++) {
796                if(this.requests[i] == name) {
797                    this.requests.splice(i, 1);
798                    break;
799                }
800            }
801            this.loaded.fire(this.requests.length);
802        };
803      Resource.prototype.loadImage = function (url, identifier, caller, callback) {      Resource.prototype.loadImage = function (url, identifier, caller, callback) {
804          var image = new Image();          var image = new Image();
805          image.src = "img/" + url;          image.src = "img/" + url;
# Line 785  var Resource = (function () { Line 829  var Resource = (function () {
829              url = name;              url = name;
830          }          }
831          this.requests.push(name);          this.requests.push(name);
832          this.loadImage(url, name, this, this.loadImageComplete);          if(url.length > 3 && url.substr(-3).toLowerCase() == ".js") {
833                this.loadScript(url, name, this, this.loadScriptComplete);
834            } else {
835                this.loadImage(url, name, this, this.loadImageComplete);
836            }
837      };      };
838      return Resource;      return Resource;
839  })();  })();
# Line 943  var Sprite = (function (_super) { Line 991  var Sprite = (function (_super) {
991      };      };
992      return Sprite;      return Sprite;
993  })(E);  })(E);
 var Angle;  
 (function (Angle) {  
     Angle._map = [];  
     Angle._map[0] = "left";  
     Angle.left = 0;  
     Angle._map[1] = "right";  
     Angle.right = 1;  
     Angle._map[2] = "up";  
     Angle.up = 2;  
     Angle._map[3] = "down";  
     Angle.down = 3;  
 })(Angle || (Angle = {}));  
994  var Character = (function (_super) {  var Character = (function (_super) {
995      __extends(Character, _super);      __extends(Character, _super);
996      function Character(width, height, image, wait) {      function Character(width, height, image, wait) {
# Line 969  var Character = (function (_super) { Line 1005  var Character = (function (_super) {
1005          this.charaCol = 1;          this.charaCol = 1;
1006          this.movePixel = 64;          this.movePixel = 64;
1007          this.moveTime = 300;          this.moveTime = 300;
1008            this.animation = true;
1009      }      }
1010      Character.prototype.moveLeft = function (stackNext) {      Character.prototype.moveLeft = function (stackNext) {
1011          if(this.move(-this.movePixel, 0, this.moveTime)) {          if(this.move(-this.movePixel, 0, this.moveTime)) {
# Line 1056  var Character = (function (_super) { Line 1093  var Character = (function (_super) {
1093          }          }
1094      };      };
1095      Character.prototype.angle = function (angle) {      Character.prototype.angle = function (angle) {
         var f;  
1096          var rowP = Math.floor(this.charaSeq / this.charaCol) * 4;          var rowP = Math.floor(this.charaSeq / this.charaCol) * 4;
1097            console.log(rowP);
1098          switch(angle) {          switch(angle) {
1099              case Angle.up: {              case Angle.up: {
1100                  f = this.animeCnt * (this.charaSeq % this.charaCol) + this.charaCol * this.animeCnt * (3 + rowP);                  rowP += (this.angleSeq ? this.angleSeq[Angle.up] : 3);
1101                  break;                  break;
1102    
1103              }              }
1104              case Angle.down: {              case Angle.down: {
1105                  f = this.animeCnt * (this.charaSeq % this.charaCol) + this.charaCol * this.animeCnt * (0 + rowP);                  rowP += (this.angleSeq ? this.angleSeq[Angle.down] : 0);
1106                  break;                  break;
1107    
1108              }              }
1109              case Angle.left: {              case Angle.left: {
1110                  f = this.animeCnt * (this.charaSeq % this.charaCol) + this.charaCol * this.animeCnt * (1 + rowP);                  rowP += (this.angleSeq ? this.angleSeq[Angle.left] : 1);
1111                  break;                  break;
1112    
1113              }              }
1114              case Angle.right: {              case Angle.right: {
1115                  f = this.animeCnt * (this.charaSeq % this.charaCol) + this.charaCol * this.animeCnt * (2 + rowP);                  rowP += (this.angleSeq ? this.angleSeq[Angle.right] : 2);
1116                  break;                  break;
1117    
1118              }              }
1119          }          }
1120            var f = this.animeCnt * (this.charaSeq % this.charaCol) + this.charaCol * this.animeCnt * rowP;
1121          this.frame = [];          this.frame = [];
1122          if(this.animeCnt % 2 == 1) {          if(this.animeCnt % 2 == 1) {
1123              for(var i = 0; i < this.animeCnt; i++) {              for(var i = 0; i < this.animeCnt; i++) {
# Line 1095  var Character = (function (_super) { Line 1133  var Character = (function (_super) {
1133          }          }
1134      };      };
1135      Character.prototype.interval = function () {      Character.prototype.interval = function () {
1136          this.fno = (this.fno + 1) % this.frame.length;          if(this.animation) {
1137          this.updated();              this.fno = (this.fno + 1) % this.frame.length;
1138                this.updated();
1139            }
1140      };      };
1141      return Character;      return Character;
1142  })(Sprite);  })(Sprite);
# Line 1121  var CharacterFactory = (function () { Line 1161  var CharacterFactory = (function () {
1161          c.moveTime = this.moveTime;          c.moveTime = this.moveTime;
1162          c.movePixel = this.movePixel;          c.movePixel = this.movePixel;
1163          c.angle((angle == undefined) ? this.angle : angle);          c.angle((angle == undefined) ? this.angle : angle);
1164            if(this.angleSeq) {
1165                c.angleSeq = this.angleSeq;
1166            }
1167          if(offset) {          if(offset) {
1168              c.moveTo(offset.x, offset.y);              c.moveTo(offset.x, offset.y);
1169          }          }
# Line 1402  var InputEvent = (function () { Line 1445  var InputEvent = (function () {
1445  })();  })();
1446  var InputKeyboardEvent = (function (_super) {  var InputKeyboardEvent = (function (_super) {
1447      __extends(InputKeyboardEvent, _super);      __extends(InputKeyboardEvent, _super);
1448      function InputKeyboardEvent(key) {      function InputKeyboardEvent(key, e) {
1449          _super.call(this, InputEventType.Keyboard, key);          _super.call(this, InputEventType.Keyboard, e);
1450          this.key = this.param;          this.key = key;
1451      }      }
1452      return InputKeyboardEvent;      return InputKeyboardEvent;
1453  })(InputEvent);  })(InputEvent);
# Line 1898  var Game = (function () { Line 1941  var Game = (function () {
1941              40: Keytype.down              40: Keytype.down
1942          };          };
1943          var onkeydown = function (e) {          var onkeydown = function (e) {
1944              if(_this.keymap[e.keyCode] != undefined) {              _this.inputDown.fire(new InputKeyboardEvent(_this.keymap[e.keyCode], e));
                 _this.inputDown.fire(new InputKeyboardEvent(_this.keymap[e.keyCode]));  
                 e.preventDefault();  
             } else {  
                 _this.inputDown.fire(new InputKeyboardEvent(null));  
             }  
1945          };          };
1946          var onkeyup = function (e) {          var onkeyup = function (e) {
1947              if(_this.keymap[e.keyCode] != undefined) {              _this.inputUp.fire(new InputKeyboardEvent(_this.keymap[e.keyCode], e));
                 _this.inputUp.fire(new InputKeyboardEvent(_this.keymap[e.keyCode]));  
                 e.preventDefault();  
             } else {  
                 _this.inputUp.fire(new InputKeyboardEvent(null));  
             }  
1948          };          };
1949          if(document.addEventListener) {          if(document.addEventListener) {
1950              document.addEventListener("keydown", onkeydown, false);              document.addEventListener("keydown", onkeydown, false);

Legend:
Removed from v.9  
changed lines
  Added in v.10

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26