Why is this acting so weird? (GRRLIB related) January 03, 2009 02:06PM | Registered: 15 years ago Posts: 7 |
/*=========================================== GRRLIB (GX version) 3.0 alpha Code : NoNameNo GX hints : RedShade Template Code (Minimum Requirement) ============================================*/ #include#include #include #include #include #include #include #include #include #include "GRRLIB/GRRLIB.h" #include "gfx/p1body.h" #include "gfx/p1crosshair.h" #include "gfx/Untitled.h" #define PI 3.14159265 Mtx GXmodelView2D; int main(){ u8 *tex_p1body=GRRLIB_LoadTexture(p1body); u8 *tex_p1crosshair=GRRLIB_LoadTexture(p1crosshair); u8 *tex_Untitled=GRRLIB_LoadTexture(Untitled); float p1rot=0; int p1x=240; int p1y=240; int p1shooting = 0; int slow = 0; static int shotfromx; static int shotfromy; static int shoottox; static int shoottoy; static int bulletx; static int bullety; VIDEO_Init(); WPAD_Init(); GRRLIB_InitVideo(); GRRLIB_Start(); WPADData *wPadp1; WPAD_Init(); WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(0, 640, 480); while(1) { wPadp1 = WPAD_Data(0); WPAD_ScanPads(); u32 wpaddownp1 = WPAD_ButtonsDown(0); u32 wpadheldp1 = WPAD_ButtonsHeld(0); GRRLIB_DrawImg(p1x, p1y, 132, 132, tex_p1body, p1rot, 1, 1, 255 ); if (wPadp1->ir.valid)//Calculates rotation of body according to pointer position. Works OK as far as I can tell. { GRRLIB_DrawImg(wPadp1->ir.x, wPadp1->ir.y, 48, 48, tex_p1crosshair, wPadp1->ir.angle, 1, 1, 255 ); p1rot = (atan2(p1y - wPadp1->ir.y, p1x - wPadp1->ir.x) * 180 / PI) - 90; } \ if (p1shooting == 1) { if (slow == 2) //slows bullet movement down a bit { bullety=((shotfromy - shoottoy)/(shotfromx - shoottox) * bulletx + shotfromy);//y=mx+b //if (shotfromx < shoottox) bulletx++; <- Using an if/else statement like this causes the bullet not to be shown at all? //else bulletx--; bulletx++; } GRRLIB_DrawImg(bulletx, bullety, 64, 64, tex_Untitled, p1rot, 1, 1, 255 ); slow++; if (slow > 2) slow = 0; if (bulletx == shoottox) p1shooting = 0; } GRRLIB_Render(); //////////////////////////////p1 movement///////////////////////////////// if (wpadheldp1 & WPAD_BUTTON_UP) p1y-=3; if (wpadheldp1 & WPAD_BUTTON_DOWN) p1y+=3; if (wpadheldp1 & WPAD_BUTTON_LEFT) p1x-=3; if (wpadheldp1 & WPAD_BUTTON_RIGHT) p1x+=3; if (p1x>560) p1x=560; if (p1x<0) p1x=0; if (p1y>400) p1y=400; if (p1y<0) p1y=0; if (wpaddownp1 & WPAD_BUTTON_A && p1shooting == 0) //Grabs current player and pointer positions for use in the shooting code block { shotfromx = p1x; shotfromy = p1y; shoottox = wPadp1->ir.x; shoottoy = wPadp1->ir.y; bulletx = shotfromx; bullety = shotfromy; p1shooting = 1; } if (wpaddownp1 & WPAD_BUTTON_B) p1shooting = 0; //Use this to cancel out of shooting if it gets stuck. if (wpaddownp1 & WPAD_BUTTON_HOME) exit(0); } return 0; }
Re: Why is this acting so weird? (GRRLIB related) January 03, 2009 02:30PM | Registered: 16 years ago Posts: 51 |
Re: Why is this acting so weird? (GRRLIB related) January 04, 2009 08:43PM | Registered: 15 years ago Posts: 7 |
Re: Why is this acting so weird? (GRRLIB related) January 04, 2009 09:29PM | Registered: 16 years ago Posts: 51 |
Re: Why is this acting so weird? (GRRLIB related) January 08, 2009 10:22AM | Registered: 15 years ago Posts: 7 |
while(1) { if (wPadp1->ir.valid) { GRRLIB_DrawImg(wPadp1->ir.x - 24, wPadp1->ir.y - 24, 48, 48, tex_p1crosshair, wPadp1->ir.angle, 1, 1, 255 ); float p1rot = (atan2(p1y - wPadp1->ir.y, p1x - wPadp1->ir.x) * 180 / PI); float ldotx = cos(p1rot - 1.5707964) * 33; // 1.5707964 = 90 degrees in radians float ldoty = sin(p1rot - 1.5707964) * 33; float rdotx = cos(p1rot + 1.5707964) * 33; float rdoty = sin(p1rot + 1.5707964) * 33; GRRLIB_DrawImg(p1x - 33, p1y - 33, 66, 66, tex_p1body, p1rot, 1, 1, 255 ); GRRLIB_DrawImg(ldotx + p1x - 24, ldoty + p1y - 24, 48, 48, tex_p1crosshair, wPadp1->ir.angle, 1, 1, 255 ); GRRLIB_DrawImg(rdotx + p1x - 24, rdoty + p1y -24, 48, 48, tex_p1crosshair, wPadp1->ir.angle, 1, 1, 255 ); } }
Re: Why is this acting so weird? (GRRLIB related) January 08, 2009 06:49PM | Registered: 15 years ago Posts: 10 |
float p1rot = (atan2(p1y - wPadp1->ir.y, p1x - wPadp1->ir.x) * 180 / PI); float ldotx = cos(p1rot - 1.5707964) * 33; // 1.5707964 = 90 degrees in radians float ldoty = sin(p1rot - 1.5707964) * 33; float rdotx = cos(p1rot + 1.5707964) * 33; float rdoty = sin(p1rot + 1.5707964) * 33;sin() and cos() expect their parameter to be in radians, not degrees - so drop the conversion after the call to atan2()
Re: Why is this acting so weird? (GRRLIB related) January 08, 2009 09:13PM | Registered: 15 years ago Posts: 7 |