smoothretro82

Square Area Testing v1.1.1

Dec 6th, 2025
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.84 KB | None | 0 0
  1. (async function() {
  2. const startX = -20;
  3. const startY = -10;
  4. const endX = 19;
  5. const endY = 9;
  6. const areaWidth = endX - startX + 1;
  7.  
  8. const typingCooldown = 10;
  9. let isRunning = true;
  10. let safetyEnabled = true;
  11. let chatText = '';
  12. let chatX = 0;
  13. let chatY = 0;
  14. let chatTimeout = null;
  15. let cloudAnimationInterval = null;
  16. let dayNightInterval = null;
  17. let timeUpdateInterval = null;
  18.  
  19. // Time phases
  20. const PHASE_DAY = 0;
  21. const PHASE_SUNSET = 1;
  22. const PHASE_NIGHT = 2;
  23. const PHASE_SUNRISE = 3;
  24.  
  25. let currentPhase = PHASE_DAY;
  26. const fullCycleDuration = 150000; // 150 seconds full cycle
  27. const phaseDuration = fullCycleDuration / 4; // 37.5 seconds per phase
  28. let phaseStartTime = Date.now();
  29.  
  30. // Colors for each phase
  31. const dayColor = 10;
  32. const sunsetColor = 5;
  33. const nightColor = 30;
  34. const sunriseColor = 26;
  35. const starColor = 0;
  36.  
  37. // Characters for each phase
  38. const dayChar = '▒';
  39. const sunsetChar = '▒';
  40. const nightChar = '▒';
  41. const sunriseChar = '▒';
  42. const starChar = '•';
  43. const cloudChar = '~';
  44.  
  45. // Star positions
  46. let starPositions = [];
  47.  
  48. // Simulation time
  49. let simYear = 0;
  50. let simMonth = 0;
  51. let simDay = 1;
  52. let simHour = 6;
  53. let simMinute = 0;
  54.  
  55. const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  56. const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  57.  
  58. // Date/Time display positions
  59. const dateDisplayX = 21;
  60. const dateDisplayY = -10;
  61. const timeDisplayX = 21;
  62. const timeDisplayY = -8;
  63.  
  64. // Previous display lengths for clearing
  65. let prevDateTextLength = 0;
  66. let prevTimeTextLength = 0;
  67.  
  68. // Correct chars list for version, coords, date, time
  69. let correctChars = [];
  70.  
  71. // World position of square
  72. let squareWorldX = 0;
  73. let squareWorldY = 0;
  74.  
  75. // Camera position
  76. let cameraWorldX = startX;
  77.  
  78. // Terrain Y levels (base values)
  79. const baseGrassY = 1;
  80. const baseDirtStartY = 2;
  81. const baseDirtEndY = 3;
  82. const baseStoneStartY = 4;
  83. const cloudEndY = -7;
  84.  
  85. // Characters
  86. const grassChar = ',';
  87. const dirtChar = '.';
  88. const stoneChar = '#';
  89.  
  90. // Colors
  91. const cloudColor = 0;
  92. const grassColor = 9;
  93. const dirtColor = 22;
  94. const stoneColor = 1;
  95. const defaultColor = 25;
  96.  
  97. // Cloud data structure
  98. let clouds = [];
  99.  
  100. // Terrain height cache
  101. let terrainHeights = {};
  102.  
  103. // World border
  104. const worldBorderMinX = -500000;
  105. const worldBorderMaxX = 500000;
  106.  
  107. // Input values for movement
  108. const inputx = 1;
  109. const inputy = 1;
  110.  
  111. // Coordinate display position
  112. const coordDisplayX = startX;
  113. const coordDisplayY = startY;
  114. const versionDisplayY = startY + 1;
  115.  
  116. const versionText = 'Square Area Testing 1.1.1';
  117.  
  118. // Previous coordinate text
  119. let prevCoordText = '';
  120. let prevCoordTextLength = 0;
  121.  
  122. // Helper function for cooldown
  123. function wait(ms) {
  124. return new Promise(resolve => setTimeout(resolve, ms));
  125. }
  126.  
  127. // Simple seeded random
  128. function seededRandom(seed) {
  129. let x = Math.sin(seed * 12.9898 + 78.233) * 43758.5453;
  130. return x - Math.floor(x);
  131. }
  132.  
  133. // Weak perlin-like noise for terrain
  134. function perlinNoise(x) {
  135. let noise = 0;
  136. noise += Math.sin(x * 0.15) * 0.4;
  137. noise += Math.sin(x * 0.4 + 100) * 0.3;
  138. noise += Math.sin(x * 0.8 + 200) * 0.15;
  139. noise += (seededRandom(Math.floor(x)) - 0.5) * 0.3;
  140. return noise;
  141. }
  142.  
  143. // Get grass height offset at world X (0 or 1)
  144. function getGrassHeightOffset(worldX) {
  145. let key = 'h' + worldX;
  146. if (terrainHeights[key] !== undefined) {
  147. return terrainHeights[key];
  148. }
  149.  
  150. let noise = perlinNoise(worldX);
  151. let offset = noise > 0.1 ? 0 : 1;
  152. terrainHeights[key] = offset;
  153. return offset;
  154. }
  155.  
  156. // Get actual grass Y at world X
  157. function getGrassY(worldX) {
  158. return baseGrassY - getGrassHeightOffset(worldX);
  159. }
  160.  
  161. // Get current sky color based on phase
  162. function getSkyColor() {
  163. switch (currentPhase) {
  164. case PHASE_DAY: return dayColor;
  165. case PHASE_SUNSET: return sunsetColor;
  166. case PHASE_NIGHT: return nightColor;
  167. case PHASE_SUNRISE: return sunriseColor;
  168. default: return dayColor;
  169. }
  170. }
  171.  
  172. // Get current sky char based on phase
  173. function getSkyChar() {
  174. switch (currentPhase) {
  175. case PHASE_DAY: return dayChar;
  176. case PHASE_SUNSET: return sunsetChar;
  177. case PHASE_NIGHT: return nightChar;
  178. case PHASE_SUNRISE: return sunriseChar;
  179. default: return dayChar;
  180. }
  181. }
  182.  
  183. // Calculate time based on phase progress
  184. function calculateSimTime() {
  185. let now = Date.now();
  186. let elapsed = now - phaseStartTime;
  187. let progress = Math.min(elapsed / phaseDuration, 1);
  188.  
  189. let startHour, hoursInPhase;
  190.  
  191. switch (currentPhase) {
  192. case PHASE_DAY:
  193. startHour = 6;
  194. hoursInPhase = 12;
  195. break;
  196. case PHASE_SUNSET:
  197. startHour = 18;
  198. hoursInPhase = 3;
  199. break;
  200. case PHASE_NIGHT:
  201. startHour = 21;
  202. hoursInPhase = 7;
  203. break;
  204. case PHASE_SUNRISE:
  205. startHour = 4;
  206. hoursInPhase = 2;
  207. break;
  208. default:
  209. startHour = 6;
  210. hoursInPhase = 12;
  211. }
  212.  
  213. let currentHourFloat = startHour + (progress * hoursInPhase);
  214.  
  215. if (currentHourFloat >= 24) {
  216. currentHourFloat -= 24;
  217. }
  218.  
  219. simHour = Math.floor(currentHourFloat);
  220. simMinute = Math.floor((currentHourFloat - simHour) * 60);
  221. }
  222.  
  223. // Generate star positions for night sky
  224. function generateStars() {
  225. starPositions = [];
  226. let seed = simDay * 100 + simMonth * 10 + simYear;
  227.  
  228. for (let y = startY; y <= cloudEndY; y++) {
  229. for (let x = startX; x <= endX; x++) {
  230. let rand = seededRandom(seed + x * 100 + y);
  231. if (rand < 0.08) {
  232. starPositions.push({ x: x, y: y });
  233. }
  234. }
  235. }
  236.  
  237. for (let y = cloudEndY + 1; y < 0; y++) {
  238. for (let x = startX; x <= endX; x++) {
  239. let rand = seededRandom(seed + x * 100 + y + 500);
  240. if (rand < 0.05) {
  241. starPositions.push({ x: x, y: y });
  242. }
  243. }
  244. }
  245. }
  246.  
  247. // Check if position has a star
  248. function hasStarAt(x, y) {
  249. if (currentPhase !== PHASE_NIGHT) return false;
  250.  
  251. for (let i = 0; i < starPositions.length; i++) {
  252. if (starPositions[i].x === x && starPositions[i].y === y) {
  253. return true;
  254. }
  255. }
  256. return false;
  257. }
  258.  
  259. // Format date string
  260. function getDateString() {
  261. return months[simMonth] + ' ' + simDay + ' ' + String(simYear).padStart(4, '0');
  262. }
  263.  
  264. // Format time string
  265. function getTimeString() {
  266. let hourStr = String(simHour).padStart(2, '0');
  267. let minStr = String(simMinute).padStart(2, '0');
  268. return hourStr + ':' + minStr;
  269. }
  270.  
  271. // Increment date (called after full day/night cycle)
  272. function incrementDate() {
  273. simDay += 1;
  274.  
  275. if (simDay > daysInMonth[simMonth]) {
  276. simDay = 1;
  277. simMonth += 1;
  278.  
  279. if (simMonth >= 12) {
  280. simMonth = 0;
  281. simYear += 1;
  282. }
  283. }
  284.  
  285. generateStars();
  286. }
  287.  
  288. // Build version correct list
  289. function buildVersionCorrectList() {
  290. for (let i = 0; i < versionText.length; i++) {
  291. let key = (coordDisplayX + i) + ',' + versionDisplayY;
  292. correctChars[key] = { char: versionText[i], color: defaultColor };
  293. }
  294. }
  295.  
  296. // Build/update coord correct list
  297. function buildCoordCorrectList() {
  298. let coordText = 'square is at ' + squareWorldX + ', ' + (-squareWorldY);
  299.  
  300. if (prevCoordTextLength > 0) {
  301. for (let i = 0; i < prevCoordTextLength; i++) {
  302. let key = (coordDisplayX + i) + ',' + coordDisplayY;
  303. delete correctChars[key];
  304. }
  305. }
  306.  
  307. for (let i = 0; i < coordText.length; i++) {
  308. let key = (coordDisplayX + i) + ',' + coordDisplayY;
  309. correctChars[key] = { char: coordText[i], color: defaultColor };
  310. }
  311.  
  312. prevCoordText = coordText;
  313. prevCoordTextLength = coordText.length;
  314. }
  315.  
  316. // Build/update date correct list
  317. function buildDateCorrectList() {
  318. let dateText = getDateString();
  319.  
  320. if (prevDateTextLength > 0) {
  321. for (let i = 0; i < prevDateTextLength; i++) {
  322. let key = (dateDisplayX + i) + ',' + dateDisplayY;
  323. delete correctChars[key];
  324. }
  325. }
  326.  
  327. for (let i = 0; i < dateText.length; i++) {
  328. let key = (dateDisplayX + i) + ',' + dateDisplayY;
  329. correctChars[key] = { char: dateText[i], color: defaultColor };
  330. }
  331.  
  332. prevDateTextLength = dateText.length;
  333. }
  334.  
  335. // Build/update time correct list
  336. function buildTimeCorrectList() {
  337. let timeText = getTimeString();
  338.  
  339. if (prevTimeTextLength > 0) {
  340. for (let i = 0; i < prevTimeTextLength; i++) {
  341. let key = (timeDisplayX + i) + ',' + timeDisplayY;
  342. delete correctChars[key];
  343. }
  344. }
  345.  
  346. for (let i = 0; i < timeText.length; i++) {
  347. let key = (timeDisplayX + i) + ',' + timeDisplayY;
  348. correctChars[key] = { char: timeText[i], color: defaultColor };
  349. }
  350.  
  351. prevTimeTextLength = timeText.length;
  352. }
  353.  
  354. // Check if position is in correct chars list
  355. function getCorrectChar(x, y) {
  356. let key = x + ',' + y;
  357. return correctChars[key] || null;
  358. }
  359.  
  360. // Generate random clouds
  361. function generateClouds() {
  362. clouds = [];
  363.  
  364. for (let y = startY; y <= cloudEndY; y++) {
  365. let x = startX;
  366. let seed = y * 1000 + currentCloudPattern * 100;
  367.  
  368. while (x <= endX) {
  369. let rand = seededRandom(seed + x);
  370.  
  371. if (rand < 0.35) {
  372. let length = Math.floor(seededRandom(seed + x + 1) * 4) + 3;
  373.  
  374. if (x + length > endX + 1) {
  375. length = endX - x + 1;
  376. }
  377.  
  378. if (length >= 3) {
  379. clouds.push({ x: x, y: y, length: length });
  380. }
  381.  
  382. x += length + Math.floor(seededRandom(seed + x + 2) * 4) + 2;
  383. } else {
  384. x += 1;
  385. }
  386. }
  387. }
  388. }
  389.  
  390. let currentCloudPattern = 0;
  391.  
  392. // Get screen X from world X
  393. function worldToScreenX(worldX) {
  394. return worldX - cameraWorldX + startX;
  395. }
  396.  
  397. // Get world X from screen X
  398. function screenToWorldX(screenX) {
  399. return screenX - startX + cameraWorldX;
  400. }
  401.  
  402. // Get square screen position
  403. function getSquareScreenX() {
  404. return worldToScreenX(squareWorldX);
  405. }
  406.  
  407. // Update camera to follow square
  408. function updateCamera() {
  409. let screenX = getSquareScreenX();
  410. let margin = 8;
  411.  
  412. if (screenX < startX + margin) {
  413. cameraWorldX = squareWorldX - margin;
  414. } else if (screenX > endX - margin - 1) {
  415. cameraWorldX = squareWorldX - (areaWidth - margin - 2);
  416. }
  417. }
  418.  
  419. // Check if screen position has a cloud
  420. function hasCloudAt(screenX, screenY) {
  421. for (let i = 0; i < clouds.length; i++) {
  422. let cloud = clouds[i];
  423. if (cloud.y === screenY && screenX >= cloud.x && screenX < cloud.x + cloud.length) {
  424. return true;
  425. }
  426. }
  427. return false;
  428. }
  429.  
  430. // Get terrain info for a screen position
  431. function getTerrainInfo(screenX, y) {
  432. let worldX = screenToWorldX(screenX);
  433. let grassY = getGrassY(worldX);
  434. let dirtStartY = grassY + 1;
  435. let dirtEndY = grassY + 2;
  436. let stoneStartY = grassY + 3;
  437.  
  438. // Cloud area
  439. if (y <= cloudEndY) {
  440. if (hasCloudAt(screenX, y)) {
  441. return { char: cloudChar, color: cloudColor, isSky: false };
  442. } else if (hasStarAt(screenX, y)) {
  443. return { char: starChar, color: starColor, isSky: true };
  444. } else {
  445. return { char: getSkyChar(), color: getSkyColor(), isSky: true };
  446. }
  447. }
  448.  
  449. // Sky area (between clouds and grass)
  450. if (y < grassY) {
  451. if (hasStarAt(screenX, y)) {
  452. return { char: starChar, color: starColor, isSky: true };
  453. } else {
  454. return { char: getSkyChar(), color: getSkyColor(), isSky: true };
  455. }
  456. }
  457.  
  458. // Grass
  459. if (y === grassY) {
  460. return { char: grassChar, color: grassColor, isSky: false };
  461. }
  462.  
  463. // Dirt
  464. if (y >= dirtStartY && y <= dirtEndY) {
  465. return { char: dirtChar, color: dirtColor, isSky: false };
  466. }
  467.  
  468. // Stone
  469. if (y >= stoneStartY && y <= endY) {
  470. return { char: stoneChar, color: stoneColor, isSky: false };
  471. }
  472.  
  473. // Default sky
  474. return { char: getSkyChar(), color: getSkyColor(), isSky: true };
  475. }
  476.  
  477. // Function to draw text at position
  478. async function drawText(x, y, text) {
  479. await w.changeColor(defaultColor);
  480. for (let i = 0; i < text.length; i++) {
  481. await w.tp(x + i, y);
  482. await w.typeChar(text[i], 1);
  483. await wait(typingCooldown);
  484. }
  485. }
  486.  
  487. // Function to clear text at position with terrain
  488. async function clearTextWithTerrain(x, y, length) {
  489. for (let i = 0; i < length; i++) {
  490. let terrain = getTerrainInfo(x + i, y);
  491. await w.changeColor(terrain.color);
  492. await w.tp(x + i, y);
  493. await w.typeChar(terrain.char, 1);
  494. await wait(typingCooldown);
  495. }
  496. }
  497.  
  498. // Function to draw sky with day/night/stars
  499. async function drawSky() {
  500. let skyColor = getSkyColor();
  501. let skyChar = getSkyChar();
  502. let squareScreenX = getSquareScreenX();
  503.  
  504. // Draw sky in cloud area
  505. for (let y = startY; y <= cloudEndY; y++) {
  506. for (let x = startX; x <= endX; x++) {
  507. if (getCorrectChar(x, y)) {
  508. continue;
  509. }
  510. if (y === squareWorldY && (x === squareScreenX || x === squareScreenX + 1)) {
  511. continue;
  512. }
  513. if (chatText.length > 0 && y === chatY && x >= chatX && x < chatX + chatText.length) {
  514. continue;
  515. }
  516.  
  517. if (hasCloudAt(x, y)) {
  518. await w.changeColor(cloudColor);
  519. await w.tp(x, y);
  520. await w.typeChar(cloudChar, 1);
  521. } else if (hasStarAt(x, y)) {
  522. await w.changeColor(starColor);
  523. await w.tp(x, y);
  524. await w.typeChar(starChar, 1);
  525. } else {
  526. await w.changeColor(skyColor);
  527. await w.tp(x, y);
  528. await w.typeChar(skyChar, 1);
  529. }
  530. await wait(typingCooldown);
  531. }
  532. }
  533.  
  534. // Draw air between clouds and lowest possible grass
  535. for (let y = cloudEndY + 1; y < baseGrassY; y++) {
  536. for (let x = startX; x <= endX; x++) {
  537. if (y === squareWorldY && (x === squareScreenX || x === squareScreenX + 1)) {
  538. continue;
  539. }
  540. if (chatText.length > 0 && y === chatY && x >= chatX && x < chatX + chatText.length) {
  541. continue;
  542. }
  543.  
  544. let terrain = getTerrainInfo(x, y);
  545.  
  546. if (terrain.isSky) {
  547. if (hasStarAt(x, y)) {
  548. await w.changeColor(starColor);
  549. await w.tp(x, y);
  550. await w.typeChar(starChar, 1);
  551. } else {
  552. await w.changeColor(skyColor);
  553. await w.tp(x, y);
  554. await w.typeChar(skyChar, 1);
  555. }
  556. } else {
  557. await w.changeColor(terrain.color);
  558. await w.tp(x, y);
  559. await w.typeChar(terrain.char, 1);
  560. }
  561. await wait(typingCooldown);
  562. }
  563. }
  564.  
  565. await w.changeColor(defaultColor);
  566. }
  567.  
  568. // Function to draw all clouds
  569. async function drawClouds() {
  570. generateClouds();
  571. await drawSky();
  572. }
  573.  
  574. // Function to draw terrain (grass, dirt, stone with perlin height)
  575. async function drawTerrain() {
  576. let squareScreenX = getSquareScreenX();
  577.  
  578. for (let x = startX; x <= endX; x++) {
  579. let worldX = screenToWorldX(x);
  580. let grassY = getGrassY(worldX);
  581. let dirtStartY = grassY + 1;
  582. let dirtEndY = grassY + 2;
  583. let stoneStartY = grassY + 3;
  584.  
  585. // Draw grass
  586. if (!(squareWorldY === grassY && (x === squareScreenX || x === squareScreenX + 1))) {
  587. await w.changeColor(grassColor);
  588. await w.tp(x, grassY);
  589. await w.typeChar(grassChar, 1);
  590. await wait(typingCooldown);
  591. }
  592.  
  593. // Draw dirt
  594. for (let y = dirtStartY; y <= dirtEndY && y <= endY; y++) {
  595. if (squareWorldY === y && (x === squareScreenX || x === squareScreenX + 1)) {
  596. continue;
  597. }
  598. await w.changeColor(dirtColor);
  599. await w.tp(x, y);
  600. await w.typeChar(dirtChar, 1);
  601. await wait(typingCooldown);
  602. }
  603.  
  604. // Draw stone
  605. for (let y = stoneStartY; y <= endY; y++) {
  606. if (squareWorldY === y && (x === squareScreenX || x === squareScreenX + 1)) {
  607. continue;
  608. }
  609. await w.changeColor(stoneColor);
  610. await w.tp(x, y);
  611. await w.typeChar(stoneChar, 1);
  612. await wait(typingCooldown);
  613. }
  614. }
  615.  
  616. await w.changeColor(defaultColor);
  617. }
  618.  
  619. // Function to draw all terrain
  620. async function drawAllTerrain() {
  621. await drawClouds();
  622. await drawTerrain();
  623. }
  624.  
  625. // Function to update coordinate display
  626. async function updateCoordDisplay() {
  627. let coordText = 'square is at ' + squareWorldX + ', ' + (-squareWorldY);
  628.  
  629. if (prevCoordTextLength > coordText.length) {
  630. await clearTextWithTerrain(coordDisplayX + coordText.length, coordDisplayY, prevCoordTextLength - coordText.length);
  631. }
  632.  
  633. buildCoordCorrectList();
  634. await drawText(coordDisplayX, coordDisplayY, coordText);
  635. }
  636.  
  637. // Function to draw version text
  638. async function drawVersionText() {
  639. buildVersionCorrectList();
  640. await drawText(coordDisplayX, versionDisplayY, versionText);
  641. }
  642.  
  643. // Function to draw date display
  644. async function drawDateDisplay() {
  645. let dateText = getDateString();
  646.  
  647. if (prevDateTextLength > dateText.length) {
  648. await clearTextWithTerrain(dateDisplayX + dateText.length, dateDisplayY, prevDateTextLength - dateText.length);
  649. }
  650.  
  651. buildDateCorrectList();
  652. await drawText(dateDisplayX, dateDisplayY, dateText);
  653. }
  654.  
  655. // Function to draw time display
  656. async function drawTimeDisplay() {
  657. let timeText = getTimeString();
  658.  
  659. if (prevTimeTextLength > timeText.length) {
  660. await clearTextWithTerrain(timeDisplayX + timeText.length, timeDisplayY, prevTimeTextLength - timeText.length);
  661. }
  662.  
  663. buildTimeCorrectList();
  664. await drawText(timeDisplayX, timeDisplayY, timeText);
  665. }
  666.  
  667. // Function to draw the square
  668. async function drawSquare() {
  669. let screenX = getSquareScreenX();
  670. await w.changeColor(defaultColor);
  671. await w.tp(screenX, squareWorldY);
  672. await w.typeChar('[', 1);
  673. await wait(typingCooldown);
  674. await w.typeChar(']', 1);
  675. await wait(typingCooldown);
  676. }
  677.  
  678. // Function to clear the square
  679. async function clearSquare() {
  680. let screenX = getSquareScreenX();
  681. let y = squareWorldY;
  682.  
  683. let terrain1 = getTerrainInfo(screenX, y);
  684. let terrain2 = getTerrainInfo(screenX + 1, y);
  685.  
  686. await w.changeColor(terrain1.color);
  687. await w.tp(screenX, y);
  688. await w.typeChar(terrain1.char, 1);
  689. await wait(typingCooldown);
  690.  
  691. await w.changeColor(terrain2.color);
  692. await w.tp(screenX + 1, y);
  693. await w.typeChar(terrain2.char, 1);
  694. await wait(typingCooldown);
  695.  
  696. await w.changeColor(defaultColor);
  697. }
  698.  
  699. // Function to clear chat text
  700. async function clearChatText() {
  701. if (chatText.length > 0) {
  702. let oldChatText = chatText;
  703. let oldChatX = chatX;
  704. let oldChatY = chatY;
  705. chatText = '';
  706.  
  707. for (let i = 0; i < oldChatText.length; i++) {
  708. let currentX = oldChatX + i;
  709. let terrain = getTerrainInfo(currentX, oldChatY);
  710. await w.changeColor(terrain.color);
  711. await w.tp(currentX, oldChatY);
  712. await w.typeChar(terrain.char, 1);
  713. await wait(typingCooldown);
  714. }
  715. await w.changeColor(defaultColor);
  716. }
  717. }
  718.  
  719. // Function to draw chat text
  720. async function drawChatText() {
  721. if (chatText.length > 0) {
  722. let screenX = getSquareScreenX();
  723. let squareMiddle = screenX + 0.5;
  724. let textHalfLength = Math.floor(chatText.length / 2);
  725. chatX = Math.round(squareMiddle - textHalfLength);
  726. chatY = squareWorldY - 1;
  727.  
  728. await w.changeColor(defaultColor);
  729. for (let i = 0; i < chatText.length; i++) {
  730. await w.tp(chatX + i, chatY);
  731. await w.typeChar(chatText[i], 1);
  732. await wait(typingCooldown);
  733. }
  734. }
  735. }
  736.  
  737. // Check if position is part of UI elements
  738. function isUIPosition(x, y) {
  739. let screenX = getSquareScreenX();
  740.  
  741. if (y === squareWorldY && (x === screenX || x === screenX + 1)) {
  742. return true;
  743. }
  744. if (chatText.length > 0 && y === chatY && x >= chatX && x < chatX + chatText.length) {
  745. return true;
  746. }
  747. if (getCorrectChar(x, y)) {
  748. return true;
  749. }
  750. return false;
  751. }
  752.  
  753. // Check if square brackets are missing or miscolored
  754. async function checkSquare() {
  755. if (!isRunning || !safetyEnabled) return;
  756.  
  757. try {
  758. let screenX = getSquareScreenX();
  759. let leftBracket = await getCharInfoXY(screenX, squareWorldY);
  760. let rightBracket = await getCharInfoXY(screenX + 1, squareWorldY);
  761.  
  762. let needRedraw = false;
  763.  
  764. if (!leftBracket || leftBracket.char !== '[' || leftBracket.color !== defaultColor) {
  765. needRedraw = true;
  766. }
  767. if (!rightBracket || rightBracket.char !== ']' || rightBracket.color !== defaultColor) {
  768. needRedraw = true;
  769. }
  770.  
  771. if (needRedraw) {
  772. await drawSquare();
  773. console.log('Square restored at (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  774. }
  775. } catch (e) {
  776. console.log('checkSquare error:', e);
  777. }
  778. }
  779.  
  780. // Check version, coord, date, time text using correct list
  781. async function checkCorrectChars() {
  782. if (!isRunning || !safetyEnabled) return;
  783.  
  784. try {
  785. for (let key in correctChars) {
  786. if (!isRunning || !safetyEnabled) return;
  787.  
  788. let parts = key.split(',');
  789. let x = parseInt(parts[0]);
  790. let y = parseInt(parts[1]);
  791. let expected = correctChars[key];
  792.  
  793. let charInfo = await getCharInfoXY(x, y);
  794.  
  795. if (!charInfo || charInfo.char !== expected.char || charInfo.color !== expected.color) {
  796. await w.changeColor(expected.color);
  797. await w.tp(x, y);
  798. await w.typeChar(expected.char, 1);
  799. await wait(typingCooldown);
  800. }
  801. }
  802. } catch (e) {
  803. console.log('checkCorrectChars error:', e);
  804. }
  805. }
  806.  
  807. // Check terrain char and color
  808. async function checkTerrain() {
  809. if (!isRunning || !safetyEnabled) return;
  810.  
  811. try {
  812. for (let y = startY; y <= endY; y++) {
  813. for (let x = startX; x <= endX; x++) {
  814. if (!isRunning || !safetyEnabled) return;
  815.  
  816. if (isUIPosition(x, y)) {
  817. continue;
  818. }
  819.  
  820. let terrain = getTerrainInfo(x, y);
  821. let charInfo = await getCharInfoXY(x, y);
  822.  
  823. if (!charInfo) {
  824. await w.changeColor(terrain.color);
  825. await w.tp(x, y);
  826. await w.typeChar(terrain.char, 1);
  827. await wait(typingCooldown);
  828. continue;
  829. }
  830.  
  831. if (charInfo.char !== terrain.char || charInfo.color !== terrain.color) {
  832. await w.changeColor(terrain.color);
  833. await w.tp(x, y);
  834. await w.typeChar(terrain.char, 1);
  835. await wait(typingCooldown);
  836. }
  837. }
  838. }
  839. await w.changeColor(defaultColor);
  840. } catch (e) {
  841. console.log('checkTerrain error:', e);
  842. }
  843. }
  844.  
  845. // Check chat text
  846. async function checkChatText() {
  847. if (!isRunning || !safetyEnabled) return;
  848. if (chatText.length === 0) return;
  849.  
  850. try {
  851. for (let i = 0; i < chatText.length; i++) {
  852. if (!isRunning || !safetyEnabled) return;
  853.  
  854. let charInfo = await getCharInfoXY(chatX + i, chatY);
  855.  
  856. if (!charInfo || charInfo.char !== chatText[i] || charInfo.color !== defaultColor) {
  857. await w.changeColor(defaultColor);
  858. await w.tp(chatX + i, chatY);
  859. await w.typeChar(chatText[i], 1);
  860. await wait(typingCooldown);
  861. }
  862. }
  863. } catch (e) {
  864. console.log('checkChatText error:', e);
  865. }
  866. }
  867.  
  868. // Animate clouds
  869. async function animateClouds() {
  870. if (!isRunning) return;
  871.  
  872. currentCloudPattern = (currentCloudPattern + 1) % 1000;
  873.  
  874. generateClouds();
  875. await drawSky();
  876.  
  877. // Redraw UI on top
  878. await drawVersionText();
  879. await updateCoordDisplay();
  880. await drawDateDisplay();
  881. await drawTimeDisplay();
  882. await drawSquare();
  883. if (chatText.length > 0) {
  884. await drawChatText();
  885. }
  886.  
  887. console.log('Clouds animated');
  888. }
  889.  
  890. // Phase transition
  891. async function transitionPhase() {
  892. if (!isRunning) return;
  893.  
  894. let oldPhase = currentPhase;
  895. currentPhase = (currentPhase + 1) % 4;
  896. phaseStartTime = Date.now();
  897.  
  898. // Increment date after full cycle (when returning to day from sunrise)
  899. if (oldPhase === PHASE_SUNRISE && currentPhase === PHASE_DAY) {
  900. incrementDate();
  901. }
  902.  
  903. // Generate stars when entering night
  904. if (currentPhase === PHASE_NIGHT) {
  905. generateStars();
  906. }
  907.  
  908. let phaseName = '';
  909. switch (currentPhase) {
  910. case PHASE_DAY: phaseName = 'Day'; break;
  911. case PHASE_SUNSET: phaseName = 'Sunset'; break;
  912. case PHASE_NIGHT: phaseName = 'Night'; break;
  913. case PHASE_SUNRISE: phaseName = 'Sunrise'; break;
  914. }
  915.  
  916. console.log('Phase changed to: ' + phaseName);
  917.  
  918. // Redraw sky with new color/char/stars
  919. await drawSky();
  920.  
  921. // Redraw UI on top
  922. await drawVersionText();
  923. await updateCoordDisplay();
  924. await drawDateDisplay();
  925. await drawTimeDisplay();
  926. await drawSquare();
  927. if (chatText.length > 0) {
  928. await drawChatText();
  929. }
  930. }
  931.  
  932. // Update time display periodically
  933. async function updateTime() {
  934. if (!isRunning) return;
  935.  
  936. calculateSimTime();
  937. buildTimeCorrectList();
  938. buildDateCorrectList();
  939.  
  940. await drawTimeDisplay();
  941. }
  942.  
  943. // Clear entire area with space detection
  944. async function clearArea() {
  945. await w.changeColor(defaultColor);
  946. for (let y = startY; y <= endY; y++) {
  947. for (let x = startX; x <= endX; x++) {
  948. try {
  949. let charInfo = await getCharInfoXY(x, y);
  950. if (charInfo && charInfo.char === ' ') {
  951. continue;
  952. }
  953. } catch (e) {}
  954. await w.tp(x, y);
  955. await w.typeChar(' ', 1);
  956. await wait(typingCooldown);
  957. }
  958. }
  959. }
  960.  
  961. // Redraw entire view
  962. async function redrawView() {
  963. await drawAllTerrain();
  964. await drawVersionText();
  965. await updateCoordDisplay();
  966. await drawDateDisplay();
  967. await drawTimeDisplay();
  968. await drawSquare();
  969. if (chatText.length > 0) {
  970. await drawChatText();
  971. }
  972. }
  973.  
  974. // Initial area clear
  975. console.log('Clearing area...');
  976. await w.changeColor(defaultColor);
  977. for (let y = startY; y <= endY; y++) {
  978. for (let x = startX; x <= endX; x++) {
  979. try {
  980. let charInfo = await getCharInfoXY(x, y);
  981. if (charInfo && charInfo.char === ' ') {
  982. continue;
  983. }
  984. } catch (e) {}
  985. await w.tp(x, y);
  986. await w.typeChar(' ', 1);
  987. await wait(typingCooldown);
  988. }
  989. }
  990. console.log('Area cleared!');
  991.  
  992. // Generate initial clouds and stars
  993. generateClouds();
  994. generateStars();
  995.  
  996. // Initialize phase start time
  997. phaseStartTime = Date.now();
  998.  
  999. // Draw all terrain
  1000. console.log('Drawing terrain...');
  1001. await drawAllTerrain();
  1002. console.log('Terrain drawn!');
  1003.  
  1004. // Draw version text
  1005. await drawVersionText();
  1006. console.log('Version text drawn!');
  1007.  
  1008. // Initial coordinate display
  1009. await updateCoordDisplay();
  1010. console.log('Coord display drawn!');
  1011.  
  1012. // Draw date display
  1013. await drawDateDisplay();
  1014. console.log('Date display drawn!');
  1015.  
  1016. // Draw time display
  1017. await drawTimeDisplay();
  1018. console.log('Time display drawn!');
  1019.  
  1020. // Initial draw
  1021. await drawSquare();
  1022. console.log('Square drawn!');
  1023.  
  1024. // Start monitoring loop
  1025. async function monitorLoop() {
  1026. while (isRunning) {
  1027. if (safetyEnabled) {
  1028. await checkSquare();
  1029. await checkCorrectChars();
  1030. await checkChatText();
  1031. await checkTerrain();
  1032. }
  1033. await wait(500);
  1034. }
  1035. }
  1036.  
  1037. // Start monitor in background
  1038. setTimeout(function() {
  1039. monitorLoop();
  1040. }, 100);
  1041.  
  1042. // Start cloud animation (every 25 seconds)
  1043. cloudAnimationInterval = setInterval(function() {
  1044. if (isRunning) {
  1045. animateClouds();
  1046. }
  1047. }, 25000);
  1048.  
  1049. // Start phase transitions
  1050. dayNightInterval = setInterval(function() {
  1051. if (isRunning) {
  1052. transitionPhase();
  1053. }
  1054. }, phaseDuration);
  1055.  
  1056. // Start time updates (every 500ms for smooth time display)
  1057. timeUpdateInterval = setInterval(function() {
  1058. if (isRunning) {
  1059. updateTime();
  1060. }
  1061. }, 500);
  1062.  
  1063. // Move right (d)
  1064. window.moved = async function(amount) {
  1065. if (!isRunning) return;
  1066. let moveAmount = (typeof amount === 'number') ? amount : inputx;
  1067.  
  1068. let oldCameraX = cameraWorldX;
  1069.  
  1070. await clearChatText();
  1071. await clearSquare();
  1072. squareWorldX += moveAmount;
  1073.  
  1074. if (squareWorldX > worldBorderMaxX - 1) {
  1075. squareWorldX = worldBorderMaxX - 1;
  1076. console.log('Hit world border at X = ' + worldBorderMaxX);
  1077. }
  1078.  
  1079. updateCamera();
  1080. buildCoordCorrectList();
  1081.  
  1082. if (cameraWorldX !== oldCameraX) {
  1083. await redrawView();
  1084. } else {
  1085. await drawSquare();
  1086. await drawChatText();
  1087. await updateCoordDisplay();
  1088. }
  1089.  
  1090. console.log('Square position: (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  1091. };
  1092.  
  1093. // Move left (a)
  1094. window.movea = async function(amount) {
  1095. if (!isRunning) return;
  1096. let moveAmount = (typeof amount === 'number') ? amount : inputx;
  1097.  
  1098. let oldCameraX = cameraWorldX;
  1099.  
  1100. await clearChatText();
  1101. await clearSquare();
  1102. squareWorldX -= moveAmount;
  1103.  
  1104. if (squareWorldX < worldBorderMinX) {
  1105. squareWorldX = worldBorderMinX;
  1106. console.log('Hit world border at X = ' + worldBorderMinX);
  1107. }
  1108.  
  1109. updateCamera();
  1110. buildCoordCorrectList();
  1111.  
  1112. if (cameraWorldX !== oldCameraX) {
  1113. await redrawView();
  1114. } else {
  1115. await drawSquare();
  1116. await drawChatText();
  1117. await updateCoordDisplay();
  1118. }
  1119.  
  1120. console.log('Square position: (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  1121. };
  1122.  
  1123. // Move up (w)
  1124. window.movew = async function(amount) {
  1125. if (!isRunning) return;
  1126. let moveAmount = (typeof amount === 'number') ? amount : inputy;
  1127. await clearChatText();
  1128. await clearSquare();
  1129. squareWorldY -= moveAmount;
  1130. if (squareWorldY < startY) squareWorldY = startY;
  1131. buildCoordCorrectList();
  1132. await drawSquare();
  1133. await drawChatText();
  1134. await updateCoordDisplay();
  1135. console.log('Square position: (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  1136. };
  1137.  
  1138. // Move down (s)
  1139. window.moves = async function(amount) {
  1140. if (!isRunning) return;
  1141. let moveAmount = (typeof amount === 'number') ? amount : inputy;
  1142. await clearChatText();
  1143. await clearSquare();
  1144. squareWorldY += moveAmount;
  1145. if (squareWorldY > endY) squareWorldY = endY;
  1146. buildCoordCorrectList();
  1147. await drawSquare();
  1148. await drawChatText();
  1149. await updateCoordDisplay();
  1150. console.log('Square position: (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  1151. };
  1152.  
  1153. // Teleport square to specific world coordinates
  1154. window.squaretake = async function(worldX, worldY) {
  1155. if (!isRunning) return;
  1156.  
  1157. if (typeof worldX !== 'number' || typeof worldY !== 'number') {
  1158. console.log('Usage: squaretake(worldX, worldY)');
  1159. return;
  1160. }
  1161.  
  1162. await clearChatText();
  1163. await clearSquare();
  1164.  
  1165. squareWorldX = worldX;
  1166. squareWorldY = -worldY;
  1167.  
  1168. if (squareWorldX < worldBorderMinX) {
  1169. squareWorldX = worldBorderMinX;
  1170. console.log('Clamped to world border at X = ' + worldBorderMinX);
  1171. }
  1172. if (squareWorldX > worldBorderMaxX - 1) {
  1173. squareWorldX = worldBorderMaxX - 1;
  1174. console.log('Clamped to world border at X = ' + worldBorderMaxX);
  1175. }
  1176. if (squareWorldY < startY) {
  1177. squareWorldY = startY;
  1178. console.log('Clamped to Y boundary');
  1179. }
  1180. if (squareWorldY > endY) {
  1181. squareWorldY = endY;
  1182. console.log('Clamped to Y boundary');
  1183. }
  1184.  
  1185. updateCamera();
  1186. buildCoordCorrectList();
  1187. await redrawView();
  1188.  
  1189. console.log('Square teleported to (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  1190. };
  1191.  
  1192. // Chat function
  1193. window.chat = async function(text) {
  1194. if (!isRunning) return;
  1195.  
  1196. if (chatTimeout) {
  1197. clearTimeout(chatTimeout);
  1198. chatTimeout = null;
  1199. }
  1200.  
  1201. await clearChatText();
  1202. chatText = text || '';
  1203.  
  1204. if (chatText.length > 0) {
  1205. await drawChatText();
  1206. console.log('Chat: "' + chatText + '" at (' + chatX + ', ' + (-chatY) + ')');
  1207.  
  1208. chatTimeout = setTimeout(async function() {
  1209. if (isRunning) {
  1210. await clearChatText();
  1211. console.log('Chat cleared (timeout)');
  1212. }
  1213. }, 6000);
  1214. } else {
  1215. console.log('Chat cleared');
  1216. }
  1217. };
  1218.  
  1219. // Disable safety function
  1220. window.disablesafety = async function() {
  1221. safetyEnabled = false;
  1222. await w.chat.send('Safety DISABLED - char detection OFF');
  1223. console.log('Safety disabled - char detection is now OFF');
  1224. };
  1225.  
  1226. // Enable safety function
  1227. window.enablesafety = async function() {
  1228. safetyEnabled = true;
  1229. await w.chat.send('Safety ENABLED - char detection ON');
  1230. console.log('Safety enabled - char detection is now ON');
  1231. };
  1232.  
  1233. // Quit function
  1234. window.quit = async function() {
  1235. isRunning = false;
  1236.  
  1237. if (chatTimeout) {
  1238. clearTimeout(chatTimeout);
  1239. chatTimeout = null;
  1240. }
  1241.  
  1242. if (cloudAnimationInterval) {
  1243. clearInterval(cloudAnimationInterval);
  1244. cloudAnimationInterval = null;
  1245. }
  1246.  
  1247. if (dayNightInterval) {
  1248. clearInterval(dayNightInterval);
  1249. dayNightInterval = null;
  1250. }
  1251.  
  1252. if (timeUpdateInterval) {
  1253. clearInterval(timeUpdateInterval);
  1254. timeUpdateInterval = null;
  1255. }
  1256.  
  1257. console.log('Clearing area for shutdown...');
  1258. await clearArea();
  1259.  
  1260. let shutdownText = 'SCRIPT SHUTDOWN.';
  1261. let centerX = Math.floor((startX + endX) / 2) - Math.floor(shutdownText.length / 2);
  1262. let centerY = Math.floor((startY + endY) / 2);
  1263.  
  1264. await w.changeColor(defaultColor);
  1265. for (let i = 0; i < shutdownText.length; i++) {
  1266. await w.tp(centerX + i, centerY);
  1267. await w.typeChar(shutdownText[i], 1);
  1268. await wait(typingCooldown);
  1269. }
  1270.  
  1271. await w.chat.send('Script Shutdown');
  1272. console.log('Script Shutdown');
  1273.  
  1274. delete window.movew;
  1275. delete window.movea;
  1276. delete window.moves;
  1277. delete window.moved;
  1278. delete window.chat;
  1279. delete window.quit;
  1280. delete window.disablesafety;
  1281. delete window.enablesafety;
  1282. delete window.squaretake;
  1283. };
  1284.  
  1285. console.log('Controls ready!');
  1286. console.log('Use: movew(n), movea(n), moves(n), moved(n) - n is optional move amount');
  1287. console.log('Use: squaretake(worldX, worldY) - teleport square to world coordinates');
  1288. console.log('Use: chat("your message") - displays text above square for 6 seconds');
  1289. console.log('Use: disablesafety() - disables char detection');
  1290. console.log('Use: enablesafety() - enables char detection');
  1291. console.log('Use: quit() - clears area and stops script');
  1292. console.log('World border: X = ' + worldBorderMinX + ' to ' + worldBorderMaxX);
  1293. console.log('Day/Night cycle: Day -> Sunset -> Night -> Sunrise (37.5s each, 150s full cycle)');
  1294. console.log('Simulation starts at: ' + getDateString() + ' ' + getTimeString());
  1295. console.log('Square starts at (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  1296. })();
Advertisement
Add Comment
Please, Sign In to add comment