ObjetoMovil.java
1
2
3
4
5
6 public abstract class ObjetoGrafico {
7 private boolean visible =false;
8 private int posX;
9 private int posY;
10 private int ancho;
11 private int alto;
12 public ObjetoGrafico (int x, int y, int an, int bl){
13 posX = x;
14 posY = y;
15 ancho = an;
16 alto = bl;
17
18 }
19 public abstract void paint (Graphics g);
20
21
22
23
24
25 public void setVisible(boolean v) {
26 visible = v;
27 }
28 public void moverArriba (int dy){
29 posY -= dy;
30 }
31 public void moverAbajo (int dy){
32 posY += dy;
33 }
34 public void moverIzquierda (int dx){
35 posX -= dx;
36 }
37 public void moverDerecha (int dx){
38 posX += dx;
39 }
40
41
42
43
44 public boolean getVisible(){
45 return visible;
46 }
47
48
49
50
51 public int getPosY() {
52 return posY;
53 }
54
55
56
57
58 public int getPosX() {
59 return posX;
60 }
61
62
63
64
65 public void setPosY(int y) {
66 posY = y;
67 }
68
69
70
71
72 public void setPosX(int x) {
73 posX = x;
74 }
75
76
77
78
79 public int getAncho() {
80 return ancho;
81 }
82
83
84
85
86 public void setAncho(int an) {
87 ancho = an;
88 }
89
90
91
92
93 public int getAlto() {
94 return alto;
95 }
96
97
98
99
100 public void setAlto(int bl) {
101 alto = bl;
102 }
103 public boolean colisiona (ObjetoGrafico otro){
104 Rectangle r1 = new Rectangle (posX, posY, ancho, alto);
105 Rectangle r2 = new Rectangle (otro.posX, otro.posY, otro.ancho, otro.alto);
106 return r1.intersects(r2) && getVisible() && otro.getVisible();
107 }
108 }
CategoryJava | CategoryProgramacion
Java/Programas/FroggerGame/ObjetoGrafico.java (last edited 2008-11-13 10:44:40 by OscarAlonso)