Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.12 KB | None | 0 0
  1. /**
  2. * Created by Valu on 13/01/2018.
  3. */
  4.  
  5. var pista_random, obstaculo, obs_random, cont_obs = 0;
  6. var chao, cam4, cam3, cam2, cam1, velocidade = 5, remendo2, remendo1;
  7. var peticao;
  8. var informa;
  9. var jogar;
  10. var instrucoes;
  11. var tempo;
  12. var spriteNumero = 1;
  13. var personagem;
  14. var tempo2;
  15. var tecla;
  16. var mov_raposa;
  17. var arrowup = 0;
  18. var arrowdown = 0;
  19. var px;
  20. var py;
  21. var ax;
  22. var bx;
  23. var ay;
  24. var dy;
  25. var posicao = 2;
  26.  
  27. window.onload = function () {
  28. mov_raposa = document.getElementById("movimento_raposa");
  29. personagem = document.getElementById("raposinha");
  30. remendo2 = document.getElementById("remendo2");
  31. remendo1 = document.getElementById("remendo1");
  32. chao = document.getElementById("chao");
  33. cam4 = document.getElementById("cam4");
  34. cam3 = document.getElementById("cam3");
  35. cam2 = document.getElementById("cam2");
  36. cam1 = document.getElementById("cam1");
  37. cam1.style.backgroundPositionX = 0;
  38. cam2.style.backgroundPositionX = 0;
  39. cam3.style.backgroundPositionX = 0;
  40. cam4.style.backgroundPositionX = 0;
  41. personagem.style.left = 7 + "%";
  42. pista1 = document.getElementById("pista1");
  43. pista2 = document.getElementById("pista2");
  44. pista3 = document.getElementById("pista3");
  45. remendo1.style.top = 0;
  46. remendo2.style.top = 80 + "%";
  47. cam1.style.top = -10 + "%";
  48. cam2.style.top = 2 + "%";
  49. cam3.style.top = 0 + "%";
  50. cam4.style.top = 5 + "%";
  51. chao.style.top = 50 + "%";
  52. tempo = setInterval("bg_movimento()", 100);
  53. inicial();
  54. document.getElementById("carrega_div").style.display = "none";
  55. pistas.style.top = 50 + "%";
  56. mov_raposa.style.top = 40 + "%";
  57. chao.style.top = 50 + "%";
  58. pista1.style.top = 0 + "%";
  59. pista2.style.top = 33 + "%";
  60. pista3.style.top = 66 + "%";
  61.  
  62.  
  63. };
  64.  
  65. function bg_movimento() {
  66. cam1.style.backgroundPositionX = parseInt(cam1.style.backgroundPositionX) - velocidade * 1 + "px";
  67. cam2.style.backgroundPositionX = parseInt(cam2.style.backgroundPositionX) - velocidade * 0.7 + "px";
  68. cam3.style.backgroundPositionX = parseInt(cam3.style.backgroundPositionX) - velocidade * 0.4 + "px";
  69. cam4.style.backgroundPositionX = parseInt(cam4.style.backgroundPositionX) - velocidade * 0.2 + "px";
  70. }
  71.  
  72. document.getElementById("jogar").onclick = function () {
  73. setInterval("obstaculos_posicao()", 900);
  74. setInterval("obstaculos_movimento()", 1000 / 60);
  75. segundocarregamento();
  76. };
  77.  
  78. document.getElementById("instrucoes_pagina").onclick = function () {
  79. primeirocarregamento();
  80. };
  81.  
  82. function primeirocarregamento() {
  83. tempo = setInterval("bg_movimento()", 100);
  84. document.getElementById("logo").style.display = "none";
  85. document.getElementById("vida").style.display = "block";
  86. document.getElementById("fundo_transparente").style.display = "none";
  87. document.getElementById("jogar").style.display = "none";
  88. document.getElementById("instrucoes_pagina").style.display = "none";
  89. document.getElementById("peticoes").style.display = "none";
  90. document.getElementById("informate").style.display = "none";
  91. document.getElementById("fundo_transparente_01").style.display = "block";
  92. document.getElementById("armadilha").style.display = "block";
  93. document.getElementById("veneno").style.display = "block";
  94. document.getElementById("incendio").style.display = "block";
  95. document.getElementById("tronco").style.display = "block";
  96. document.getElementById("pedra").style.display = "block";
  97. document.getElementById("atropelamento").style.display = "block";
  98. document.getElementById("avancar").style.display = "block";
  99. overs();
  100. }
  101.  
  102. function overs() {
  103. //armadilha x
  104. document.getElementById("armadilha").onmouseover = function () {
  105. document.getElementById("armadilha_over").style.display = "block";
  106. };
  107. document.getElementById("armadilha").onmouseout = function () {
  108. document.getElementById("armadilha_over").style.display = "none"
  109. };
  110. //atroplamento x
  111. document.getElementById("atropelamento").onmouseover = function () {
  112. document.getElementById("atropelamento_over").style.display = "block"
  113. };
  114. document.getElementById("atropelamento").onmouseout = function () {
  115. document.getElementById("atropelamento_over").style.display = "none"
  116. };
  117. //incendio x
  118. document.getElementById("incendio").onmouseover = function () {
  119. document.getElementById("incendio_over").style.display = "block"
  120. };
  121. document.getElementById("incendio").onmouseout = function () {
  122. document.getElementById("incendio_over").style.display = "none"
  123. };
  124. //veneno x
  125. document.getElementById("veneno").onmouseover = function () {
  126. document.getElementById("veneno_over").style.display = "block"
  127. };
  128. document.getElementById("veneno").onmouseout = function () {
  129. document.getElementById("veneno_over").style.display = "none"
  130. };
  131. //pedra
  132. document.getElementById("pedra").onmouseover = function () {
  133. document.getElementById("pedra_over").style.display = "block"
  134. };
  135. document.getElementById("pedra").onmouseout = function () {
  136. document.getElementById("pedra_over").style.display = "none"
  137. };
  138. //tronco
  139. document.getElementById("tronco").onmouseover = function () {
  140. document.getElementById("tronco_over").style.display = "block"
  141. };
  142. document.getElementById("tronco").onmouseout = function () {
  143. document.getElementById("tronco_over").style.display = "none"
  144. };
  145. //vida
  146. document.getElementById("vida").onmouseover = function () {
  147. document.getElementById("vida_over").style.display = "block"
  148. };
  149. document.getElementById("vida").onmouseout = function () {
  150. document.getElementById("vida_over").style.display = "none"
  151. };
  152. }
  153.  
  154. function inicial() {
  155. peticao = document.getElementById("peticoes");
  156. peticao.onmouseover = function () {
  157. peticao.style.fontWeight = "bold";
  158. };
  159. peticao.onmouseout = function () {
  160. peticao.style.fontWeight = "normal";
  161. };
  162. instrucoes = document.getElementById("instrucoes_pagina");
  163. instrucoes.onmouseover = function () {
  164. instrucoes.style.fontWeight = "bold";
  165. };
  166. instrucoes.onmouseout = function () {
  167. instrucoes.style.fontWeight = "normal";
  168. };
  169. jogar = document.getElementById("jogar");
  170. jogar.onmouseover = function () {
  171. jogar.style.fontWeight = "bold";
  172. };
  173. jogar.onmouseout = function () {
  174. jogar.style.fontWeight = "normal";
  175. };
  176. informa = document.getElementById("informate");
  177. informa.onmouseover = function () {
  178. informa.style.fontWeight = "bold";
  179. };
  180. informa.onmouseout = function () {
  181. informa.style.fontWeight = "normal";
  182. };
  183. }
  184.  
  185. function segundocarregamento() {
  186. tempo = setInterval("bg_movimento()", 100);
  187. document.getElementById("logo").style.display = "none";
  188. document.getElementById("fundo_transparente").style.display = "none";
  189. document.getElementById("jogar").style.display = "none";
  190. document.getElementById("instrucoes_pagina").style.display = "none";
  191. document.getElementById("peticoes").style.display = "none";
  192. document.getElementById("informate").style.display = "none";
  193. personagem.style.display = "block";
  194. personagem.style.top = 25 + "%";
  195. tempo2 = setInterval("mudar()", 100);
  196. }
  197.  
  198. function mudar() {
  199. personagem.src = "img/sprite/correr_" + spriteNumero + ".png";
  200. spriteNumero++;
  201. if (spriteNumero == 7) {
  202. spriteNumero = 1
  203. }
  204. }
  205.  
  206. //---------------------------------
  207. // a div pistas e uma copia da div chao so que com um z-index maior para que os obstaculos passassem por cima das sombras das arvores
  208.  
  209.  
  210. //qual e o obstaculo que vai aparecer
  211. function obstaculos_random(pista, tipoPista) {
  212. //console.log(pista);
  213. obs_random = parseInt(Math.random() * (8) + 1);
  214. // oitavo caso nao aparece nenhum obstaculo
  215. if (obs_random != 8) {
  216. if(cont_obs < 8){
  217. cont_obs++;
  218. if (tipoPista == "pista1") {
  219. pista.innerHTML += "<img src='img/elements/obs_" + obs_random + ".png' id='obstaculo" + cont_obs + " ' alt='pista1'/>";
  220. } else if (tipoPista == "pista2") {
  221. pista.innerHTML += "<img src='img/elements/obs_" + obs_random + ".png' id='obstaculo" + cont_obs + "' alt='pista2'/>";
  222. } else {
  223. pista.innerHTML += "<img src='img/elements/obs_" + obs_random + ".png' id='obstaculo" + cont_obs + "' alt='pista3'/>";
  224. }
  225. obs = document.getElementById("obstaculo" + cont_obs);
  226. obs.style.width = "4%";
  227. obsw = obs.width;
  228. obs.style.position = "relative";
  229. obs.style.left = innerWidth - obsw + "px";
  230. obs.style.top = 0;
  231. }
  232.  
  233. }
  234.  
  235.  
  236. }
  237.  
  238. window.onkeydown = function () {
  239. ProcessaRaposa();
  240. };
  241.  
  242. //pista onde o obstaculo vai aparecer
  243. function obstaculos_posicao(obstaculo) {
  244. random = parseInt(Math.random() * (2));
  245. if (random == 1) {
  246. pista_random = parseInt(Math.random() * (3));
  247. switch (pista_random) {
  248. case 0:
  249. pista1 = document.getElementById("pista1");
  250. obstaculos_random(pista1, "pista1");
  251. break;
  252. case 1:
  253. pista2 = document.getElementById("pista2");
  254. obstaculos_random(pista2, "pista2");
  255. break;
  256. case 2:
  257. pista3 = document.getElementById("pista3");
  258. obstaculos_random(pista3, "pista3");
  259. break;
  260.  
  261. }
  262. }
  263. }
  264.  
  265.  
  266. function obstaculos_movimento() {
  267. if (cont_obs != 0) {
  268. for (var i = 1; i < cont_obs; i++) {
  269.  
  270. var obstaculo = document.getElementById("obstaculo" + i);
  271. obstaculo.style.left = (parseInt(obstaculo.style.left) - 5) + "px";
  272. console.log(obstaculo.style.left)
  273. detetaColisao();
  274. /*if (parseInt(obstaculo.style.left) <= (0 - parseInt(obstaculo.width))) {
  275. obs = document.getElementById("obstaculo" + i);
  276. obsw = obs.width;
  277. obs.style.left = innerWidth - obsw + "px";
  278.  
  279.  
  280. }*/
  281.  
  282. }
  283. }
  284.  
  285. }
  286.  
  287. function ProcessaRaposa() {
  288. tecla = event.key;
  289. switch (tecla) {
  290. case "ArrowUp":
  291. if (arrowup != 1) {
  292. if(posicao > 1){
  293. posicao--;
  294. }
  295. personagem.style.top = parseInt(personagem.style.top) - 25 + "%";
  296. arrowup++;
  297. arrowdown--;
  298.  
  299. }
  300. break;
  301. case "ArrowDown":
  302. if (arrowdown != 1) {
  303. if(posicao < 3){
  304. posicao++;
  305. }
  306. personagem.style.top = parseInt(personagem.style.top) + 25 + "%";
  307. arrowup--;
  308. arrowdown++;
  309. }
  310. break;
  311. }
  312. }
  313.  
  314. function detetaColisao() {
  315. for (var i = 1; i < cont_obs; i++) {
  316. var objAtual = document.getElementById("obstaculo"+i);
  317. var alpista =document.getElementById("obstaculo"+i).alt;
  318. console.log(alpista);
  319. if(alpista == "pista1" && posicao == 1){
  320. var obj = document.getElementById("obstaculo" + i);
  321. px = parseInt(personagem.style.left) + parseInt(personagem.width);
  322. py = parseInt(personagem.style.top) + (parseInt(personagem.height) / 2);
  323. py2 = parseInt(personagem.style.top) + parseInt(personagem.height);
  324. ax = parseInt(obj.style.left);
  325. bx = parseInt(obj.style.left) + parseInt(obj.width);
  326. ay = py2 - parseInt(obj.height);
  327. dy = py2;
  328. //console.log(ax+" "+px+" "+bx);
  329. // console.log(ay+" "+py+" "+dy);
  330. if (ax <= px && bx >= px) {
  331. //if ((ay > py && ay < py2) || (dy < py2 && dy > py)) {
  332. obj.style.left = innerWidth + "px";
  333. //}
  334. }else if((obj.style.left+obj.width) <= 0){
  335. obj.style.left = innerWidth + "px";
  336. }
  337. //voltar a fazer random de pista e tempo ate aparecer
  338. //comparação
  339. }else if(alpista == "pista2" && posicao == 2){
  340. var obj = document.getElementById("obstaculo" + i);
  341. px = parseInt(personagem.style.left) + parseInt(personagem.width);
  342. py = parseInt(personagem.style.top) + (parseInt(personagem.height) / 2);
  343. py2 = parseInt(personagem.style.top) + parseInt(personagem.height);
  344. ax = parseInt(obj.style.left);
  345. bx = parseInt(obj.style.left) + parseInt(obj.width);
  346. ay = py2 - parseInt(obj.height);
  347. dy = py2;
  348. //console.log(ax+" "+px+" "+bx);
  349. // console.log(ay+" "+py+" "+dy);
  350. if (ax <= px && bx >= px) {
  351. //if ((ay > py && ay < py2) || (dy < py2 && dy > py)) {
  352. obj.style.left = innerWidth + "px";
  353. //}
  354. }else if((obj.style.left+obj.width) <= 0){
  355. obj.style.left = innerWidth + "px";
  356. }
  357. }else if(alpista == "pista3" && posicao == 3){
  358. var obj = document.getElementById("obstaculo" + i);
  359. px = parseInt(personagem.style.left) + parseInt(personagem.width);
  360. py = parseInt(personagem.style.top) + (parseInt(personagem.height) / 2);
  361. py2 = parseInt(personagem.style.top) + parseInt(personagem.height);
  362. ax = parseInt(obj.style.left);
  363. bx = parseInt(obj.style.left) + parseInt(obj.width);
  364. ay = py2 - parseInt(obj.height);
  365. dy = py2;
  366. //console.log(ax+" "+px+" "+bx);
  367. // console.log(ay+" "+py+" "+dy);
  368. if (ax <= px && bx >= px) {
  369. //if ((ay > py && ay < py2) || (dy < py2 && dy > py)) { //pode ser desnecessário
  370. obj.style.left = innerWidth + "px";
  371. //}
  372. } else if((obj.style.left+obj.width) <= 0){
  373. console.log(innerWidth);
  374. obj.style.left = innerWidth + "px";
  375. }
  376. }
  377.  
  378. }
  379. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement