ObjetoGrafico.java
1 /**
2 *@author Andres Felipe Quevedo vega. andresfe118@hotmail.com
3 */
4 import java.awt.*;
5 import java.io.Serializable;
6
7 public abstract class ObjetoGrafico implements Serializable{
8 private int x, y, ancho, alto,direccion;
9 private boolean visible=true;
10
11 public ObjetoGrafico (int posx, int posy, int an, int alt) {
12 x = posx;
13 y = posy;
14 ancho = an;
15 alto = alt;
16 direccion = 1;
17 }
18 public boolean getVisible(){
19 return visible;
20 }
21 public void setVisible (boolean v){
22 visible=v;
23 }
24 public boolean colisiona (ObjetoGrafico otro){
25 if (!getVisible ()){
26 return false;
27 }
28 if (!otro.getVisible ()){
29 return false;
30 }
31 if (this==otro){
32 return false;
33 }
34 Rectangle r1= new Rectangle (x, y, ancho, alto);
35 Rectangle r2= new Rectangle (otro.x, otro.y, otro.ancho, otro.ancho);
36 return r1.intersects(r2);
37 }
38 public abstract void paint (Graphics g);
39 public int getX (){
40 return x;
41 }
42 public int getY (){
43 return y;
44 }
45 public int getAncho (){
46 return ancho;
47 }
48 public int getAlto (){
49 return alto;
50 }
51 public void incX(int dx){
52 if (x+getAncho()>= 615) {
53 direccion = -1;
54 }
55 else if (x <= 0){
56 direccion = 1;
57 }
58 x += dx *direccion;
59
60 }
61 public void incY(int dy){
62 if (y>=620){
63 }
64 else{
65 y+=dy;
66 }
67 }
68 public void decX (int dx){
69 if (x <= 0) {
70 x+=dx;
71 }
72 else{
73 x-= dx;
74
75 }
76 }
77
78 public void decY (int dy){
79 y-=dy;
80 }
81 }
CategoryJava | CategoryProgramacion
