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 67 by tsugehara, Fri Mar 22 05:57:24 2013 UTC revision 69 by tsugehara, Sat Mar 23 13:41:21 2013 UTC
# Line 1434  var Character = (function (_super) { Line 1434  var Character = (function (_super) {
1434          return false;          return false;
1435      };      };
1436      Character.prototype.moveDown = function (stackNext) {      Character.prototype.moveDown = function (stackNext) {
1437          if(this.move(0, 64, this.moveTime)) {          if(this.move(0, this.movePixel, this.moveTime)) {
1438              this.angle(Angle.Down);              this.angle(Angle.Down);
1439              return true;              return true;
1440          }          }
# Line 1456  var Character = (function (_super) { Line 1456  var Character = (function (_super) {
1456              f: f,              f: f,
1457              t: 0              t: 0
1458          };          };
1459          this.start();          if(this.beginMove) {
1460                this.beginMove.fire(this.moveInfo);
1461            }
1462            if(this.moving) {
1463                this.start();
1464            }
1465          return true;          return true;
1466      };      };
1467      Character.prototype.update = function (t) {      Character.prototype.update = function (t) {
# Line 1948  var MultilineText = (function (_super) { Line 1953  var MultilineText = (function (_super) {
1953      };      };
1954      return MultilineText;      return MultilineText;
1955  })(E);  })(E);
1956    var ChipSet = (function () {
1957        function ChipSet(tile, image) {
1958            this.image = image;
1959            this.tile = tile;
1960            this.sep = Math.floor(this.image.width / this.tile.tileWidth);
1961        }
1962        ChipSet.prototype.count = function () {
1963            return Math.round((this.image.width * this.image.height) / (this.tile.tileWidth * this.tile.tileHeight));
1964        };
1965        ChipSet.prototype.draw = function (c, x, y, chip) {
1966            var tw = this.tile.tileWidth;
1967            var th = this.tile.tileHeight;
1968            c.drawImage(this.image, (chip % this.sep) * tw, Math.floor(chip / this.sep) * th, tw, th, x * tw, y * th, tw, th);
1969        };
1970        return ChipSet;
1971    })();
1972    var AutoTileChipSet = (function (_super) {
1973        __extends(AutoTileChipSet, _super);
1974        function AutoTileChipSet() {
1975            _super.apply(this, arguments);
1976    
1977        }
1978        AutoTileChipSet.prototype.map = function (x, y) {
1979            if(x < 0 || y < 0 || x >= this.tile.size.width || y >= this.tile.size.height) {
1980                return -1;
1981            }
1982            return this.tile.data[x][y];
1983        };
1984        AutoTileChipSet.prototype.draw = function (c, x, y, chip) {
1985            var tw = this.tile.tileWidth;
1986            var th = this.tile.tileHeight;
1987            var tw2 = Math.floor(this.tile.tileWidth / 2);
1988            var th2 = Math.floor(this.tile.tileHeight / 2);
1989            for(var i = 0; i < 4; i++) {
1990                for(var j = 0; j < 4; j++) {
1991                    var ox = x + (Math.floor((i + 1) / 2) - 1);
1992                    var oy = y + (Math.floor((j + 1) / 2) - 1);
1993                    var n = this.map(ox, oy);
1994                    if(n == -1) {
1995                        continue;
1996                    }
1997                    var tx = ox + (i % 2 == 0 ? 1 : -1);
1998                    var ty = oy + (j % 2 == 0 ? 1 : -1);
1999                    var sel;
2000                    var v = this.map(tx, oy);
2001                    var h = this.map(ox, ty);
2002                    var vh = this.map(tx, ty);
2003                    sel = 0;
2004                    if(h == n) {
2005                        sel++;
2006                    }
2007                    if(v == n) {
2008                        sel += 2;
2009                    }
2010                    if(sel == 3 && vh == n) {
2011                        sel++;
2012                    }
2013                    c.drawImage(this.image, (sel % this.sep) * tw + tw2 * (i % 2 == 0 ? 1 : 0), Math.floor(sel / this.sep) * th + th2 * (j % 2 == 0 ? 1 : 0), tw2, th2, x * tw + tw2 * (i - 1), y * th + th2 * (j - 1), tw2, th2);
2014                }
2015            }
2016        };
2017        return AutoTileChipSet;
2018    })(ChipSet);
2019  var Tile = (function (_super) {  var Tile = (function (_super) {
2020      __extends(Tile, _super);      __extends(Tile, _super);
2021      function Tile(tileWidth, tileHeight, image) {      function Tile(tileWidth, tileHeight, image) {
2022          _super.call(this);          _super.call(this);
2023          this.tileWidth = tileWidth;          this.tileWidth = tileWidth;
2024          this.tileHeight = tileHeight;          this.tileHeight = tileHeight;
2025          this.image = image;          this.chips = new Array();
2026            this.chipMap = new Array();
2027            this.chipCount = 0;
2028            if(image) {
2029                this.addChipSet(image);
2030            }
2031          this.x = 0;          this.x = 0;
2032          this.y = 0;          this.y = 0;
         this.sep = Math.floor(this.image.width / this.tileWidth);  
2033          this.disableTransform = true;          this.disableTransform = true;
2034      }      }
2035        Tile.prototype.addChipSet = function (image, opt) {
2036            var chipset;
2037            if(opt) {
2038                if(opt.autoTile) {
2039                    chipset = new AutoTileChipSet(this, image);
2040                }
2041            }
2042            if(!chipset) {
2043                chipset = new ChipSet(this, image);
2044            }
2045            chipset.chipOffset = this.chipCount;
2046            this.chips.push(chipset);
2047            var cnt = chipset.count();
2048            var cnt2 = this.chipCount + cnt;
2049            for(var i = this.chipCount; i < cnt2; i++) {
2050                this.chipMap[i] = chipset;
2051            }
2052            this.chipCount = cnt2;
2053        };
2054      Tile.prototype.generate = function (data, width, height) {      Tile.prototype.generate = function (data, width, height) {
2055          this.data = data;          this.data = data;
2056          if(!width) {          if(!width) {
# Line 1968  var Tile = (function (_super) { Line 2059  var Tile = (function (_super) {
2059          if(!height) {          if(!height) {
2060              height = this.data[0].length;              height = this.data[0].length;
2061          }          }
2062          this.chipCount = {          this.size = {
2063              width: width,              width: width,
2064              height: height              height: height
2065          };          };
# Line 1979  var Tile = (function (_super) { Line 2070  var Tile = (function (_super) {
2070      Tile.prototype.refresh = function () {      Tile.prototype.refresh = function () {
2071          this.canvas = window.createCanvas(this.width, this.height);          this.canvas = window.createCanvas(this.width, this.height);
2072          var c = this.canvas.getContext("2d");          var c = this.canvas.getContext("2d");
2073          for(var x = 0; x < this.chipCount.width; x++) {          for(var x = 0; x < this.size.width; x++) {
2074              for(var y = 0; y < this.chipCount.height; y++) {              for(var y = 0; y < this.size.height; y++) {
2075                  c.drawImage(this.image, (this.data[x][y] % this.sep) * this.tileWidth, Math.floor(this.data[x][y] / this.sep) * this.tileHeight, this.tileWidth, this.tileHeight, x * this.tileWidth, y * this.tileHeight, this.tileWidth, this.tileHeight);                  if(this.data[x][y] < 0) {
2076                        continue;
2077                    }
2078                    var cs = this.chipMap[this.data[x][y]];
2079                    cs.draw(c, x, y, this.data[x][y] - cs.chipOffset);
2080              }              }
2081          }          }
2082      };      };
# Line 3798  var Tween = (function (_super) { Line 3893  var Tween = (function (_super) {
3893                  this.old[prop] = {                  this.old[prop] = {
3894                  };                  };
3895                  for(var j in this.props[prop]) {                  for(var j in this.props[prop]) {
3896                      if(typeof this.props[prop] === "function") {                      if(typeof this.props[prop][j] === "function") {
3897                          this.target[prop][j] = this.props[prop][j].call(this.entity);                          this.target[prop][j] = this.props[prop][j].call(this.entity);
3898                      } else {                      } else {
3899                          this.target[prop][j] = this.props[prop][j];                          this.target[prop][j] = this.props[prop][j];

Legend:
Removed from v.67  
changed lines
  Added in v.69

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