Advertisement
zacmaster

Torreta Laser-Fer (incompleto)

May 30th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.43 KB | None | 0 0
  1. //Clase Torreta Laser_________________________________________________________________________________
  2. package juego;
  3. import java.awt.Color;
  4. import entorno.Entorno;
  5.  
  6. public class TorretaLaser {
  7.     private double x, y;
  8.     private double angulo;
  9.     private int ancho;
  10.     private int alto;
  11.     private boolean vivo;
  12.     private boolean dispara;
  13.      
  14.     public TorretaLaser() {
  15.         this.x = -50;
  16.         this.y = -50;
  17.         this.angulo = 0;
  18.         this.vivo = false;
  19.         this.ancho = 50;
  20.         this.alto = 50;
  21.         this.dispara = false;
  22.     }
  23.     public int getAncho() {
  24.         return ancho;
  25.     }
  26.     public void setAncho(int ancho) {
  27.         this.ancho = ancho;
  28.     }
  29.     public int getAlto() {
  30.         return alto;
  31.     }
  32.     public void setAlto(int alto) {
  33.         this.alto = alto;
  34.     }
  35.  
  36.     //dibujarlo
  37.     public void dibujarse(Entorno entorno){
  38.         entorno.dibujarRectangulo(this.x, this.y, this.ancho, this.alto,this.angulo, Color.yellow);
  39.     }
  40.     public void dispara(Entorno entorno){
  41.         entorno.dibujarRectangulo(this.x, this.y, 2000, 10,0, Color.yellow);
  42.            
  43.     }
  44.  
  45.  
  46.     public double getX() {
  47.         return x;
  48.     }
  49.     public void setX(double x) {
  50.         this.x = x;
  51.     }
  52.     public double getY() {
  53.         return y;
  54.     }
  55.     public void setY(double y) {
  56.         this.y = y;
  57.     }
  58.     public boolean isVivo() {
  59.         return vivo;
  60.     }
  61.     public void setVivo(boolean vivo) {
  62.         this.vivo = vivo;
  63.     }      
  64.         public boolean getDispara() {
  65.         return dispara;
  66.     }
  67.     public void setDispara(boolean dispara) {
  68.         this.dispara = dispara;
  69.     }
  70.    
  71. }
  72.        
  73.  
  74. //metodo en clase Todo_arreglos_______________________________________________
  75.  
  76.     private TorretaLaser[] torretasLaser;
  77.  
  78.         public TorretaLaser[] getTorretasLaser() {
  79.             return torretasLaser;
  80.         }
  81.         public void setTorretasLaser( TorretaLaser[] torretasLaser) {
  82.             this.torretasLaser = torretasLaser;
  83.     }
  84.    
  85.     public void Arr_TorretaLaser(int cantidad) {        
  86.         this.torretasLaser = new TorretaLaser[cantidad];        
  87.         for(int i=0;i<cantidad;i++){
  88.             torretasLaser[i]= new TorretaLaser();            
  89.         }      }
  90.  
  91.  
  92. //metodo en clase Coliiones_________________________________
  93.  
  94.     public void zombieChocaTorretaLaser(){ //devuelve true si el zombie toca a la torreta
  95.         for (int i = 0; i < todo_Arreglos.getZombies().length; i++) {
  96.             for (int j = 0; j < todo_Arreglos.getTorretasLaser().length; j++) {
  97.                 if ((distanciaZombieTorretaLaser(todo_Arreglos.getZombies()[i],todo_Arreglos.getTorretasLaser()[j]) <= todo_Arreglos.getTorretasLaser()[j].getAlto()/2+todo_Arreglos.getZombies()[i].getDiametro()/2)){                
  98.                    
  99.                     todo_Arreglos.getTorretasLaser()[j].setVivo(false);
  100.                     todo_Arreglos.getTorretasLaser()[j].setX(-50);
  101.                     todo_Arreglos.getTorretasLaser()[j].setY(-50);
  102.                    
  103.                     todo_Arreglos.getZombies()[i].setX(-50);
  104.                     todo_Arreglos.getZombies()[i].setY(-50);
  105.                     todo_Arreglos.getZombies()[i].setVivo(false);
  106.                 }
  107.             }
  108.         }
  109.  
  110.     }
  111.  
  112. static double distanciaZombieTorretaLaser(Zombie z1, TorretaLaser t1){
  113.     double distancia;      
  114.     distancia = Math.pow((Math.pow((z1.getX()-t1.getX()), 2)+Math.pow((z1.getY()-t1.getY()), 2)), 0.5);        
  115.     return distancia;        
  116. }
  117.  
  118. metodo en clase ingeniero ________________________________________________________
  119.  
  120.             if (entorno.estaPresionada(entorno.TECLA_SHIFT)){
  121.                 this.creaTorretaLaser = true;
  122.                   }
  123.  
  124. implementacion en clase juego________________________________________________________
  125.  
  126. package juego;
  127. //import java.util.Random;
  128. import java.awt.Color;
  129.  
  130. import entorno.*;
  131.  
  132.  
  133. public class Juego_2 extends InterfaceJuego{
  134.     private Entorno entorno;
  135.     Ingeniero juan;
  136.     Todo_Arreglos todo_arreglos;
  137.     Colisiones colisiones;
  138.     int delay;
  139.     // otras variables del juego aqui
  140.     int puntero;
  141.     int contadorLaser = 0;
  142.    
  143.     Juego_2(){        
  144.         delay = 0;
  145.         todo_arreglos = new Todo_Arreglos();
  146.         todo_arreglos.Arr_Zombie(10);
  147.         todo_arreglos.Arr_Torreta(30);
  148.         todo_arreglos.Arr_TorretaLaser(30);
  149.         todo_arreglos.Arr_Mina(100);
  150.         juan = new Ingeniero();
  151.         colisiones = new Colisiones(juan,todo_arreglos);
  152.         entorno = new Entorno(this, "Aguanten los zombies vieja, no me importa nada!!", 800, 600);    
  153.         entorno.iniciar();
  154.         puntero = 0;
  155.        
  156.        
  157.     }
  158.    
  159.     /*
  160.      * Durante el juego, el método tick() será ejecutado en cada instante y
  161.      * por lo tanto es el método más importante de esta clase. Aquí se debe
  162.      * actualizar el estado interno del juego para simular el paso del tiempo
  163.      * (ver el enunciado del TP para mayor detalle).
  164.      */
  165.     public void tick(){
  166.         delay++;
  167.    
  168.            
  169.             if (juan.isCreaTorreta() == true && delay % 50 == 0 && puntero < todo_arreglos.getTorretas().length) {
  170.                 todo_arreglos.getTorretas()[puntero].setVivo(true);
  171.                 todo_arreglos.getTorretas()[puntero].setX(juan.getX());
  172.                 todo_arreglos.getTorretas()[puntero].setY(juan.getY());
  173.                
  174.                 puntero++;
  175.                 juan.setCreaTorreta(false);
  176.             }
  177.             if (juan.isCreaTorretaLaser() == true && delay % 50 == 0 && puntero < todo_arreglos.getTorretasLaser().length) {
  178.                 todo_arreglos.getTorretasLaser()[puntero].setVivo(true);
  179.                 todo_arreglos.getTorretasLaser()[puntero].setX(juan.getX());
  180.                 todo_arreglos.getTorretasLaser()[puntero].setY(juan.getY());
  181.                
  182.                 puntero++;
  183.                 juan.setCreaTorretaLaser(false);
  184.             }
  185.            
  186.            
  187.            
  188.        
  189.         for (int i = 0; i < todo_arreglos.getTorretas().length; i++) {
  190.             if(todo_arreglos.getTorretas()[i].isVivo() == true ){
  191.                 todo_arreglos.getTorretas()[i].dibujarse(entorno);    
  192.             }
  193.         }
  194.         colisiones.zombieChocaTorreta();
  195.         todo_arreglos.avanzarZombie();
  196.         todo_arreglos.dibujarZombie(entorno);
  197.        
  198.         for (int i = 0; i < todo_arreglos.getTorretasLaser().length; i++) {
  199.             if(todo_arreglos.getTorretasLaser()[i].isVivo() == true ){
  200.                 todo_arreglos.getTorretasLaser()[i].dibujarse(entorno);    
  201.             }
  202.                
  203.         }
  204.         for (int i = 0; i < todo_arreglos.getTorretasLaser().length; i++) {
  205.             if(todo_arreglos.getTorretasLaser()[i].getDispara()){
  206.                 todo_arreglos.getTorretasLaser()[i].dispara(entorno);    
  207.             }
  208.                
  209.         }
  210.        
  211.         for (int i = 0; i < todo_arreglos.getTorretasLaser().length; i++) {
  212.             contadorLaser++;           
  213.             if(todo_arreglos.getTorretasLaser()[i].isVivo() == true ){
  214.                 todo_arreglos.getTorretasLaser()[i].dibujarse(entorno);
  215.             if (contadorLaser>4000){
  216.                 todo_arreglos.getTorretasLaser()[i].setDispara(true);
  217.             } if (contadorLaser>8000){
  218.                 todo_arreglos.getTorretasLaser()[i].setDispara(false);
  219.                 contadorLaser=0;
  220.             }
  221.             }
  222.                
  223.         }
  224.         colisiones.zombieChocaTorretaLaser();
  225.         todo_arreglos.avanzarZombie();
  226.         todo_arreglos.dibujarZombie(entorno);
  227.        
  228.         if (colisiones.zombieMataIngeniero() == false){
  229.             juan.dibujarse(entorno);            
  230.         }
  231.         else{
  232.             juan.setVivo(false);
  233.         }
  234.        
  235.  
  236.         entorno.cambiarFont("Arial", 18, Color.white);
  237.        
  238.        
  239.     }
  240.     static Zombie[] quitarMuerto(Zombie[] array){
  241.         Zombie[] aux;
  242.         int largo = 0;
  243.         for (int i = 0; i < array.length; i++) {
  244.             if (array[i].isVivo() == true) {
  245.                 largo++;
  246.             }
  247.         }
  248.         aux = new Zombie[largo];
  249.         int c = 0;
  250.         for (int i = 0; i < array.length; i++) {
  251.             if (array[i].isVivo() == true) {
  252.                 aux[c] = array[i];
  253.                 c++;
  254.             }
  255.            
  256.         }
  257.         return aux;
  258.     }
  259.  
  260.     @SuppressWarnings("unused")
  261.     public static void main(String[] args){
  262.        
  263.         Juego_2 juego = new Juego_2();                      
  264.     }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement