void Draw::DrawNode(HexNode * n, int x, int y) { if(n==highlighted) GRRLIB_Circle(x,y, a/2+1,0xFFFFFFFF,1); if(n->isGround) GRRLIB_Circle(x, y, a/2, GREEN, 1); else GRRLIB_Circle(x, y, a/2, BLUE, 1); switch(n->location) { case EAST_POLE: GRRLIB_Circle(x+5, y, 5, 0x000000FF, 1); break; case PRIME: GRRLIB_Circle(x, y, 5, 0x000000FF, 1); break; case WEST_POLE: GRRLIB_Circle(x-5, y, 5, 0x000000FF, 1); break; case ANTI_PRIME: GRRLIB_Line(x+3, y+4, x-5, y-4, 0x000000FF); GRRLIB_Line(x+4, y+4, x-4, y-4, 0x000000FF); GRRLIB_Line(x+5, y+4, x-3, y-4, 0x000000FF); GRRLIB_Line(x-5, y+4, x+3, y-4, 0x000000FF); GRRLIB_Line(x-4, y+4, x+4, y-4, 0x000000FF); GRRLIB_Line(x-3, y+4, x+5, y-4, 0x000000FF); break; case NORTH_POLE: GRRLIB_Circle(x, y-5, 5, 0x000000FF, 1); break; default: ; } if(n->city) GRRLIB_Circle(x, y, 2, 0xFFFFFFFF, 1); }
int main(int argc, char **argv) { SYS_SetResetCallback(WiiResetPressed); SYS_SetPowerCallback(WiiPowerPressed); usleep(250*1000); GRRLIB_Init(); GRRLIB_ttfFont *font = GRRLIB_LoadTTF(verdana_ttf, verdana_ttf_size); WPAD_Init(); USB_Initialize(); USB_DeviceChangeNotifyAsync(USB_CLASS_HID, change_notify_cb, NULL); int dev_id = get_device_id(); int fd = open_device(dev_id); struct ds4_input data; memset(&data, 0, sizeof(data)); fetch_data(fd, &data); random_leds(fd); int screenW = rmode->fbWidth, screenH = rmode->efbHeight; float pos_x = screenW/2, pos_y = screenH/2; while (run) { WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); if (pressed & WPAD_BUTTON_B) { dev_id = get_device_id(); fd = open_device(dev_id); } if (pressed & WPAD_BUTTON_A) { random_leds(fd); } GRRLIB_FillScreen(0x0); GRRLIB_PrintfTTF(15, 15, font, "ds4wii by xerpi | L1: center | R1: random color", 15, 0xFFFFFFFF); u32 color = (r<<24)|(g<<16)|(b<<8)|0xFF; GRRLIB_Circle(pos_x, pos_y, 15, color, 0); GRRLIB_Circle(pos_x, pos_y, 14, color, 0); memset(&data, 0, sizeof(data)); fetch_data(fd, &data); if (data.L1) {pos_x = screenW/2, pos_y = screenH/2;} if (data.R1) {random_leds(fd);} //1920x940 if (data.finger1active) { GRRLIB_Circle((screenW/1920.0f)*data.finger1X, (screenH/940.0f)*data.finger1Y, 10, 0x00FF00FF, 1); } if (data.finger2active) { GRRLIB_Circle((screenW/1920.0f)*data.finger2X, (screenH/940.0f)*data.finger2Y, 10, 0x0000FFFF, 1); } /*char buf1[256]; sprintf(buf1, "aX: %8hi aY: %8hi aZ: %8hi", data.accelX, data.accelY, data.accelZ); char buf2[256]; sprintf(buf2, "gyroX: %8hi gyroY: %8hi gyroZ: %8hi", data.gyroX, data.gyroY, data.gyroZ); GRRLIB_PrintfTTF(15, 30, font, buf1, 14, 0xFFFFFFFF); GRRLIB_PrintfTTF(15, 45, font, buf2, 14, 0xFFFFFFFF); */ #define THRESHOLD 50.0f if (fabs(data.accelX) > THRESHOLD) pos_y -= data.accelX/55.0f; if (fabs(data.accelY) > THRESHOLD) pos_x -= data.accelY/55.0f; if (pressed & WPAD_BUTTON_HOME) run = 0; GRRLIB_Render(); } USB_CloseDevice(&fd); USB_Deinitialize(); GRRLIB_FreeTTF (font); GRRLIB_Exit(); exit(0); return 0; }
int main() { // Initializing GRRLIB GRRLIB_Init(); // Initializing Wiimotes WPAD_Init(); // IR init rmode = VIDEO_GetPreferredMode(NULL); GXRModeObj *rmode = IR_Init(); WPAD_SetVRes(WPAD_CHAN_ALL,rmode->fbWidth,rmode->xfbHeight); WPAD_SetDataFormat(WPAD_CHAN_0,WPAD_FMT_BTNS_ACC_IR); //IR pointer ir_t irPointer; // Data textures GRRLIB_texImg * texFont = GRRLIB_LoadTexture(font_png); GRRLIB_InitTileSet(texFont, 8, 16, 0); GRRLIB_texImg* pointer = GRRLIB_LoadTexture(pointer_png); GRRLIB_SetMidHandle(pointer,true); // Objects Button left; left.initButton(0, maxY/2, 15, 60); Button right; right.initButton(maxX-15, maxY/2, 15, 60); Circle move; move.initCircle(maxX/2, maxY/2, 10); // Globals variables bool finProgramme = false; int pass = 0; float b=0.0; float speed = 3; int scoreL = 0; int scoreR = 0; while (!finProgramme){ WPAD_ScanPads(); //Scan wiimotes WPAD_IR(WPAD_CHAN_0, &irPointer); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) finProgramme = true; //==================== DRAW START ======================== GRRLIB_Rectangle(left.x, left.y, left.width, left.height, 0xFF0000FF, 1); GRRLIB_Rectangle(right.x, right.y, right.width, right.height, 0x00FF00FF, 1); GRRLIB_Circle(move.x, move.y, move.radius, CLR_WHITE, 2); //GRRLIB_DrawImg(irPointer.x, irPointer.y, pointer, 0, 1, 1, CLR_WHITE); //GRRLIB_DrawImg(0,0,titlescreen,0,1,1,CLR_UNKNOW); char* posX =(char*)malloc(sizeof(char)); char* posY =(char*)malloc(sizeof(char)); char* showScoreL = (char*)malloc(sizeof(char)); char* showScoreR = (char*)malloc(sizeof(char)); sprintf(posX,"%.3f",irPointer.x); sprintf(posY,"%.3f",irPointer.y); sprintf(showScoreL, "%d", scoreL); sprintf(showScoreR, "%d", scoreR); GRRLIB_Printf(20 + 15, 16 + 15, texFont, CLR_WHITE, 2, posX); GRRLIB_Printf(20 + 15, 16 + 60, texFont, CLR_WHITE, 2, posY); GRRLIB_Printf(300, 50, texFont, 0xFF0000FF, 2, showScoreL); GRRLIB_Printf(340, 50, texFont, 0x00FF00FF, 2, showScoreR); free(posX); free(posY); free(showScoreL); free(showScoreR); GRRLIB_Render(); //================== DRAW END ============================== // Calculate the new positions, speeds, etc… isMoving(move, right, left, pass, speed, b); // Move the player's pointer bMove(right, irPointer); // Move the IA player ia(left, move, speed); // If the ball reaches one side of the screen, // Start a new game and count the points ! if(move.x - move.radius > maxX) { scoreL += 1; move.x = maxX/2; move.y = maxY/2; b = 0.0; pass = 0; speed = 3; } if (move.x + move.radius < 0) { scoreR += 1; move.x = maxX/2; move.y = maxY/2; b = 0.0; pass = 0; speed = 3; } } // Clean memory GRRLIB_Exit(); exit(0); }