// Player movement behaviour and controls // void Player::Move(int screenX, int screenY) { if(IsKeyDown(KEY_UP) && y > height/2) { MoveY(-1.4); } else if(IsKeyDown(KEY_DOWN) && y < screenY-height/2) { MoveY(1.4); } if(IsKeyDown(KEY_LEFT) && x > width/2) { state = 3; MoveX(-1.4); } else if(IsKeyDown(KEY_RIGHT) && x < screenX-width/2) { state = 4; MoveX(1.4); } else state = 0; UpdatePosition(); }
int main() { int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing"); Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 }; SetTargetFPS(60); while(!WindowShouldClose()) { if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8f; if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8f; if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8f; if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8f; BeginDrawing(); ClearBackground(RAYWHITE); DrawCircleV(ballPosition, 50, MAROON); EndDrawing(); } CloseWindow(); return 0; }
//----------------------------------------------------- void nsNativeDragTarget::DispatchDragDropEvent(PRUint32 aEventType, POINTL aPT) { nsEventStatus status; nsDragEvent event(PR_TRUE, aEventType, mWindow); nsWindow * win = static_cast<nsWindow *>(mWindow); win->InitEvent(event); POINT cpos; cpos.x = aPT.x; cpos.y = aPT.y; if (mHWnd != NULL) { ::ScreenToClient(mHWnd, &cpos); event.refPoint.x = cpos.x; event.refPoint.y = cpos.y; } else { event.refPoint.x = 0; event.refPoint.y = 0; } event.isShift = IsKeyDown(NS_VK_SHIFT); event.isControl = IsKeyDown(NS_VK_CONTROL); event.isMeta = PR_FALSE; event.isAlt = IsKeyDown(NS_VK_ALT); mWindow->DispatchEvent(&event, status); }
bool nuiMatrixView::MouseMoved(nuiSize X, nuiSize Y) { if (!mClicked || !mCanChange) return false; nuiSize deltaX = X - mClickPos[0]; nuiSize deltaY = mClickPos[1] - Y; mClickPos[0] = X; mClickPos[1] = Y; nuiSize delta = (abs(deltaX) > abs(deltaY))? deltaX : deltaY; // fine change if (IsKeyDown(mFineSensitivityKey)) delta = (delta > 0)? 1 : (-1); // look at the selection if (mSelectedItems.size() >0) { if (IsKeyDown(mRelativeKey)) RelativeSpinCells(delta); else SpinCells(delta); return true; } // no selection. change the currently clicked item mClickedItem->SetRelativeValue(delta); return true; }
XMFLOAT2 Input::GetLookVector() const { float x = 0.0f; float y = 0.0f; GetRightThumbStickValue(&x, &y); if (IsKeyDown(VK_RIGHT)) { x = 1.0f; } if (IsKeyDown(VK_LEFT)) { x = -1.0f; } if (IsKeyDown(VK_UP)) { y = 1.0f; } if (IsKeyDown(VK_DOWN)) { y = -1.0f; } return XMFLOAT2(x, y); }
void PathFindApp::OnMouseMove(float X, float Y) { if (this->IsLeftButtonDown() && !IsKeyDown(HK_LCONTROL) && !IsKeyDown(HK_RCONTROL)) { m_map.Set(X,Y,this->IsShiftKeyDown() ? 1:0); } }
XMFLOAT2 Input::GetMovementVector() const { float x = 0.0f; float y = 0.0f; GetLeftThumbStickValue(&x, &y); if (IsKeyDown('D')) { x = 1.0f; } if (IsKeyDown('A')) { x = -1.0f; } if (IsKeyDown('W')) { y = 1.0f; } if (IsKeyDown('S')) { y = -1.0f; } return XMFLOAT2(x, y); }
// checks if score is greater than zero to decide winner // void WinLose(int &redScore, int &blueScore, bool &winLose, bool &quit) { static char cWinText[128] = {'\n'}; static char cOptionsText[128] = {'\n'}; if(redScore >= 5) { winLose = true; sprintf_s(cWinText, "You Won! Play again?"); sprintf_s(cOptionsText, "Y / N"); DrawString(cWinText, 520, 300, SColour(0,255,0,255)); DrawString(cOptionsText, 620, 345, SColour(0,255,0,255)); } else if(blueScore >= 5) { winLose = true; sprintf_s(cWinText, "You Lost.. Play again?"); sprintf_s(cOptionsText, "Y / N"); DrawString(cWinText, 520, 300, SColour(0,255,0,255)); DrawString(cOptionsText, 620, 345, SColour(0,255,0,255)); } if(IsKeyDown('Y')) { winLose = false; redScore = 0; blueScore = 0; } else if(IsKeyDown('N')) { quit = true; } }
// menu state draws screen and checks for a key command // void UpdateMenu(bool &play, bool &quit) { DrawSprite(menu); if(IsKeyDown(294)) play = true; if(IsKeyDown('Q')) quit = true; }
void PathFindApp::OnLeftButtonUp() { if (IsKeyDown(HK_LCONTROL)) m_from.Set(GetMouseX(),GetMouseY()); else if (IsKeyDown(HK_RCONTROL)) m_to.Set(GetMouseX(),GetMouseY()); else m_map.Set(GetMouseX(),GetMouseY(),this->IsShiftKeyDown() ? 1:0); }
STATE StateTemp::Update() { SmartPointer<PacketAddr> pAddr; m_pNetworkControl->ReceivePacket(); ISceneManager * smgr = Irrdevice::GetInstance()->GetSceneManager(); if((pAddr= m_pNetworkControl->GetPacket()) != NULL) { ServerPacketParsing(pAddr.getPoint()); } if(IsKeyDown(irr::KEY_KEY_T)) { smgr->setActiveCamera(m_pCamera); } if(IsKeyDown(irr::KEY_KEY_H)) { m_pMe->SetActiveCamera(); } if(IsKeyDown(irr::KEY_KEY_N)) { m_pYou->SetActiveCamera(); } // if(IsKeyDown(irr::KEY_KEY_T)) // { // Packet p(BASE_ACK,m_MyId); // p<<1; // m_pNetworkControl->SendClientToPacket(p); // } // if(IsKeyDown(irr::KEY_KEY_F)) // { // Packet p(BASE_ACK,m_MyId); // p<<2; // m_pNetworkControl->SendClientToPacket(p); // } // if(IsKeyDown(irr::KEY_KEY_G)) // { // Packet p(BASE_ACK,m_MyId); // p<<3; // m_pNetworkControl->SendClientToPacket(p); // } // if(IsKeyDown(irr::KEY_KEY_H)) // { // Packet p(BASE_ACK,m_MyId); // p<<4; // m_pNetworkControl->SendClientToPacket(p); // } return STATE_NONE; }
// Update game (one frame) void UpdateGame(void) { if (!gameOver) { if (IsKeyPressed('P')) pause = !pause; if (!pause) { // Player movement if (IsKeyDown(KEY_LEFT)) player.position.x -= 5; if ((player.position.x - player.size.x/2) <= 0) player.position.x = player.size.x/2; if (IsKeyDown(KEY_RIGHT)) player.position.x += 5; if ((player.position.x + player.size.x/2) >= screenWidth) player.position.x = screenWidth - player.size.x/2; // Launch ball if (!ball.active) { if (IsKeyPressed(KEY_SPACE)) { ball.active = true; ball.speed = (Vector2){ 0, -5 }; } } UpdateBall(); // Game over logic if (player.life <= 0) gameOver = true; else { gameOver = true; for (int i = 0; i < LINES_OF_BRICKS; i++) { for (int j = 0; j < BRICKS_PER_LINE; j++) { if (brick[i][j].active) gameOver = false; } } } } } else { if (IsKeyPressed(KEY_ENTER)) { InitGame(); gameOver = false; } } }
void IntroState::HandleEvents(GameEngine* a_opGame) { // look for key presses to quit or go to the menu?? if (IsKeyDown(GLFW_KEY_ENTER)) { a_opGame->ChangeState(PlayState::Instance()); } if (IsKeyDown('Q')) { a_opGame->Quit(); } }
void get_button_state(bool *a, bool *b, bool *up, bool *down, bool *l, bool *r) { KeyInputConfig *keyConf = config->get_key_config(); if (a) *a = IsKeyJustUp(KeyConfig::KEY_MENU_SELECT) || IsControllerButtonJustUp(KeyConfig::KEY_MENU_SELECT); if (b) *b = IsKeyJustUp(KeyConfig::KEY_MENU_BACK) || IsControllerButtonJustUp(KeyConfig::KEY_MENU_BACK); if (up) *up = IsKeyDown(KeyConfig::KEY_MENU_UP) || IsControllerButtonDown(KeyConfig::KEY_MENU_UP); if (down) *down = IsKeyDown(KeyConfig::KEY_MENU_DOWN) || IsControllerButtonDown(KeyConfig::KEY_MENU_DOWN); if (r) *r = IsKeyDown(KeyConfig::KEY_MENU_RIGHT) || IsControllerButtonDown(KeyConfig::KEY_MENU_RIGHT); if (l) *l = IsKeyDown(KeyConfig::KEY_MENU_LEFT) || IsControllerButtonDown(KeyConfig::KEY_MENU_LEFT); }
static void SetTransform (const NewtonBody* body, const dFloat* matrix, int threadId) { NewtonUserJoint* player; PlayerController* controller; // find the player joint; player = NULL; for (NewtonJoint* joint = NewtonBodyGetFirstJoint(body); joint; joint = NewtonBodyGetNextJoint(body, joint)) { NewtonUserJoint* tmp; tmp = (NewtonUserJoint*) NewtonJointGetUserData(joint); if (CustomGetJointID (tmp) == PLAYER_JOINT_ID) { player = tmp; break; } } // call the generic transform callback controller = (PlayerController*) CustomGetUserData(player); #if 1 // this will project the visual mesh to the ground dMatrix visualMatrix; CustomPlayerControllerGetVisualMaTrix (player, &visualMatrix[0][0]); #else // this will display the player at the collision shape position const dMatrix& visualMatrix = *((dMatrix*) matrix); #endif controller->m_setTransformOriginal (body, &visualMatrix[0][0], threadId); // now we will set the camera to follow the player dVector eyePoint (visualMatrix.TransformVector(controller->m_point)); // check if the player wants third person view static int prevCKeyDown = IsKeyDown ('C'); int isCkeyDwon = IsKeyDown ('C'); if (isCkeyDwon && !prevCKeyDown) { controller->m_isThirdView = !controller->m_isThirdView; } prevCKeyDown = isCkeyDwon; if (controller->m_isThirdView) { dVector dir (GetCameraDir ()); eyePoint -= dir.Scale (8.0f); } SetCameraEyePoint (eyePoint); // NewtonBodyGetMatrix (body, &matrix[0][0]); // cameraEyepoint = matrix.m_posit; // cameraEyepoint.m_y += 1.0f; }
void ProcessInput(Game_Input *input) { input->UP.KeyDown = IsKeyDown(&Keys, input->UP.Button); input->UP.KeyUp = IsKeyUp(&Keys, input->UP.Button); input->DOWN.KeyDown = IsKeyDown(&Keys, input->DOWN.Button); input->DOWN.KeyUp = IsKeyUp(&Keys, input->DOWN.Button); input->RIGHT.KeyDown = IsKeyDown(&Keys, input->RIGHT.Button); input->RIGHT.KeyUp = IsKeyUp(&Keys, input->RIGHT.Button); input->LEFT.KeyDown = IsKeyDown(&Keys, input->LEFT.Button); input->LEFT.KeyUp = IsKeyUp(&Keys, input->LEFT.Button); }
void CPlayerController::ProcessKeys(void) { DIRECTION tDir = m_player->GetDirection(); b2Vec2 speed(0,0); if (IsKeyDown(ALLEGRO_KEY_D) && !IsKeyDown(ALLEGRO_KEY_A)) { speed.x += 5; tDir = RIGHT; } else if (IsKeyDown(ALLEGRO_KEY_A) && !IsKeyDown(ALLEGRO_KEY_D)) { speed.x -= 5; tDir = LEFT; } if (IsKeyDown(ALLEGRO_KEY_W) && !IsKeyDown(ALLEGRO_KEY_S)) { speed.y -= 5; tDir = UP; } else if (IsKeyDown(ALLEGRO_KEY_S) && !IsKeyDown(ALLEGRO_KEY_W)) { speed.y += 5; tDir = DOWN; } m_player->SetSpeed(speed); m_player->SetDirection(tDir); }
bool InputHandler::IsKeyDown(int key, int modifiers) { if (!IsKeyDown(key)) return false; if ((modifiers & 1) != 0 && !IsKeyDown(0x11)) // Ctrl return false; if ((modifiers & 2) != 0 && !IsKeyDown(0x10)) // Shift return false; if ((modifiers & 4) != 0 && !IsKeyDown(0x12)) // Alt return false; return true; }
void Update() { // Calculate delta time clock_t clockNow = clock(); clock_t deltaClock = clockNow - clockLastFrame; float deltaTime = float(deltaClock) / CLOCKS_PER_SEC; clockLastFrame = clockNow; // Calculate FPS framesCounter++; framesTimeCounter += deltaTime; if( framesTimeCounter >= 1.0 ) { framesTimeCounter -= 1.0; fps = framesCounter; framesCounter = 0; } // Hero control if( IsKeyDown(VK_UP) ) unitsData[heroIndex].yOrder = UnitOrder_Backward; else unitsData[heroIndex].yOrder = UnitOrder_None; if( IsKeyDown(VK_LEFT) ) unitsData[heroIndex].xOrder = UnitOrder_Backward; else { if( IsKeyDown(VK_RIGHT) ) unitsData[heroIndex].xOrder = UnitOrder_Forward; else unitsData[heroIndex].xOrder = UnitOrder_None; } // Update all units for( int u = 0; u < unitsCount; u++ ) UpdateUnit( &unitsData[u], deltaTime ); // Update AI UpdateAI(); // Hero dead if( unitsData[heroIndex].health <= 0 ) Initialize(); }
void Player::Control() { WeaponManager(); SetSpeed(c_v2DStill); if(IsKeyDown('A')) SetSpeedX(-1.0f); if(IsKeyDown('D')) SetSpeedX(1.0f); if(IsKeyDown('W')) SetSpeedY(-1.0f); if(IsKeyDown('S')) SetSpeedY(1.0f); }
void OnUpdate(float dt) { if (IsKeyDown('W')) walk(30 * dt); else if (IsKeyDown('S')) walk(-30 * dt); if (IsKeyDown('A')) strafe(30 * dt); else if (IsKeyDown('D')) strafe(-30 * dt); float calcedX = GetMouseX() - lastMouseX, calcedY = GetMouseY() - lastMouseY; lastMouseX = GetMouseX(); lastMouseY = GetMouseY(); if (calcedY < 0) pitch(0.5f * dt * abs(calcedY)); else if (calcedY > 0) pitch(-0.5f * dt * abs(calcedY)); if (calcedX > 0) yaw(0.5f * dt * abs(calcedX)); else if (calcedX < 0) yaw(-0.5f * dt * abs(calcedX)); }
void CKeyEdit::OnKeyDown( UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/ ) { //debug( _T("OnKeyDown: nChar=%u nRepCnt=%u nFlags=%08x\n"), nChar, nRepCnt, nFlags ); if ( IsKeyDown( VK_MENU ) ) { return; } if ( IsKeyDown( VK_CONTROL ) ) { return; } if ( ! KEY_XALNUM( nChar ) ) return; m_dwVk = (DWORD) nChar | ( IsKeyDown( VK_SHIFT ) ? 0x80000000UL : 0UL ); _Update( ); }
void Player::Update(float a_dt) { m_fTimer += a_dt; // Why are we incrementing m_fTimer? To set a bullet fire rate if (IsKeyDown('A')) m_x -= m_speed * a_dt; if (IsKeyDown('D')) m_x += m_speed * a_dt; if (IsKeyDown('W')) m_y -= m_speed * a_dt; if (IsKeyDown('S')) m_y += m_speed * a_dt; if (IsKeyDown(' ')) Fire(); // Check tos ee if we hit a boundary, this is concise- but if you expand // it a little bit, it doesn't look much different from what you have done already if (m_x < 0 + (m_pad + m_w2)) m_x = 0 + (m_pad + m_w2); if (m_x > g_w - (m_pad + m_w2)) m_x = g_w - (m_pad + m_w2); }
// Received Mouse events: bool nuiKnob::MouseClicked(nuiSize X, nuiSize Y, nglMouseInfo::Flags Button) { mClickX = X; mClickY = Y; if ((Button & nglMouseInfo::ButtonLeft) && (Button & nglMouseInfo::ButtonDoubleClick)) { return false; } else if (Button & nglMouseInfo::ButtonLeft) { mClicked = true; Grab(); Invalidate(); mClickValue = mRange.GetValue(); return true; } else if (Button & nglMouseInfo::ButtonWheelUp) { if (IsKeyDown(mFineSensitivityKey)) { mRange.SetValue(mRange.GetValue() + mRange.GetIncrement() / mFineSensitivityRatio); } else { mRange.Increment(); } InteractiveValueChanged(); ActivateToolTip(this, true); return true; } else if (Button & nglMouseInfo::ButtonWheelDown) { if (IsKeyDown(mFineSensitivityKey)) { mRange.SetValue(mRange.GetValue() - mRange.GetIncrement() / mFineSensitivityRatio); } else { mRange.Decrement(); } InteractiveValueChanged(); ActivateToolTip(this, true); return true; } return false; }
void Input::OnKeyPressedMsgApply(KeyboardKey key) { if (IsKeyDown(key) || IsKeyPressed(key)) return; mPressedKeys.Add(key); }
char CInputManager::GetChar(bool enableShift, bool enableCapslock) const { BYTE input[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', 0xc0, 0xbd, 0xbb, 0xdc, 0xdb, 0xdd, 0xba, 0xde, 0xbc, 0xbe, 0xbf, ' ', 0x0d, '\t', '\b' }; BYTE output[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '`', '-', '=', '\\', '[', ']', ';', '\'', ',', '.', '/', ' ', '\n', '\t', '\b' }; BYTE output2[] = { ')', '!', '@', '#', '$', '%', '^', '&', '*', '(', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '~', '_', '+', '|', '{', '}', ':', '\"', '<', '>', '?', ' ', '\n', '\t', '\b' }; // from combination of capslock and shit, figure out what is the case char mod = (enableShift && IsKeyDown(Keys::Shift)) + (enableCapslock && IsCapslockActive()); for (int i = 0; i < sizeof(input); i++) { if (IsKeyPressed((Keys)input[i])) { if (mod == 1) return output2[i]; else return output[i]; } } return 0; }
// movement code used to position the red paddle // void PaddleMovement(DynamObject &obj) { if(IsKeyDown('W') && obj.position.y > 0) { obj.position.y -= 1.1f; } else if(IsKeyDown('S') && obj.position.y < 652) { obj.position.y += 1.1f; } MoveSprite(obj.sprite, obj.position.x, obj.position.y); }
void Player::Control() { SetSpeed(0,0); if(IsKeyDown('A')) SetSpeedX(-1.0f); if(IsKeyDown('D')) SetSpeedX(1.0f); if(IsKeyDown('W')) SetSpeedY(-1.0f); if(IsKeyDown('S')) SetSpeedY(1.0f); if(IsKeyDown('T')) Shoot(); }
void enter(bool &bSplashActive) { if (IsKeyDown(32)) { bSplashActive = false; } }
void HermiteSpline::HandleUI(StateManager* stateMan) { if (IsKeyDown('M')) { stateMan->PopState(); return; } if (GetMouseButtonDown(MOUSE_BUTTON_1)) { //loop through objects and see if clicked for (Sprite* object : objectList) { if (object->ID == objectList[0]->ID) { double mousePosX = 0.0; double mousePosY = 0.0; GetMouseLocation(mousePosX, mousePosY); mousePosY = screenHeight - mousePosY; //std::cout << "x: " << mousePosX << " y: " << mousePosY << std::endl; bool isCollided = object->IsCollided(Vector2(mousePosX, mousePosY)); //std::cout << "object: " << object->name << " clicked: " << isCollided << std::endl; if (object->IsCollided(Vector2(mousePosX, mousePosY))) { object->position = Vector2(mousePosX, mousePosY); } } } } }