You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

911 lines
20 KiB

  1. define([
  2. 'js/resources',
  3. 'js/system/events',
  4. 'js/misc/physics',
  5. 'js/rendering/effects',
  6. 'js/rendering/tileOpacity',
  7. 'js/rendering/particles',
  8. 'js/rendering/shaders/outline',
  9. 'js/rendering/spritePool',
  10. 'js/system/globals',
  11. 'js/rendering/renderLoginBackground'
  12. ], function (
  13. resources,
  14. events,
  15. physics,
  16. effects,
  17. tileOpacity,
  18. particles,
  19. shaderOutline,
  20. spritePool,
  21. globals,
  22. renderLoginBackground
  23. ) {
  24. const mRandom = Math.random.bind(Math);
  25. const particleLayers = ['particlesUnder', 'particles'];
  26. const particleEngines = {};
  27. return {
  28. stage: null,
  29. layers: {
  30. particlesUnder: null,
  31. objects: null,
  32. mobs: null,
  33. characters: null,
  34. attacks: null,
  35. effects: null,
  36. particles: null,
  37. lightPatches: null,
  38. lightBeams: null,
  39. tileSprites: null,
  40. hiders: null
  41. },
  42. titleScreen: false,
  43. width: 0,
  44. height: 0,
  45. showTilesW: 0,
  46. showTilesH: 0,
  47. pos: {
  48. x: 0,
  49. y: 0
  50. },
  51. moveTo: null,
  52. moveSpeed: 0,
  53. moveSpeedMax: 1.50,
  54. moveSpeedInc: 0.5,
  55. lastUpdatePos: {
  56. x: 0,
  57. y: 0
  58. },
  59. zoneId: null,
  60. textures: {},
  61. textureCache: {},
  62. sprites: [],
  63. lastTick: null,
  64. hiddenRooms: null,
  65. init: function () {
  66. PIXI.settings.GC_MODE = PIXI.GC_MODES.AUTO;
  67. PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
  68. PIXI.settings.SPRITE_MAX_TEXTURES = Math.min(PIXI.settings.SPRITE_MAX_TEXTURES, 16);
  69. PIXI.settings.RESOLUTION = 1;
  70. events.on('onGetMap', this.onGetMap.bind(this));
  71. events.on('onToggleFullscreen', this.toggleScreen.bind(this));
  72. events.on('onMoveSpeedChange', this.adaptCameraMoveSpeed.bind(this));
  73. this.width = $('body').width();
  74. this.height = $('body').height();
  75. this.showTilesW = Math.ceil((this.width / scale) / 2) + 3;
  76. this.showTilesH = Math.ceil((this.height / scale) / 2) + 3;
  77. this.renderer = new PIXI.Renderer({
  78. width: this.width,
  79. height: this.height,
  80. backgroundColor: '0x2d2136'
  81. });
  82. window.addEventListener('resize', this.onResize.bind(this));
  83. $(this.renderer.view).appendTo('.canvas-container');
  84. this.stage = new PIXI.Container();
  85. let layers = this.layers;
  86. Object.keys(layers).forEach(l => {
  87. layers[l] = new PIXI.Container();
  88. layers[l].layer = (l === 'tileSprites') ? 'tiles' : l;
  89. this.stage.addChild(layers[l]);
  90. });
  91. const textureList = globals.clientConfig.textureList;
  92. const sprites = resources.sprites;
  93. textureList.forEach(t => {
  94. this.textures[t] = new PIXI.BaseTexture(sprites[t]);
  95. this.textures[t].scaleMode = PIXI.SCALE_MODES.NEAREST;
  96. });
  97. particleLayers.forEach(p => {
  98. const engine = $.extend({}, particles);
  99. engine.init({
  100. r: this,
  101. renderer: this.renderer,
  102. stage: this.layers[p]
  103. });
  104. particleEngines[p] = engine;
  105. });
  106. this.buildSpritesTexture();
  107. },
  108. buildSpritesTexture: function () {
  109. const { clientConfig: { atlasTextureDimensions, atlasTextures } } = globals;
  110. let container = new PIXI.Container();
  111. let totalHeight = 0;
  112. atlasTextures.forEach(t => {
  113. let texture = this.textures[t];
  114. let tile = new PIXI.Sprite(new PIXI.Texture(texture));
  115. tile.width = texture.width;
  116. tile.height = texture.height;
  117. tile.x = 0;
  118. tile.y = totalHeight;
  119. atlasTextureDimensions[t] = {
  120. w: texture.width / 8,
  121. h: texture.height / 8
  122. };
  123. container.addChild(tile);
  124. totalHeight += tile.height;
  125. });
  126. let renderTexture = PIXI.RenderTexture.create(this.textures.tiles.width, totalHeight);
  127. this.renderer.render(container, renderTexture);
  128. this.textures.sprites = renderTexture;
  129. this.textures.scaleMult = PIXI.SCALE_MODES.NEAREST;
  130. },
  131. toggleScreen: function () {
  132. let isFullscreen = (window.innerHeight === screen.height);
  133. if (isFullscreen) {
  134. let doc = document;
  135. (doc.cancelFullscreen || doc.msCancelFullscreen || doc.mozCancelFullscreen || doc.webkitCancelFullScreen).call(doc);
  136. return 'Windowed';
  137. }
  138. let el = $('body')[0];
  139. (el.requestFullscreen || el.msRequestFullscreen || el.mozRequestFullscreen || el.webkitRequestFullscreen).call(el);
  140. return 'Fullscreen';
  141. },
  142. buildTitleScreen: function () {
  143. this.titleScreen = true;
  144. renderLoginBackground(this);
  145. },
  146. onResize: function () {
  147. if (isMobile)
  148. return;
  149. this.width = $('body').width();
  150. this.height = $('body').height();
  151. this.showTilesW = Math.ceil((this.width / scale) / 2) + 3;
  152. this.showTilesH = Math.ceil((this.height / scale) / 2) + 3;
  153. this.renderer.resize(this.width, this.height);
  154. if (window.player) {
  155. this.setPosition({
  156. x: (window.player.x - (this.width / (scale * 2))) * scale,
  157. y: (window.player.y - (this.height / (scale * 2))) * scale
  158. }, true);
  159. }
  160. if (this.titleScreen) {
  161. this.clean();
  162. this.buildTitleScreen();
  163. }
  164. events.emit('onResize');
  165. },
  166. getTexture: function (baseTex, cell, size) {
  167. size = size || 8;
  168. let textureName = baseTex + '_' + cell;
  169. let textureCache = this.textureCache;
  170. let cached = textureCache[textureName];
  171. if (!cached) {
  172. let y = ~~(cell / 8);
  173. let x = cell - (y * 8);
  174. cached = new PIXI.Texture(this.textures[baseTex], new PIXI.Rectangle(x * size, y * size, size, size));
  175. textureCache[textureName] = cached;
  176. }
  177. return cached;
  178. },
  179. clean: function () {
  180. this.stage.removeChild(this.layers.hiders);
  181. this.layers.hiders = new PIXI.Container();
  182. this.layers.hiders.layer = 'hiders';
  183. this.stage.addChild(this.layers.hiders);
  184. let container = this.layers.tileSprites;
  185. this.stage.removeChild(container);
  186. this.layers.tileSprites = container = new PIXI.Container();
  187. container.layer = 'tiles';
  188. this.stage.addChild(container);
  189. this.stage.children.sort((a, b) => {
  190. if (a.layer === 'hiders')
  191. return 1;
  192. else if (b.layer === 'hiders')
  193. return -1;
  194. else if (a.layer === 'tiles')
  195. return -1;
  196. else if (b.layer === 'tiles')
  197. return 1;
  198. return 0;
  199. });
  200. },
  201. buildTile: function (c, i, j) {
  202. let alpha = tileOpacity.map(c);
  203. let canFlip = tileOpacity.canFlip(c);
  204. let tile = new PIXI.Sprite(this.getTexture('sprites', c));
  205. tile.alpha = alpha;
  206. tile.position.x = i * scale;
  207. tile.position.y = j * scale;
  208. tile.width = scale;
  209. tile.height = scale;
  210. if (canFlip && mRandom() < 0.5) {
  211. tile.position.x += scale;
  212. tile.scale.x = -scaleMult;
  213. }
  214. return tile;
  215. },
  216. onGetMap: function (msg) {
  217. this.titleScreen = false;
  218. physics.init(msg.collisionMap);
  219. let map = this.map = msg.map;
  220. let w = this.w = map.length;
  221. let h = this.h = map[0].length;
  222. for (let i = 0; i < w; i++) {
  223. let row = map[i];
  224. for (let j = 0; j < h; j++) {
  225. if (!row[j].split)
  226. row[j] += '';
  227. row[j] = row[j].split(',');
  228. }
  229. }
  230. this.clean();
  231. spritePool.clean();
  232. this.stage.filters = [new PIXI.filters.AlphaFilter()];
  233. this.stage.filterArea = new PIXI.Rectangle(0, 0, Math.max(w * scale, this.width), Math.max(h * scale, this.height));
  234. this.hiddenRooms = msg.hiddenRooms;
  235. this.sprites = _.get2dArray(w, h, 'array');
  236. this.stage.children.sort((a, b) => {
  237. if (a.layer === 'tiles')
  238. return -1;
  239. else if (b.layer === 'tiles')
  240. return 1;
  241. return 0;
  242. });
  243. if (this.zoneId !== null)
  244. events.emit('onRezone', this.zoneId);
  245. this.zoneId = msg.zoneId;
  246. msg.clientObjects.forEach(c => {
  247. c.zoneId = this.zoneId;
  248. events.emit('onGetObject', c);
  249. });
  250. },
  251. setPosition: function (pos, instant) {
  252. pos.x += 16;
  253. pos.y += 16;
  254. let player = window.player;
  255. if (player) {
  256. let px = player.x;
  257. let py = player.y;
  258. let hiddenRooms = this.hiddenRooms || [];
  259. let hLen = hiddenRooms.length;
  260. for (let i = 0; i < hLen; i++) {
  261. let h = hiddenRooms[i];
  262. if (!h.discoverable)
  263. continue;
  264. if (
  265. px < h.x ||
  266. px >= h.x + h.width ||
  267. py < h.y ||
  268. py >= h.y + h.height ||
  269. !physics.isInPolygon(px, py, h.area)
  270. )
  271. continue;
  272. h.discovered = true;
  273. }
  274. }
  275. if (instant) {
  276. this.moveTo = null;
  277. this.pos = pos;
  278. this.stage.x = -~~this.pos.x;
  279. this.stage.y = -~~this.pos.y;
  280. } else
  281. this.moveTo = pos;
  282. this.updateSprites();
  283. },
  284. isVisible: function (x, y) {
  285. let stage = this.stage;
  286. let sx = -stage.x;
  287. let sy = -stage.y;
  288. let sw = this.width;
  289. let sh = this.height;
  290. return (!(x < sx || y < sy || x >= sx + sw || y >= sy + sh));
  291. },
  292. isHidden: function (x, y) {
  293. let hiddenRooms = this.hiddenRooms;
  294. let hLen = hiddenRooms.length;
  295. if (!hLen)
  296. return false;
  297. const { player: { x: px, y: py } } = window;
  298. let foundVisibleLayer = null;
  299. let foundHiddenLayer = null;
  300. hiddenRooms.forEach(h => {
  301. const { discovered, layer, interior } = h;
  302. const { x: hx, y: hy, width, height, area } = h;
  303. //Is the tile outside the hider
  304. if (
  305. x < hx ||
  306. x >= hx + width ||
  307. y < hy ||
  308. y >= hy + height
  309. ) {
  310. //If the hider is an interior, the tile should be hidden if the player is inside the hider
  311. if (interior) {
  312. if (physics.isInPolygon(px, py, area))
  313. foundHiddenLayer = layer;
  314. }
  315. return;
  316. }
  317. //Is the tile inside the hider
  318. if (!physics.isInPolygon(x, y, area))
  319. return;
  320. if (discovered) {
  321. foundVisibleLayer = layer;
  322. return;
  323. }
  324. //Is the player outside the hider
  325. if (
  326. px < hx ||
  327. px >= hx + width ||
  328. py < hy ||
  329. py >= hy + height
  330. ) {
  331. foundHiddenLayer = layer;
  332. return;
  333. }
  334. //Is the player inside the hider
  335. if (!physics.isInPolygon(px, py, area)) {
  336. foundHiddenLayer = layer;
  337. return;
  338. }
  339. foundVisibleLayer = layer;
  340. });
  341. //We compare hider layers to cater for hiders inside hiders
  342. return (foundHiddenLayer > foundVisibleLayer) || (foundHiddenLayer === 0 && foundVisibleLayer === null);
  343. },
  344. updateSprites: function () {
  345. if (this.titleScreen)
  346. return;
  347. const player = window.player;
  348. if (!player)
  349. return;
  350. const { w, h, width, height, stage, map, sprites } = this;
  351. const x = ~~((-stage.x / scale) + (width / (scale * 2)));
  352. const y = ~~((-stage.y / scale) + (height / (scale * 2)));
  353. this.lastUpdatePos.x = stage.x;
  354. this.lastUpdatePos.y = stage.y;
  355. const container = this.layers.tileSprites;
  356. const sw = this.showTilesW;
  357. const sh = this.showTilesH;
  358. let lowX = Math.max(0, x - sw + 1);
  359. let lowY = Math.max(0, y - sh + 2);
  360. let highX = Math.min(w, x + sw - 2);
  361. let highY = Math.min(h, y + sh - 2);
  362. let addedSprite = false;
  363. const checkHidden = this.isHidden.bind(this);
  364. const buildTile = this.buildTile.bind(this);
  365. const newVisible = [];
  366. const newHidden = [];
  367. for (let i = lowX; i < highX; i++) {
  368. let mapRow = map[i];
  369. let spriteRow = sprites[i];
  370. for (let j = lowY; j < highY; j++) {
  371. const cell = mapRow[j];
  372. if (!cell)
  373. continue;
  374. const cLen = cell.length;
  375. if (!cLen)
  376. return;
  377. const rendered = spriteRow[j];
  378. const isHidden = checkHidden(i, j);
  379. if (isHidden) {
  380. const nonFakeRendered = rendered.filter(r => !r.isFake);
  381. const rLen = nonFakeRendered.length;
  382. for (let k = 0; k < rLen; k++) {
  383. const sprite = nonFakeRendered[k];
  384. sprite.visible = false;
  385. spritePool.store(sprite);
  386. rendered.spliceWhere(s => s === sprite);
  387. }
  388. if (cell.visible) {
  389. cell.visible = false;
  390. newHidden.push({
  391. x: i,
  392. y: j
  393. });
  394. }
  395. const hasFake = cell.some(c => c[0] === '-');
  396. if (hasFake) {
  397. const isFakeRendered = rendered.some(r => r.isFake);
  398. if (isFakeRendered)
  399. continue;
  400. } else
  401. continue;
  402. } else {
  403. const fakeRendered = rendered.filter(r => r.isFake);
  404. const rLen = fakeRendered.length;
  405. for (let k = 0; k < rLen; k++) {
  406. const sprite = fakeRendered[k];
  407. sprite.visible = false;
  408. spritePool.store(sprite);
  409. rendered.spliceWhere(s => s === sprite);
  410. }
  411. if (!cell.visible) {
  412. cell.visible = true;
  413. newVisible.push({
  414. x: i,
  415. y: j
  416. });
  417. }
  418. const hasNonFake = cell.some(c => c[0] !== '-');
  419. if (hasNonFake) {
  420. const isNonFakeRendered = rendered.some(r => !r.isFake);
  421. if (isNonFakeRendered)
  422. continue;
  423. } else
  424. continue;
  425. }
  426. for (let k = 0; k < cLen; k++) {
  427. let c = cell[k];
  428. if (c === '0' || c === '')
  429. continue;
  430. const isFake = +c < 0;
  431. if (isFake && !isHidden)
  432. continue;
  433. else if (!isFake && isHidden)
  434. continue;
  435. if (isFake)
  436. c = -c;
  437. c--;
  438. let flipped = '';
  439. if (tileOpacity.canFlip(c)) {
  440. if (mRandom() < 0.5)
  441. flipped = 'flip';
  442. }
  443. let tile = spritePool.getSprite(flipped + c);
  444. if (!tile) {
  445. tile = buildTile(c, i, j);
  446. container.addChild(tile);
  447. tile.type = c;
  448. tile.sheetNum = tileOpacity.getSheetNum(c);
  449. addedSprite = true;
  450. } else {
  451. tile.position.x = i * scale;
  452. tile.position.y = j * scale;
  453. if (flipped !== '')
  454. tile.position.x += scale;
  455. tile.visible = true;
  456. }
  457. if (isFake)
  458. tile.isFake = isFake;
  459. tile.z = k;
  460. rendered.push(tile);
  461. }
  462. }
  463. }
  464. lowX = Math.max(0, lowX - 10);
  465. lowY = Math.max(0, lowY - 10);
  466. highX = Math.min(w - 1, highX + 10);
  467. highY = Math.min(h - 1, highY + 10);
  468. for (let i = lowX; i < highX; i++) {
  469. const mapRow = map[i];
  470. let spriteRow = sprites[i];
  471. let outside = ((i >= x - sw) && (i < x + sw));
  472. for (let j = lowY; j < highY; j++) {
  473. if ((outside) && (j >= y - sh) && (j < y + sh))
  474. continue;
  475. const cell = mapRow[j];
  476. if (cell.visible) {
  477. cell.visible = false;
  478. newHidden.push({ x: i, y: j });
  479. }
  480. let list = spriteRow[j];
  481. let lLen = list.length;
  482. for (let k = 0; k < lLen; k++) {
  483. let sprite = list[k];
  484. sprite.visible = false;
  485. spritePool.store(sprite);
  486. }
  487. spriteRow[j] = [];
  488. }
  489. }
  490. events.emit('onTilesVisible', newVisible, true);
  491. events.emit('onTilesVisible', newHidden, false);
  492. if (addedSprite)
  493. container.children.sort((a, b) => a.z - b.z);
  494. },
  495. update: function () {
  496. let time = +new Date();
  497. if (this.moveTo) {
  498. let deltaX = this.moveTo.x - this.pos.x;
  499. let deltaY = this.moveTo.y - this.pos.y;
  500. if (deltaX !== 0 || deltaY !== 0) {
  501. let distance = Math.max(Math.abs(deltaX), Math.abs(deltaY));
  502. let moveSpeedMax = this.moveSpeedMax;
  503. if (this.moveSpeed < moveSpeedMax)
  504. this.moveSpeed += this.moveSpeedInc;
  505. let moveSpeed = this.moveSpeed;
  506. if (moveSpeedMax < 1.6)
  507. moveSpeed *= 1 + (distance / 200);
  508. let elapsed = time - this.lastTick;
  509. moveSpeed *= (elapsed / 15);
  510. if (moveSpeed > distance)
  511. moveSpeed = distance;
  512. deltaX = (deltaX / distance) * moveSpeed;
  513. deltaY = (deltaY / distance) * moveSpeed;
  514. this.pos.x = this.pos.x + deltaX;
  515. this.pos.y = this.pos.y + deltaY;
  516. } else {
  517. this.moveSpeed = 0;
  518. this.moveTo = null;
  519. }
  520. let stage = this.stage;
  521. if (window.staticCamera !== true) {
  522. stage.x = -~~this.pos.x;
  523. stage.y = -~~this.pos.y;
  524. }
  525. let halfScale = scale / 2;
  526. if (Math.abs(stage.x - this.lastUpdatePos.x) > halfScale || Math.abs(stage.y - this.lastUpdatePos.y) > halfScale)
  527. this.updateSprites();
  528. events.emit('onSceneMove');
  529. }
  530. this.lastTick = time;
  531. },
  532. buildContainer: function (obj) {
  533. let container = new PIXI.Container();
  534. this.layers[obj.layerName || obj.sheetName].addChild(container);
  535. return container;
  536. },
  537. buildRectangle: function (obj) {
  538. let graphics = new PIXI.Graphics();
  539. let alpha = obj.alpha;
  540. if (obj.has('alpha'))
  541. graphics.alpha = alpha;
  542. let fillAlpha = obj.fillAlpha;
  543. if (obj.has('fillAlpha'))
  544. fillAlpha = 1;
  545. graphics.beginFill(obj.color || '0x48edff', fillAlpha);
  546. if (obj.strokeColor)
  547. graphics.lineStyle(scaleMult, obj.strokeColor);
  548. graphics.drawRect(0, 0, obj.w, obj.h);
  549. graphics.endFill();
  550. (obj.parent || this.layers[obj.layerName || obj.sheetName]).addChild(graphics);
  551. graphics.position.x = obj.x;
  552. graphics.position.y = obj.y;
  553. return graphics;
  554. },
  555. moveRectangle: function (obj) {
  556. obj.sprite.position.x = obj.x;
  557. obj.sprite.position.y = obj.y;
  558. obj.sprite.width = obj.w;
  559. obj.sprite.height = obj.h;
  560. },
  561. buildObject: function (obj) {
  562. const { sheetName, parent: container, layerName, visible = true } = obj;
  563. const sprite = new PIXI.Sprite();
  564. obj.sprite = sprite;
  565. this.setSprite(obj);
  566. sprite.visible = visible;
  567. const spriteContainer = container || this.layers[layerName || sheetName] || this.layers.objects;
  568. spriteContainer.addChild(sprite);
  569. obj.w = sprite.width;
  570. obj.h = sprite.height;
  571. return sprite;
  572. },
  573. addFilter: function (sprite) {
  574. let thickness = (sprite.width > scale) ? 8 : 16;
  575. let filter = new shaderOutline(this.renderer.width, this.renderer.height, thickness, '0xffffff');
  576. if (!sprite.filters)
  577. sprite.filters = [filter];
  578. else
  579. sprite.filters.push();
  580. return filter;
  581. },
  582. removeFilter: function (sprite, filter) {
  583. if (sprite.filters)
  584. sprite.filters = null;
  585. },
  586. buildText: function (obj) {
  587. let textSprite = new PIXI.Text(obj.text, {
  588. fontFamily: 'bitty',
  589. fontSize: (obj.fontSize || 14),
  590. fill: obj.color || 0xF2F5F5,
  591. stroke: 0x2d2136,
  592. strokeThickness: 4,
  593. align: 'center'
  594. });
  595. textSprite.x = obj.x - (textSprite.width / 2);
  596. textSprite.y = obj.y;
  597. let parentSprite = obj.parent || this.layers[obj.layerName];
  598. parentSprite.addChild(textSprite);
  599. return textSprite;
  600. },
  601. buildEmitter: function (config) {
  602. const { layerName = 'particles' } = config;
  603. const particleEngine = particleEngines[layerName];
  604. return particleEngine.buildEmitter(config);
  605. },
  606. destroyEmitter: function (emitter) {
  607. const particleEngine = emitter.particleEngine;
  608. particleEngine.destroyEmitter(emitter);
  609. },
  610. setSprite: function (obj) {
  611. const { sprite, sheetName, cell } = obj;
  612. const bigSheets = globals.clientConfig.bigTextures;
  613. const isBigSheet = bigSheets.includes(sheetName);
  614. const newSize = isBigSheet ? 24 : 8;
  615. obj.w = newSize * scaleMult;
  616. obj.h = obj.w;
  617. sprite.width = obj.w;
  618. sprite.height = obj.h;
  619. sprite.texture = this.getTexture(sheetName, cell, newSize);
  620. if (newSize !== sprite.size) {
  621. sprite.size = newSize;
  622. this.setSpritePosition(obj);
  623. }
  624. },
  625. setSpritePosition: function (obj) {
  626. const { sprite, x, y, flipX, offsetX = 0, offsetY = 0 } = obj;
  627. sprite.x = (x * scale) + (flipX ? scale : 0) + offsetX;
  628. const oldY = sprite.y;
  629. sprite.y = (y * scale) + offsetY;
  630. if (sprite.width > scale) {
  631. if (flipX)
  632. sprite.x += scale;
  633. else
  634. sprite.x -= scale;
  635. sprite.y -= (scale * 2);
  636. }
  637. if (oldY !== sprite.y)
  638. this.reorder();
  639. sprite.scale.x = flipX ? -scaleMult : scaleMult;
  640. },
  641. reorder: function () {
  642. this.layers.mobs.children.sort((a, b) => b.y - a.y);
  643. },
  644. destroyObject: function (obj) {
  645. if (obj.sprite.parent)
  646. obj.sprite.parent.removeChild(obj.sprite);
  647. },
  648. //Changes the moveSpeedMax and moveSpeedInc variables
  649. // moveSpeed changes when mounting and unmounting
  650. // moveSpeed: 0 | moveSpeedMax: 1.5 | moveSpeedInc: 0.5
  651. // moveSpeed: 200 | moveSpeedMax: 5.5 | moveSpeedInc: 0.2
  652. // Between these values we should follow an exponential curve for moveSpeedInc since
  653. // a higher chance will proc more often, meaning the buildup in distance becomes greater
  654. adaptCameraMoveSpeed: function (moveSpeed) {
  655. const factor = Math.sqrt(moveSpeed);
  656. const maxValue = Math.sqrt(200);
  657. this.moveSpeedMax = 1.5 + ((moveSpeed / 200) * 3.5);
  658. this.moveSpeedInc = 0.2 + (((maxValue - factor) / maxValue) * 0.3);
  659. },
  660. updateMapAtPosition: function (x, y, mapCellString) {
  661. const { map, sprites, layers: { tileSprites: container } } = this;
  662. const row = sprites[x];
  663. if (!row)
  664. return;
  665. const cell = row[y];
  666. if (!cell)
  667. return;
  668. cell.forEach(c => {
  669. c.visible = false;
  670. spritePool.store(c);
  671. });
  672. cell.length = 0;
  673. map[x][y] = mapCellString.split(',');
  674. map[x][y].forEach(m => {
  675. m--;
  676. let tile = spritePool.getSprite(m);
  677. if (!tile) {
  678. tile = this.buildTile(m, x, y);
  679. container.addChild(tile);
  680. tile.type = m;
  681. tile.sheetNum = tileOpacity.getSheetNum(m);
  682. } else {
  683. tile.position.x = x * scale;
  684. tile.position.y = y * scale;
  685. tile.visible = true;
  686. }
  687. cell.push(tile);
  688. cell.visible = true;
  689. });
  690. },
  691. render: function () {
  692. if (!this.stage)
  693. return;
  694. effects.render();
  695. particleLayers.forEach(p => particleEngines[p].update());
  696. this.renderer.render(this.stage);
  697. }
  698. };
  699. });