void Logic::HandleEvent(const SDL_Event& event) { if( pieces_.get_matches() >= layout_.total()) { // do nothing } else if( event.type == SDL_MOUSEBUTTONDOWN ) { cursor_.position = layout_.ScreenToGame(event.button.x, event.button.y); if(event.button.button == SDL_BUTTON_LEFT/* && !rightdrag*/) { leftDown(); } else if(event.button.button == SDL_BUTTON_RIGHT) { rightDown(); } } else if( event.type == SDL_MOUSEBUTTONUP ) { cursor_.position = layout_.ScreenToGame(event.button.x, event.button.y); if(event.button.button == SDL_BUTTON_LEFT/* && rect_up*/) { leftUp(); } else if(event.button.button == SDL_BUTTON_RIGHT) { rightUp(); } } else if( event.type == SDL_MOUSEMOTION ) { // Keep track of the mouse position in a handy format. cursor_.position = layout_.ScreenToGame(event.motion.x, event.motion.y); } }
void individualMove(struct board_position pos, int i, int j, int turn, int *nc, char *child_ptr) { struct board_position p; if (pos.board[i][j] != WPAWN) { p = pos; if (leftDown(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } p = pos; if (rightDown(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } } if (pos.board[i][j] != BPAWN) { p = pos; if (leftUp(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } p = pos; if (rightUp(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } } stacks(pos, i, j, turn, nc, child_ptr); }
/// ------------------------------------------------ // /// 长方形 /// [4/18/2014 jianglei.kinly] /// ------------------------------------------------ // xObjectSet XGameMap::CaptureObjectByRectangle( const XVector3& vCenter, xgc_uint32 dwXRadius, xgc_uint32 dwYRadius, const std::function< xgc_bool( xObject ) > &fnFilter ) { XVector3 leftTop( vCenter.x - dwXRadius, vCenter.y - dwYRadius, 0 ); XVector3 rightDown( vCenter.x + dwXRadius, vCenter.y + dwYRadius, 0 ); auto fn = [&]( xObject hObject )->xgc_bool { if( xgc_nullptr == fnFilter || fnFilter( hObject ) ) { XGameObject* pObj = ObjectCast<XGameObject>( hObject ); XGC_ASSERT_RETURN( pObj, false ); return pObj->GetPosX() >= leftTop.x && pObj->GetPosY() >= leftTop.y && pObj->GetPosX() <= rightDown.x && pObj->GetPosY() <= rightDown.y; } return false; }; iRect rc( WorldToArea( vCenter.x - dwXRadius, vCenter.y - dwYRadius ), WorldToArea( vCenter.x + dwXRadius, vCenter.y + dwYRadius ) ); return FetchObject( rc, fn ); }
void Keyboard::checkKeys(System* system) { if( system->action.type == SDL_KEYDOWN ) { switch(system->action.key.keysym.sym) { case SDLK_UP: break; case SDLK_DOWN: break; case SDLK_LEFT: leftDown(system); break; case SDLK_RIGHT: rightDown(system); break; case SDLK_LSHIFT: { // this is a stack frame variable, for use of local hero Hero* hero = system->sprite_director->getHero(); if(!(hero->jumping) ) { Mix_PlayChannel( -1, system->jukebox->jump, 0 ); hero->jump_start_time = SDL_GetTicks(); hero->jumping = true; } } break; } } else if( system->action.type == SDL_KEYUP ) { //Adjust the velocity switch( system->action.key.keysym.sym ) { case SDLK_DOWN: break; case SDLK_LEFT: leftUp(system); break; case SDLK_RIGHT: rightUp(system); break; case SDLK_LSHIFT: break; } } }