The Tricycle's Ninja
|
00001 #ifndef _CAJA_H_ 00002 #define _CAJA_H_ 00003 00004 00005 struct Caja{ 00007 float x, y; 00008 00010 float w, h; 00011 00012 float derecha(){ return x + w; } 00013 float abajo(){ return y + h; } 00014 00015 bool colisionaCon(Caja & B){ 00016 if(x > B.x + B.w || B.x > x + w) 00017 return false; 00018 00019 if(y > B.y + B.h || B.y > y + h) 00020 return false; 00021 00022 return true; 00023 } 00024 }; 00025 00026 #define BLOQUE_VACIO 0 00027 #define BLOQUE_NARANJA 1 00028 #define BLOQUE_AZUL 2 00029 #define BLOQUE_VERDE 3 00030 #define BLOQUE_ROJO 4 00031 #define BLOQUE_AMARILLO 5 00032 00033 struct Bloque : public Caja{ 00034 00035 int tipo; 00036 00037 Bloque(){ 00038 w = h = 48; 00039 tipo = BLOQUE_VACIO; 00040 } 00041 00042 int tocado(Caja & B){ 00043 if(colisionaCon(B)){ 00044 int up, left, right, down; 00045 up = left = right = down = 0; 00046 00047 if(B.x < x && x < B.derecha() && B.derecha() < derecha()){ 00048 left = x - B.x; 00049 } 00050 00051 if(x < B.x && B.x < derecha() && derecha() < B.derecha()){ 00052 right = B.derecha() - derecha(); 00053 } 00054 00055 if(B.y < y && y < B.abajo() && B.abajo() < abajo()){ 00056 up = y - B.y; 00057 } 00058 00059 if(y < B.y && B.y < abajo() && abajo() < B.abajo()){ 00060 down = B.abajo() - abajo(); 00061 } 00062 00063 int horizontal = (left > right)? left : right; 00064 int vertical = (up > down) ? up : down; 00065 00066 return 1 + (int)(horizontal > vertical); 00067 00068 } 00069 return 0; 00070 } 00071 }; 00072 00073 00074 #endif /* _CAJA_H_ */