Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.48 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <style>
  5. body {
  6. background: #222;
  7. }
  8.  
  9. h2 {
  10. color: #666;
  11. font-family: monospace;
  12. text-align: center;
  13. }
  14.  
  15. .background {
  16. table-layout: fixed;
  17. border-spacing: 0;
  18. }
  19.  
  20. .background td {
  21. padding: 0;
  22. }
  23.  
  24. .lava, .actor {
  25. background: #e55;
  26. }
  27.  
  28. .wall {
  29. background: #444;
  30. border: solid 3px #333;
  31. box-sizing: content-box;
  32. }
  33.  
  34. .actor {
  35. position: absolute;
  36. }
  37.  
  38. .coin {
  39. background: #e2e838;
  40. border-radius: 50%;
  41. }
  42.  
  43. .player {
  44. background: #335699;
  45. box-shadow: none;
  46. }
  47.  
  48. .lost .player {
  49. background: #a04040;
  50. }
  51.  
  52. .won .player {
  53. background: green;
  54. }
  55.  
  56. .game {
  57. position: relative;
  58. overflow: hidden;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. </body><script>
  64. var LEVELS = [
  65. [" ",
  66. " ",
  67. " ",
  68. " ",
  69. " ",
  70. " ",
  71. " xxx ",
  72. " xx xx xx!xx ",
  73. " o o xx x!!!x ",
  74. " xx!xx ",
  75. " xxxxx xvx ",
  76. " xx ",
  77. " xx o o x ",
  78. " x o x ",
  79. " x xxxxx o x ",
  80. " x xxxx o x ",
  81. " x @ x x xxxxx x ",
  82. " xxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxx ",
  83. " x x x x ",
  84. " x!!!x x!!!!!x ",
  85. " x!!!x x!!!!!x ",
  86. " xxxxx xxxxxxx ",
  87. " ",
  88. " "
  89. ],
  90. [" x!!x xxxxxxx x!x ",
  91. " x!!x xxxx xxxx x!x ",
  92. " x!!xxxxxxxxxx xx xx x!x ",
  93. " xx!!!!!!!!!!xx xx xx x!x ",
  94. " xxxxxxxxxx!!x x o o o x!x ",
  95. " xx!x x o o xx!x ",
  96. " x!x x xxxxxxxxxxxxxxx!!x ",
  97. " xvx x x x !!!!!!!!!!!!!!xx ",
  98. " xx | | | xx xxxxxxxxxxxxxxxxxxxxx ",
  99. " xx!!!!!!!!!!!xx v ",
  100. " xxxx!!!!!xxxx ",
  101. " x x xxxxxxx xxx xxx ",
  102. " x x x x x x ",
  103. " x x x x ",
  104. " x x xx x ",
  105. " xx x x x ",
  106. " x x o o x x x x ",
  107. " xxxxxxx xxx xxx x x x x x x ",
  108. " xx xx x x x x xxxxxx x x xxxxxxxxx x ",
  109. " xx xx x o x x xx x x x x ",
  110. " @ x x x x x x x x x x ",
  111. " xxx x x x x x x x xxxxx xxxxxx x ",
  112. " x x x x xx o xx x x x o x x x ",
  113. "!!!!x x!!!!!!x x!!!!!!xx xx!!!!!!!!xx x!!!!!!!!!! x = x x x ",
  114. "!!!!x x!!!!!!x x!!!!!xx xxxxxxxxxx x!!!!!!!xx! xxxxxxxxxxxxx xx o o xx ",
  115. "!!!!x x!!!!!!x x!!!!!x o xx!!!!!!xx ! xx xx ",
  116. "!!!!x x!!!!!!x x!!!!!x xx!!!!!!xx ! xxxxxxx ",
  117. "!!!!x x!!!!!!x x!!!!!xx xxxxxxxxxxxxxx!!!!!!xx ! ",
  118. "!!!!x x!!!!!!x x!!!!!!xxxxxxxxx!!!!!!!!!!!!!!!!!!xx ! ",
  119. "!!!!x x!!!!!!x x!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!xx ! "
  120. ],
  121. [" ",
  122. " ",
  123. " ",
  124. " ",
  125. " ",
  126. " o ",
  127. " ",
  128. " x ",
  129. " x ",
  130. " x ",
  131. " x ",
  132. " xxx ",
  133. " x x !!! !!! xxx ",
  134. " x x !x! !x! ",
  135. " xxx xxx x x ",
  136. " x x x oooo x xxx ",
  137. " x x x x x!!!x ",
  138. " x x xxxxxxxxxxxx xxx ",
  139. " xx xx x x x ",
  140. " x xxxxxxxxx xxxxxxxx x x ",
  141. " x x x x!!!x ",
  142. " x x x xxx ",
  143. " xx xx x ",
  144. " x x= = = = x xxx ",
  145. " x x x x!!!x ",
  146. " x x = = = =x o xxx xxx ",
  147. " xx xx x x!!!x ",
  148. " o o x x x x xxv xxx ",
  149. " x x x x x!!!x ",
  150. " xxx xxx xxx xxx o o x!!!!!!!!!!!!!!x vx ",
  151. " x xxx x x xxx x x!!!!!!!!!!!!!!x ",
  152. " x x xxxxxxxxxxxxxxxxxxxxxxx ",
  153. " xx xx xxx ",
  154. " xxx x x x x!!!x xxx ",
  155. " x x x xxx x xxx x x ",
  156. " x x xxx xxxxxxx xxxxx x ",
  157. " x x x x x x ",
  158. " x xx x x x x x ",
  159. " x x |xxxx| |xxxx| xxx xxx x ",
  160. " x xxx o o x x xxx x ",
  161. " x xxxxx xx x xxx x!!!x x x ",
  162. " x oxxxo x xxx x x x xxx xxx x ",
  163. " x xxx xxxxxxxxxxxxx x oo x x oo x x oo xx xx xxx x ",
  164. " x @ x x x!!x x!!!!x x!!!!x xx xx x x ",
  165. " xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ",
  166. " ",
  167. " "
  168. ],
  169. [" xxx x ",
  170. " x ",
  171. " xxxxx ",
  172. " x ",
  173. " x xxx ",
  174. " o x x x ",
  175. " o o oxxx x ",
  176. " xxx x ",
  177. " ! o ! xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx ",
  178. " x x x x x x x x x x x x x x x ",
  179. " x= o x x xxx x xxx x xxx x xxx x xxx x xxx x xxxxx ",
  180. " x x x x x x x x x x x x x x x ",
  181. " ! o ! o xxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxxxx ",
  182. " ",
  183. " o xxx xx ",
  184. " ",
  185. " ",
  186. " xx ",
  187. " xxx xxx ",
  188. " ",
  189. " o x x ",
  190. " xx xx ",
  191. " xxx xxx xxx x x ",
  192. " ",
  193. " || ",
  194. " xxxxxxxxxxx ",
  195. " x x o xxxxxxxxx o xxxxxxxxx o xx x ",
  196. " x x x x x x x || x x ",
  197. " x @ xxxxx o xxxxx o xxxxx ",
  198. " xxxxxxx xxxxx xx xx xxx ",
  199. " x= = =x x xxx ",
  200. " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x!!!!!!!!!!!!!!!!!!!!!xxx!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
  201. " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  202. " "
  203. ]
  204. ];
  205.  
  206. function Vector(x, y) {
  207. this.x = x;
  208. this.y = y;
  209. }
  210.  
  211. Vector.prototype.plus = function(other) {
  212. return new Vector(this.x + other.x, this.y + other.y);
  213. };
  214.  
  215. Vector.prototype.times = function(scale) {
  216. return new Vector(this.x * scale, this.y * scale);
  217. };
  218.  
  219. // Note: uppercase words are used that means constructor are values
  220. var actorchars = {
  221. "@": Player,
  222. "o": Coin,
  223. "=": Lava,
  224. "|": Lava,
  225. "v": Lava
  226. };
  227.  
  228. function Player(pos) {
  229. this.pos = pos.plus(new Vector(0, -.5));
  230. this.size = new Vector(.5, 1);
  231. this.speed = new Vector(0, 0);
  232. }
  233. Player.prototype.type = "player";
  234.  
  235. function Lava(pos, ch) {
  236. this.pos = pos;
  237. this.size = new Vector(1, 1);
  238. if (ch === "=")
  239. this.speed = new Vector(2, 0);
  240. else if (ch === '|')
  241. this.speed = new Vector(0, 2);
  242. else if (ch === 'v') {
  243. this.speed = new Vector(0, 3);
  244. this.repeatPos = pos;
  245. }
  246. }
  247. Lava.prototype.type = "Lava";
  248.  
  249. function Coin(pos) {
  250. this.basePos = this.pos = pos;
  251. this.size = new Vector(.6, .6);
  252. // take a look back
  253. this.wobble = Math.random() * Math.PI * 2;
  254. }
  255. Coin.prototype.type = "coin";
  256.  
  257. Level.prototype.isFinished = function() {
  258. return this.status != null && this.finishDelay < 0;
  259. };
  260.  
  261. function Level(plan) {
  262. this.width = plan[0].length;
  263. this.height = plan.length;
  264. this.grid = [];
  265. this.actors = [];
  266.  
  267. for (var y = 0; y < this.height; y++) {
  268. var line = plan[y],
  269. gridLine = [];
  270. for (var x = 0; x < this.width; x++) {
  271. var ch = line[x],
  272. fieldType = null;
  273. var Actor = actorchars[ch];
  274. if (Actor)
  275. this.actors.push(new Actor(new Vector(x, y), ch));
  276. else if (ch === "x")
  277. fieldType = "wall";
  278. else if (ch === "!")
  279. fieldType = "lava";
  280. else if (ch === "|")
  281. fieldType = "lava";
  282. else if (ch === "=")
  283. fieldType = "lava";
  284. else if (ch === "v") {
  285. fieldType = "lava";
  286. console.log(fieldType);
  287. }
  288. gridLine.push(fieldType)
  289. }
  290. this.grid.push(gridLine);
  291. }
  292. this.player = this.actors.filter(function(actor) {
  293. return actor.type === "player"
  294. })[0];
  295. this.status = this.finishDelay = null;
  296. }
  297.  
  298. function element(name, className) {
  299. var elem = document.createElement(name);
  300. if (className) elem.className = className;
  301. return elem;
  302. }
  303.  
  304. function DOMDisplay(parent, level) {
  305. this.wrap = parent.appendChild(element("div", "game"));
  306. this.level = level;
  307.  
  308. this.wrap.appendChild(this.drawBackground());
  309. this.actorLayer = null;
  310. this.drawFrame();
  311. }
  312.  
  313. var scale = 15;
  314.  
  315. DOMDisplay.prototype.drawBackground = function() {
  316. var table = element("table", "background");
  317. table.style.width = this.level.width * scale + "px";
  318. table.style.height = this.level.height * scale + "px";
  319. this.level.grid.forEach(function(row) {
  320. var rowElement = table.appendChild(element("tr"));
  321. rowElement.style.height = scale + "px";
  322. row.forEach(function(type) {
  323. rowElement.appendChild(element("td", type));
  324. });
  325. });
  326. return table;
  327. };
  328.  
  329. DOMDisplay.prototype.drawActors = function() {
  330. var wrap = element("div");
  331. this.level.actors.forEach(function(actor) {
  332. var rect = wrap.appendChild(element("div", "actor " + actor.type));
  333. rect.style.width = actor.size.x * scale + "px";
  334. rect.style.height = actor.size.y * scale + "px";
  335. rect.style.left = actor.pos.x * scale + "px";
  336. rect.style.top = actor.pos.y * scale + "px";
  337. });
  338. return wrap;
  339. }
  340.  
  341. DOMDisplay.prototype.drawFrame = function() {
  342. if (this.actorLayer)
  343. this.wrap.removeChild(this.actorLayer);
  344. this.actorLayer = this.wrap.appendChild(this.drawActors());
  345. this.wrap.className = "game " + (this.level.status || "");
  346. this.scrollPlayerIntoView();
  347. };
  348.  
  349. // clear it later
  350. DOMDisplay.prototype.scrollPlayerIntoView = function() {
  351. var width = this.wrap.clientWidth;
  352. var height = this.wrap.clientHeight;
  353. var margin = width / 3;
  354.  
  355. // The viewport
  356. var left = this.wrap.scrollLeft,
  357. right = left + width;
  358. var top = this.wrap.scrollTop,
  359. bottom = top + height;
  360.  
  361. var player = this.level.player;
  362. var center = player.pos.plus(player.size.times(0.5))
  363. .times(scale);
  364.  
  365. if (center.x < left + margin)
  366. this.wrap.scrollLeft = center.x - margin;
  367. else if (center.x > right - margin)
  368. this.wrap.scrollLeft = center.x + margin - width;
  369. if (center.y < top + margin)
  370. this.wrap.scrollTop = center.y - margin;
  371. else if (center.y > bottom - margin)
  372. this.wrap.scrollTop = center.y + margin - height;
  373. };
  374.  
  375. DOMDisplay.prototype.clear = function() {
  376. this.wrap.parentNode.removeChild(this.wrap);
  377. };
  378.  
  379. Level.prototype.obstacleAt = function(pos, size) {
  380. var xStart = Math.floor(pos.x);
  381. var xEnd = Math.ceil(pos.x + size.x);
  382. var yStart = Math.floor(pos.y);
  383. var yEnd = Math.ceil(pos.y + size.y);
  384.  
  385. if (xStart < 0 || xEnd > this.width || yStart < 0)
  386. return "wall";
  387. if (yEnd > this.height)
  388. return "lava";
  389. for (var y = yStart; y < yEnd; y++) {
  390. for (var x = xStart; x < xEnd; x++) {
  391. var fieldType = this.grid[y][x];
  392. if (fieldType) return fieldType;
  393. }
  394. }
  395. };
  396.  
  397. Level.prototype.actorAt = function(actor) {
  398. for (var i = 0; i < this.actors.length; i++) {
  399. var other = this.actors[i];
  400. if (other != actor &&
  401. actor.pos.x + actor.size.x > other.pos.x &&
  402. actor.pos.x < other.pos.x + other.size.x &&
  403. actor.pos.y + actor.size.y > other.pos.y &&
  404. actor.pos.y < other.pos.y + other.size.y)
  405. return other;
  406. }
  407. };
  408.  
  409. var maxStep = 0.05;
  410.  
  411. Level.prototype.animate = function(step, keys) {
  412. if (this.status != null)
  413. this.finishDelay -= step;
  414.  
  415. while (step > 0) {
  416. var thisStep = Math.min(step, maxStep);
  417. this.actors.forEach(function(actor) {
  418. actor.act(thisStep, this, keys);
  419. }, this);
  420. step -= thisStep;
  421. }
  422. };
  423.  
  424. Lava.prototype.act = function(step, level) {
  425. var newPos = this.pos.plus(this.speed.times(step));
  426. if (!level.obstacleAt(newPos, this.size))
  427. this.pos = newPos;
  428. else if (this.repeatPos)
  429. this.pos = this.repeatPos;
  430. else
  431. this.speed = this.speed.times(-1);
  432. };
  433.  
  434. var wobbleSpeed = 8,
  435. wobbleDist = 0.07;
  436.  
  437. Coin.prototype.act = function(step) {
  438. this.wobble += step * wobbleSpeed;
  439. var wobblePos = Math.sin(this.wobble) * wobbleDist;
  440. this.pos = this.basePos.plus(new Vector(0, wobblePos));
  441. };
  442.  
  443. var playerXSpeed = 10;
  444.  
  445. Player.prototype.moveX = function(step, level, keys) {
  446. this.speed.x = 0;
  447. if (keys.left) this.speed.x -= playerXSpeed;
  448. if (keys.right) this.speed.x += playerXSpeed;
  449.  
  450. var motion = new Vector(this.speed.x * step, 0);
  451. var newPos = this.pos.plus(motion);
  452. var obstacle = level.obstacleAt(newPos, this.size);
  453. if (obstacle)
  454. level.playerTouched(obstacle);
  455. else
  456. this.pos = newPos;
  457. };
  458.  
  459. var gravity = 30;
  460. var jumpSpeed = 17;
  461.  
  462. Player.prototype.moveY = function(step, level, keys) {
  463. this.speed.y += step * gravity;
  464. var motion = new Vector(0, this.speed.y * step);
  465. var newPos = this.pos.plus(motion);
  466. var obstacle = level.obstacleAt(newPos, this.size);
  467. if (obstacle) {
  468. level.playerTouched(obstacle);
  469. if (keys.up && this.speed.y > 0)
  470. this.speed.y = -jumpSpeed;
  471. else
  472. this.speed.y = 0;
  473. } else {
  474. this.pos = newPos;
  475. }
  476. };
  477.  
  478. Player.prototype.act = function(step, level, keys) {
  479. this.moveX(step, level, keys);
  480. this.moveY(step, level, keys);
  481.  
  482. var otherActor = level.actorAt(this);
  483. if (otherActor)
  484. level.playerTouched(otherActor.type, otherActor);
  485.  
  486. // Losing animation
  487. if (level.status == "lost") {
  488. this.pos.y += step;
  489. this.size.y -= step;
  490. }
  491. };
  492.  
  493. Level.prototype.playerTouched = function(type, actor) {
  494. if (type == "lava" && this.status == null) {
  495. this.status = "lost";
  496. this.finishDelay = 1;
  497. } else if (type == "coin") {
  498. this.actors = this.actors.filter(function(other) {
  499. return other != actor;
  500. });
  501. if (!this.actors.some(function(actor) {
  502. return actor.type == "coin";
  503. })) {
  504. this.status = "won";
  505. this.finishDelay = 1;
  506. }
  507. }
  508. };
  509.  
  510. var arrowCodes = {
  511. 37: "left",
  512. 38: "up",
  513. 39: "right"
  514. };
  515.  
  516. function trackKeys(codes) {
  517. var pressed = Object.create(null);
  518.  
  519. function handler(event) {
  520. if (codes.hasOwnProperty(event.keyCode)) {
  521. var down = event.type == "keydown";
  522. pressed[codes[event.keyCode]] = down;
  523. event.preventDefault();
  524. }
  525. }
  526. addEventListener("keydown", handler);
  527. addEventListener("keyup", handler);
  528. return pressed;
  529. }
  530.  
  531. function runAnimation(frameFunc) {
  532. var lastTime = null;
  533.  
  534. function frame(time) {
  535. var stop = false;
  536. if (lastTime != null) {
  537. var timeStep = Math.min(time - lastTime, 100) / 1000;
  538. stop = frameFunc(timeStep) === false;
  539. }
  540. lastTime = time;
  541. if (!stop)
  542. requestAnimationFrame(frame);
  543. }
  544. requestAnimationFrame(frame);
  545. }
  546.  
  547. var arrows = trackKeys(arrowCodes);
  548.  
  549. function runLevel(level, Display, andThen) {
  550. var display = new Display(document.body, level);
  551. runAnimation(function(step) {
  552. level.animate(step, arrows);
  553. display.drawFrame(step);
  554. if (level.isFinished()) {
  555. display.clear();
  556. if (andThen)
  557. andThen(level.status);
  558. return false;
  559. }
  560. });
  561. }
  562.  
  563. function runGame(plans, Display) {
  564. function startLevel(n) {
  565. runLevel(new Level(plans[n]), Display, function(status) {
  566. if (status == "lost")
  567. startLevel(n);
  568. else if (n < plans.length - 1)
  569. startLevel(n + 1);
  570. else
  571. alert("You win!");
  572. });
  573. }
  574. startLevel(0);
  575. }
  576.  
  577. runGame(LEVELS, DOMDisplay);
  578. </script>
  579.  
  580.  
  581. <!-- BDTJ -->
  582. <script>
  583. var _hmt = _hmt || [];
  584. (function() {
  585. var hm = document.createElement("script");
  586. hm.src = "https://hm.baidu.com/hm.js?2bae8724db0609337da1aacd4eed5f2c";
  587. var s = document.getElementsByTagName("script")[0];
  588. s.parentNode.insertBefore(hm, s);
  589. })();
  590. </script>
  591. <!-- BDTJ -->
  592. <script language="JavaScript" src="online_yun.php?watch=0&id=&f=aHR0cDovL3NlYXJjaC5taW9taW8udHYvP2tleXdvcmQ9JUU5JUJBJTkyJUU5JUJBJTlGJUUzJTgxJThDJUUzJTgxJThGJUUzJTgyJThC"></script>
  593. <!-- Native --><script src="//pushance.com/ntfc.php?p=1647490" data-cfasync="false" async></script><!-- Native -->
  594. <script type='text/javascript' src='//8mdphsb8fm.com/9a/ca/cc/9acacc2c9ea02409531171c4855a6b50.js'></script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement