long ExtObject::cKeyReleased(LPVAL params) { int key = params[0].GetInt(); bool& first = keyReleaseFirst[keyTable[key].vk]; bool ret = MakeConditionTrigger(pRuntime, !KeyIsDown(keyTable[key].vk)) && !first; first = false; return ret; }
bool Keyboard::AddKey(int vKey) { //add for loop to check keys if (m_numKeys >= MAX_KEYS) { GameLogger::Log(LogMsgType::cFatalError, " Keyboard::AddKey() is full at %d", MAX_KEYS); return false; } m_keys[m_numKeys++] = vKey; m_previousKeyboardState[vKey] = { vKey, KeyIsDown(vKey), false, false }; return true; }
bool WebP_InUI( WebP_InUI_Data *params, bool have_alpha, const void *plugHndl, const void *mwnd) { bool continue_reading = true; g_alpha = DIALOG_ALPHA_TRANSPARENCY; g_mult = false; g_autoD = false; ReadPrefs(); // check for that shift key bool shift_key = ( KeyIsDown(VK_LSHIFT) || KeyIsDown(VK_RSHIFT) || KeyIsDown(VK_LMENU) || KeyIsDown(VK_RMENU) ); if((g_autoD && have_alpha) || shift_key) { int status = DialogBox(hDllInstance, (LPSTR)"IN_DIALOG", (HWND)mwnd, (DLGPROC)DialogProc); if(g_item_clicked == IN_OK) { WriteAutoPrefs(); continue_reading = true; } else continue_reading = false; } params->alpha = g_alpha; params->mult = g_mult; return continue_reading; }
void Keyboard::HandleKeys() { for (int j = 0; j < m_numKeys; ++j) { int vKey = m_keys[j]; Key * key = &m_previousKeyboardState[vKey]; bool isDown = KeyIsDown(vKey); bool wasDown = m_previousKeyboardState[vKey].wasDownLastTime; if (isDown) key->justPressed = !wasDown; else key->justReleased = wasDown; m_previousKeyboardState[vKey].wasDownLastTime = isDown; } }
LRESULT WINAPI LoopFafaCheck( HWND w, UINT msg, WPARAM mw, LPARAM ml ) { HDC h ; switch( msg ) { case WM_SYSCOLORCHANGE: CreatePensBrushes() ; break ; case WM_CREATE : InitButtonWords( w ) ; if ( TstF( GetStyle(), FC_PRESELECT ) ) SetState( (WORD)FB_SELECTED ) ; break ; case WM_SETFONT: { HFONT f = (HFONT)mw ; SetFont(f) ; h = GetDC( w ) ; if ( TstF( GetStyle(), FC_BUTTONDRAW ) ) DrawFafaButton( w ,h ) ; else DrawFafaCheck( w ,h ) ; ReleaseDC( w, h ) ; break ; } case WM_CHANGEBITMAP: { HBITMAP f = (HBITMAP)ml ; WORD width = LOBYTE(mw) ; WORD height = HIBYTE(mw) ; LONG style = GetStyle() ; if (width == 255) { SIZE s; GetBitmapDimensionEx(f, &s); width = s.cx; height = s.cy; } SetBitmap(f) ; SetBitmapW(width) ; SetBitmapH(height) ; if (f) { /* Switch to Bitmap button */ style &= 0xffffff70 ; style |= (FC_BUTTONDRAW|FB_BITMAP) ; } else { /* Switch to Text button */ style &= 0xffffff70 ; /* default text style for check items */ if (style&FC_RADIO) style |= FC_CIR_DWN ; else style |= FC_REC_DWN ; } SetStyle(style) ; h = GetDC( w ) ; if ( TstF( GetStyle(), FC_BUTTONDRAW ) ) DrawFafaButton( w ,h) ; else DrawFafaCheck( w ,h) ; ReleaseDC( w, h ) ; break ; } case WM_GETFONT: return (LRESULT)GetFont() ; case WM_PAINT : if ( TstF( GetStyle(), FC_BUTTONDRAW ) ) RedrawFafaButton( w ) ; else RedrawFafaCheck( w ) ; break ; case WM_SETFOCUS: ChangeCheckFocus( w, 1 ) ; if ( GetAcc() && KeyIsDown( GetAcc() ) ) CheckKeyDown( w, 1 ) ; break ; case WM_KILLFOCUS: ChangeCheckFocus( w, 0 ) ; break ; case WM_ENABLE: if ( ( mw != 0 ) ^ IsDisabled() ) InvalidateRect( w, 0, 0 ) ; break ; case WM_RBUTTONDOWN: if ( ! TstF( GetStyle(), FC_RIGHTBUT ) ) break ; case WM_LBUTTONDOWN: SetFocus( w ) ; MouseDown( w ) ; break ; case WM_MOUSEMOVE: MouseMove( w, ml ) ; break ; case WM_RBUTTONUP: if ( ! TstF( GetStyle(), FC_RIGHTBUT ) ) break ; case WM_LBUTTONUP: MouseUp( w, ml ) ; break ; case FAFA_GETCHECK : #ifdef DEBUG_FAFA MyDebugMsg("State of check %x is %d\n",w,TstState(FB_SELECTED)); #endif return ( LONG ) TstState( FB_SELECTED ) ; case FAFA_SETCHECK : #ifdef DEBUG_FAFA MyDebugMsg("Setting Check %x to %d\n",w,mw) ; #endif if ( ChangeCheckSelect( w, ( mw != 0 ) ) && mw ) MakeRadioIteration( w ) ; break ; case WM_KEYDOWN: case WM_SYSKEYDOWN: case WM_KEYUP: case WM_SYSKEYUP: if ( mw == ' ' || KeyIsAcc( w, mw ) ) CheckKeyDown( w, IsMessDown( msg ) ) ; else return DefWindowProc( w, msg, mw, ml ) ; break; case WM_WHOAREYOU : return ( LONG ) FB_CHECK ; case WM_SETTEXT : InvalidateRect( w, 0, 0 ) ; default: return DefWindowProc( w, msg, mw, ml ) ; } return 0l ; }
bool KeyIsReleased(const keyboard_t *k, const int key) { return !KeyIsDown(k, key) && k->previousKeys[key].isPressed; }
int KeyIsReleased(keyboard_t *keyboard, int key) { return !KeyIsDown(keyboard, key) && keyboard->previous_keys[key]; }
int KeyIsPressed(keyboard_t *keyboard, int key) { return KeyIsDown(keyboard, key) && !keyboard->previous_keys[key]; }
/** * Other Methods */ bool Keyboard::KeyIsDown(char key) { return KeyIsDown((int)key); }
static HandleInputResult HandleInput( int c, int m, int *xc, int *yc, int *xcOld, int *ycOld, Mission *scrap) { HandleInputResult result = { false, false, false, false }; Mission *mission = CampaignGetCurrentMission(&gCampaign); UIObject *o = NULL; brush.Pos = GetMouseTile(&gEventHandlers); // Find whether the mouse has hovered over a tooltip bool hadTooltip = sTooltipObj != NULL; if (!UITryGetObject(sObjs, gEventHandlers.mouse.currentPos, &sTooltipObj) || !sTooltipObj->Tooltip) { sTooltipObj = NULL; } // Need to redraw if we either had a tooltip (draw to remove) or there's a // tooltip to draw if (hadTooltip || sTooltipObj) { result.Redraw = true; } // Make sure a redraw is done immediately if the resolution changes // Otherwise the resolution change is ignored and we try to redraw // later, when the draw buffer has not yet been recreated if (gEventHandlers.HasResolutionChanged) { result.Redraw = true; } // Also need to redraw if the brush is active to update the highlight if (brush.IsActive) { result.Redraw = true; } if (m && (m == SDL_BUTTON_LEFT || m == SDL_BUTTON_RIGHT || m == SDL_BUTTON_WHEELUP || m == SDL_BUTTON_WHEELDOWN)) { result.Redraw = true; if (UITryGetObject(sObjs, gEventHandlers.mouse.currentPos, &o)) { if (!o->DoNotHighlight) { if (sLastHighlightedObj) { UIObjectUnhighlight(sLastHighlightedObj); } sLastHighlightedObj = o; UIObjectHighlight(o); } CArrayTerminate(&sDrawObjs); *xcOld = *xc; *ycOld = *yc; // Only change selection on left/right click if (m == SDL_BUTTON_LEFT || m == SDL_BUTTON_RIGHT) { if (!(o->Flags & UI_LEAVE_YC)) { *yc = o->Id; AdjustYC(yc); } if (!(o->Flags & UI_LEAVE_XC)) { *xc = o->Id2; AdjustXC(*yc, xc); } } if (!(o->Flags & UI_SELECT_ONLY) && (!(o->Flags & UI_SELECT_ONLY_FIRST) || (*xc == *xcOld && *yc == *ycOld))) { if (m == SDL_BUTTON_LEFT || m == SDL_BUTTON_WHEELUP) { c = SDLK_PAGEUP; } else if (m == SDL_BUTTON_RIGHT || m == SDL_BUTTON_WHEELDOWN) { c = SDLK_PAGEDOWN; } } } else { if (!(brush.IsActive && mission)) { UIObjectUnhighlight(sObjs); CArrayTerminate(&sDrawObjs); sLastHighlightedObj = NULL; } } } if (!o && (MouseIsDown(&gEventHandlers.mouse, SDL_BUTTON_LEFT) || MouseIsDown(&gEventHandlers.mouse, SDL_BUTTON_RIGHT))) { result.Redraw = true; if (brush.IsActive && mission->Type == MAPTYPE_STATIC) { // Draw a tile if (IsBrushPosValid(brush.Pos, mission)) { int isMain = MouseIsDown(&gEventHandlers.mouse, SDL_BUTTON_LEFT); EditorResult r = EditorBrushStartPainting(&brush, mission, isMain); if (r == EDITOR_RESULT_CHANGED || r == EDITOR_RESULT_CHANGED_AND_RELOAD) { fileChanged = 1; Autosave(); result.RemakeBg = true; sHasUnbakedChanges = true; } if (r == EDITOR_RESULT_CHANGED_AND_RELOAD) { Setup(0); } } } } else { if (mission) { // Clamp brush position brush.Pos = Vec2iClamp( brush.Pos, Vec2iZero(), Vec2iMinus(mission->Size, Vec2iUnit())); EditorResult r = EditorBrushStopPainting(&brush, mission); if (r == EDITOR_RESULT_CHANGED || r == EDITOR_RESULT_CHANGED_AND_RELOAD) { fileChanged = 1; Autosave(); result.Redraw = true; result.RemakeBg = true; sHasUnbakedChanges = true; } if (r == EDITOR_RESULT_CHANGED_AND_RELOAD) { Setup(0); } } } // Pan the camera based on keyboard cursor keys if (mission) { if (KeyIsDown(&gEventHandlers.keyboard, SDLK_LEFT)) { camera.x -= CAMERA_PAN_SPEED; result.Redraw = result.RemakeBg = true; } else if (KeyIsDown(&gEventHandlers.keyboard, SDLK_RIGHT)) { camera.x += CAMERA_PAN_SPEED; result.Redraw = result.RemakeBg = true; } if (KeyIsDown(&gEventHandlers.keyboard, SDLK_UP)) { camera.y -= CAMERA_PAN_SPEED; result.Redraw = result.RemakeBg = true; } else if (KeyIsDown(&gEventHandlers.keyboard, SDLK_DOWN)) { camera.y += CAMERA_PAN_SPEED; result.Redraw = result.RemakeBg = true; } // Also pan the camera based on middle mouse drag if (MouseIsDown(&gEventHandlers.mouse, SDL_BUTTON_MIDDLE)) { camera = Vec2iAdd(camera, Vec2iMinus( gEventHandlers.mouse.previousPos, gEventHandlers.mouse.currentPos)); result.Redraw = result.RemakeBg = true; } camera.x = CLAMP(camera.x, 0, Vec2iCenterOfTile(mission->Size).x); camera.y = CLAMP(camera.y, 0, Vec2iCenterOfTile(mission->Size).y); } bool hasQuit = false; if (gEventHandlers.keyboard.modState & (KMOD_ALT | KMOD_CTRL)) { result.Redraw = true; switch (c) { case 'z': // Undo // Do this by swapping the current mission with the last mission // This requires a bit of copy-acrobatics; because missions // are saved in Setup(), but by this stage the mission has already // changed, _two_ mission caches are used, copied in sequence. // That is, if the current mission is at state B, the first cache // is still at state B (copied after the mission has changed // already), and the second cache is at state A. // If we were to perform an undo and still maintain functionality, // we need to copy such that the states change from B,B,A to // A,A,B. // However! The above is true only if we have "baked" changes // The editor has been optimised to perform some changes // without reloading map files; that is, the files are actually // in states C,B,A. // In this case, another set of "acrobatics" is required if (sHasUnbakedChanges) { MissionCopy(&lastMission, mission); // B,A,Z -> B,A,B } else { MissionCopy(mission, &lastMission); // B,B,A -> A,B,A MissionCopy(&lastMission, ¤tMission); // A,B,A -> A,B,B } fileChanged = 1; Setup(0); // A,B,B -> A,A,B break; case 'x': MissionTerminate(scrap); MissionCopy(scrap, mission); Delete(*xc, *yc); break; case 'c': MissionTerminate(scrap); MissionCopy(scrap, mission); break; case 'v': // Use map size as a proxy to whether there's a valid scrap mission if (!Vec2iEqual(scrap->Size, Vec2iZero())) { InsertMission(&gCampaign, scrap, gCampaign.MissionIndex); fileChanged = 1; Setup(0); } break; case 'q': hasQuit = true; break; case 'n': InsertMission(&gCampaign, NULL, gCampaign.Setting.Missions.size); gCampaign.MissionIndex = gCampaign.Setting.Missions.size - 1; fileChanged = 1; Setup(0); break; case 'o': if (!fileChanged || ConfirmScreen( "File has been modified, but not saved", "Open anyway? (Y/N)")) { Open(); } break; case 's': Save(); break; case 'm': result.WillDisplayAutomap = true; break; case 'e': EditCharacters(&gCampaign.Setting); Setup(0); UIObjectUnhighlight(sObjs); CArrayTerminate(&sDrawObjs); break; } } else { if (c != 0) { result.Redraw = true; } switch (c) { case SDLK_F1: HelpScreen(); break; case SDLK_HOME: if (gCampaign.MissionIndex > 0) { gCampaign.MissionIndex--; } Setup(0); break; case SDLK_END: if (gCampaign.MissionIndex < (int)gCampaign.Setting.Missions.size) { gCampaign.MissionIndex++; } Setup(0); break; case SDLK_INSERT: switch (*yc) { case YC_CHARACTERS: if (gCampaign.Setting.characters.OtherChars.size > 0) { int ch = 0; CArrayPushBack(&mission->Enemies, &ch); CharacterStoreAddBaddie(&gCampaign.Setting.characters, ch); *xc = mission->Enemies.size - 1; } break; case YC_SPECIALS: if (gCampaign.Setting.characters.OtherChars.size > 0) { int ch = 0; CArrayPushBack(&mission->SpecialChars, &ch); CharacterStoreAddSpecial(&gCampaign.Setting.characters, ch); *xc = mission->SpecialChars.size - 1; } break; case YC_ITEMS: { int item = 0; CArrayPushBack(&mission->Items, &item); CArrayPushBack(&mission->ItemDensities, &item); *xc = mission->Items.size - 1; } break; default: if (*yc >= YC_OBJECTIVES) { AddObjective(mission); } else { InsertMission(&gCampaign, NULL, gCampaign.MissionIndex); } break; } fileChanged = 1; Setup(0); break; case SDLK_DELETE: Delete(*xc, *yc); break; case SDLK_PAGEUP: if (Change(o, *yc, 1)) { fileChanged = 1; } Setup(0); break; case SDLK_PAGEDOWN: if (Change(o, *yc, -1)) { fileChanged = 1; } Setup(0); break; case SDLK_ESCAPE: hasQuit = true; break; case SDLK_BACKSPACE: fileChanged |= UIObjectDelChar(sObjs); break; default: c = KeyGetTyped(&gEventHandlers.keyboard); if (c) { fileChanged |= UIObjectAddChar(sObjs, (char)c); } break; } } if (gEventHandlers.HasQuit) { hasQuit = true; } if (hasQuit && (!fileChanged || ConfirmScreen( "File has been modified, but not saved", "Quit anyway? (Y/N)"))) { result.Done = true; } return result; }
int Game::Update( double p_DeltaTime ) { // ///////////////////////////////////////////// // INPUT // Exit if we press Escape if( KeyIsJustPressed( SDLK_ESCAPE ) ) { return 1; } if( KeyIsDown( SDLK_w ) ) { m_Player.BurstForwards( ); } else if( KeyIsDown( SDLK_s ) ) { m_Player.BurstBackwards( ); } if( KeyIsDown( SDLK_a ) ) { m_Player.BurstLeft( ); } else if( KeyIsDown( SDLK_d ) ) { m_Player.BurstRight( ); } // Shoot pumps / lazer m_ActiveLazer = false; if( KeyIsDown( SDLK_SPACE ) ) { if( m_PumpBullets.size( ) == 0 ) { // Shoot bullets if( !m_Planets[ m_CurrPlanet ].IsPumpActive( ) && KeyIsJustPressed( SDLK_SPACE ) ) { PumpBullet * pPumpBullet = new PumpBullet( ); pPumpBullet->SetPosition( m_Player.GetPosition( ) ); pPumpBullet->SetDirection( m_Player.GetViewDirection( ) ); pPumpBullet->SetSpeed( m_StartBulletSpeed ); pPumpBullet->SetColor( m_Player.GetColor( ) ); m_PumpBullets.push_back( pPumpBullet ); } // Shoot lazer else if( m_Planets[ m_CurrPlanet ].IsPumpActive( ) ) { m_ActiveLazer = true; } } } // Fill test if( KeyIsDown( SDLK_z ) ) { if( m_Planets[ m_CurrPlanet ].GetResources( ) != 1.0f ) { m_Planets[ m_CurrPlanet ].SetResources( m_Planets[ m_CurrPlanet ].GetResources( ) + ( 0.25f * p_DeltaTime) ); } } else if( KeyIsDown( SDLK_x ) ) { if( m_Planets[ m_CurrPlanet ].GetResources( ) != 0.0f ) { m_Planets[ m_CurrPlanet ].SetResources( m_Planets[ m_CurrPlanet ].GetResources( ) - ( 0.25f * p_DeltaTime) ); } } // ////////////////////////////////////////////////////////////// // Game update // Update the player m_Player.Update( p_DeltaTime ); // Update the planet m_Planets[ m_CurrPlanet ].Update( p_DeltaTime ); // Update all pump bullets UpdatePumpBullets( p_DeltaTime ); const LDE::Vector2f pumpPosition = m_Planets[ m_CurrPlanet ].GetGlobalPumpPosition( ); // Update the lazer m_LazerHittingPump = false; if( m_ActiveLazer ) { m_LazerPoints[ 0 ] = m_Player.GetPosition( ); m_LazerPoints[ 1 ] = m_Player.GetPosition( ) + ( m_Player.GetViewDirection( ) * 1000.0f ); // Check if any bullet hit the planet // Get the In and Out point of the intersection LDE::Vector2f inPump; LDE::Vector2f out; int pumpCol = LDE::LineCircleIntersection( m_LazerPoints[ 0 ], m_LazerPoints[ 1 ], pumpPosition, m_Planets[ m_CurrPlanet ].GetPumpSize( ), inPump, out); LDE::Vector2f inPlanet; int planetCol = LDE::LineCircleIntersection( m_LazerPoints[ 0 ], m_LazerPoints[ 1 ], m_Planets[ m_CurrPlanet ].GetPosition( ), m_Planets[ m_CurrPlanet ].GetSize( ), inPlanet, out); if( pumpCol == 1 && planetCol == 1) { float planetDist = LDE::Vector2f( m_LazerPoints[ 0 ] - inPlanet ).Magnitude( ); float pumpDist = LDE::Vector2f( m_LazerPoints[ 0 ] - inPump ).Magnitude( ); if( pumpDist <= planetDist ) { m_LazerPoints[ 1 ] = inPump; m_Planets[ m_CurrPlanet ].DrainPlanet( ); } else { m_LazerPoints[ 1 ] = inPlanet; } } else if( pumpCol == 1) { m_LazerPoints[ 1 ] = inPump; m_Planets[ m_CurrPlanet ].DrainPlanet( ); } else if( planetCol == 1) { m_LazerPoints[ 1 ] = inPlanet; } } // Add planet gravity if we are close enought LDE::Vector2f planetDirection = m_Planets[ m_CurrPlanet ].GetPosition( ) - m_Player.GetPosition( ); float planetDistance = planetDirection.Magnitude( ); const float planetGravityStart = m_Planets[ m_CurrPlanet ].GetSize( ) * 7.5f; if( planetDistance <= planetGravityStart ) { float gravityPower = 1.0f - ( planetDistance / planetGravityStart ); gravityPower *= 35.0f; LDE::Vector2f gravityVector = planetDirection.Normal( ) * gravityPower * p_DeltaTime * (m_Planets[ m_CurrPlanet ].GetSize( ) / 50.0f ); m_Player.SetDirection( m_Player.GetDirection( ) + gravityVector ); } // Collision detect the player and the player/pump if( CircleCircleIntersection( m_Player.GetPosition( ), m_StartPlayerRadius, m_Planets[ m_CurrPlanet ].GetPosition( ), m_Planets[ m_CurrPlanet ].GetSize( ) ) ) { // We died! ResetGame( ); } // Are we coliding with the pump? if( CircleCircleIntersection( m_Player.GetPosition( ), m_StartPlayerRadius, pumpPosition, m_Planets[ m_CurrPlanet ].GetPumpSize( ) ) ) { // We died! ResetGame( ); return 0; } //std::cout << pumpPosition.x << " " << pumpPosition.y << std::endl; // Are we outside the navigation system? Then reset if( planetDistance >= m_StartMaxPlanetRange + m_Planets[ m_CurrPlanet ].GetSize( ) ) { // We are lost! ResetGame( ); return 0; } // Are we out of time? m_GameTimer.Stop( ); if( m_GameTimer.GetTime( ) >= m_BestTime ) { ResetGame( ); return 0; } // Update the overlay alpha which is depending on the planet distance const float distMaxSurface = m_StartMaxPlanetRange + m_Planets[ m_CurrPlanet ].GetSize( ); const float distToSurface = planetDistance - m_Planets[ m_CurrPlanet ].GetSize( ); const float minOffset = distToSurface / 2.0f; const float maxOffset = distToSurface; const float offsetDiff1 = minOffset / distToSurface; const float offsetDiff2 = 1.0f / offsetDiff1; m_OverlayAlpha = ((distToSurface / distMaxSurface ) * offsetDiff2 ) - offsetDiff1; m_OverlayAlpha = std::max( 0.0f, m_OverlayAlpha ); // Is the current planet out of resources? if( m_Planets[ m_CurrPlanet ].GetResources( ) == 0 ) { if( m_CurrPlanet < PLANET_COUNT - 1 ) { m_CurrPlanet++; // Set the planet's start position to the pump's position m_Planets[ m_CurrPlanet ].SetPosition( pumpPosition ); } // We won the game. else { WinGame( ); } } return 0; }
long ExtObject::cOnKey(LPVAL params) { int key = params[0].GetInt(); return MakeConditionTrigger(pRuntime, KeyIsDown(keyTable[key].vk)); }
long ExtObject::cKeyDown(LPVAL params) { return KeyIsDown(keyTable[params[0].GetInt()].vk); }
long ExtObject::cMouseButtonDown(LPVAL params) { int mouseButton = params[0].GetInt(); return KeyIsDown(mouseButtonTable[mouseButton]); }
int KeyIsReleased(keyboard_t *keyboard, int key) { return !KeyIsDown(keyboard, key) && keyboard->previousKeys[key].isPressed; }