Objeto Grafico.java
1
2 /**
3 *@ Andrea Forero andreita_9009@hotmail.com
4 *@ Claudia Leon claudialeon18@hotmail.com
5 *@ Erika Santana eesantana61@hotmail.com
6 **/
7
8 import java.awt.Graphics;
9 import java.awt.Rectangle;
10 import java.io.Serializable;
11
12
13 public abstract class ObjetoGrafico implements Serializable{
14 private static final long serialVersionUID = 76288570343555L;
15 private int posX, posY,ancho,alto;
16 private boolean visible=true;
17 public ObjetoGrafico( int x, int y,int an, int al){
18 posX=x;
19 posY=y;
20 ancho=an;
21 alto=al;
22
23 }
24 public abstract void paint(Graphics g);
25 public boolean getVisible() {
26 // TODO Auto-generated method stub
27 return visible;
28 }
29
30 public void setVisible(boolean v){
31 visible=v;
32 }
33
34 public int getPosX() {
35 return posX;
36
37
38 }
39 public int getPosY() {
40 return posY;
41 }
42 public int getAncho() {
43 return ancho;
44 }
45 public int getAlto() {
46 return alto;
47 }
48 public void incX(int dx){
49 posX += dx;
50 }
51 public void incY(int dy){
52 posY += dy;
53 if (posY > 470){
54 posY= 8;
55 }
56 }
57 public void decX(int dx){
58 posX -= dx;
59 }
60 public void decY(int dy){
61 posY -= dy;
62 if (posY < 10){
63 posY= 485;
64 }
65
66 }
67
68 public boolean colisiona (ObjetoGrafico otro){
69 if(this==otro){
70 return false;
71 }
72 if (this.getVisible()==false || otro.getVisible()== false) {
73 return false;
74 }
75 Rectangle r1=new Rectangle (posX, posY, ancho , alto);
76 Rectangle r2=new Rectangle (otro.posX, otro.posY,otro. ancho ,otro. alto);
77 return r1.intersects(r2);
78 }
79 public void setAlto(int alto) {
80 this.alto = alto;
81 }
82 public void setAncho(int ancho) {
83 this.ancho = ancho;
84 }
85 public void setPosX(int posX) {
86 this.posX = posX;
87 }
88 public void setPosY(int posY) {
89 this.posY = posY;
90 }
91 }
92
93
94
95
96
CategoryJava | CategoryProgramacion
