void InputManager::update() { updateJoystick(); // for(list<Button*>::iterator i=buffer.begin(); // i!=buffer.end(); // i++) // cout<<(*i)->value; // cout<<endl; // cout.flush(); const Uint8* currentKeyStates = SDL_GetKeyboardState( NULL ); bool is_button_pressed = false; for(int i=0;i<possible_buttons.size();i++) { if(isPressed(possible_buttons[i])) { buffer.push_back(new Button(possible_buttons[i])); buffer.pop_front(); is_button_pressed=true; break; } } for(map<char,int>::iterator i=joystick_map.begin(); i!=joystick_map.end(); i++) { if(isJoyDown((*i).second,0)) { buffer.push_back(new Button((*i).first)); is_button_pressed=true; } } // if(isJoyDown(0,0)) // { // buffer.push_back(new Button('a')); // is_button_pressed=true; // } // // if(isJoyDown(-4,0)) // { // buffer.push_back(new Button('4')); // is_button_pressed=true; // } // // if(isJoyDown(-6,0)) // { // buffer.push_back(new Button('6')); // is_button_pressed=true; // } if(!is_button_pressed) { buffer.push_back(new Button('5')); buffer.pop_front(); } }
void Joystick::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event) { std::vector<Touch*>::const_iterator touchIter = touches.begin(); Touch* touch = (Touch*)(*touchIter); if(m_pJoystick->isVisible()) { updateJoystick(touch); return; } }
void Joystick::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event) { std::vector<Touch*>::const_iterator touchIter = touches.begin(); Touch* touch = (Touch*)(*touchIter); if(m_pJoystick->getBoundingBox().containsPoint(touch->getLocation())) { this->showJoystick(); updateJoystick(touch); CCLOG("***"); CCLOG("update touch:%f %f",touch->getLocation().x,touch->getLocation().y); return; } }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) { printf("3DS Controller Server %s\n", VERSION); DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN); DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN); double widthMultiplier = screenWidth / 320.0; double heightMultiplier = screenHeight / 240.0; if(!readSettings()) { printf("Couldn't read settings file, using default key bindings.\n"); } bool vJoy = true; UINT iInterface = settings.vJoyDevice; iReport.wAxisX = JOY_MIDDLE; iReport.wAxisY = JOY_MIDDLE; iReport.wAxisZ = JOY_MIDDLE; iReport.wAxisXRot = JOY_MIDDLE; iReport.wAxisYRot = JOY_MIDDLE; iReport.wAxisZRot = JOY_MIDDLE; iReport.wSlider = JOY_MIDDLE; iReport.wDial = JOY_MIDDLE; iReport.lButtons = 0; iReport.bHats = -1; if(vJoy && !vJoyEnabled()) { printf("vJoy failed (1)! Buttons will still work, but joy stick won't work.\n"); vJoy = false; } enum VjdStat status = GetVJDStatus(iInterface); if(vJoy && (status == VJD_STAT_OWN || (status == VJD_STAT_FREE && !AcquireVJD(iInterface)))) { printf("vJoy failed (2)! Buttons will still work, but joy stick won't work.\n"); vJoy = false; } ContPovNumber = GetVJDContPovNumber(iInterface); //int DiscPovNumber = GetVJDDiscPovNumber(iInterface); if((settings.dPad == pov) && !(ContPovNumber == 0)) settings.dPad = cPov; if(vJoy && !updateJoystick(iInterface)) { printf("vJoy failed (3)! Buttons will still work, but joystick won't work.\nIs vJoy device %d configured?\n",iInterface); vJoy = false; } else printf("Connected to vJoy device %d\n",iInterface); initNetwork(); char nButtons = GetVJDButtonNumber(iInterface); if(vJoy && nButtons <16) printf("Your vJoy has %d buttons, 3DSController supports 16!\n", nButtons); printf("Port: %d\n", settings.port); printf("Running on: %s\n", hostName); printf("Your local IP(s):\n"); printIPs(); printf("\n"); startListening(); while(1) { memset(&buffer, 0, sizeof(struct packet)); while(receiveBuffer(sizeof(struct packet)) <= 0) { // Waiting Sleep(settings.throttle); } keyboardActive = buffer.keyboardActive; switch(buffer.command) { case CONNECT: lastKeys = 0; currentKeys = 0; circlePad.x = 0; circlePad.y = 0; lastTouch.x = 0; lastTouch.y = 0; currentTouch.x = 0; currentTouch.y = 0; cStick.x = 0; cStick.y = 0; buffer.command = CONNECT; printf("3DS Connected!\n"); Sleep(50); sendBuffer(1); Sleep(50); sendBuffer(1); Sleep(50); sendBuffer(1); break; case KEYS: lastKeys = currentKeys; if(currentKeys & KEY_TOUCH) lastTouch = currentTouch; memcpy(¤tKeys, &buffer.keys, 4); memcpy(&circlePad, &buffer.circlePad, 4); memcpy(¤tTouch, &buffer.touch, 4); memcpy(&cStick, &buffer.cStick, 4); memcpy(&volume, &buffer.volume, 4); //printf("\rVolume is currently: %x ", volume); //test handleKey(KEY_A, settings.A); handleKey(KEY_B, settings.B); handleKey(KEY_SELECT, settings.Select); handleKey(KEY_START, settings.Start); if(settings.dPad == key) { //Handle normally if not using POV in settings. handleKey(KEY_DRIGHT, settings.Right); handleKey(KEY_DLEFT, settings.Left); handleKey(KEY_DUP, settings.Up); handleKey(KEY_DDOWN, settings.Down); } handleKey(KEY_R, settings.R); handleKey(KEY_L, settings.L); handleKey(KEY_ZR, settings.ZR); handleKey(KEY_ZL, settings.ZL); handleKey(KEY_X, settings.X); handleKey(KEY_Y, settings.Y); if(settings.circlePad == keys) { handleKey(KEY_CPAD_RIGHT, settings.PadRight); handleKey(KEY_CPAD_LEFT, settings.PadLeft); handleKey(KEY_CPAD_UP, settings.PadUp); handleKey(KEY_CPAD_DOWN, settings.PadDown); } if(settings.cStick == keys) { handleKey(KEY_CSTICK_RIGHT, settings.CSRight); handleKey(KEY_CSTICK_LEFT, settings.CSLeft); handleKey(KEY_CSTICK_UP, settings.CSUp); handleKey(KEY_CSTICK_DOWN, settings.CSDown); } //handleKey(KEY_LID, 'I'); if(newpress(KEY_TOUCH)) { lastTouch.x = currentTouch.x; lastTouch.y = currentTouch.y; } if((currentKeys & KEY_TOUCH)) { if(keyboardActive) { if(newpress(KEY_TOUCH)) { char letter = currentKeyboardKey(); if(letter) { simulateKeyNewpress(letter); simulateKeyRelease(letter); } } } else if(settings.touch == mouse) { if(settings.mouseSpeed) { POINT p; GetCursorPos(&p); SetCursorPos(p.x + (currentTouch.x - lastTouch.x) * settings.mouseSpeed, p.y + (currentTouch.y - lastTouch.y) * settings.mouseSpeed); } else { SetCursorPos((int)((double)currentTouch.x * widthMultiplier), (int)((double)currentTouch.y * heightMultiplier)); } } else if(settings.touch == joystick1) { //made a little bit more accurate to the screen size. joyX = (int)((float)(currentTouch.x) * 102.3f); joyY = (int)((float)(currentTouch.y) * 136.5f); } else if(settings.touch == joystick2) { joyRX = (int)((float)(currentTouch.x) * 102.3f); joyRY = (int)((float)(currentTouch.y) * 136.5f); } else { handleKey(KEY_TOUCH, settings.Tap); } } else { //If we are not touching, move to center (Like if you release the joystick on a normal controller). if(settings.touch == joystick1) { joyX = 16383; //Halfway between the x joyY = 16383; //Halfway between the y } else if(settings.touch == joystick2) { joyRX = 16383; //Halfway between the rx joyRY = 16383; //Halfway between the ry } } if(settings.circlePad == mouse) { if(abs(circlePad.x) < settings.mouseSpeed * 3) circlePad.x = 0; if(abs(circlePad.y) < settings.mouseSpeed * 3) circlePad.y = 0; POINT p; GetCursorPos(&p); SetCursorPos(p.x + (circlePad.x * settings.mouseSpeed) / 32, p.y - (circlePad.y * settings.mouseSpeed) / 32); } else if(settings.circlePad == joystick1) { joyX = (circlePad.x + 128) * 128; joyY = (128 - circlePad.y) * 128; } else if(settings.circlePad == joystick2) { joyRX = (circlePad.x + 128) * 128; joyRY = (128 - circlePad.y) * 128; } if(settings.cStick == mouse) { if(abs(cStick.x) < settings.mouseSpeed * 3) cStick.x = 0; if(abs(cStick.y) < settings.mouseSpeed * 3) cStick.y = 0; POINT p; GetCursorPos(&p); SetCursorPos(p.x + (cStick.x * settings.mouseSpeed) / 32, p.y - (cStick.y * settings.mouseSpeed) / 32); } else if(settings.cStick == joystick1) { joyX = (cStick.x + 128) * 128; joyY = (128 - cStick.y) * 128; } else if(settings.cStick == joystick2) { joyRX = (cStick.x + 128) * 128; joyRY = (128 - cStick.y) * 128; } if(settings.dPad == cPov) { if((currentKeys & KEY_DUP) && !(currentKeys & KEY_DLEFT)) { if((currentKeys & KEY_DRIGHT)) { povHat = 4500; } else { povHat = 0; } } else if((currentKeys & KEY_DRIGHT)) { if((currentKeys & KEY_DDOWN)) { povHat = 13500; } else { povHat = 9000; } } else if((currentKeys & KEY_DDOWN)) { if((currentKeys & KEY_DLEFT)) { povHat = 22500; } else { povHat = 18000; } } else if((currentKeys & KEY_DLEFT)) { if ((currentKeys & KEY_DUP)) { povHat = 31500; } else { povHat = 27000; } } if(!((currentKeys & KEY_DUP) || (currentKeys & KEY_DRIGHT) || (currentKeys & KEY_DDOWN) || (currentKeys & KEY_DLEFT))) { //If none are pressed, reset the POV hat povHat = -1; } } else if(settings.dPad == pov) { if((currentKeys & KEY_DUP) && !(currentKeys & KEY_DLEFT)) iReport.bHats = 0; else if(currentKeys & KEY_DRIGHT) iReport.bHats = 1; else if (currentKeys & KEY_DDOWN) iReport.bHats = 2; else if (currentKeys & KEY_DLEFT) iReport.bHats = 3; else iReport.bHats = -1; } joyVolume = volume * 512; break; } if(vJoy) updateJoystick(iInterface); } error("accept()"); return 0; }
bool MWindow::onEvents(void) { JOYCAPS caps; MWindow * window = MWindow::getInstance(); // joystick 1 if(joyGetDevCaps(JOYSTICKID1, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR) { JOYINFOEX joyinfo; MJoystick * joystick = window->getJoystick1(); joyinfo.dwSize = sizeof(JOYINFOEX); memset(&(joyinfo.dwFlags), 0, sizeof(JOYINFOEX) - sizeof(DWORD)); joyinfo.dwFlags = JOY_RETURNALL; joyGetPosEx(JOYSTICKID1, &joyinfo); updateJoystick(joystick, &caps, &joyinfo); MWinEvent events; events.type = MWIN_EVENT_JOYSTICK1_UPDATE; window->sendEvents(&events); joystick->flush(); } // joystick 2 if(joyGetDevCaps(JOYSTICKID2, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR) { JOYINFOEX joyinfo; MJoystick * joystick = window->getJoystick2(); joyinfo.dwSize = sizeof(JOYINFOEX); memset(&(joyinfo.dwFlags), 0, sizeof(JOYINFOEX) - sizeof(DWORD)); joyinfo.dwFlags = JOY_RETURNALL; joyGetPosEx(JOYSTICKID2, &joyinfo); updateJoystick(joystick, &caps, &joyinfo); MWinEvent events; events.type = MWIN_EVENT_JOYSTICK2_UPDATE; window->sendEvents(&events); joystick->flush(); } // mouse move event { POINT p; MWinEvent events; MMouse * mouse = MMouse::getInstance(); GetCursorPos(&p); p.x -= window->getXPosition(); p.y -= window->getYPosition(); int dx = p.x - mouse->getXPosition(); int dy = p.y - mouse->getYPosition(); if((dx != 0) || (dy != 0)) { mouse->setPosition(p.x, p.y); events.type = MWIN_EVENT_MOUSE_MOVE; events.data[0] = p.x; events.data[1] = p.y; window->sendEvents(&events); } } MSG msg; if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); return false; } return true; }
/** * Main function that starts the pong game. * * @param None * * @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful * * @note None * ******************************************************************************/ int main(void) { u32 Data; Joystick joy1,joy2; initJoysticks(); initGraphics(); //create a white tile int i, ii; for (i = 0; i<8; ++i) for (ii = 0; ii<8; ++ii) setPixel(1,i,ii,WHITE); //start making the ball for (i = 3; i<5; ++i) for (ii = 1; ii<7; ++ii) { setPixel(2,i,ii,WHITE); setPixel(2,ii,i,WHITE); } setPixel(2,2,2,WHITE); setPixel(2,2,5,WHITE); setPixel(2,5,2,WHITE); setPixel(2,5,5,WHITE); setMoveableBlock(0, 2); setMoveableBlockRowTransparency(0, 0, 0xFF); setMoveableBlockRowTransparency(0, 1, 0xE7); setMoveableBlockRowTransparency(0, 2, 0xC3); setMoveableBlockRowTransparency(0, 3, 0x81); setMoveableBlockRowTransparency(0, 4, 0x81); setMoveableBlockRowTransparency(0, 5, 0xC3); setMoveableBlockRowTransparency(0, 6, 0xE7); setMoveableBlockRowTransparency(0, 7, 0xFF); //finished making the ball setMoveableBlockPosition(0, ballX, ballY); //draw the ball once //draw the two paddles for (i = paddle1Y; i<(paddle1Y+10) && i<80; ++i) setBackgroundBlock(0,i,1); for (i = paddle2Y; i<(paddle2Y+10) && i<80; ++i) setBackgroundBlock(79,i,1); //start game loop while (1) { ++ballMovementCounter; ++paddleMovementCounter; if(ballMovementCounter > BALL_MOVEMENT_DELAY) { ballMovementCounter = 0; ballX += ballSpdX; ballY += ballSpdY; if (ballY == 0 || ballY == 472) ballSpdY *= -1; if (ballX == 0) //left side lost 1 point { ballX = 628; ballSpdIncreaseCounter = 0; BALL_MOVEMENT_DELAY = 10000; if (paddle1X>0) { erasePaddle1(); --paddle1X; drawPaddle1(); } else { erasePaddle2(); --paddle2X; if (paddle2X<40) paddle2X = 40; drawPaddle2(); } } else if (ballX>=(paddle1X*8) && ballX<=(paddle1X*8+8)) //start collision detection with left paddle { if ((ballY+4)>(paddle1Y*8) && (ballY+4)<=((paddle1Y+10)*8)) { ballSpdX = 1; ++ballSpdIncreaseCounter; } } if (ballX == 632) // right side lost 1 point { ballX = 4; ballSpdIncreaseCounter = 0; BALL_MOVEMENT_DELAY = 10000; if (paddle2X<79) { erasePaddle2(); ++paddle2X; drawPaddle2(); } else { erasePaddle1(); ++paddle1X; if (paddle1X>40) paddle1X = 40; drawPaddle1(); } } else if ((ballX+8)>=(paddle2X*8) && (ballX+8)<=(paddle2X*8+8)) //start collision detection with right paddle { if ((ballY+4)>=(paddle2Y*8) && (ballY+4)<=((paddle2Y+10)*8)) { ballSpdX = -1; ++ballSpdIncreaseCounter; } } setMoveableBlockPosition(0, ballX, ballY); } if (paddleMovementCounter > PADDLE_MOVEMENT_DELAY) { paddleMovementCounter = 0; updateJoystick(&joy1,JOYSTICK_1_CHANNEL); if (joy1.y > 750) { --paddle1Y; if (paddle1Y<0) paddle1Y = 0; } else if (joy1.y < 250) { ++paddle1Y; if (paddle1Y>50) paddle1Y = 50; } if (joy1.y>750 || joy1.y<250) { setBackgroundBlock(paddle1X,paddle1Y-1,0); setBackgroundBlock(paddle1X,paddle1Y+10,0); drawPaddle1(); } updateJoystick(&joy2,JOYSTICK_2_CHANNEL); if (joy2.y > 750) { --paddle2Y; if (paddle2Y<0) paddle2Y = 0; } else if (joy2.y < 250) { ++paddle2Y; if (paddle2Y>50) paddle2Y = 50; } if (joy2.y>750 || joy2.y<250) { setBackgroundBlock(paddle2X,paddle2Y-1,0); setBackgroundBlock(paddle2X,paddle2Y+10,0); drawPaddle2(); } } if (ballSpdIncreaseCounter>=BALL_SPEED_INCREASE_DELAY) { ballSpdIncreaseCounter = 0; BALL_MOVEMENT_DELAY -= 500; if (BALL_MOVEMENT_DELAY < 500) BALL_MOVEMENT_DELAY = 500; } } //end infinite game loop return XST_SUCCESS; }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) { printf("3DS Controller Server %.1f\n", VERSION); DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN); DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN); double widthMultiplier = screenWidth / 320.0; double heightMultiplier = screenHeight / 240.0; //screenshot(SCREENSHOT_NAMEL, TRUE, 0, 0, 18); bool vJoy = true; UINT iInterface = 1; iReport.wAxisZ = JOY_MIDDLE; iReport.wAxisXRot = JOY_MIDDLE; iReport.wAxisYRot = JOY_MIDDLE; iReport.wAxisZRot = JOY_MIDDLE; iReport.wSlider = JOY_MIDDLE; iReport.lButtons = 0; iReport.bHats = -1; if(vJoy && !vJoyEnabled()) { printf("vJoy failed (1)! Buttons will still work, but joy stick won't work.\n"); vJoy = false; } enum VjdStat status = GetVJDStatus(iInterface); if(vJoy && (status == VJD_STAT_OWN || (status == VJD_STAT_FREE && !AcquireVJD(iInterface)))) { printf("vJoy failed (2)! Buttons will still work, but joy stick won't work.\n"); vJoy = false; } ContPovNumber = GetVJDContPovNumber(iInterface); //int DiscPovNumber = GetVJDDiscPovNumber(iInterface); if(vJoy && !updateJoystick()) { printf("vJoy failed (3)! Buttons will still work, but joystick won't work.\n"); vJoy = false; } if(!readSettings()) { printf("Couldn't read settings file, using default key bindings.\n"); } initNetwork(); printf("Port: %d\n", settings.port); printf("Running on: %s\n", hostName); printf("Your local IP(s):\n"); printIPs(); printf("\n"); startListening(); while(1) { memset(&buffer, 0, sizeof(struct packet)); while(receiveBuffer(sizeof(struct packet)) <= 0) { // Waiting Sleep(settings.throttle); } keyboardActive = buffer.keyboardActive; switch(buffer.command) { case CONNECT: lastKeys = 0; currentKeys = 0; circlePad.x = 0; circlePad.y = 0; lastTouch.x = 0; lastTouch.y = 0; currentTouch.x = 0; currentTouch.y = 0; buffer.command = CONNECT; printf("3DS Connected!\n"); Sleep(50); sendBuffer(1); Sleep(50); sendBuffer(1); Sleep(50); sendBuffer(1); break; case KEYS: lastKeys = currentKeys; if(currentKeys & KEY_TOUCH) lastTouch = currentTouch; memcpy(¤tKeys, &buffer.keys, 4); memcpy(&circlePad, &buffer.circlePad, 4); memcpy(¤tTouch, &buffer.touch, 4); handleKey(KEY_A, settings.A); handleKey(KEY_B, settings.B); handleKey(KEY_SELECT, settings.Select); handleKey(KEY_START, settings.Start); handleKey(KEY_DRIGHT, settings.Right); handleKey(KEY_DLEFT, settings.Left); handleKey(KEY_DUP, settings.Up); handleKey(KEY_DDOWN, settings.Down); handleKey(KEY_R, settings.R); handleKey(KEY_L, settings.L); handleKey(KEY_X, settings.X); handleKey(KEY_Y, settings.Y); //handleKey(KEY_LID, 'I'); if(newpress(KEY_TOUCH)) { lastTouch.x = currentTouch.x; lastTouch.y = currentTouch.y; } if((currentKeys & KEY_TOUCH)) { if(keyboardActive) { if(newpress(KEY_TOUCH)) { char letter = currentKeyboardKey(); if(letter) { simulateKeyNewpress(letter); simulateKeyRelease(letter); } } } else if(settings.touch == mouse) { if(settings.mouseSpeed) { POINT p; GetCursorPos(&p); SetCursorPos(p.x + (currentTouch.x - lastTouch.x) * settings.mouseSpeed, p.y + (currentTouch.y - lastTouch.y) * settings.mouseSpeed); } else { SetCursorPos((int)((double)currentTouch.x * widthMultiplier), (int)((double)currentTouch.y * heightMultiplier)); } } else if(settings.touch == joystick) { joyX = (currentTouch.x) * 128; joyY = (currentTouch.y) * 128; } else { handleKey(KEY_TOUCH, settings.Tap); } } if(settings.circlePad == mouse) { if(abs(circlePad.x) < settings.mouseSpeed * 3) circlePad.x = 0; if(abs(circlePad.y) < settings.mouseSpeed * 3) circlePad.y = 0; POINT p; GetCursorPos(&p); SetCursorPos(p.x + (circlePad.x * settings.mouseSpeed) / 32, p.y - (circlePad.y * settings.mouseSpeed) / 32); } else if(settings.circlePad == joystick) { joyX = (circlePad.x + 128) * 128; joyY = (128 - circlePad.y) * 128; } break; } if(vJoy) updateJoystick(); //sendScreenshot(); } error("accept()"); return 0; }