Drawaria Jump Game

Enhanced version of the Google Dinosaur Game on Drawaria Online with decorated background and music

当前为 2024-10-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Drawaria Jump Game
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-09-29
  5. // @description Enhanced version of the Google Dinosaur Game on Drawaria Online with decorated background and music
  6. // @author YouTube Drawaria
  7. // @match https://drawaria.online/game
  8. // @license MIT
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=drawaria.online
  10. // @grant none
  11.  
  12.  
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Remove the "Cannot GET /dinosaur" text
  19. document.body.innerHTML = "";
  20.  
  21. // Change the tab title
  22. document.title = "Drawaria Jump Game";
  23.  
  24. // Change the tab icon
  25. const link = document.createElement("link");
  26. link.rel = "icon";
  27. link.href = "/favicon-32x32.png";
  28. document.head.appendChild(link);
  29.  
  30. // Add music when the game starts
  31. const audio = document.createElement('audio');
  32. audio.src = 'https://ia601307.us.archive.org/0/items/gdps-2.2-song-500476/500476.mp3';
  33. audio.loop = true;
  34. audio.autoplay = true;
  35. document.body.appendChild(audio);
  36.  
  37. // Create the game area
  38. const gameArea = document.createElement('div');
  39. gameArea.id = 'gameArea';
  40. gameArea.style.position = 'relative';
  41. gameArea.style.width = '100vw';
  42. gameArea.style.height = '100vh';
  43. gameArea.style.overflow = 'hidden';
  44. document.body.appendChild(gameArea);
  45.  
  46. // Style the game background with gray squares
  47. const shapesStyle = document.createElement('style');
  48. shapesStyle.innerHTML = `
  49. #gameArea {
  50. background: linear-gradient(#87ceeb, #f7f7f7);
  51. overflow: hidden;
  52. }
  53.  
  54. .background-square {
  55. position: absolute;
  56. width: 80px; /* Square size */
  57. height: 80px; /* Square size */
  58. background: rgba(128, 128, 128, 0.5); /* Gray color */
  59. }
  60.  
  61. @keyframes moveShapes {
  62. 0% {
  63. transform: translateY(0);
  64. }
  65. 100% {
  66. transform: translateY(100vh);
  67. }
  68. }
  69. `;
  70. document.head.appendChild(shapesStyle);
  71.  
  72. // Create the background with gray squares
  73. for (let i = 0; i < 50; i++) {
  74. const square = document.createElement('div');
  75. square.classList.add('background-square');
  76. square.style.left = Math.random() * 100 + 'vw';
  77. square.style.top = Math.random() * 100 + 'vh';
  78. gameArea.appendChild(square);
  79. }
  80.  
  81. // Create the ground
  82. const ground = document.createElement('div');
  83. ground.id = 'ground';
  84. ground.style.position = 'absolute';
  85. ground.style.bottom = '0';
  86. ground.style.width = '100%';
  87. ground.style.height = '50px';
  88. ground.style.background = '#e0c568';
  89. ground.style.borderTop = '5px solid #a67c00';
  90. gameArea.appendChild(ground);
  91.  
  92. // Create the dinosaur
  93. const dinosaur = document.createElement('div');
  94. dinosaur.style.position = 'absolute';
  95. dinosaur.style.bottom = '50px';
  96. dinosaur.style.left = '50px';
  97. dinosaur.style.width = '40px';
  98. dinosaur.style.height = '40px';
  99. dinosaur.style.backgroundColor = '#808080'; // Dark gray color
  100. dinosaur.style.transition = 'bottom 0.1s';
  101. gameArea.appendChild(dinosaur);
  102.  
  103. // Create the game title and logo
  104.  
  105.  
  106. const titleDisplay = document.createElement('h1');
  107. titleDisplay.innerText = 'Drawaria Jump Game';
  108. titleDisplay.style.position = 'absolute';
  109. titleDisplay.style.top = '120px'; // Position title below logo
  110. titleDisplay.style.left = '50%';
  111. titleDisplay.style.transform = 'translateX(-50%)';
  112. titleDisplay.style.color = '#000'; // Text color
  113. gameArea.appendChild(titleDisplay);
  114.  
  115. // Create score, time, and creator displays
  116. let score = 0;
  117. const scoreDisplay = document.createElement('div');
  118. scoreDisplay.style.position = 'absolute';
  119. scoreDisplay.style.top = '10px';
  120. scoreDisplay.style.left = '10px';
  121. scoreDisplay.style.fontSize = '20px';
  122. gameArea.appendChild(scoreDisplay);
  123.  
  124. const timeDisplay = document.createElement('div');
  125. timeDisplay.style.position = 'absolute';
  126. timeDisplay.style.top = '40px';
  127. timeDisplay.style.left = '10px';
  128. timeDisplay.style.fontSize = '20px';
  129. gameArea.appendChild(timeDisplay);
  130.  
  131. const creatorDisplay = document.createElement('div');
  132. creatorDisplay.style.position = 'absolute';
  133. creatorDisplay.style.top = '70px';
  134. creatorDisplay.style.left = '10px';
  135. creatorDisplay.style.fontSize = '20px';
  136. creatorDisplay.innerText = 'Creator: YouTube Drawaria';
  137. gameArea.appendChild(creatorDisplay);
  138.  
  139. // Update score and time
  140. setInterval(() => {
  141. scoreDisplay.innerText = `Score: ${score}`;
  142. const now = new Date();
  143. timeDisplay.innerText = `Time: ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
  144. }, 1000);
  145.  
  146. // Create obstacles container
  147. const obstacles = document.createElement('div');
  148. obstacles.style.position = 'absolute';
  149. obstacles.style.width = '100%';
  150. obstacles.style.height = '100%';
  151. gameArea.appendChild(obstacles);
  152.  
  153. // Create points container
  154. const pointItems = document.createElement('div');
  155. pointItems.style.position = 'absolute';
  156. pointItems.style.width = '100%';
  157. pointItems.style.height = '100%';
  158. pointItems.style.zIndex = '2';
  159. gameArea.appendChild(pointItems);
  160.  
  161. // Create power-ups container
  162. const powerUps = document.createElement('div');
  163. powerUps.style.position = 'absolute';
  164. powerUps.style.width = '100%';
  165. powerUps.style.height = '100%';
  166. powerUps.style.zIndex = '2';
  167. gameArea.appendChild(powerUps);
  168.  
  169. // Move the dinosaur
  170. let dinosaurPosition = 50;
  171. let isJumping = false;
  172.  
  173. document.addEventListener('keydown', (event) => {
  174. if (event.code === 'Space' || event.code === 'ArrowUp') {
  175. if (!isJumping) {
  176. isJumping = true;
  177. dinosaur.style.bottom = '200px';
  178. setTimeout(() => {
  179. dinosaur.style.bottom = '50px';
  180. isJumping = false;
  181. }, 800);
  182. }
  183. }
  184. if (event.code === 'ArrowRight') {
  185. dinosaurPosition += 10;
  186. dinosaur.style.left = dinosaurPosition + 'px';
  187. }
  188. if (event.code === 'ArrowLeft') {
  189. dinosaurPosition -= 10;
  190. dinosaur.style.left = dinosaurPosition + 'px';
  191. }
  192. });
  193.  
  194. // Create obstacles
  195. const createObstacle = () => {
  196. const obstacle = document.createElement('div');
  197. obstacle.style.position = 'absolute';
  198. obstacle.style.width = '30px';
  199. obstacle.style.height = '60px';
  200. obstacle.style.backgroundColor = 'red';
  201. obstacle.style.bottom = '50px';
  202. obstacle.style.left = '100%';
  203. obstacles.appendChild(obstacle);
  204.  
  205. let obstacleInterval = setInterval(() => {
  206. const obstaclePosition = parseInt(window.getComputedStyle(obstacle).getPropertyValue('left'));
  207. if (obstaclePosition < -60) {
  208. obstacle.remove();
  209. clearInterval(obstacleInterval);
  210. } else {
  211. obstacle.style.left = (obstaclePosition - 5) + 'px';
  212. }
  213. checkCollisionWithObstacle(obstacle);
  214. }, 30);
  215. };
  216.  
  217. // Create points
  218. const createPoint = () => {
  219. const point = document.createElement('div');
  220. point.style.position = 'absolute';
  221. point.style.width = '20px';
  222. point.style.height = '20px';
  223. point.style.backgroundColor = 'yellow';
  224. point.style.borderRadius = '50%';
  225. point.style.bottom = '200px'; // Match max dinosaur jump height
  226. point.style.left = '100%';
  227. pointItems.appendChild(point);
  228.  
  229. let pointInterval = setInterval(() => {
  230. const pointPosition = parseInt(window.getComputedStyle(point).getPropertyValue('left'));
  231. if (pointPosition < -20) {
  232. point.remove();
  233. clearInterval(pointInterval);
  234. } else {
  235. point.style.left = (pointPosition - 5) + 'px';
  236. }
  237. checkCollisionWithPoint(point);
  238. }, 30);
  239. };
  240.  
  241. // Create power-up
  242. const createPowerUp = () => {
  243. const powerUp = document.createElement('div');
  244. powerUp.style.position = 'absolute';
  245. powerUp.style.width = '20px';
  246. powerUp.style.height = '20px';
  247. powerUp.style.backgroundColor = 'blue';
  248. powerUp.style.borderRadius = '50%';
  249. powerUp.style.bottom = '100px'; // Match dinosaur jump height
  250. powerUp.style.left = '100%';
  251. powerUps.appendChild(powerUp);
  252.  
  253. let powerUpInterval = setInterval(() => {
  254. const powerUpPosition = parseInt(window.getComputedStyle(powerUp).getPropertyValue('left'));
  255. if (powerUpPosition < -20) {
  256. powerUp.remove();
  257. clearInterval(powerUpInterval);
  258. } else {
  259. powerUp.style.left = (powerUpPosition - 5) + 'px';
  260. }
  261. checkCollisionWithPowerUp(powerUp);
  262. }, 30);
  263. };
  264.  
  265. // Check collision with obstacles
  266. const checkCollisionWithObstacle = (obstacle) => {
  267. const dinoRect = dinosaur.getBoundingClientRect();
  268. const obsRect = obstacle.getBoundingClientRect();
  269.  
  270. if (
  271. dinoRect.left < obsRect.right &&
  272. dinoRect.right > obsRect.left &&
  273. dinoRect.bottom > obsRect.top &&
  274. dinoRect.top < obsRect.bottom
  275. ) {
  276. alert('You hit an obstacle! Your final score is: ' + score);
  277. location.reload();
  278. }
  279. };
  280.  
  281. // Check collision with points
  282. const checkCollisionWithPoint = (point) => {
  283. const dinoRect = dinosaur.getBoundingClientRect();
  284. const pointRect = point.getBoundingClientRect();
  285.  
  286. if (
  287. dinoRect.left < pointRect.right &&
  288. dinoRect.right > pointRect.left &&
  289. dinoRect.bottom > pointRect.top &&
  290. dinoRect.top < pointRect.bottom
  291. ) {
  292. score += 10;
  293. point.remove();
  294. }
  295. };
  296.  
  297. // Check collision with power-ups
  298. const checkCollisionWithPowerUp = (powerUp) => {
  299. const dinoRect = dinosaur.getBoundingClientRect();
  300. const powerUpRect = powerUp.getBoundingClientRect();
  301.  
  302. if (
  303. dinoRect.left < powerUpRect.right &&
  304. dinoRect.right > powerUpRect.left &&
  305. dinoRect.bottom > powerUpRect.top &&
  306. dinoRect.top < powerUpRect.bottom
  307. ) {
  308. score += 20; // Increase score for collecting power-up
  309. powerUp.remove();
  310. }
  311. };
  312.  
  313. // Create obstacles, points, and power-ups periodically
  314. setInterval(createObstacle, 1500);
  315. setInterval(createPoint, 2000);
  316. setInterval(createPowerUp, 5000);
  317.  
  318. // Display the score every second
  319. setInterval(() => {
  320. scoreDisplay.innerText = `Score: ${score}`;
  321. }, 1000);
  322. })();