Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package juego;
- import java.awt.Color;
- import java.awt.Image;
- import java.awt.Rectangle;
- import entorno.Entorno;
- import entorno.Herramientas;
- public class NewElement {
- double x;
- double y;
- double ancho;
- double alto;
- double angulo;
- Image imgBirdCambio;
- Image Element;
- Image Element2;
- Color color2 = new Color(10,175,175);
- Color colorRosa = new Color(255,175,175);
- public NewElement(double x, double y, double ancho, double alto,String imglink) {
- this.x = x;
- this.y = y;
- this.ancho = ancho;
- this.alto = alto;
- Element= Herramientas.cargarImagen(imglink);
- }
- public NewElement(double x, double y, double ancho, double alto) {
- this.x = x;
- this.y = y;
- this.ancho = ancho;
- this.alto = alto;
- }
- public void dibujarse(Entorno entorno,Double x) {
- entorno.dibujarRectangulo(this.x, this.y, this.ancho, this.alto, this.angulo, colorRosa);
- entorno.dibujarImagen(Element, this.x, this.y, this.angulo, 1);
- if(this.x==0)
- this.x=x;
- }
- public void dibujarse(Entorno entorno) {
- entorno.dibujarRectangulo(this.x, this.y, this.ancho, this.alto, this.angulo, colorRosa);
- entorno.dibujarImagen(Element, this.x, this.y, this.angulo, 0.05);
- }
- public boolean colision(NewElement rect1,NewElement rect2) {
- Rectangle rectangulo1=new Rectangle((int)rect1.x,(int)rect1.y,(int)rect1.alto,(int)rect1.ancho);
- Rectangle rectangulo2=new Rectangle((int)rect2.x,(int)rect2.y,(int)rect2.alto,(int)rect2.ancho);
- return rectangulo2.intersects(rectangulo1);
- /*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)
- return true;
- return false;*/
- /*for(double x1=rect1.x;x1<=rect1.x/2;x1--) {
- for(double y1=rect1.y;y1<=rect1.y/2;y1++) {
- }
- }
- Punto punto1=new Punto(rect1.x,rect1.y);
- Punto punto2=new Punto(rect2.x,rect2.y);
- if(punto1.Distancia(punto1, punto2)==0.0)
- return true;
- return false;*/
- //new Rectangle((int)rect1.x,(int)rect1.y,(int)rect1.alto,(int)rect1.ancho).intersectsLine(rect2.x,rect2.y,rect2.alto,rect2.ancho)
- /*Rectangle rectangulo1=new Rectangle((int)rect1.x,(int)rect1.y,(int)rect1.alto,(int)rect1.ancho);
- Rectangle rectangulo2=new Rectangle((int)rect2.x,(int)rect2.y,(int)rect2.alto,(int)rect2.ancho);
- if(rectangulo1.intersects(rectangulo2))
- return true;
- return false;*/
- /*if (rect1.x + rect1.ancho >= rect2.x && // r1 right edge past r2 left
- rect1.x <= rect2.x + rect2.ancho && // r1 left edge past r2 right
- rect1.y + rect1.alto >= rect2.y && // r1 top edge past r2 bottom
- rect1.y <= rect2.y + rect2.alto) { // r1 bottom edge past r2 top
- return true;
- }
- return false;*/
- }
- /* public boolean colision(NewElement rect1,NewElement rect2) {
- double x1= rect1.x-(rect1.x/2);
- double y1= rect1.y+(rect1.y/2);
- double w1= rect1.ancho;
- double h1= rect1.alto;
- double x2= rect2.x-(rect2.x/2);
- double y2= rect2.y+(rect2.y/2);
- double w2= rect2.ancho;
- double h2= rect2.alto;
- if(( x1 > x2+w2 )&&( x1+w1 < x2 )&&( y1 > y2+h2 )&&( y1+h1 < y2 ))
- return true;
- return false;
- }*/
- public void cambio(Entorno entorno,String img) {
- Element2= Herramientas.cargarImagen(img);
- entorno.dibujarRectangulo(this.x, this.y, this.ancho, this.alto, this.angulo, colorRosa);
- entorno.dibujarImagen(Element2, this.x, this.y, this.angulo, 0.05);
- }
- public void movimiento() {
- this.x -= +1;
- }
- public void reiniciar(double x) {
- if(this.x==0)
- this.x=x;
- }
- public void saltar() {
- if (this.y>0)
- this.y -= Math.sin(this.angulo)+1;
- }
- public void caer() {
- if(this.y<550)
- this.y += Math.sin(this.angulo)+1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement