Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Valu on 13/01/2018.
- */
- var pista_random, obstaculo, obs_random, cont_obs = 0;
- var chao, cam4, cam3, cam2, cam1, velocidade = 5, remendo2, remendo1;
- var peticao;
- var informa;
- var jogar;
- var instrucoes;
- var tempo;
- var spriteNumero = 1;
- var personagem;
- var tempo2;
- var tecla;
- var mov_raposa;
- var arrowup = 0;
- var arrowdown = 0;
- var px;
- var py;
- var ax;
- var bx;
- var ay;
- var dy;
- var posicao = 2;
- window.onload = function () {
- mov_raposa = document.getElementById("movimento_raposa");
- personagem = document.getElementById("raposinha");
- remendo2 = document.getElementById("remendo2");
- remendo1 = document.getElementById("remendo1");
- chao = document.getElementById("chao");
- cam4 = document.getElementById("cam4");
- cam3 = document.getElementById("cam3");
- cam2 = document.getElementById("cam2");
- cam1 = document.getElementById("cam1");
- cam1.style.backgroundPositionX = 0;
- cam2.style.backgroundPositionX = 0;
- cam3.style.backgroundPositionX = 0;
- cam4.style.backgroundPositionX = 0;
- personagem.style.left = 7 + "%";
- pista1 = document.getElementById("pista1");
- pista2 = document.getElementById("pista2");
- pista3 = document.getElementById("pista3");
- remendo1.style.top = 0;
- remendo2.style.top = 80 + "%";
- cam1.style.top = -10 + "%";
- cam2.style.top = 2 + "%";
- cam3.style.top = 0 + "%";
- cam4.style.top = 5 + "%";
- chao.style.top = 50 + "%";
- tempo = setInterval("bg_movimento()", 100);
- inicial();
- document.getElementById("carrega_div").style.display = "none";
- pistas.style.top = 50 + "%";
- mov_raposa.style.top = 40 + "%";
- chao.style.top = 50 + "%";
- pista1.style.top = 0 + "%";
- pista2.style.top = 33 + "%";
- pista3.style.top = 66 + "%";
- };
- function bg_movimento() {
- cam1.style.backgroundPositionX = parseInt(cam1.style.backgroundPositionX) - velocidade * 1 + "px";
- cam2.style.backgroundPositionX = parseInt(cam2.style.backgroundPositionX) - velocidade * 0.7 + "px";
- cam3.style.backgroundPositionX = parseInt(cam3.style.backgroundPositionX) - velocidade * 0.4 + "px";
- cam4.style.backgroundPositionX = parseInt(cam4.style.backgroundPositionX) - velocidade * 0.2 + "px";
- }
- document.getElementById("jogar").onclick = function () {
- setInterval("obstaculos_posicao()", 900);
- setInterval("obstaculos_movimento()", 1000 / 60);
- segundocarregamento();
- };
- document.getElementById("instrucoes_pagina").onclick = function () {
- primeirocarregamento();
- };
- function primeirocarregamento() {
- tempo = setInterval("bg_movimento()", 100);
- document.getElementById("logo").style.display = "none";
- document.getElementById("vida").style.display = "block";
- document.getElementById("fundo_transparente").style.display = "none";
- document.getElementById("jogar").style.display = "none";
- document.getElementById("instrucoes_pagina").style.display = "none";
- document.getElementById("peticoes").style.display = "none";
- document.getElementById("informate").style.display = "none";
- document.getElementById("fundo_transparente_01").style.display = "block";
- document.getElementById("armadilha").style.display = "block";
- document.getElementById("veneno").style.display = "block";
- document.getElementById("incendio").style.display = "block";
- document.getElementById("tronco").style.display = "block";
- document.getElementById("pedra").style.display = "block";
- document.getElementById("atropelamento").style.display = "block";
- document.getElementById("avancar").style.display = "block";
- overs();
- }
- function overs() {
- //armadilha x
- document.getElementById("armadilha").onmouseover = function () {
- document.getElementById("armadilha_over").style.display = "block";
- };
- document.getElementById("armadilha").onmouseout = function () {
- document.getElementById("armadilha_over").style.display = "none"
- };
- //atroplamento x
- document.getElementById("atropelamento").onmouseover = function () {
- document.getElementById("atropelamento_over").style.display = "block"
- };
- document.getElementById("atropelamento").onmouseout = function () {
- document.getElementById("atropelamento_over").style.display = "none"
- };
- //incendio x
- document.getElementById("incendio").onmouseover = function () {
- document.getElementById("incendio_over").style.display = "block"
- };
- document.getElementById("incendio").onmouseout = function () {
- document.getElementById("incendio_over").style.display = "none"
- };
- //veneno x
- document.getElementById("veneno").onmouseover = function () {
- document.getElementById("veneno_over").style.display = "block"
- };
- document.getElementById("veneno").onmouseout = function () {
- document.getElementById("veneno_over").style.display = "none"
- };
- //pedra
- document.getElementById("pedra").onmouseover = function () {
- document.getElementById("pedra_over").style.display = "block"
- };
- document.getElementById("pedra").onmouseout = function () {
- document.getElementById("pedra_over").style.display = "none"
- };
- //tronco
- document.getElementById("tronco").onmouseover = function () {
- document.getElementById("tronco_over").style.display = "block"
- };
- document.getElementById("tronco").onmouseout = function () {
- document.getElementById("tronco_over").style.display = "none"
- };
- //vida
- document.getElementById("vida").onmouseover = function () {
- document.getElementById("vida_over").style.display = "block"
- };
- document.getElementById("vida").onmouseout = function () {
- document.getElementById("vida_over").style.display = "none"
- };
- }
- function inicial() {
- peticao = document.getElementById("peticoes");
- peticao.onmouseover = function () {
- peticao.style.fontWeight = "bold";
- };
- peticao.onmouseout = function () {
- peticao.style.fontWeight = "normal";
- };
- instrucoes = document.getElementById("instrucoes_pagina");
- instrucoes.onmouseover = function () {
- instrucoes.style.fontWeight = "bold";
- };
- instrucoes.onmouseout = function () {
- instrucoes.style.fontWeight = "normal";
- };
- jogar = document.getElementById("jogar");
- jogar.onmouseover = function () {
- jogar.style.fontWeight = "bold";
- };
- jogar.onmouseout = function () {
- jogar.style.fontWeight = "normal";
- };
- informa = document.getElementById("informate");
- informa.onmouseover = function () {
- informa.style.fontWeight = "bold";
- };
- informa.onmouseout = function () {
- informa.style.fontWeight = "normal";
- };
- }
- function segundocarregamento() {
- tempo = setInterval("bg_movimento()", 100);
- document.getElementById("logo").style.display = "none";
- document.getElementById("fundo_transparente").style.display = "none";
- document.getElementById("jogar").style.display = "none";
- document.getElementById("instrucoes_pagina").style.display = "none";
- document.getElementById("peticoes").style.display = "none";
- document.getElementById("informate").style.display = "none";
- personagem.style.display = "block";
- personagem.style.top = 25 + "%";
- tempo2 = setInterval("mudar()", 100);
- }
- function mudar() {
- personagem.src = "img/sprite/correr_" + spriteNumero + ".png";
- spriteNumero++;
- if (spriteNumero == 7) {
- spriteNumero = 1
- }
- }
- //---------------------------------
- // 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
- //qual e o obstaculo que vai aparecer
- function obstaculos_random(pista, tipoPista) {
- //console.log(pista);
- obs_random = parseInt(Math.random() * (8) + 1);
- // oitavo caso nao aparece nenhum obstaculo
- if (obs_random != 8) {
- if(cont_obs < 8){
- cont_obs++;
- if (tipoPista == "pista1") {
- pista.innerHTML += "<img src='img/elements/obs_" + obs_random + ".png' id='obstaculo" + cont_obs + " ' alt='pista1'/>";
- } else if (tipoPista == "pista2") {
- pista.innerHTML += "<img src='img/elements/obs_" + obs_random + ".png' id='obstaculo" + cont_obs + "' alt='pista2'/>";
- } else {
- pista.innerHTML += "<img src='img/elements/obs_" + obs_random + ".png' id='obstaculo" + cont_obs + "' alt='pista3'/>";
- }
- obs = document.getElementById("obstaculo" + cont_obs);
- obs.style.width = "4%";
- obsw = obs.width;
- obs.style.position = "relative";
- obs.style.left = innerWidth - obsw + "px";
- obs.style.top = 0;
- }
- }
- }
- window.onkeydown = function () {
- ProcessaRaposa();
- };
- //pista onde o obstaculo vai aparecer
- function obstaculos_posicao(obstaculo) {
- random = parseInt(Math.random() * (2));
- if (random == 1) {
- pista_random = parseInt(Math.random() * (3));
- switch (pista_random) {
- case 0:
- pista1 = document.getElementById("pista1");
- obstaculos_random(pista1, "pista1");
- break;
- case 1:
- pista2 = document.getElementById("pista2");
- obstaculos_random(pista2, "pista2");
- break;
- case 2:
- pista3 = document.getElementById("pista3");
- obstaculos_random(pista3, "pista3");
- break;
- }
- }
- }
- function obstaculos_movimento() {
- if (cont_obs != 0) {
- for (var i = 1; i < cont_obs; i++) {
- var obstaculo = document.getElementById("obstaculo" + i);
- obstaculo.style.left = (parseInt(obstaculo.style.left) - 5) + "px";
- console.log(obstaculo.style.left)
- detetaColisao();
- /*if (parseInt(obstaculo.style.left) <= (0 - parseInt(obstaculo.width))) {
- obs = document.getElementById("obstaculo" + i);
- obsw = obs.width;
- obs.style.left = innerWidth - obsw + "px";
- }*/
- }
- }
- }
- function ProcessaRaposa() {
- tecla = event.key;
- switch (tecla) {
- case "ArrowUp":
- if (arrowup != 1) {
- if(posicao > 1){
- posicao--;
- }
- personagem.style.top = parseInt(personagem.style.top) - 25 + "%";
- arrowup++;
- arrowdown--;
- }
- break;
- case "ArrowDown":
- if (arrowdown != 1) {
- if(posicao < 3){
- posicao++;
- }
- personagem.style.top = parseInt(personagem.style.top) + 25 + "%";
- arrowup--;
- arrowdown++;
- }
- break;
- }
- }
- function detetaColisao() {
- for (var i = 1; i < cont_obs; i++) {
- var objAtual = document.getElementById("obstaculo"+i);
- var alpista =document.getElementById("obstaculo"+i).alt;
- console.log(alpista);
- if(alpista == "pista1" && posicao == 1){
- var obj = document.getElementById("obstaculo" + i);
- px = parseInt(personagem.style.left) + parseInt(personagem.width);
- py = parseInt(personagem.style.top) + (parseInt(personagem.height) / 2);
- py2 = parseInt(personagem.style.top) + parseInt(personagem.height);
- ax = parseInt(obj.style.left);
- bx = parseInt(obj.style.left) + parseInt(obj.width);
- ay = py2 - parseInt(obj.height);
- dy = py2;
- //console.log(ax+" "+px+" "+bx);
- // console.log(ay+" "+py+" "+dy);
- if (ax <= px && bx >= px) {
- //if ((ay > py && ay < py2) || (dy < py2 && dy > py)) {
- obj.style.left = innerWidth + "px";
- //}
- }else if((obj.style.left+obj.width) <= 0){
- obj.style.left = innerWidth + "px";
- }
- //voltar a fazer random de pista e tempo ate aparecer
- //comparação
- }else if(alpista == "pista2" && posicao == 2){
- var obj = document.getElementById("obstaculo" + i);
- px = parseInt(personagem.style.left) + parseInt(personagem.width);
- py = parseInt(personagem.style.top) + (parseInt(personagem.height) / 2);
- py2 = parseInt(personagem.style.top) + parseInt(personagem.height);
- ax = parseInt(obj.style.left);
- bx = parseInt(obj.style.left) + parseInt(obj.width);
- ay = py2 - parseInt(obj.height);
- dy = py2;
- //console.log(ax+" "+px+" "+bx);
- // console.log(ay+" "+py+" "+dy);
- if (ax <= px && bx >= px) {
- //if ((ay > py && ay < py2) || (dy < py2 && dy > py)) {
- obj.style.left = innerWidth + "px";
- //}
- }else if((obj.style.left+obj.width) <= 0){
- obj.style.left = innerWidth + "px";
- }
- }else if(alpista == "pista3" && posicao == 3){
- var obj = document.getElementById("obstaculo" + i);
- px = parseInt(personagem.style.left) + parseInt(personagem.width);
- py = parseInt(personagem.style.top) + (parseInt(personagem.height) / 2);
- py2 = parseInt(personagem.style.top) + parseInt(personagem.height);
- ax = parseInt(obj.style.left);
- bx = parseInt(obj.style.left) + parseInt(obj.width);
- ay = py2 - parseInt(obj.height);
- dy = py2;
- //console.log(ax+" "+px+" "+bx);
- // console.log(ay+" "+py+" "+dy);
- if (ax <= px && bx >= px) {
- //if ((ay > py && ay < py2) || (dy < py2 && dy > py)) { //pode ser desnecessário
- obj.style.left = innerWidth + "px";
- //}
- } else if((obj.style.left+obj.width) <= 0){
- console.log(innerWidth);
- obj.style.left = innerWidth + "px";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement