ObjetoGrafico.java
Categorías: CategoryJava | CategoryProgramacion |
1 /**
2 *@author Elkin Andrey Garzón Alarcón...Geek Master
3 *@author Ingrid Lorena Guerrero Mayorga...
4 *@author Jefferson Fabian Idarraga Idarraga Pinilla...
5 */
6 package pinguinogg;
7
8 import java.awt.Graphics;
9 import java.awt.Rectangle;
10 import java.io.Serializable;
11
12 public abstract class ObjetoGrafico implements Serializable{
13 protected int x, y, ancho,alto;
14 protected boolean visible = true;
15
16 public ObjetoGrafico (int x, int y, int ancho, int alto){
17 this.x = x;
18 this.y = y;
19 this.ancho = ancho;
20 this.alto = alto;
21 }
22 /*
23 * ubicacion de los objetos graficos
24 */
25 public abstract void paint(Graphics g);
26 public void incx(int dx){
27 x += dx;
28 }
29 public void decx(int dx){
30 x -= dx;
31 }
32 public void incy(int dy){
33 y += dy;
34 }
35 public void decy(int dy){
36 y -= dy;
37 }
38 /*
39 * creacion de las condiciones para las coliciones
40 */
41 public boolean colisiona (ObjetoGrafico otro){
42 if (this == otro)
43 return false;
44
45 if (visible == false ||otro.visible == false)
46 return false;
47
48
49 Rectangle r1 = new Rectangle (this.x, this.y,this.ancho,this.alto);
50 Rectangle r2 = new Rectangle (otro.x, otro.y, otro.ancho, otro.alto);
51 return r1.intersects(r2);
52
53
54 }
55
56 /*
57 * visibilidad de los objetos
58 */
59 public void setVisible(boolean visible) {
60 this.visible = visible;
61 }
62
63 public void setX(int x) {
64 this.x = x;
65 }
66
67 public void setY(int y) {
68 this.y = y;
69 }
70
71
72
73 }
