Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.16 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. }
  221. if (tipoPista == "pista2") {
  222. pista.innerHTML += "<img src='img/elements/obs_" + obs_random + ".png' id='obstaculo" + cont_obs + "' alt='pista2'/>";
  223. }
  224. if (tipoPista == "pista3") {
  225. pista.innerHTML += "<img src='img/elements/obs_" + obs_random + ".png' id='obstaculo" + cont_obs + "' alt='pista3'/>";
  226. }
  227. obs = document.getElementById("obstaculo" + cont_obs);
  228. obs.style.width = 4 + "%";
  229. obsw = obs.width;
  230. obs.style.position = "relative";
  231. obs.style.left = innerWidth - obsw + "px";
  232. obs.style.top = 0;
  233. }
  234.  
  235. }
  236.  
  237.  
  238. }
  239.  
  240. window.onkeydown = function () {
  241. ProcessaRaposa();
  242. };
  243.  
  244. //pista onde o obstaculo vai aparecer
  245. function obstaculos_posicao(obstaculo) {
  246. random = parseInt(Math.random() * (2));
  247. if (random == 1) {
  248. pista_random = parseInt(Math.random() * (3));
  249. switch (pista_random) {
  250. case 0:
  251. pista1 = document.getElementById("pista1");
  252. obstaculos_random(pista1, "pista1");
  253. break;
  254. case 1:
  255. pista2 = document.getElementById("pista2");
  256. obstaculos_random(pista2, "pista2");
  257. break;
  258. case 2:
  259. pista3 = document.getElementById("pista3");
  260. obstaculos_random(pista3, "pista3");
  261. break;
  262.  
  263. }
  264. }
  265. }
  266.  
  267.  
  268. function obstaculos_movimento() {
  269. if (cont_obs != 0) {
  270. for (var i = 1; i < cont_obs; i++) {
  271.  
  272. var obstaculo = document.getElementById("obstaculo"+i);
  273. obstaculo.style.left = (parseInt(obstaculo.style.left) - 5) + "px";
  274. //console.log(obstaculo.style.left)
  275. detetaColisao();
  276. /*if (parseInt(obstaculo.style.left) <= (0 - parseInt(obstaculo.width))) {
  277. obs = document.getElementById("obstaculo" + i);
  278. obsw = obs.width;
  279. obs.style.left = innerWidth - obsw + "px";
  280.  
  281.  
  282. }*/
  283.  
  284. }
  285. }
  286.  
  287. }
  288.  
  289. function ProcessaRaposa() {
  290. tecla = event.key;
  291. switch (tecla) {
  292. case "ArrowUp":
  293. if (arrowup != 1) {
  294. if(posicao > 1){
  295. posicao--;
  296. }
  297. personagem.style.top = parseInt(personagem.style.top) - 25 + "%";
  298. arrowup++;
  299. arrowdown--;
  300.  
  301. }
  302. break;
  303. case "ArrowDown":
  304. if (arrowdown != 1) {
  305. if(posicao < 3){
  306. posicao++;
  307. }
  308. personagem.style.top = parseInt(personagem.style.top) + 25 + "%";
  309. arrowup--;
  310. arrowdown++;
  311. }
  312. break;
  313. }
  314. }
  315.  
  316. function detetaColisao() {
  317. for (var i = 1; i < cont_obs; i++) {
  318. var objAtual = document.getElementById("obstaculo"+i);
  319. var alpista =document.getElementById("obstaculo"+i).alt;
  320. console.log(alpista);
  321. if(alpista == "pista1" && posicao == 1){
  322. var obj = document.getElementById("obstaculo" + i);
  323. px = parseInt(personagem.style.left) + parseInt(personagem.width);
  324. py = parseInt(personagem.style.top) + (parseInt(personagem.height) / 2);
  325. py2 = parseInt(personagem.style.top) + parseInt(personagem.height);
  326. ax = parseInt(obj.style.left);
  327. bx = parseInt(obj.style.left) + parseInt(obj.width);
  328. ay = py2 - parseInt(obj.height);
  329. dy = py2;
  330. //console.log(ax+" "+px+" "+bx);
  331. // console.log(ay+" "+py+" "+dy);
  332. if (ax <= px && bx >= px) {
  333. //if ((ay > py && ay < py2) || (dy < py2 && dy > py)) {
  334. obj.style.left = innerWidth + "px";
  335. //}
  336. }else if((obj.style.left+obj.width) <= 0){
  337. obj.style.left = innerWidth + "px";
  338. }
  339. //voltar a fazer random de pista e tempo ate aparecer
  340. //comparação
  341. }else if(alpista == "pista2" && posicao == 2){
  342. var obj = document.getElementById("obstaculo" + i);
  343. px = parseInt(personagem.style.left) + parseInt(personagem.width);
  344. py = parseInt(personagem.style.top) + (parseInt(personagem.height) / 2);
  345. py2 = parseInt(personagem.style.top) + parseInt(personagem.height);
  346. ax = parseInt(obj.style.left);
  347. bx = parseInt(obj.style.left) + parseInt(obj.width);
  348. ay = py2 - parseInt(obj.height);
  349. dy = py2;
  350. //console.log(ax+" "+px+" "+bx);
  351. // console.log(ay+" "+py+" "+dy);
  352. if (ax <= px && bx >= px) {
  353. //if ((ay > py && ay < py2) || (dy < py2 && dy > py)) {
  354. obj.style.left = innerWidth + "px";
  355. //}
  356. }else if((obj.style.left+obj.width) <= 0){
  357. obj.style.left = innerWidth + "px";
  358. }
  359. }else if(alpista == "pista3" && posicao == 3){
  360. var obj = document.getElementById("obstaculo" + i);
  361. px = parseInt(personagem.style.left) + parseInt(personagem.width);
  362. py = parseInt(personagem.style.top) + (parseInt(personagem.height) / 2);
  363. py2 = parseInt(personagem.style.top) + parseInt(personagem.height);
  364. ax = parseInt(obj.style.left);
  365. bx = parseInt(obj.style.left) + parseInt(obj.width);
  366. ay = py2 - parseInt(obj.height);
  367. dy = py2;
  368. //console.log(ax+" "+px+" "+bx);
  369. // console.log(ay+" "+py+" "+dy);
  370. if (ax <= px && bx >= px) {
  371. //if ((ay > py && ay < py2) || (dy < py2 && dy > py)) { //pode ser desnecessário
  372. obj.style.left = innerWidth + "px";
  373. //}
  374. } else if((obj.style.left+obj.width) <= 0){
  375. console.log(innerWidth);
  376. obj.style.left = innerWidth + "px";
  377. }
  378. }
  379.  
  380. }
  381. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement