smoothretro82

Square Area Testing v1.0.9

Dec 6th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.88 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.  
  18. // Day/Night cycle
  19. let isDay = true;
  20. const dayColor = 10;
  21. const nightColor = 12;
  22. const dayChar = '▒';
  23. const nightChar = '▒';
  24. const dayNightCycleDuration = 60000;
  25.  
  26. // Correct chars list for version and coords
  27. let correctChars = [];
  28.  
  29. // World position of square
  30. let squareWorldX = 0;
  31. let squareWorldY = 0;
  32.  
  33. // Camera position
  34. let cameraWorldX = startX;
  35.  
  36. // Terrain Y levels
  37. const grassY = 1;
  38. const dirtStartY = 2;
  39. const dirtEndY = 3;
  40. const stoneStartY = 4;
  41. const cloudEndY = -7;
  42.  
  43. // Characters
  44. const grassChar = ',';
  45. const dirtChar = '.';
  46. const stoneChar = '#';
  47. const cloudChar = '~';
  48.  
  49. // Colors
  50. const cloudColor = 0;
  51. const grassColor = 9;
  52. const dirtColor = 22;
  53. const stoneColor = 1;
  54. const defaultColor = 25;
  55.  
  56. // Get current sky color and char based on day/night
  57. function getSkyColor() {
  58. return isDay ? dayColor : nightColor;
  59. }
  60.  
  61. function getSkyChar() {
  62. return isDay ? dayChar : nightChar;
  63. }
  64.  
  65. // Cloud data structure
  66. let clouds = [];
  67.  
  68. // World border
  69. const worldBorderMinX = -500000;
  70. const worldBorderMaxX = 500000;
  71.  
  72. // Input values for movement
  73. const inputx = 1;
  74. const inputy = 1;
  75.  
  76. // Coordinate display position
  77. const coordDisplayX = startX;
  78. const coordDisplayY = startY;
  79. const versionDisplayY = startY + 1;
  80.  
  81. const versionText = 'Square Area Testing 1.0.9';
  82.  
  83. // Previous coordinate text
  84. let prevCoordText = '';
  85. let prevCoordTextLength = 0;
  86.  
  87. // Helper function for cooldown
  88. function wait(ms) {
  89. return new Promise(resolve => setTimeout(resolve, ms));
  90. }
  91.  
  92. // Build correct chars list for version text
  93. function buildVersionCorrectList() {
  94. for (let i = 0; i < versionText.length; i++) {
  95. let key = (coordDisplayX + i) + ',' + versionDisplayY;
  96. correctChars[key] = { char: versionText[i], color: defaultColor };
  97. }
  98. }
  99.  
  100. // Build/update correct chars list for coord text
  101. function buildCoordCorrectList() {
  102. let coordText = 'square is at ' + squareWorldX + ', ' + (-squareWorldY);
  103.  
  104. // Clear old coord entries first
  105. if (prevCoordTextLength > 0) {
  106. for (let i = 0; i < prevCoordTextLength; i++) {
  107. let key = (coordDisplayX + i) + ',' + coordDisplayY;
  108. delete correctChars[key];
  109. }
  110. }
  111.  
  112. // Add new coord entries
  113. for (let i = 0; i < coordText.length; i++) {
  114. let key = (coordDisplayX + i) + ',' + coordDisplayY;
  115. correctChars[key] = { char: coordText[i], color: defaultColor };
  116. }
  117.  
  118. prevCoordText = coordText;
  119. prevCoordTextLength = coordText.length;
  120. }
  121.  
  122. // Check if position is in correct chars list
  123. function getCorrectChar(x, y) {
  124. let key = x + ',' + y;
  125. return correctChars[key] || null;
  126. }
  127.  
  128. // Simple seeded random for consistent cloud generation
  129. function seededRandom(seed) {
  130. let x = Math.sin(seed * 12.9898 + 78.233) * 43758.5453;
  131. return x - Math.floor(x);
  132. }
  133.  
  134. // Generate random clouds
  135. function generateClouds() {
  136. clouds = [];
  137.  
  138. for (let y = startY; y <= cloudEndY; y++) {
  139. let x = startX;
  140. let seed = y * 1000 + currentCloudPattern * 100;
  141.  
  142. while (x <= endX) {
  143. let rand = seededRandom(seed + x);
  144.  
  145. if (rand < 0.35) {
  146. let length = Math.floor(seededRandom(seed + x + 1) * 4) + 3;
  147.  
  148. if (x + length > endX + 1) {
  149. length = endX - x + 1;
  150. }
  151.  
  152. if (length >= 3) {
  153. clouds.push({ x: x, y: y, length: length });
  154. }
  155.  
  156. x += length + Math.floor(seededRandom(seed + x + 2) * 4) + 2;
  157. } else {
  158. x += 1;
  159. }
  160. }
  161. }
  162. }
  163.  
  164. let currentCloudPattern = 0;
  165.  
  166. // Get screen X from world X
  167. function worldToScreenX(worldX) {
  168. return worldX - cameraWorldX + startX;
  169. }
  170.  
  171. // Get world X from screen X
  172. function screenToWorldX(screenX) {
  173. return screenX - startX + cameraWorldX;
  174. }
  175.  
  176. // Get square screen position
  177. function getSquareScreenX() {
  178. return worldToScreenX(squareWorldX);
  179. }
  180.  
  181. // Update camera to follow square
  182. function updateCamera() {
  183. let screenX = getSquareScreenX();
  184. let margin = 8;
  185.  
  186. if (screenX < startX + margin) {
  187. cameraWorldX = squareWorldX - margin;
  188. } else if (screenX > endX - margin - 1) {
  189. cameraWorldX = squareWorldX - (areaWidth - margin - 2);
  190. }
  191. }
  192.  
  193. // Terrain type checks
  194. function isCloudPosition(y) {
  195. return y >= startY && y <= cloudEndY;
  196. }
  197.  
  198. function isGrassPosition(y) {
  199. return y === grassY;
  200. }
  201.  
  202. function isDirtPosition(y) {
  203. return y >= dirtStartY && y <= dirtEndY;
  204. }
  205.  
  206. function isStonePosition(y) {
  207. return y >= stoneStartY && y <= endY;
  208. }
  209.  
  210. function isSkyPosition(y) {
  211. return y > cloudEndY && y < grassY;
  212. }
  213.  
  214. // Check if screen position has a cloud
  215. function hasCloudAt(screenX, screenY) {
  216. for (let i = 0; i < clouds.length; i++) {
  217. let cloud = clouds[i];
  218. if (cloud.y === screenY && screenX >= cloud.x && screenX < cloud.x + cloud.length) {
  219. return true;
  220. }
  221. }
  222. return false;
  223. }
  224.  
  225. // Get terrain info for a screen position
  226. function getTerrainInfo(screenX, y) {
  227. if (isCloudPosition(y)) {
  228. if (hasCloudAt(screenX, y)) {
  229. return { char: cloudChar, color: cloudColor, isSky: false };
  230. } else {
  231. return { char: getSkyChar(), color: getSkyColor(), isSky: true };
  232. }
  233. } else if (isSkyPosition(y)) {
  234. return { char: getSkyChar(), color: getSkyColor(), isSky: true };
  235. } else if (isGrassPosition(y)) {
  236. return { char: grassChar, color: grassColor, isSky: false };
  237. } else if (isDirtPosition(y)) {
  238. return { char: dirtChar, color: dirtColor, isSky: false };
  239. } else if (isStonePosition(y)) {
  240. return { char: stoneChar, color: stoneColor, isSky: false };
  241. } else {
  242. return { char: getSkyChar(), color: getSkyColor(), isSky: true };
  243. }
  244. }
  245.  
  246. // Function to draw text at position
  247. async function drawText(x, y, text) {
  248. await w.changeColor(defaultColor);
  249. for (let i = 0; i < text.length; i++) {
  250. await w.tp(x + i, y);
  251. await w.typeChar(text[i], 1);
  252. await wait(typingCooldown);
  253. }
  254. }
  255.  
  256. // Function to clear text at position with terrain
  257. async function clearTextWithTerrain(x, y, length) {
  258. for (let i = 0; i < length; i++) {
  259. let terrain = getTerrainInfo(x + i, y);
  260. await w.changeColor(terrain.color);
  261. await w.tp(x + i, y);
  262. await w.typeChar(terrain.char, 1);
  263. await wait(typingCooldown);
  264. }
  265. }
  266.  
  267. // Function to draw sky with day/night
  268. async function drawSky() {
  269. let skyColor = getSkyColor();
  270. let skyChar = getSkyChar();
  271. let squareScreenX = getSquareScreenX();
  272.  
  273. // Draw sky in cloud area
  274. for (let y = startY; y <= cloudEndY; y++) {
  275. for (let x = startX; x <= endX; x++) {
  276. // Skip UI elements
  277. if (getCorrectChar(x, y)) {
  278. continue;
  279. }
  280. if (y === squareWorldY && (x === squareScreenX || x === squareScreenX + 1)) {
  281. continue;
  282. }
  283. if (chatText.length > 0 && y === chatY && x >= chatX && x < chatX + chatText.length) {
  284. continue;
  285. }
  286.  
  287. if (hasCloudAt(x, y)) {
  288. await w.changeColor(cloudColor);
  289. await w.tp(x, y);
  290. await w.typeChar(cloudChar, 1);
  291. } else {
  292. await w.changeColor(skyColor);
  293. await w.tp(x, y);
  294. await w.typeChar(skyChar, 1);
  295. }
  296. await wait(typingCooldown);
  297. }
  298. }
  299.  
  300. // Draw air between clouds and grass
  301. for (let y = cloudEndY + 1; y < grassY; y++) {
  302. for (let x = startX; x <= endX; x++) {
  303. if (y === squareWorldY && (x === squareScreenX || x === squareScreenX + 1)) {
  304. continue;
  305. }
  306. if (chatText.length > 0 && y === chatY && x >= chatX && x < chatX + chatText.length) {
  307. continue;
  308. }
  309.  
  310. await w.changeColor(skyColor);
  311. await w.tp(x, y);
  312. await w.typeChar(skyChar, 1);
  313. await wait(typingCooldown);
  314. }
  315. }
  316.  
  317. await w.changeColor(defaultColor);
  318. }
  319.  
  320. // Function to draw all clouds
  321. async function drawClouds() {
  322. generateClouds();
  323. await drawSky();
  324. }
  325.  
  326. // Function to draw grass line
  327. async function drawGrass() {
  328. await w.changeColor(grassColor);
  329. let squareScreenX = getSquareScreenX();
  330. for (let x = startX; x <= endX; x++) {
  331. if (squareWorldY === grassY && (x === squareScreenX || x === squareScreenX + 1)) {
  332. continue;
  333. }
  334. await w.tp(x, grassY);
  335. await w.typeChar(grassChar, 1);
  336. await wait(typingCooldown);
  337. }
  338. await w.changeColor(defaultColor);
  339. }
  340.  
  341. // Function to draw dirt
  342. async function drawDirt() {
  343. await w.changeColor(dirtColor);
  344. let squareScreenX = getSquareScreenX();
  345. for (let y = dirtStartY; y <= dirtEndY; y++) {
  346. for (let x = startX; x <= endX; x++) {
  347. if (squareWorldY === y && (x === squareScreenX || x === squareScreenX + 1)) {
  348. continue;
  349. }
  350. await w.tp(x, y);
  351. await w.typeChar(dirtChar, 1);
  352. await wait(typingCooldown);
  353. }
  354. }
  355. await w.changeColor(defaultColor);
  356. }
  357.  
  358. // Function to draw stone
  359. async function drawStone() {
  360. await w.changeColor(stoneColor);
  361. let squareScreenX = getSquareScreenX();
  362. for (let y = stoneStartY; y <= endY; y++) {
  363. for (let x = startX; x <= endX; x++) {
  364. if (squareWorldY === y && (x === squareScreenX || x === squareScreenX + 1)) {
  365. continue;
  366. }
  367. await w.tp(x, y);
  368. await w.typeChar(stoneChar, 1);
  369. await wait(typingCooldown);
  370. }
  371. }
  372. await w.changeColor(defaultColor);
  373. }
  374.  
  375. // Function to draw all terrain
  376. async function drawAllTerrain() {
  377. await drawClouds();
  378. await drawGrass();
  379. await drawDirt();
  380. await drawStone();
  381. }
  382.  
  383. // Function to update coordinate display
  384. async function updateCoordDisplay() {
  385. let coordText = 'square is at ' + squareWorldX + ', ' + (-squareWorldY);
  386.  
  387. // Clear old text with terrain if longer
  388. if (prevCoordTextLength > coordText.length) {
  389. await clearTextWithTerrain(coordDisplayX + coordText.length, coordDisplayY, prevCoordTextLength - coordText.length);
  390. }
  391.  
  392. // Update correct list before drawing
  393. buildCoordCorrectList();
  394.  
  395. await drawText(coordDisplayX, coordDisplayY, coordText);
  396. }
  397.  
  398. // Function to draw version text
  399. async function drawVersionText() {
  400. buildVersionCorrectList();
  401. await drawText(coordDisplayX, versionDisplayY, versionText);
  402. }
  403.  
  404. // Function to draw the square
  405. async function drawSquare() {
  406. let screenX = getSquareScreenX();
  407. await w.changeColor(defaultColor);
  408. await w.tp(screenX, squareWorldY);
  409. await w.typeChar('[', 1);
  410. await wait(typingCooldown);
  411. await w.typeChar(']', 1);
  412. await wait(typingCooldown);
  413. }
  414.  
  415. // Function to clear the square
  416. async function clearSquare() {
  417. let screenX = getSquareScreenX();
  418. let y = squareWorldY;
  419.  
  420. let terrain1 = getTerrainInfo(screenX, y);
  421. let terrain2 = getTerrainInfo(screenX + 1, y);
  422.  
  423. await w.changeColor(terrain1.color);
  424. await w.tp(screenX, y);
  425. await w.typeChar(terrain1.char, 1);
  426. await wait(typingCooldown);
  427.  
  428. await w.changeColor(terrain2.color);
  429. await w.tp(screenX + 1, y);
  430. await w.typeChar(terrain2.char, 1);
  431. await wait(typingCooldown);
  432.  
  433. await w.changeColor(defaultColor);
  434. }
  435.  
  436. // Function to clear chat text
  437. async function clearChatText() {
  438. if (chatText.length > 0) {
  439. let oldChatText = chatText;
  440. let oldChatX = chatX;
  441. let oldChatY = chatY;
  442. chatText = '';
  443.  
  444. for (let i = 0; i < oldChatText.length; i++) {
  445. let currentX = oldChatX + i;
  446. let terrain = getTerrainInfo(currentX, oldChatY);
  447. await w.changeColor(terrain.color);
  448. await w.tp(currentX, oldChatY);
  449. await w.typeChar(terrain.char, 1);
  450. await wait(typingCooldown);
  451. }
  452. await w.changeColor(defaultColor);
  453. }
  454. }
  455.  
  456. // Function to draw chat text
  457. async function drawChatText() {
  458. if (chatText.length > 0) {
  459. let screenX = getSquareScreenX();
  460. let squareMiddle = screenX + 0.5;
  461. let textHalfLength = Math.floor(chatText.length / 2);
  462. chatX = Math.round(squareMiddle - textHalfLength);
  463. chatY = squareWorldY - 1;
  464.  
  465. await w.changeColor(defaultColor);
  466. for (let i = 0; i < chatText.length; i++) {
  467. await w.tp(chatX + i, chatY);
  468. await w.typeChar(chatText[i], 1);
  469. await wait(typingCooldown);
  470. }
  471. }
  472. }
  473.  
  474. // Check if position is part of UI elements
  475. function isUIPosition(x, y) {
  476. let screenX = getSquareScreenX();
  477.  
  478. if (y === squareWorldY && (x === screenX || x === screenX + 1)) {
  479. return true;
  480. }
  481. if (chatText.length > 0 && y === chatY && x >= chatX && x < chatX + chatText.length) {
  482. return true;
  483. }
  484. if (getCorrectChar(x, y)) {
  485. return true;
  486. }
  487. return false;
  488. }
  489.  
  490. // Check if square brackets are missing or miscolored
  491. async function checkSquare() {
  492. if (!isRunning || !safetyEnabled) return;
  493.  
  494. try {
  495. let screenX = getSquareScreenX();
  496. let leftBracket = await getCharInfoXY(screenX, squareWorldY);
  497. let rightBracket = await getCharInfoXY(screenX + 1, squareWorldY);
  498.  
  499. let needRedraw = false;
  500.  
  501. if (!leftBracket || leftBracket.char !== '[' || leftBracket.color !== defaultColor) {
  502. needRedraw = true;
  503. }
  504. if (!rightBracket || rightBracket.char !== ']' || rightBracket.color !== defaultColor) {
  505. needRedraw = true;
  506. }
  507.  
  508. if (needRedraw) {
  509. await drawSquare();
  510. console.log('Square restored at (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  511. }
  512. } catch (e) {
  513. console.log('checkSquare error:', e);
  514. }
  515. }
  516.  
  517. // Check version and coord text using correct list
  518. async function checkCorrectChars() {
  519. if (!isRunning || !safetyEnabled) return;
  520.  
  521. try {
  522. for (let key in correctChars) {
  523. if (!isRunning || !safetyEnabled) return;
  524.  
  525. let parts = key.split(',');
  526. let x = parseInt(parts[0]);
  527. let y = parseInt(parts[1]);
  528. let expected = correctChars[key];
  529.  
  530. let charInfo = await getCharInfoXY(x, y);
  531.  
  532. if (!charInfo || charInfo.char !== expected.char || charInfo.color !== expected.color) {
  533. await w.changeColor(expected.color);
  534. await w.tp(x, y);
  535. await w.typeChar(expected.char, 1);
  536. await wait(typingCooldown);
  537. }
  538. }
  539. } catch (e) {
  540. console.log('checkCorrectChars error:', e);
  541. }
  542. }
  543.  
  544. // Check terrain char and color
  545. async function checkTerrain() {
  546. if (!isRunning || !safetyEnabled) return;
  547.  
  548. try {
  549. for (let y = startY; y <= endY; y++) {
  550. for (let x = startX; x <= endX; x++) {
  551. if (!isRunning || !safetyEnabled) return;
  552.  
  553. // Skip UI elements
  554. if (isUIPosition(x, y)) {
  555. continue;
  556. }
  557.  
  558. let terrain = getTerrainInfo(x, y);
  559. let charInfo = await getCharInfoXY(x, y);
  560.  
  561. if (!charInfo) {
  562. await w.changeColor(terrain.color);
  563. await w.tp(x, y);
  564. await w.typeChar(terrain.char, 1);
  565. await wait(typingCooldown);
  566. continue;
  567. }
  568.  
  569. // Check both char and color
  570. if (charInfo.char !== terrain.char || charInfo.color !== terrain.color) {
  571. await w.changeColor(terrain.color);
  572. await w.tp(x, y);
  573. await w.typeChar(terrain.char, 1);
  574. await wait(typingCooldown);
  575. }
  576. }
  577. }
  578. await w.changeColor(defaultColor);
  579. } catch (e) {
  580. console.log('checkTerrain error:', e);
  581. }
  582. }
  583.  
  584. // Check chat text
  585. async function checkChatText() {
  586. if (!isRunning || !safetyEnabled) return;
  587. if (chatText.length === 0) return;
  588.  
  589. try {
  590. for (let i = 0; i < chatText.length; i++) {
  591. if (!isRunning || !safetyEnabled) return;
  592.  
  593. let charInfo = await getCharInfoXY(chatX + i, chatY);
  594.  
  595. if (!charInfo || charInfo.char !== chatText[i] || charInfo.color !== defaultColor) {
  596. await w.changeColor(defaultColor);
  597. await w.tp(chatX + i, chatY);
  598. await w.typeChar(chatText[i], 1);
  599. await wait(typingCooldown);
  600. }
  601. }
  602. } catch (e) {
  603. console.log('checkChatText error:', e);
  604. }
  605. }
  606.  
  607. // Animate clouds
  608. async function animateClouds() {
  609. if (!isRunning) return;
  610.  
  611. currentCloudPattern = (currentCloudPattern + 1) % 1000;
  612.  
  613. generateClouds();
  614. await drawSky();
  615.  
  616. // Redraw UI on top
  617. await drawVersionText();
  618. await updateCoordDisplay();
  619. await drawSquare();
  620. if (chatText.length > 0) {
  621. await drawChatText();
  622. }
  623.  
  624. console.log('Clouds animated');
  625. }
  626.  
  627. // Day/Night cycle transition
  628. async function transitionDayNight() {
  629. if (!isRunning) return;
  630.  
  631. isDay = !isDay;
  632. let timeOfDay = isDay ? 'Day' : 'Night';
  633. console.log('Time changed to: ' + timeOfDay);
  634.  
  635. // Redraw sky with new color and char
  636. await drawSky();
  637.  
  638. // Redraw UI on top
  639. await drawVersionText();
  640. await updateCoordDisplay();
  641. await drawSquare();
  642. if (chatText.length > 0) {
  643. await drawChatText();
  644. }
  645. }
  646.  
  647. // Clear entire area with space detection
  648. async function clearArea() {
  649. await w.changeColor(defaultColor);
  650. for (let y = startY; y <= endY; y++) {
  651. for (let x = startX; x <= endX; x++) {
  652. try {
  653. let charInfo = await getCharInfoXY(x, y);
  654. if (charInfo && charInfo.char === ' ') {
  655. continue;
  656. }
  657. } catch (e) {}
  658. await w.tp(x, y);
  659. await w.typeChar(' ', 1);
  660. await wait(typingCooldown);
  661. }
  662. }
  663. }
  664.  
  665. // Redraw entire view
  666. async function redrawView() {
  667. await drawAllTerrain();
  668. await drawVersionText();
  669. await updateCoordDisplay();
  670. await drawSquare();
  671. if (chatText.length > 0) {
  672. await drawChatText();
  673. }
  674. }
  675.  
  676. // Initial area clear
  677. console.log('Clearing area...');
  678. await w.changeColor(defaultColor);
  679. for (let y = startY; y <= endY; y++) {
  680. for (let x = startX; x <= endX; x++) {
  681. try {
  682. let charInfo = await getCharInfoXY(x, y);
  683. if (charInfo && charInfo.char === ' ') {
  684. continue;
  685. }
  686. } catch (e) {}
  687. await w.tp(x, y);
  688. await w.typeChar(' ', 1);
  689. await wait(typingCooldown);
  690. }
  691. }
  692. console.log('Area cleared!');
  693.  
  694. // Generate initial clouds
  695. generateClouds();
  696.  
  697. // Draw clouds
  698. console.log('Drawing sky and clouds...');
  699. await drawClouds();
  700. console.log('Sky and clouds drawn!');
  701.  
  702. // Draw grass line
  703. console.log('Drawing grass...');
  704. await drawGrass();
  705. console.log('Grass drawn!');
  706.  
  707. // Draw dirt
  708. console.log('Drawing dirt...');
  709. await drawDirt();
  710. console.log('Dirt drawn!');
  711.  
  712. // Draw stone
  713. console.log('Drawing stone...');
  714. await drawStone();
  715. console.log('Stone drawn!');
  716.  
  717. // Draw version text
  718. await drawVersionText();
  719. console.log('Version text drawn!');
  720.  
  721. // Initial coordinate display
  722. await updateCoordDisplay();
  723. console.log('Coord display drawn!');
  724.  
  725. // Initial draw
  726. await drawSquare();
  727. console.log('Square drawn!');
  728.  
  729. // Start monitoring loop
  730. async function monitorLoop() {
  731. while (isRunning) {
  732. if (safetyEnabled) {
  733. await checkSquare();
  734. await checkCorrectChars();
  735. await checkChatText();
  736. await checkTerrain();
  737. }
  738. await wait(500);
  739. }
  740. }
  741.  
  742. // Start monitor in background
  743. setTimeout(function() {
  744. monitorLoop();
  745. }, 100);
  746.  
  747. // Start cloud animation (every 25 seconds)
  748. cloudAnimationInterval = setInterval(function() {
  749. if (isRunning) {
  750. animateClouds();
  751. }
  752. }, 25000);
  753.  
  754. // Start day/night cycle
  755. dayNightInterval = setInterval(function() {
  756. if (isRunning) {
  757. transitionDayNight();
  758. }
  759. }, dayNightCycleDuration);
  760.  
  761. // Move right (d)
  762. window.moved = async function(amount) {
  763. if (!isRunning) return;
  764. let moveAmount = (typeof amount === 'number') ? amount : inputx;
  765.  
  766. let oldCameraX = cameraWorldX;
  767.  
  768. await clearChatText();
  769. await clearSquare();
  770. squareWorldX += moveAmount;
  771.  
  772. if (squareWorldX > worldBorderMaxX - 1) {
  773. squareWorldX = worldBorderMaxX - 1;
  774. console.log('Hit world border at X = ' + worldBorderMaxX);
  775. }
  776.  
  777. updateCamera();
  778. buildCoordCorrectList();
  779.  
  780. if (cameraWorldX !== oldCameraX) {
  781. await redrawView();
  782. } else {
  783. await drawSquare();
  784. await drawChatText();
  785. await updateCoordDisplay();
  786. }
  787.  
  788. console.log('Square position: (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  789. };
  790.  
  791. // Move left (a)
  792. window.movea = async function(amount) {
  793. if (!isRunning) return;
  794. let moveAmount = (typeof amount === 'number') ? amount : inputx;
  795.  
  796. let oldCameraX = cameraWorldX;
  797.  
  798. await clearChatText();
  799. await clearSquare();
  800. squareWorldX -= moveAmount;
  801.  
  802. if (squareWorldX < worldBorderMinX) {
  803. squareWorldX = worldBorderMinX;
  804. console.log('Hit world border at X = ' + worldBorderMinX);
  805. }
  806.  
  807. updateCamera();
  808. buildCoordCorrectList();
  809.  
  810. if (cameraWorldX !== oldCameraX) {
  811. await redrawView();
  812. } else {
  813. await drawSquare();
  814. await drawChatText();
  815. await updateCoordDisplay();
  816. }
  817.  
  818. console.log('Square position: (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  819. };
  820.  
  821. // Move up (w)
  822. window.movew = async function(amount) {
  823. if (!isRunning) return;
  824. let moveAmount = (typeof amount === 'number') ? amount : inputy;
  825. await clearChatText();
  826. await clearSquare();
  827. squareWorldY -= moveAmount;
  828. if (squareWorldY < startY) squareWorldY = startY;
  829. buildCoordCorrectList();
  830. await drawSquare();
  831. await drawChatText();
  832. await updateCoordDisplay();
  833. console.log('Square position: (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  834. };
  835.  
  836. // Move down (s)
  837. window.moves = async function(amount) {
  838. if (!isRunning) return;
  839. let moveAmount = (typeof amount === 'number') ? amount : inputy;
  840. await clearChatText();
  841. await clearSquare();
  842. squareWorldY += moveAmount;
  843. if (squareWorldY > endY) squareWorldY = endY;
  844. buildCoordCorrectList();
  845. await drawSquare();
  846. await drawChatText();
  847. await updateCoordDisplay();
  848. console.log('Square position: (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  849. };
  850.  
  851. // Teleport square to specific world coordinates
  852. window.squaretake = async function(worldX, worldY) {
  853. if (!isRunning) return;
  854.  
  855. if (typeof worldX !== 'number' || typeof worldY !== 'number') {
  856. console.log('Usage: squaretake(worldX, worldY)');
  857. return;
  858. }
  859.  
  860. await clearChatText();
  861. await clearSquare();
  862.  
  863. squareWorldX = worldX;
  864. squareWorldY = -worldY;
  865.  
  866. if (squareWorldX < worldBorderMinX) {
  867. squareWorldX = worldBorderMinX;
  868. console.log('Clamped to world border at X = ' + worldBorderMinX);
  869. }
  870. if (squareWorldX > worldBorderMaxX - 1) {
  871. squareWorldX = worldBorderMaxX - 1;
  872. console.log('Clamped to world border at X = ' + worldBorderMaxX);
  873. }
  874. if (squareWorldY < startY) {
  875. squareWorldY = startY;
  876. console.log('Clamped to Y boundary');
  877. }
  878. if (squareWorldY > endY) {
  879. squareWorldY = endY;
  880. console.log('Clamped to Y boundary');
  881. }
  882.  
  883. updateCamera();
  884. buildCoordCorrectList();
  885. await redrawView();
  886.  
  887. console.log('Square teleported to (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  888. };
  889.  
  890. // Chat function
  891. window.chat = async function(text) {
  892. if (!isRunning) return;
  893.  
  894. if (chatTimeout) {
  895. clearTimeout(chatTimeout);
  896. chatTimeout = null;
  897. }
  898.  
  899. await clearChatText();
  900. chatText = text || '';
  901.  
  902. if (chatText.length > 0) {
  903. await drawChatText();
  904. console.log('Chat: "' + chatText + '" at (' + chatX + ', ' + (-chatY) + ')');
  905.  
  906. chatTimeout = setTimeout(async function() {
  907. if (isRunning) {
  908. await clearChatText();
  909. console.log('Chat cleared (timeout)');
  910. }
  911. }, 6000);
  912. } else {
  913. console.log('Chat cleared');
  914. }
  915. };
  916.  
  917. // Disable safety function
  918. window.disablesafety = async function() {
  919. safetyEnabled = false;
  920. await w.chat.send('Safety DISABLED - char detection OFF');
  921. console.log('Safety disabled - char detection is now OFF');
  922. };
  923.  
  924. // Enable safety function
  925. window.enablesafety = async function() {
  926. safetyEnabled = true;
  927. await w.chat.send('Safety ENABLED - char detection ON');
  928. console.log('Safety enabled - char detection is now ON');
  929. };
  930.  
  931. // Quit function
  932. window.quit = async function() {
  933. isRunning = false;
  934.  
  935. if (chatTimeout) {
  936. clearTimeout(chatTimeout);
  937. chatTimeout = null;
  938. }
  939.  
  940. if (cloudAnimationInterval) {
  941. clearInterval(cloudAnimationInterval);
  942. cloudAnimationInterval = null;
  943. }
  944.  
  945. if (dayNightInterval) {
  946. clearInterval(dayNightInterval);
  947. dayNightInterval = null;
  948. }
  949.  
  950. console.log('Clearing area for shutdown...');
  951. await clearArea();
  952.  
  953. let shutdownText = 'SCRIPT SHUTDOWN.';
  954. let centerX = Math.floor((startX + endX) / 2) - Math.floor(shutdownText.length / 2);
  955. let centerY = Math.floor((startY + endY) / 2);
  956.  
  957. await w.changeColor(defaultColor);
  958. for (let i = 0; i < shutdownText.length; i++) {
  959. await w.tp(centerX + i, centerY);
  960. await w.typeChar(shutdownText[i], 1);
  961. await wait(typingCooldown);
  962. }
  963.  
  964. await w.chat.send('Script Shutdown');
  965. console.log('Script Shutdown');
  966.  
  967. delete window.movew;
  968. delete window.movea;
  969. delete window.moves;
  970. delete window.moved;
  971. delete window.chat;
  972. delete window.quit;
  973. delete window.disablesafety;
  974. delete window.enablesafety;
  975. delete window.squaretake;
  976. };
  977.  
  978. console.log('Controls ready!');
  979. console.log('Use: movew(n), movea(n), moves(n), moved(n) - n is optional move amount');
  980. console.log('Use: squaretake(worldX, worldY) - teleport square to world coordinates');
  981. console.log('Use: chat("your message") - displays text above square for 6 seconds');
  982. console.log('Use: disablesafety() - disables char detection');
  983. console.log('Use: enablesafety() - enables char detection');
  984. console.log('Use: quit() - clears area and stops script');
  985. console.log('World border: X = ' + worldBorderMinX + ' to ' + worldBorderMaxX);
  986. console.log('Day/Night cycle: ' + (dayNightCycleDuration / 1000) + ' seconds per cycle');
  987. console.log('Square starts at (' + squareWorldX + ', ' + (-squareWorldY) + ')');
  988. })();
Advertisement
Add Comment
Please, Sign In to add comment