/** Checks if any item was collected by the given kart. This function calls * collectedItem if an item was collected. * \param kart Pointer to the kart. */ void ItemManager::checkItemHit(AbstractKart* kart) { // We could use m_items_in_quads to to check for item hits: take the quad // of the graph node of the kart, and only check items in that quad. But // then we also need to check for any adjacent quads (since an item just // on the order of one quad might get hit from an adjacent quad). Then // it is possible that a quad is that short that we need to test adjacent // of adjacent quads. And check for items outside of the track. // Since at this stace item detection is by far not a bottle neck, // the original, simple and stable algorithm is left in place. for(AllItemTypes::iterator i =m_all_items.begin(); i!=m_all_items.end(); i++) { if((!*i) || (*i)->wasCollected()) continue; // To allow inlining and avoid including kart.hpp in item.hpp, // we pass the kart and the position separately. if((*i)->hitKart(kart->getXYZ(), kart)) { // if we're not playing online, pick the item. if (!NetworkWorld::getInstance()->isRunning()) collectedItem(*i, kart); else if (NetworkManager::getInstance()->isServer()) { collectedItem(*i, kart); NetworkWorld::getInstance()->collectedItem(*i, kart); } } // if hit } // for m_all_items } // checkItemHit
/** Checks if any item was collected by the given kart. This function calls * collectedItem if an item was collected. * \param kart Pointer to the kart. */ void ItemManager::checkItemHit(Kart* kart) { // Only do this on the server if(network_manager->getMode()==NetworkManager::NW_CLIENT) return; for(AllItemTypes::iterator i =m_all_items.begin(); i!=m_all_items.end(); i++) { if((!*i) || (*i)->wasCollected()) continue; if((*i)->hitKart(kart)) { collectedItem(i-m_all_items.begin(), kart); } // if hit } // for m_all_items } // checkItemHit
void Actor::updateGravity(Map *map) { if( ay!=0) { printf("y=%.2f; vy=%.2f; ay=%.2f\n",y,vy,ay); } vy=vy+ay; vy=vy+GRAVITY; // earth gravity is 9.8 m/s^2, or whatever it works out to in your units. // apply terminal velocity if( vy<MINVEL) { vy=MINVEL; ay=0; // hit minimum negative velocity so stop jumping. } if( vy>MAXVEL) { vy=MAXVEL; ay=0; // hit maximum velocity so stop jumping. } // propose new position, and test for collision: float newy=y+vy; int i; for( i=0; i<8; i++) { int item=map->collide(x, newy+32, 32, 32 ); if( item==MAP_SKY ) break; // a safe place to move the item to. if( (item!=MAP_BARRIER_A && item!=MAP_BARRIER_B)) { item=map->collect(x,newy+32, 32, 32); collectedItem(item); break; } if( item==MAP_BARRIER_A || item==MAP_BARRIER_B) { if(vy<0) break; // Jump up through walls! } // we don't want to be inside the object, so guess we can move half the distance. vy/=2.0f; newy=y+vy; } if( i==8) { newy=y; // we can't find a place closer to the ground/ceiling so we need to stop moving. vy=0; ay=0; } y=newy; // our new vertical position with gravity and jumping factored in! }