Advertisement
PastebinHTMLboy

game.html

Sep 22nd, 2019
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.58 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4. <title>dodge dots game thing</title>
  5. <meta charset="UTF-8">
  6. <meta name="description" content="i guess this is a game where you dodge things on a tic tac board"/>
  7. <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
  8. <style>
  9. html {
  10. height: 100%;
  11. width: 100%;
  12. }
  13. body {
  14. margin: 0;
  15. color: white;
  16. background-image: linear-gradient(75deg,#FF5226 0%,#FF5226 33%,#FF6F26 33%,#FF6F26 67%,#FFAF00 67%,#FFAF00 100%);
  17. font-family: 'Montserrat', sans-serif;
  18. }
  19. a {
  20. color: inherit;
  21. background: rgba(0,0,0,0.1);
  22. text-decoration: none;
  23. border-radius: 3px;
  24. }
  25. a:hover {background: rgba(0,0,0,0.2);}
  26. a:active {background: rgba(0,0,0,0.3);}
  27. game {
  28. display: block;
  29. background: white;
  30. font-size: 0;
  31. position: fixed;
  32. margin: auto;
  33. top: 0;
  34. left: 0;
  35. right: 0;
  36. bottom: 0;
  37. width: 165px;
  38. height: 165px;
  39. padding: 40px 160px;
  40. border-radius: 10px;
  41. box-shadow: 0 0 3px rgba(0,0,0,0.3);
  42. }
  43. row {
  44. display: block;
  45. height: 55px;
  46. width: 165px;
  47. }
  48. place {
  49. display: inline-block;
  50. height: 15px;
  51. width: 15px;
  52. border-radius: 50%;
  53. background: #BDC8CE;
  54. margin: 20px;
  55. }
  56. p {
  57. margin: 10px;
  58. }
  59. player {
  60. margin: 20px;
  61. height: 15px;
  62. width: 15px;
  63. border-radius: 50%;
  64. background: #FF6F26;
  65. display: block;
  66. position: absolute;
  67. transform: translateX(160px) translateY(40px) scale(1.1);
  68. transition: top .3s, left .3s;
  69. transition-timing-function: cubic-bezier(1,0,0,1);
  70. }
  71. player.x0 {left:0px;}
  72. player.x1 {left:55px;}
  73. player.x2 {left:110px;}
  74. player.y0 {top:0px;}
  75. player.y1 {top:55px;}
  76. player.y2 {top:110px;}
  77. score {
  78. color: #FF5A26;
  79. position: absolute;
  80. top: 10px;
  81. left: 15px;
  82. display: block;
  83. font-size: 40px;
  84. font-weight: bold;
  85. }
  86. message {
  87. color: #FF9E07;
  88. display: block;
  89. font-size: 20px;
  90. margin: auto;
  91. position: absolute;
  92. top: 0;
  93. bottom: 0;
  94. width: 100%;
  95. text-align: center;
  96. left: 0;
  97. height: 20px;
  98. animation: fadein .25s;
  99. }
  100. @keyframes fadein {
  101. from {opacity:0;}
  102. to {opacity:1;}
  103. }
  104. bullet {
  105. margin: 20px;
  106. height: 15px;
  107. width: 15px;
  108. border-radius: 7.5px;
  109. background: #FF5A26;
  110. display: block;
  111. position: absolute;
  112. transform: translateX(160px) translateY(40px);
  113. animation-delay: 0.5s;
  114. animation-duration: 0.5s;
  115. animation-timing-function: cubic-bezier(1,0,0,1);
  116. animation-fill-mode: forwards;
  117. }
  118. bullet.appear {
  119. animation: appear .3s cubic-bezier(1,0,0,1);
  120. }
  121. bullet.up {
  122. animation-name: up;
  123. }
  124. bullet.down {
  125. animation-name: down;
  126. }
  127. bullet.right {
  128. animation-name: right;
  129. }
  130. bullet.left {
  131. animation-name: left;
  132. }
  133. @keyframes appear {
  134. 0% {
  135. margin: 27.5px;
  136. height: 0;
  137. width: 0;
  138. }
  139. 100% {
  140. margin: 20px;
  141. height: 15px;
  142. width: 15px;
  143. }
  144. }
  145. @keyframes up {
  146. 0% {height:15px;top:165px;}
  147. 50% {height:235px;top:-55px;}
  148. 100% {height:15px;top:-55px;}
  149. }
  150. @keyframes down {
  151. 0% {height:15px;top:-55px;}
  152. 50% {height:235px;top:-55px;}
  153. 100% {height:15px;top:165px;}
  154. }
  155. @keyframes left {
  156. 0% {width:15px;left:165px;}
  157. 50% {width:235px;left:-55px;}
  158. 100% {width:15px;left:-55px;}
  159. }
  160. @keyframes right {
  161. 0% {width:15px;left:-55px;}
  162. 50% {width:235px;left:-55px;}
  163. 100% {width:15px;left:165px;}
  164. }
  165. game.fade > *:not(score) {
  166. transition: opacity .25s forwards;
  167. opacity: 0;
  168. }
  169. @media (max-width: 500px) {
  170. game {
  171. padding: 40px;
  172. }
  173. player {
  174. transform: translateX(40px) translateY(40px) scale(1.1);
  175. }
  176. bullet {
  177. transform: translateX(40px) translateY(40px);
  178. }
  179. }
  180. </style>
  181. </head>
  182. <body>
  183. <p>pretty much a copy of <a href="https://scratch.mit.edu/projects/122881995/">reds</a> by <a href="https://scratch.mit.edu/users/EPlCUS/">eplcus on scratch</a>; all credits to them for the unique game concept / arrow keys or swipe to move</p>
  184. <game>
  185. <message>click/tap to start</message>
  186. </game>
  187. <script src="https://pastebin.com/raw/6vsYd0q4"></script>
  188. <script>
  189. function start() {
  190. for (var i=0;i<3;i++) {
  191. var s=document.createElement('row');
  192. for (var j=0;j<3;j++) s.appendChild(document.createElement('place'));
  193. document.querySelector('game').appendChild(s);
  194. }
  195. document.querySelector('game').appendChild(document.createElement('player'));
  196. document.querySelector('score').innerHTML=0;
  197. var x=1,
  198. y=1,
  199. moving=false,
  200. score=0,
  201. scoreinterval,
  202. bulletinterval,
  203. touch={};
  204. function newbullet() {
  205. var bulletcount,
  206. bulletDirs=[];
  207. if (score>25) bulletcount=Math.floor(Math.random()*3+1);
  208. else if (score>12) bulletcount=2;
  209. else bulletcount=1;
  210. function create(n) {
  211. var s=document.createElement('bullet'),
  212. way=Math.floor(Math.random()*2);
  213. if (Math.floor(Math.random()*2)) {
  214. bulletDirs[n]='h';
  215. s.style.left=(way?'-5':'16')+'5px';
  216. s.style.top=(Math.floor(Math.random()*3)*55)+'px';
  217. s.dataset.dir=way?'right':'left';
  218. } else {
  219. bulletDirs[n]='v';
  220. s.style.top=(way?'-5':'16')+'5px';
  221. s.style.left=(Math.floor(Math.random()*3)*55)+'px';
  222. s.dataset.dir=way?'down':'up';
  223. }
  224. s.className='appear';
  225. document.querySelector('game').appendChild(s);
  226. }
  227. create(0);
  228. if (bulletcount>1) create(1);
  229. if (bulletcount>2) {
  230. create(2);
  231. if (bulletDirs[0]===bulletDirs[1]&&bulletDirs[1]===bulletDirs[2]) {
  232. var s=document.querySelectorAll('bullet')[2], // get third bullet
  233. left=s.style.left; // save left style
  234. s.style.left=s.style.top; // swap left and top styles
  235. s.style.top=left;
  236. switch (s.dataset.dir) {
  237. case 'right':
  238. s.dataset.dir='down';
  239. break;
  240. case 'down':
  241. s.dataset.dir='right';
  242. break;
  243. case 'up':
  244. s.dataset.dir='left';
  245. break;
  246. case 'left':
  247. s.dataset.dir='up';
  248. break;
  249. }
  250. }
  251. }
  252. setTimeout(_=>{
  253. var s=document.querySelectorAll('bullet');
  254. for (var i=0;i<s.length;i++) s[i].className=s[i].dataset.dir;
  255. setTimeout(_=>{
  256. var s=document.querySelectorAll('bullet');
  257. for (var i=0;i<s.length;i++) {
  258. if (Math.abs(55-Number(s[i].style.left.slice(0,-2)))===110) {
  259. var ty=Number(s[i].style.top.slice(0,-2))/55;
  260. if (ty==y) {
  261. die();
  262. break;
  263. }
  264. } else {
  265. var tx=Number(s[i].style.left.slice(0,-2))/55;
  266. if (tx==x) {
  267. die();
  268. break;
  269. }
  270. }
  271. }
  272. },500);
  273. setTimeout(_=>{
  274. var s=document.querySelectorAll('bullet');
  275. for (var i=0;i<s.length;i++) s[i].parentNode.removeChild(s[i]);
  276. },1000);
  277. },300);
  278. }
  279. document.querySelector('player').className='x'+x+' y'+y;
  280. document.body.onkeydown=e=>{
  281. if (!moving) {
  282. var change=true;
  283. switch (e.keyCode) {
  284. case 38:
  285. y--;
  286. break;
  287. case 40:
  288. y++;
  289. break;
  290. case 37:
  291. x--;
  292. break;
  293. case 39:
  294. x++;
  295. break;
  296. default:
  297. change=false;
  298. }
  299. if (change) {
  300. if (x<0||x>2||y<0||y>2) {
  301. if (x<0) x=0;
  302. if (x>2) x=2;
  303. if (y<0) y=0;
  304. if (y>2) y=2;
  305. } else {
  306. moving=true;
  307. setTimeout(_=>{if (moving) moving=false;},300);
  308. document.querySelector('player').className='x'+x+' y'+y;
  309. e.preventDefault();
  310. return false;
  311. }
  312. }
  313. }
  314. };
  315. document.ontouchstart=e=>{
  316. // if (moving) return 'false';
  317. touch.x=e.touches[0].clientX;
  318. touch.y=e.touches[0].clientY;
  319. touch.lastx=e.touches[0].clientX;
  320. touch.lasty=e.touches[0].clientY;
  321. document.ontouchmove=e=>{
  322. touch.lastx=e.touches[0].clientX;
  323. touch.lasty=e.touches[0].clientY;
  324. e.preventDefault();
  325. return false;
  326. };
  327. document.ontouchend=e=>{
  328. var diffx=touch.lastx-touch.x,
  329. diffy=touch.lasty-touch.y;
  330. if (diffx!==0&&diffy!==0) {
  331. if (Math.abs(diffx)>Math.abs(diffy)) {
  332. if (diffx>0) x++;
  333. else x--;
  334. } else {
  335. if (diffy>0) y++;
  336. else y--;
  337. }
  338. if (x<0||x>2||y<0||y>2) {
  339. if (x<0) x=0;
  340. if (x>2) x=2;
  341. if (y<0) y=0;
  342. if (y>2) y=2;
  343. } else {
  344. // moving=true;
  345. // setTimeout(_=>{if (moving) moving=false;},300);
  346. document.querySelector('player').className='x'+x+' y'+y;
  347. }
  348. }
  349. touch={};
  350. document.ontouchmove=null;
  351. document.ontouchend=null;
  352. };
  353. };
  354. scoreinterval=setInterval(_=>{
  355. score++;
  356. document.querySelector('score').innerHTML=score;
  357. },800);
  358. console.log('clearInterval('+scoreinterval+') // stop score counting');
  359. setTimeout(_=>bulletinterval=setInterval(_=>newbullet(),1500),500);
  360. function die() {
  361. clearInterval(scoreinterval);
  362. clearInterval(bulletinterval);
  363. document.body.onkeydown=null;
  364. document.body.ontouchstart=null;
  365. document.body.ontouchmove=null;
  366. document.body.ontouchend=null;
  367. document.querySelector('game').className='fade';
  368. setTimeout(_=>{
  369. var s=document.querySelectorAll('bullet');
  370. for (var i=0;i<s.length;i++) s[i].parentNode.removeChild(s[i]);
  371. var s=document.querySelectorAll('row');
  372. for (var i=0;i<s.length;i++) s[i].parentNode.removeChild(s[i]);
  373. document.querySelector('game').removeChild(document.querySelector('player'));
  374. document.querySelector('game').className='';
  375. },250);
  376. var s=document.createElement('message');
  377. s.innerHTML='click/tap to play again';
  378. document.querySelector('game').appendChild(s);
  379. document.querySelector('game').ontouchstart=document.querySelector('game').onclick=e=>{
  380. document.querySelector('game').removeChild(document.querySelector('message'));
  381. document.querySelector('game').onclick=null;
  382. document.querySelector('game').ontouchstart=null;
  383. start();
  384. };
  385. }
  386. }
  387. document.querySelector('game').ontouchstart=document.querySelector('game').onclick=e=>{
  388. document.querySelector('game').removeChild(document.querySelector('message'));
  389. document.querySelector('game').appendChild(document.createElement('score'));
  390. document.querySelector('game').onclick=null;
  391. document.querySelector('game').ontouchstart=null;
  392. start();
  393. };
  394. </script>
  395. </body>
  396. <!-- MADE BY SEAN -->
  397. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement