Skip to content
This repository has been archived by the owner on Jun 3, 2018. It is now read-only.

Commit

Permalink
Fourth delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
Toscan0 committed Jun 3, 2018
1 parent 6f2535e commit f7ce0a4
Show file tree
Hide file tree
Showing 25 changed files with 620 additions and 407 deletions.
16 changes: 11 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<html>
<head>
<meta charset = "utf-8">
<title>Projeto CG- 3&ordf; entrega</title>
<title>Projeto CG- 4&ordf; entrega</title>
<!--
<sub-title> G27 <sub-title>
-->
<style>
body{
margin: 0px;
Expand All @@ -20,11 +23,14 @@
<script src="js/EventListener.js"></script>
<script src="js/movimento.js"></script>
<script src="js/lights.js"></script>
<script src="js/resultado.js"></script>
<script src="js/aux.js"></script>
<!-- Objects Files -->
<script src="js/objects/nave.js"></script>
<script src="js/objects/invader.js"></script>
<script src="js/objects/campo.js"></script>
<script src="js/objects/tiro.js"></script>
<script src="js/Objects/nave.js"></script>
<script src="js/Objects/invader.js"></script>
<script src="js/Objects/campo.js"></script>
<script src="js/Objects/tiro.js"></script>
<script src="js/Objects/msg.js"></script>
</head>
<body>
<script>
Expand Down
150 changes: 115 additions & 35 deletions js/EventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,79 +8,131 @@ function onKeyDown(e){
//se a tecla 'a' ou 'A' for premida alterna entre os modelos de arame e solidos
case 65: //A
case 97: //a
changeWireframe();
if(gf_pause == false){
changeWireframe();
}
break;
//Dispara um tiro
case 32: // tecla espaco
case 66: //B
case 98: //b
gf_tiros = true;
disparaTiro(gf_gouraud);
case 32:
if(gf_pause == false){
gf_tiros = true;
disparaTiro(gf_gouraud);
}
break;
//ativa e desativa as estrelinhas(Point Light)
case 67: //c
case 99: //c
if(gf_basic == false){
gf_pointLight = !gf_pointLight;
if(gf_pause == false){
if(gf_basic == false){
gf_pointLight = !gf_pointLight;
}
}
break;
//Sombreamento Gouraud e Phong
case 71: //G
case 103: //g
gf_gouraud = !gf_gouraud;
gf_basic = false;
changeMaterial();
if(gf_pause == false){
gf_gouraud = !gf_gouraud;
gf_basic = false;
changeMaterial();
}
break;
//ativa/desativa o SpotLight
case 72: //H
case 104: //h
if(gf_pause == false){
if(gf_basic == false){
gf_spotLight = !gf_spotLight;
}
}
break;
case 73: //I
case 105: //i
//imprime os materiais, e as variaveis
globalPrint();
break;
//Ativa/desativa calculo da iluminacao
case 76: //L
case 108: //l
gf_basic = !gf_basic;
changeMaterial();
if(gf_pause == false){
gf_basic = !gf_basic;
changeMaterial();
}
break;
//Ativa luz
case 78: //N
case 110: //n
//So e possivel alterar se estivermos em modo Phong/Gouraund
if(gf_basic == false){
gf_dirlight = !gf_dirlight;
if(gf_pause == false){
//So e possivel alterar se estivermos em modo Phong/Gouraund
if(gf_basic == false){
gf_dirlight = !gf_dirlight;
}
}
break;
reinicia
case 82: //R
case 114: //r
if(gf_terminou == true){
restart();
}
break;
//Pausa
case 80: //P
case 113: //p
console.log("p", gf_pause);
gf_pause = !gf_pause;
case 112: //p
case 83: //S
case 115: //s
if(gf_terminou == false){
gf_pause = !gf_pause;
//estamos em pausa
if((gf_pause == true) && (gf_terminou == false)){
materialMsg.map = textureMsg[2];
}
}
break;
//nave a mover para a esquerda
case 37: //seta esquerda (<-)
nave.userData.moverEsquerda = true;
nave.userData.moverDireita = false;
if(gf_pause == false){
nave.userData.moverEsquerda = true;
nave.userData.moverDireita = false;
//nave.rotation.y = -60;
}
break;
//nave a mover para a direita
case 39: //seta direita (->)
nave.userData.moverDireita = true;
nave.userData.moverEsquerda = false;
if(gf_pause == false){
nave.userData.moverDireita = true;
nave.userData.moverEsquerda = false;
//nave.rotation.y = 60;
}
break;
//ativa a camera ortogonal
case 49: //1
gf_cameraOrtogonal = true;
gf_cameraPrespective1 = false;
gf_cameraPrespective2 = false;
if(gf_pause == false){
gf_cameraOrtogonal = true;
gf_cameraPrespective1 = false;
gf_cameraPrespective2 = false;
}
break;
//ativa a camera em prespetiva1
case 50: //2
gf_cameraOrtogonal = false;
gf_cameraPrespective1 = true;
gf_cameraPrespective2 = false;
case 50: //2
if(gf_pause == false){
gf_cameraOrtogonal = false;
gf_cameraPrespective1 = true;
gf_cameraPrespective2 = false;
}
break;
//ativa a camera em prespetiva2
case 51: //3
gf_cameraOrtogonal = false;
gf_cameraPrespective1 = false;
gf_cameraPrespective2 = true;
if(gf_pause == false){
gf_cameraOrtogonal = false;
gf_cameraPrespective1 = false;
gf_cameraPrespective2 = true;
}
break;
}
//imprime os materiais, e as variaveis
printSombr();
}

//verifica se alguma tecla que estava a ser permida deixou de o ser
Expand All @@ -89,6 +141,7 @@ function onKeyUp(e){

switch (e.keyCode){
//Parou de disparar
case 32: //tecla espaco
case 66: //B
case 98: //b
gf_reoladed = true;
Expand All @@ -98,6 +151,7 @@ function onKeyUp(e){
case 39: // seta direita (->)
nave.userData.moverEsquerda = false;
nave.userData.moverDireita = false;
nave.rotation.y = 0;
break;
}

Expand All @@ -115,12 +169,20 @@ function onResize() {
camera.right = limite*rel_asp;
camera.top = limite;
camera.bottom = -limite;
camera2.left = -5*rel_asp;
camera2.right = 5*rel_asp;
camera2.top = 15;
camera2.bottom = -15;
}
else{
camera.left = -limite;
camera.right = limite;
camera.top = limite/rel_asp;
camera.bottom = -limite/rel_asp;
camera2.left = -5;
camera2.right = 5;
camera2.top = 15/rel_asp;
camera2.bottom = -15/rel_asp;
}
camera.updateProjectionMatrix();
}
Expand All @@ -141,8 +203,6 @@ function changeMaterial(){
invaderListTemp = [];
tiroListTemp = [];
naveListTemp = [];

createCampo(0, 0, -3.5, gf_gouraud);

if(naveList.length == 1){
scene.remove(naveList[0]);
Expand Down Expand Up @@ -182,5 +242,25 @@ function changeMaterial(){
tiroListTemp[i].position.y,
tiroListTemp[i].position.z, gf_gouraud)
}

}

function restart(){
'use strict';

if(naveList.length == 1){
scene.remove(naveList[0]);
}
naveList = [];
for (i=0; i < invaderList.length; i++){
scene.remove(invaderList[i].inv);
}
invaderList = [];
for (i=0; i < tiroList.length; i++){
scene.remove(tiroList[i]);
}
tiroList = [];

vidasList = [];

createInterectiveObjects();
}
Binary file added js/Objects/Img/Paused.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added js/Objects/Img/You win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added js/Objects/Img/fundo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added js/Objects/Img/fundo2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added js/Objects/Img/fundo3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added js/Objects/Img/ganhou.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added js/Objects/Img/pausa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added js/Objects/Img/perdeu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added js/Objects/Img/you lose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions js/Objects/campo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*------------Limites do campo--------------*/
function addBaseCampo(obj, material, x, y, z){
'use strict';

geometry = new THREE.PlaneGeometry(160, 160);

mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);

obj.add(mesh);
}

function createCampo(x, y, z){
'use strict'

campo = new THREE.Object3D();

loaderCampo = new THREE.TextureLoader();
//textureCampo = loaderCampo.load("...");

//posicao 0 -> fundo em jpeg
textureCampo.push(loaderCampo.load("js/Objects/Img/fundo2.jpeg"));
//posicao 1 -> fundo em png
textureCampo.push(loaderCampo.load("js/Objects/Img/fundo1.png"));
//posicao 2 -> fundo em jpg
textureCampo.push(loaderCampo.load("js/Objects/Img/fundo3.jpg"));

materialCampo = new THREE.MeshBasicMaterial();
//Imagem inicial de fundo

materialCampo.map = textureCampo[2];

addBaseCampo(campo, materialCampo, 0, 0, 0);

scene.add(campo);

campo.position.x = x;
campo.position.y = y;
campo.position.z = z;
}
2 changes: 1 addition & 1 deletion js/objects/invader.js → js/Objects/invader.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ function colocaInvader( y, met){
createInvader(-25, y, 0, met, 0, 0);
createInvader(25, y, 0, met, 0, 0);
createInvader(50, y, 0, met, 0, 0);
}
}
39 changes: 39 additions & 0 deletions js/Objects/msg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var msg, materialMsg, loaderMsg, textureMsg = [];

function addBaseMsg(obj, material, x, y, z){
'use strict';

geometry = new THREE.PlaneGeometry(40, 40);

mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);

obj.add(mesh);
}

function createMsg(x, y, z){
'use strict'

msg = new THREE.Object3D();

loaderMsg = new THREE.TextureLoader();

//posicao 0 -> O jogador perdeu
textureMsg.push(loaderMsg.load("js/Objects/Img/perdeu.png"));
//posicao 1 -> O jogador ganhou
textureMsg.push(loaderMsg.load("js/Objects/Img/ganhou.png"));
//posicao 2 -> O jogador carregou na pausa
textureMsg.push(loaderMsg.load("js/Objects/Img/pausa.png"));

materialMsg = new THREE.MeshBasicMaterial();
//Imagem inicial de fundo
//materialMsg.map = textureMsg[0];

addBaseMsg(msg, materialMsg, 0, 0, 0);

scene.add(msg);

msg.position.x = x;
msg.position.y = y;
msg.position.z = z;
}
Loading

0 comments on commit f7ce0a4

Please sign in to comment.