Advertisement
Davidsale96

Nuevo elemento(dibuja un rectángulo y carga una imagen)

Oct 20th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.74 KB | None | 0 0
  1. package juego;
  2. import java.awt.Color;
  3. import java.awt.Image;
  4. import java.awt.Rectangle;
  5. import entorno.Entorno;
  6. import entorno.Herramientas;
  7.  
  8. public class NewElement {
  9.     double x;
  10.     double y;
  11.     double ancho;
  12.     double alto;
  13.     double angulo;
  14.     Image imgBirdCambio;
  15.     Image Element;
  16.     Image Element2;
  17.     Color color2 = new Color(10,175,175);
  18.     Color colorRosa = new Color(255,175,175);
  19.    
  20.     public NewElement(double x, double y, double ancho, double alto,String imglink) {
  21.         this.x = x;
  22.         this.y = y;
  23.         this.ancho = ancho;
  24.         this.alto = alto;
  25.         Element= Herramientas.cargarImagen(imglink);
  26.     }
  27.     public NewElement(double x, double y, double ancho, double alto) {
  28.         this.x = x;
  29.         this.y = y;
  30.         this.ancho = ancho;
  31.         this.alto = alto;
  32.        
  33.     }
  34.  
  35.     public void dibujarse(Entorno entorno,Double x) {
  36.        
  37.         entorno.dibujarRectangulo(this.x, this.y, this.ancho, this.alto, this.angulo, colorRosa);
  38.         entorno.dibujarImagen(Element, this.x, this.y, this.angulo, 1);
  39.         if(this.x==0)
  40.             this.x=x;
  41.     }
  42.     public void dibujarse(Entorno entorno) {
  43.    
  44.         entorno.dibujarRectangulo(this.x, this.y, this.ancho, this.alto, this.angulo, colorRosa);
  45.         entorno.dibujarImagen(Element, this.x, this.y, this.angulo, 0.05);
  46.  
  47.     }
  48.    
  49.    
  50.                                                                                
  51.     public boolean colision(NewElement rect1,NewElement rect2) {
  52.        
  53.         Rectangle rectangulo1=new Rectangle((int)rect1.x,(int)rect1.y,(int)rect1.alto,(int)rect1.ancho);
  54.         Rectangle rectangulo2=new Rectangle((int)rect2.x,(int)rect2.y,(int)rect2.alto,(int)rect2.ancho);
  55.         return rectangulo2.intersects(rectangulo1);
  56.        
  57.        
  58.         /*if(rect1.x>rect2.x+rect2.ancho && rect1.x+rect1.ancho<rect2.x && rect1.y>rect2.y+rect2.alto && rect1.y+rect1.alto<rect2.y)
  59.             return true;
  60.         return false;*/
  61.         /*for(double x1=rect1.x;x1<=rect1.x/2;x1--) {
  62.             for(double y1=rect1.y;y1<=rect1.y/2;y1++) {
  63.                
  64.             }
  65.            
  66.         }
  67.        
  68.         Punto punto1=new Punto(rect1.x,rect1.y);
  69.         Punto punto2=new Punto(rect2.x,rect2.y);
  70.         if(punto1.Distancia(punto1, punto2)==0.0)
  71.             return true;
  72.         return false;*/
  73.        
  74.         //new Rectangle((int)rect1.x,(int)rect1.y,(int)rect1.alto,(int)rect1.ancho).intersectsLine(rect2.x,rect2.y,rect2.alto,rect2.ancho)
  75.         /*Rectangle rectangulo1=new Rectangle((int)rect1.x,(int)rect1.y,(int)rect1.alto,(int)rect1.ancho);
  76.         Rectangle rectangulo2=new Rectangle((int)rect2.x,(int)rect2.y,(int)rect2.alto,(int)rect2.ancho);
  77.         if(rectangulo1.intersects(rectangulo2))
  78.             return true;
  79.         return false;*/
  80.        
  81.         /*if (rect1.x + rect1.ancho >= rect2.x &&     // r1 right edge past r2 left
  82.                 rect1.x <= rect2.x + rect2.ancho &&       // r1 left edge past r2 right
  83.                   rect1.y + rect1.alto >= rect2.y &&       // r1 top edge past r2 bottom
  84.                   rect1.y <= rect2.y + rect2.alto) {       // r1 bottom edge past r2 top
  85.                     return true;
  86.                 }
  87.                 return false;*/
  88.        
  89.     }
  90.    
  91.    
  92.    
  93.    
  94.     /*  public boolean colision(NewElement rect1,NewElement rect2) {
  95.     double x1= rect1.x-(rect1.x/2);
  96.     double y1= rect1.y+(rect1.y/2);
  97.     double w1= rect1.ancho;
  98.     double h1= rect1.alto;
  99.     double x2= rect2.x-(rect2.x/2);
  100.     double y2= rect2.y+(rect2.y/2);
  101.     double w2= rect2.ancho;
  102.     double h2= rect2.alto;
  103.    
  104.     if(( x1 > x2+w2 )&&( x1+w1 < x2 )&&( y1 > y2+h2 )&&( y1+h1 < y2 ))
  105.         return true;
  106.     return false;
  107. }*/
  108.    
  109.  
  110.     public void cambio(Entorno entorno,String img) {
  111.         Element2= Herramientas.cargarImagen(img);
  112.         entorno.dibujarRectangulo(this.x, this.y, this.ancho, this.alto, this.angulo, colorRosa);
  113.         entorno.dibujarImagen(Element2, this.x, this.y, this.angulo, 0.05);
  114.  
  115.        
  116. }
  117.    
  118.     public void movimiento() { 
  119.         this.x -= +1;
  120.     }
  121.    
  122.     public void reiniciar(double x) {
  123.         if(this.x==0)
  124.             this.x=x;
  125.     }
  126.    
  127.     public void saltar() {
  128.         if (this.y>0)  
  129.             this.y -= Math.sin(this.angulo)+1;
  130.        
  131.     }
  132.    
  133.     public void caer() {
  134.         if(this.y<550)
  135.             this.y += Math.sin(this.angulo)+1;
  136.     }
  137.    
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement