mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 15:02:20 +00:00
[NEW] GRRLIB_RectInRect and GRRLIB_RectOnRect
This commit is contained in:
parent
58226d57ae
commit
141e14ed07
4 changed files with 28 additions and 9 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue