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 146 by tsugehara, Tue Aug 6 14:59:31 2013 UTC revision 147 by tsugehara, Wed Aug 7 15:59:56 2013 UTC
# Line 2019  var jg; Line 2019  var jg;
2019  var jg;  var jg;
2020  (function (jg) {  (function (jg) {
2021      var ChipSet = (function () {      var ChipSet = (function () {
2022          function ChipSet(tile, image) {          function ChipSet(image) {
2023              this.image = image;              this.image = image;
             this.tile = tile;  
             this.sep = Math.floor(this.image.width / this.tile.tileWidth);  
2024          }          }
2025          ChipSet.prototype.count = function () {          ChipSet.prototype.count = function (tile) {
2026              return Math.round((this.image.width * this.image.height) / (this.tile.tileWidth * this.tile.tileHeight));              return Math.round((this.image.width * this.image.height) / (tile.tileWidth * tile.tileHeight));
2027          };          };
2028    
2029          ChipSet.prototype.draw = function (c, x, y, chip) {          ChipSet.prototype.draw = function (tile, c, x, y, chip) {
2030              var tw = this.tile.tileWidth;              var tw = tile.tileWidth;
2031              var th = this.tile.tileHeight;              var th = tile.tileHeight;
2032              c.drawImage(this.image, (chip % this.sep) * tw, Math.floor(chip / this.sep) * th, tw, th, x * tw, y * th, tw, th);              var sep = Math.floor(this.image.width / tile.tileWidth);
2033                c.drawImage(this.image, (chip % sep) * tw, Math.floor(chip / sep) * th, tw, th, x * tw, y * th, tw, th);
2034          };          };
2035    
2036          ChipSet.prototype.getChips = function () {          ChipSet.prototype.getChips = function (tile) {
2037              var len = this.count();              var len = this.count(tile);
2038              var sprite = new jg.Sprite(this.image);              var sprite = new jg.Sprite(this.image);
2039              var buf = new jg.BufferedRenderer(sprite);              var buf = new jg.BufferedRenderer(sprite);
2040              var ret = [];              var ret = [];
2041              var w = this.tile.tileWidth;              var w = tile.tileWidth;
2042              var h = this.tile.tileHeight;              var h = tile.tileHeight;
2043              var area = {              var area = {
2044                  x: 0,                  x: 0,
2045                  y: 0,                  y: 0,
# Line 2048  var jg; Line 2047  var jg;
2047                  height: h                  height: h
2048              };              };
2049              buf.renderUnit(sprite);              buf.renderUnit(sprite);
2050                var sep = Math.floor(this.image.width / tile.tileWidth);
2051    
2052              for (var i = 0; i < len; i++) {              for (var i = 0; i < len; i++) {
2053                  ret.push(buf.createSprite({                  ret.push(buf.createSprite({
2054                      x: (i % this.sep) * w,                      x: (i % sep) * w,
2055                      y: Math.floor(i / this.sep) * h,                      y: Math.floor(i / sep) * h,
2056                      width: w,                      width: w,
2057                      height: h                      height: h
2058                  }, area, area));                  }, area, area));
# Line 2068  var jg; Line 2068  var jg;
2068          function AutoTileChipSet() {          function AutoTileChipSet() {
2069              _super.apply(this, arguments);              _super.apply(this, arguments);
2070          }          }
2071          AutoTileChipSet.prototype.map = function (x, y) {          AutoTileChipSet.prototype.map = function (tile, x, y) {
2072              if (x < 0 || y < 0 || x >= this.tile.size.width || y >= this.tile.size.height)              if (x < 0 || y < 0 || x >= tile.size.width || y >= tile.size.height)
2073                  return -1;                  return -1;
2074              return this.tile.data[x][y];              return tile.data[x][y];
2075          };          };
2076    
2077          AutoTileChipSet.prototype.count = function () {          AutoTileChipSet.prototype.count = function (tile) {
2078              return 1;              return 1;
2079          };          };
2080    
2081          AutoTileChipSet.prototype.draw = function (c, x, y, chip) {          AutoTileChipSet.prototype.draw = function (tile, c, x, y, chip) {
2082              var tw = this.tile.tileWidth;              var tw = tile.tileWidth;
2083              var th = this.tile.tileHeight;              var th = tile.tileHeight;
2084              var tw2 = Math.floor(this.tile.tileWidth / 2);              var tw2 = Math.floor(tw / 2);
2085              var th2 = Math.floor(this.tile.tileHeight / 2);              var th2 = Math.floor(th / 2);
2086                var sep = Math.floor(this.image.width / tile.tileWidth);
2087    
2088              chip += this.chipOffset;              chip += this.chipOffset;
2089              for (var i = 0; i < 2; i++) {              for (var i = 0; i < 2; i++) {
2090                  for (var j = 0; j < 2; j++) {                  for (var j = 0; j < 2; j++) {
2091                      var tx = x + (i == 0 ? -1 : 1);                      var tx = x + (i == 0 ? -1 : 1);
2092                      var ty = y + (j == 0 ? -1 : 1);                      var ty = y + (j == 0 ? -1 : 1);
2093                      var v = this.map(tx, y);                      var v = this.map(tile, tx, y);
2094                      var h = this.map(x, ty);                      var h = this.map(tile, x, ty);
2095                      var vh = this.map(tx, ty);                      var vh = this.map(tile, tx, ty);
2096                      var sel = 0;                      var sel = 0;
2097                      if (h == chip)                      if (h == chip)
2098                          sel++;                          sel++;
# Line 2099  var jg; Line 2101  var jg;
2101                      if (sel == 3 && vh == chip)                      if (sel == 3 && vh == chip)
2102                          sel++;                          sel++;
2103    
2104                      c.drawImage(this.image, (sel % this.sep) * tw + tw2 * i, Math.floor(sel / this.sep) * th + th2 * j, tw2, th2, x * tw + tw2 * i, y * th + th2 * j, tw2, th2);                      c.drawImage(this.image, (sel % sep) * tw + tw2 * i, Math.floor(sel / sep) * th + th2 * j, tw2, th2, x * tw + tw2 * i, y * th + th2 * j, tw2, th2);
2105                  }                  }
2106              }              }
2107          };          };
2108    
2109          AutoTileChipSet.prototype.getChips = function () {          AutoTileChipSet.prototype.getChips = function (tile) {
2110              var len = this.count();              var len = this.count(tile);
2111              var sprite = new jg.Sprite(this.image, this.tile.tileWidth, this.tile.tileHeight);              var sprite = new jg.Sprite(this.image, tile.tileWidth, tile.tileHeight);
2112    
2113              return [sprite.createSprite()];              return [sprite.createSprite()];
2114          };          };
# Line 2133  var jg; Line 2135  var jg;
2135              var chipset;              var chipset;
2136              if (opt) {              if (opt) {
2137                  if (opt.autoTile) {                  if (opt.autoTile) {
2138                      chipset = new AutoTileChipSet(this, image);                      chipset = new AutoTileChipSet(image);
2139                  }                  }
2140              }              }
2141    
2142              if (!chipset)              if (!chipset)
2143                  chipset = new ChipSet(this, image);                  chipset = new ChipSet(image);
2144    
2145              chipset.chipOffset = this.chipCount;              chipset.chipOffset = this.chipCount;
2146              this.chips.push(chipset);              this.chips.push(chipset);
2147              var cnt = chipset.count();              var cnt = chipset.count(this);
2148              var cnt2 = this.chipCount + cnt;              var cnt2 = this.chipCount + cnt;
2149              for (var i = this.chipCount; i < cnt2; i++)              for (var i = this.chipCount; i < cnt2; i++)
2150                  this.chipMap[i] = chipset;                  this.chipMap[i] = chipset;
2151              this.chipCount = cnt2;              this.chipCount = cnt2;
2152          };          };
2153    
2154            Tile.prototype.copyChips = function (tile) {
2155                tile.chips = this.chips;
2156                tile.chipCount = this.chipCount;
2157                tile.chipMap = this.chipMap;
2158            };
2159    
2160          Tile.prototype._clear = function (width, height) {          Tile.prototype._clear = function (width, height) {
2161              this.size = {              this.size = {
2162                  width: width,                  width: width,
# Line 2216  var jg; Line 2224  var jg;
2224              if (this.data[x][y] < 0)              if (this.data[x][y] < 0)
2225                  return;                  return;
2226              var cs = this.chipMap[this.data[x][y]];              var cs = this.chipMap[this.data[x][y]];
2227              cs.draw(context, x, y, this.data[x][y] - cs.chipOffset);              cs.draw(this, context, x, y, this.data[x][y] - cs.chipOffset);
2228          };          };
2229    
2230          Tile.prototype.draw = function (context) {          Tile.prototype.draw = function (context) {
# Line 2272  var jg; Line 2280  var jg;
2280              var ret = [];              var ret = [];
2281              var len = this.chips.length;              var len = this.chips.length;
2282              for (var i = 0; i < len; i++)              for (var i = 0; i < len; i++)
2283                  ret = ret.concat(this.chips[i].getChips());                  ret = ret.concat(this.chips[i].getChips(this));
2284              return ret;              return ret;
2285          };          };
2286          return Tile;          return Tile;

Legend:
Removed from v.146  
changed lines
  Added in v.147

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