[NEW] GRRLIB_RectInRect and GRRLIB_RectOnRect

This commit is contained in:
Crayon2000 2009-01-27 06:05:28 +00:00
parent 58226d57ae
commit 141e14ed07
4 changed files with 28 additions and 9 deletions

View file

@ -50,7 +50,7 @@ ChangeLog :
* InitVideo() and GRRLIB_Start() merge into GRRLIB_Init().
* add GRRLIB_PtInRect that return True/False if a point is in a specific zone
* add GRRLIB_PtInRect, GRRLIB_RectInRect and GRRLIB_RectOnRect.
* add GRRLIB_Exit to free the memory allocated by GRRLIB

View file

@ -411,11 +411,25 @@ void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, c
* @return If the specified point lies within the rectangle, the return value is true otherwise it's false.
*/
bool GRRLIB_PtInRect(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpady) {
if(((wpadx>hotx) & (wpadx<(hotx+hotw))) & ((wpady>hoty) & (wpady<(hoty+hoth)))) {
return true;
return(((wpadx>=hotx) & (wpadx<=(hotx+hotw))) & ((wpady>=hoty) & (wpady<=(hoty+hoth))));
}
return false;
/**
* Determines whether a specified rectangle lies within another rectangle.
*/
bool GRRLIB_RectInRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h) {
return ((rect1x >= rect2x) && (rect1y >= rect2y) &&
(rect1x+rect1w <= rect2x+rect2w) && (rect1y+rect1h <= rect2y+rect2h));
}
/**
* Determines whether a part of a specified rectangle lies on another rectangle.
*/
bool GRRLIB_RectOnRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h) {
return (GRRLIB_PtInRect(rect1x, rect1y, rect1w, rect1h, rect2x, rect2y) ||
GRRLIB_PtInRect(rect1x, rect1y, rect1w, rect1h, rect2x+rect2w, rect2y) ||
GRRLIB_PtInRect(rect1x, rect1y, rect1w, rect1h, rect2x+rect2w, rect2y+rect2h) ||
GRRLIB_PtInRect(rect1x, rect1y, rect1w, rect1h, rect2x, rect2y+rect2h));
}
/**

View file

@ -59,6 +59,8 @@ inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees
void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, const char *text, ...);
bool GRRLIB_PtInRect(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpady);
bool GRRLIB_RectInRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h);
bool GRRLIB_RectOnRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2x, int rect2y, int rect2w, int rect2h);
void GRRLIB_GXEngine(Vector v[], u32 color, long count, u8 fmt);

View file

@ -82,6 +82,7 @@ int main() {
WPAD_IR(WPAD_CHAN_0, &ir1);
GRRLIB_FillScreen(GRRLIB_BLACK); // Clear the screen
WPAD_Rumble(WPAD_CHAN_0, 0);
switch(page)
{
case 1: // Draw images
@ -91,6 +92,8 @@ int main() {
// Draw a sprite
GRRLIB_DrawTile(600, 400, tex_link_png, 0, 2, 2, GRRLIB_WHITE, 12*4); // Rupy
GRRLIB_DrawTile(320+left, 240+top, tex_link_png, 0, 2, 2, GRRLIB_WHITE, frame);
if(GRRLIB_RectOnRect(320+left, 240+top, 48, 64, 618, 434, 12, 30))
WPAD_Rumble(WPAD_CHAN_0, 1);
if(direction_new != direction) {
// Direction has changed, modify frame immidiately
direction = direction_new;