本文整理汇总了C++中AbstractKart::getController方法的典型用法代码示例。如果您正苦于以下问题:C++ AbstractKart::getController方法的具体用法?C++ AbstractKart::getController怎么用?C++ AbstractKart::getController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractKart
的用法示例。
在下文中一共展示了AbstractKart::getController方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resetAxisDirection
void GamePadDevice::resetAxisDirection(const int axis,
Input::AxisDirection direction)
{
// ignore this while in menus
if (StateManager::get()->getGameState() != GUIEngine::GAME) return;
AbstractKart* pk = getPlayer()->getKart();
if (!pk)
{
Log::error("Binding", "Trying to reset axis for an unknown player.");
return;
}
for(int n=PA_BEFORE_FIRST+1; n<PA_COUNT; n++)
{
const Binding& bind = m_configuration->getBinding(n);
if(bind.getType() == Input::IT_STICKMOTION &&
bind.getId() == axis &&
bind.getDirection()== direction &&
pk->getController() != NULL)
{
((PlayerController*)(pk->getController()))
->action((PlayerAction)n, 0);
return;
}
}
} // resetAxisDirection
示例2: addAttachment
// ----------------------------------------------------------------------------
void addAttachment(Attachment::AttachmentType type)
{
World* world = World::getWorld();
if (world == NULL) return;
for (unsigned int i = 0; i < world->getNumKarts(); i++)
{
AbstractKart *kart = world->getKart(i);
if (!kart->getController()->isLocalPlayerController())
continue;
if (type == Attachment::ATTACH_ANVIL)
{
kart->getAttachment()
->set(type, kart->getKartProperties()->getAnvilDuration());
kart->adjustSpeed(kart->getKartProperties()->getAnvilSpeedFactor());
kart->updateWeight();
}
else if (type == Attachment::ATTACH_PARACHUTE)
{
kart->getAttachment()
->set(type, kart->getKartProperties()->getParachuteDuration());
}
else if (type == Attachment::ATTACH_BOMB)
{
kart->getAttachment()
->set(type, stk_config->m_bomb_time);
}
}
} // addAttachment
示例3: addAttachment
void addAttachment(Attachment::AttachmentType type)
{
World* world = World::getWorld();
if (world == NULL) return;
for(unsigned int i = 0; i < world->getNumKarts(); i++)
{
AbstractKart *kart = world->getKart(i);
if (kart->getController()->isPlayerController()) {
if (type == Attachment::ATTACH_ANVIL)
{
kart->getAttachment()
->set(type, stk_config->m_anvil_time);
kart->adjustSpeed(stk_config->m_anvil_speed_factor);
kart->updateWeight();
}
else if (type == Attachment::ATTACH_PARACHUTE)
{
kart->getAttachment()
->set(type, stk_config->m_parachute_time);
}
else if (type == Attachment::ATTACH_BOMB)
{
kart->getAttachment()
->set(type, stk_config->m_bomb_time);
}
}
}
}
示例4: resetAxisDirection
void GamePadDevice::resetAxisDirection(const int axis,
Input::AxisDirection direction,
StateManager::ActivePlayer* player)
{
// ignore this while in menus
if (StateManager::get()->getGameState() != GUIEngine::GAME) return;
AbstractKart* pk = player->getKart();
if (pk == NULL)
{
fprintf(stderr, "Error, trying to reset axis for an unknown player\n");
return;
}
for(int n=0; n<PA_COUNT; n++)
{
Binding& bind = m_configuration->getBinding(n);
if(bind.getType() == Input::IT_STICKMOTION &&
bind.getId() == axis &&
bind.getDirection()== direction)
{
((PlayerController*)(pk->getController()))
->action((PlayerAction)n, 0);
return;
}
}
} // resetAxisDirection
示例5: kc
/** Receives a kart control message.
* \param kart_id_offset is the global id of the first kart on the host from
* which this packet was received.
*/
KartControlMessage::KartControlMessage(ENetPacket* pkt, int kart_id_offset,
int num_local_players)
: Message(pkt, MT_KART_CONTROL)
{
// FIXME: This probably does not work anymore - it assume that
// num_local_Players is the number of all local karts, while it might
// only be the number of all network karts.
for(int i=kart_id_offset; i<kart_id_offset+num_local_players; i++)
{
KartControl kc(this);
AbstractKart *kart = World::getWorld()->getKart(i);
if(kart->getController()->isNetworkController())
{
((NetworkKart*)kart)->setControl(kc);
}
}
}; // KartControlMessage
示例6: eliminateKart
/** Remove (eliminate) a kart from the race */
void World::eliminateKart(int kart_number, bool notify_of_elimination)
{
AbstractKart *kart = m_karts[kart_number];
// Display a message about the eliminated kart in the race gui
if (notify_of_elimination)
{
for (KartList::iterator i = m_karts.begin(); i != m_karts.end(); i++ )
{
if(!(*i)->getCamera()) continue;
if(*i==kart)
{
m_race_gui->addMessage(_("You have been eliminated!"), *i,
2.0f);
}
else
{
m_race_gui->addMessage(_("'%s' has been eliminated.",
core::stringw(kart->getName())), *i,
2.0f);
}
} // for i in kart
}
if(kart->getController()->isPlayerController())
{
// Change the camera so that it will be attached to the leader
// and facing backwards.
Camera* camera=kart->getCamera();
camera->setMode(Camera::CM_LEADER_MODE);
m_eliminated_players++;
}
// The kart can't be really removed from the m_kart array, since otherwise
// a race can't be restarted. So it's only marked to be eliminated (and
// ignored in all loops). Important:world->getCurrentNumKarts() returns
// the number of karts still racing. This value can not be used for loops
// over all karts, use race_manager->getNumKarts() instead!
kart->eliminate();
m_eliminated_karts++;
} // eliminateKart
示例7: endRaceEarly
/** Ends the race early and places still active player karts at the back.
* The race immediately goes to the result stage, estimating the time for the
* karts still in the race. Still active player karts get a penalty in time
* as well as being placed at the back. Players that already finished keep
* their position.
*
* End time for the punished players is calculated as follows
* end_time = current_time + (estimated_time - current_time)
* + (estimated_time_for_last - current_time)
* = estimated_time + estimated_time_for_last - current_time
* This will put them at the end at all times. The further you (and the last in
* the race) are from the finish line, the harsher the punishment will be.
*/
void StandardRace::endRaceEarly()
{
const unsigned int kart_amount = (unsigned int)m_karts.size();
std::vector<int> active_players;
// Required for debugging purposes
beginSetKartPositions();
for (unsigned int i = 1; i <= kart_amount; i++)
{
int kartid = m_position_index[i-1];
AbstractKart* kart = m_karts[kartid];
if (kart->hasFinishedRace())
{
// Have to do this to keep endSetKartPosition happy
setKartPosition(kartid, kart->getPosition());
continue;
}
if (kart->getController()->isPlayerController())
{
// Keep active players apart for now
active_players.push_back(kartid);
}
else
{
// AI karts finish
setKartPosition(kartid, i - (unsigned int) active_players.size());
kart->finishedRace(estimateFinishTimeForKart(kart));
}
} // i <= kart_amount
// Now make the active players finish
for (unsigned int i = 0; i < active_players.size(); i++)
{
int kartid = active_players[i];
int position = getNumKarts() - (int) active_players.size() + 1 + i;
setKartPosition(kartid, position);
m_karts[kartid]->eliminate();
} // Finish the active players
endSetKartPositions();
setPhase(RESULT_DISPLAY_PHASE);
if (!isNetworkWorld() || NetworkConfig::get()->isServer())
terminateRace();
} // endRaceEarly
示例8: newLap
/** Is called by check structures if a kart starts a new lap.
* \param kart_index Index of the kart.
*/
void LinearWorld::newLap(unsigned int kart_index)
{
KartInfo &kart_info = m_kart_info[kart_index];
AbstractKart *kart = m_karts[kart_index];
// Reset reset-after-lap achievements
StateManager::ActivePlayer *c = kart->getController()->getPlayer();
PlayerProfile *p = PlayerManager::getCurrentPlayer();
if (c && c->getConstProfile() == p)
{
p->getAchievementsStatus()->onLapEnd();
}
// Only update the kart controller if a kart that has already finished
// the race crosses the start line again. This avoids 'fastest lap'
// messages if the end controller does a fastest lap, but especially
// allows the end controller to switch end cameras
if(kart->hasFinishedRace())
{
kart->getController()->newLap(kart_info.m_race_lap);
return;
}
const int lap_count = race_manager->getNumLaps();
// Only increase the lap counter and set the new time if the
// kart hasn't already finished the race (otherwise the race_gui
// will begin another countdown).
if(kart_info.m_race_lap+1 <= lap_count)
{
assert(kart->getWorldKartId()==kart_index);
kart_info.m_time_at_last_lap=getTime();
kart_info.m_race_lap++;
m_kart_info[kart_index].m_overall_distance =
m_kart_info[kart_index].m_race_lap * m_track->getTrackLength()
+ getDistanceDownTrackForKart(kart->getWorldKartId());
}
// Last lap message (kart_index's assert in previous block already)
if (raceHasLaps() && kart_info.m_race_lap+1 == lap_count)
{
m_race_gui->addMessage(_("Final lap!"), kart,
3.0f, video::SColor(255, 210, 100, 50), true);
if(!m_last_lap_sfx_played && lap_count > 1)
{
if (UserConfigParams::m_music)
{
m_last_lap_sfx->play();
m_last_lap_sfx_played = true;
m_last_lap_sfx_playing = true;
// In case that no music is defined
if(music_manager->getCurrentMusic() &&
music_manager->getMasterMusicVolume() > 0.2f)
{
music_manager->setTemporaryVolume(0.2f);
}
}
else
{
m_last_lap_sfx_played = true;
m_last_lap_sfx_playing = false;
}
}
}
else if (raceHasLaps() && kart_info.m_race_lap > 0 &&
kart_info.m_race_lap+1 < lap_count)
{
m_race_gui->addMessage(_("Lap %i", kart_info.m_race_lap+1),
kart, 3.0f, video::SColor(255, 210, 100, 50),
true);
}
// The race positions must be updated here: consider the situation where
// the first kart does not cross the finish line in its last lap, instead
// it passes it, the kart reverses and crosses the finishing line
// backwards. Just before crossing the finishing line the kart will be on
// the last lap, but with a distance along the track close to zero.
// Therefore its position will be wrong. If the race position gets updated
// after increasing the number of laps (but before tagging the kart to have
// finished the race) the position will be correct (since the kart now
// has one additional lap it will be ahead of the other karts).
// Without this call the incorrect position for this kart would remain
// (since a kart that has finished the race does not get its position
// changed anymore), potentially resulting in a duplicated race position
// (since the first kart does not have position 1, no other kart can get
// position 1, so one rank will be duplicated).
// Similarly the situation can happen if the distance along track should
// go back to zero before actually crossing the finishing line. While this
// should not happen, it could potentially be caused by floating point
// errors. In this case the call to updateRacePosition will avoid
// duplicated race positions as well.
updateRacePosition();
// Race finished
if(kart_info.m_race_lap >= race_manager->getNumLaps() && raceHasLaps())
{
kart->finishedRace(getTime());
//.........这里部分代码省略.........
示例9: handleContextMenuAction
//.........这里部分代码省略.........
case DEBUG_POWERUP_NITRO:
{
if (!world) return false;
const unsigned int num_local_players =
race_manager->getNumLocalPlayers();
for (unsigned int i = 0; i < num_local_players; i++)
{
AbstractKart* kart = world->getLocalPlayerKart(i);
kart->setEnergy(100.0f);
}
break;
}
case DEBUG_ATTACHMENT_ANVIL:
addAttachment(Attachment::ATTACH_ANVIL);
break;
case DEBUG_ATTACHMENT_BOMB:
addAttachment(Attachment::ATTACH_BOMB);
break;
case DEBUG_ATTACHMENT_PARACHUTE:
addAttachment(Attachment::ATTACH_PARACHUTE);
break;
case DEBUG_GUI_TOGGLE:
{
if (!world) return false;
RaceGUIBase* gui = world->getRaceGUI();
if (gui != NULL) gui->m_enabled = !gui->m_enabled;
break;
}
case DEBUG_GUI_HIDE_KARTS:
if (!world) return false;
for (unsigned int n = 0; n<world->getNumKarts(); n++)
{
AbstractKart* kart = world->getKart(n);
if (kart->getController()->isPlayerController())
kart->getNode()->setVisible(false);
}
break;
case DEBUG_GUI_CAM_TOP:
CameraDebug::setDebugType(CameraDebug::CM_DEBUG_TOP_OF_KART);
Camera::changeCamera(0, Camera::CM_TYPE_DEBUG);
irr_driver->getDevice()->getCursorControl()->setVisible(true);
break;
case DEBUG_GUI_CAM_WHEEL:
CameraDebug::setDebugType(CameraDebug::CM_DEBUG_GROUND);
Camera::changeCamera(0, Camera::CM_TYPE_DEBUG);
irr_driver->getDevice()->getCursorControl()->setVisible(true);
break;
case DEBUG_GUI_CAM_BEHIND_KART:
CameraDebug::setDebugType(CameraDebug::CM_DEBUG_BEHIND_KART);
Camera::changeCamera(0, Camera::CM_TYPE_DEBUG);
irr_driver->getDevice()->getCursorControl()->setVisible(true);
break;
case DEBUG_GUI_CAM_SIDE_OF_KART:
CameraDebug::setDebugType(CameraDebug::CM_DEBUG_SIDE_OF_KART);
Camera::changeCamera(0, Camera::CM_TYPE_DEBUG);
irr_driver->getDevice()->getCursorControl()->setVisible(true);
break;
case DEBUG_GUI_CAM_FREE:
{
Camera *camera = Camera::getActiveCamera();
Camera::changeCamera(camera->getIndex(), Camera::CM_TYPE_FPS);
irr_driver->getDevice()->getCursorControl()->setVisible(false);
// Reset camera rotation
CameraFPS *cam = dynamic_cast<CameraFPS*>(Camera::getActiveCamera());
if(cam)
{
示例10: notifyEvent
// ----------------------------------------------------------------------------
bool GameEventsProtocol::notifyEvent(Event* event)
{
// Avoid crash in case that we still receive race events when
// the race is actually over.
if (event->getType() != EVENT_TYPE_MESSAGE || !World::getWorld())
return true;
NetworkString &data = event->data();
if (data.size() < 1) // for type
{
Log::warn("GameEventsProtocol", "Too short message.");
return true;
}
uint8_t type = data.getUInt8();
CaptureTheFlag* ctf = dynamic_cast<CaptureTheFlag*>(World::getWorld());
FreeForAll* ffa = dynamic_cast<FreeForAll*>(World::getWorld());
SoccerWorld* sw = dynamic_cast<SoccerWorld*>(World::getWorld());
LinearWorld* lw = dynamic_cast<LinearWorld*>(World::getWorld());
switch (type)
{
case GE_KART_FINISHED_RACE:
kartFinishedRace(data); break;
case GE_RESET_BALL:
{
if (!sw)
throw std::invalid_argument("No soccer world");
sw->handleResetBallFromServer(data);
break;
}
case GE_PLAYER_GOAL:
{
if (!sw)
throw std::invalid_argument("No soccer world");
sw->handlePlayerGoalFromServer(data);
break;
}
case GE_BATTLE_KART_SCORE:
{
if (!ffa)
throw std::invalid_argument("No free-for-all world");
ffa->setKartScoreFromServer(data);
break;
}
case GE_CTF_SCORED:
{
if (!ctf)
throw std::invalid_argument("No CTF world");
uint8_t kart_id = data.getUInt8();
bool red_team_scored = data.getUInt8() == 1;
int16_t new_kart_scores = data.getUInt16();
int new_red_scores = data.getUInt8();
int new_blue_scores = data.getUInt8();
ctf->ctfScored(kart_id, red_team_scored, new_kart_scores,
new_red_scores, new_blue_scores);
break;
}
case GE_STARTUP_BOOST:
{
if (NetworkConfig::get()->isServer())
{
uint8_t kart_id = data.getUInt8();
if (!event->getPeer()->availableKartID(kart_id))
{
Log::warn("GameProtocol", "Wrong kart id %d from %s.",
kart_id, event->getPeer()->getAddress().toString().c_str());
return true;
}
float f = LobbyProtocol::get<ServerLobby>()
->getStartupBoostOrPenaltyForKart(
event->getPeer()->getAveragePing(), kart_id);
NetworkString *ns = getNetworkString();
ns->setSynchronous(true);
ns->addUInt8(GE_STARTUP_BOOST).addUInt8(kart_id).addFloat(f);
sendMessageToPeers(ns, true);
delete ns;
}
else
{
uint8_t kart_id = data.getUInt8();
float boost = data.getFloat();
AbstractKart* k = World::getWorld()->getKart(kart_id);
if (boost < 0.0f)
{
PlayerController* pc =
dynamic_cast<PlayerController*>(k->getController());
pc->displayPenaltyWarning();
}
else
k->setStartupBoost(boost);
}
break;
}
case GE_CHECK_LINE:
{
if (!lw)
throw std::invalid_argument("No linear world");
if (NetworkConfig::get()->isClient())
lw->updateCheckLinesClient(data);
break;
}
//.........这里部分代码省略.........
示例11: onEvent
//.........这里部分代码省略.........
{
addPowerup(PowerupManager::POWERUP_PLUNGER);
}
else if (cmdID == DEBUG_POWERUP_RUBBERBALL)
{
addPowerup(PowerupManager::POWERUP_RUBBERBALL);
}
else if (cmdID == DEBUG_POWERUP_SWATTER)
{
addPowerup(PowerupManager::POWERUP_SWATTER);
}
else if (cmdID == DEBUG_POWERUP_SWITCH)
{
addPowerup(PowerupManager::POWERUP_SWITCH);
}
else if (cmdID == DEBUG_POWERUP_ZIPPER)
{
addPowerup(PowerupManager::POWERUP_ZIPPER);
}
else if (cmdID == DEBUG_POWERUP_NITRO)
{
World* world = World::getWorld();
if (world == NULL) return false;
for(unsigned int i = 0; i < race_manager->getNumLocalPlayers(); i++)
{
AbstractKart* kart = world->getLocalPlayerKart(i);
kart->setEnergy(100.0f);
}
}
else if (cmdID == DEBUG_ATTACHMENT_ANVIL)
{
addAttachment(Attachment::ATTACH_ANVIL);
}
else if (cmdID == DEBUG_ATTACHMENT_BOMB)
{
addAttachment(Attachment::ATTACH_BOMB);
}
else if (cmdID == DEBUG_ATTACHMENT_PARACHUTE)
{
addAttachment(Attachment::ATTACH_PARACHUTE);
}
else if (cmdID == DEBUG_TOGGLE_GUI)
{
World* world = World::getWorld();
if (world == NULL) return false;
RaceGUIBase* gui = world->getRaceGUI();
if (gui != NULL) gui->m_enabled = !gui->m_enabled;
}
else if (cmdID == DEBUG_HIDE_KARTS)
{
World* world = World::getWorld();
if (world == NULL) return false;
const int count = World::getWorld()->getNumKarts();
for (int n = 0; n<count; n++)
{
AbstractKart* kart = world->getKart(n);
if (kart->getController()->isPlayerController())
kart->getNode()->setVisible(false);
}
}
else if (cmdID == DEBUG_VISUAL_VALUES)
{
#if !defined(__APPLE__)
DebugSliderDialog *dsd = new DebugSliderDialog();
dsd->setSliderHook( "red_slider", 0, 255, [](){ return irr_driver->getAmbientLight().r * 255.f; },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
ambient.setColorComponentValue(0, v / 255.f);
irr_driver->setAmbientLight(ambient); }
);
dsd->setSliderHook("green_slider", 0, 255, [](){ return irr_driver->getAmbientLight().g * 255.f; },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
ambient.setColorComponentValue(1, v / 255.f);
irr_driver->setAmbientLight(ambient); }
);
dsd->setSliderHook("blue_slider", 0, 255, [](){ return irr_driver->getAmbientLight().b * 255.f; },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
ambient.setColorComponentValue(2, v / 255.f);
irr_driver->setAmbientLight(ambient); }
);
dsd->setSliderHook("ssao_radius", 0, 100, [](){ return irr_driver->getSSAORadius() * 10.f; },
[](int v){irr_driver->setSSAORadius(v / 10.f); }
);
dsd->setSliderHook("ssao_k", 0, 100, [](){ return irr_driver->getSSAOK() * 10.f; },
[](int v){irr_driver->setSSAOK(v / 10.f); }
);
dsd->setSliderHook("ssao_sigma", 0, 100, [](){ return irr_driver->getSSAOSigma() * 10.f; },
[](int v){irr_driver->setSSAOSigma(v / 10.f); }
);
#endif
}
}
return false; // event has been handled
}
}
return true; // continue event handling
}
示例12: dispatchInput
//.........这里部分代码省略.........
}
if (device != NULL)
{
KartSelectionScreen::getInstance()->playerJoin(device,
false );
}
}
return; // we're done here, ignore devices that aren't
// associated with players
}
}
// ... when in-game
if (StateManager::get()->getGameState() == GUIEngine::GAME &&
!GUIEngine::ModalDialog::isADialogActive() )
{
if (player == NULL)
{
// Prevent null pointer crash
return;
}
// Find the corresponding PlayerKart from our ActivePlayer instance
AbstractKart* pk = player->getKart();
if (pk == NULL)
{
std::cerr <<
"Error, trying to process action for an unknown player\n";
return;
}
Controller* controller = pk->getController();
if (controller != NULL) controller->action(action, abs(value));
}
// ... when in menus
else
{
// reset timer when released
if (abs(value) == 0 && type == Input::IT_STICKBUTTON)
{
m_timer_in_use = false;
m_timer = 0;
}
// When in master-only mode, we can safely assume that players
// are set up, contrarly to early menus where we accept every
// input because players are not set-up yet
if (m_master_player_only && player == NULL)
{
if (type == Input::IT_STICKMOTION ||
type == Input::IT_STICKBUTTON)
{
GamePadDevice* gp =
getDeviceList()->getGamePadFromIrrID(deviceID);
if (gp != NULL &&
abs(value)>gp->m_deadzone)
{
//I18N: message shown when an input device is used but
// is not associated to any player
GUIEngine::showMessage(
_("Ignoring '%s', you needed to join earlier to play!",
irr::core::stringw(gp->m_name.c_str()).c_str()) );
示例13: update
//.........这里部分代码省略.........
kart->setSquash(kp->getSquashDuration() * kart->getPlayerDifficulty()->getSquashDuration(),
kp->getSquashSlowdown() * kart->getPlayerDifficulty()->getSquashSlowdown());
}
continue;
}
// now the first object must be a projectile
// =========================================
if(p->getUserPointer(1)->is(UserPointer::UP_TRACK))
{
// Projectile hits track
// ---------------------
p->getUserPointer(0)->getPointerFlyable()->hitTrack();
}
else if(p->getUserPointer(1)->is(UserPointer::UP_PHYSICAL_OBJECT))
{
// Projectile hits physical object
// -------------------------------
Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
Flyable* flyable = p->getUserPointer(0)->getPointerFlyable();
PhysicalObject* obj = p->getUserPointer(1)->getPointerPhysicalObject();
std::string obj_id = obj->getID();
std::string scripting_function = obj->getOnItemCollisionFunction();
if (scripting_function.size() > 0)
{
script_engine->runFunction("void " + scripting_function + "(int, int, const string)",
[&](asIScriptContext* ctx) {
ctx->SetArgDWord(0, (int)flyable->getType());
ctx->SetArgDWord(1, flyable->getOwnerId());
ctx->SetArgObject(2, &obj_id);
});
}
flyable->hit(NULL, obj);
if (obj->isSoccerBall() &&
race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
{
int kartId = p->getUserPointer(0)->getPointerFlyable()->getOwnerId();
SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld();
soccerWorld->setLastKartTohitBall(kartId);
}
}
else if(p->getUserPointer(1)->is(UserPointer::UP_KART))
{
// Projectile hits kart
// --------------------
// Only explode a bowling ball if the target is
// not invulnerable
AbstractKart* target_kart = p->getUserPointer(1)->getPointerKart();
PowerupManager::PowerupType type = p->getUserPointer(0)->getPointerFlyable()->getType();
if(type != PowerupManager::POWERUP_BOWLING || !target_kart->isInvulnerable())
{
Flyable *f = p->getUserPointer(0)->getPointerFlyable();
f->hit(target_kart);
// Check for achievements
AbstractKart * kart = World::getWorld()->getKart(f->getOwnerId());
PlayerController *c = dynamic_cast<PlayerController*>(kart->getController());
// Check that it's not a kart hitting itself (this can
// happen at the time a flyable is shot - release too close
// to the kart, and it's the current player. At this stage
// only the current player can get achievements.
if (target_kart != kart && c &&
c->getPlayer()->getConstProfile() == PlayerManager::getCurrentPlayer())
{
// Compare the current value of hits with the 'hit' goal value
// (otherwise it would be compared with the kart id goal value,
// which doesn't exist.
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_ARCH_ENEMY,
target_kart->getIdent(), 1, "hit");
if (type == PowerupManager::POWERUP_BOWLING)
{
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_STRIKE,
"ball", 1);
} // is bowling ball
} // if target_kart != kart && is a player kart and is current player
}
}
else
{
// Projectile hits projectile
// --------------------------
p->getUserPointer(0)->getPointerFlyable()->hit(NULL);
p->getUserPointer(1)->getPointerFlyable()->hit(NULL);
}
} // for all p in m_all_collisions
m_physics_loop_active = false;
// Now remove the karts that were removed while the above loop
// was active. Now we can safely call removeKart, since the loop
// is finished and m_physics_world_active is not set anymore.
for(unsigned int i=0; i<m_karts_to_delete.size(); i++)
removeKart(m_karts_to_delete[i]);
m_karts_to_delete.clear();
PROFILER_POP_CPU_MARKER();
} // update
示例14: update
//.........这里部分代码省略.........
if (kart->setSquash(kp->getSwatterSquashDuration(),
kp->getSwatterSquashSlowdown()) && !was_squashed)
{
World::getWorld()->kartHit(kart->getWorldKartId());
}
}
continue;
}
// now the first object must be a projectile
// =========================================
if(p->getUserPointer(1)->is(UserPointer::UP_TRACK))
{
// Projectile hits track
// ---------------------
p->getUserPointer(0)->getPointerFlyable()->hitTrack();
}
else if(p->getUserPointer(1)->is(UserPointer::UP_PHYSICAL_OBJECT))
{
// Projectile hits physical object
// -------------------------------
Scripting::ScriptEngine* script_engine = Scripting::ScriptEngine::getInstance();
Flyable* flyable = p->getUserPointer(0)->getPointerFlyable();
PhysicalObject* obj = p->getUserPointer(1)->getPointerPhysicalObject();
std::string obj_id = obj->getID();
std::string scripting_function = obj->getOnItemCollisionFunction();
if (scripting_function.size() > 0)
{
script_engine->runFunction(true, "void " + scripting_function + "(int, int, const string)",
[&](asIScriptContext* ctx) {
ctx->SetArgDWord(0, (int)flyable->getType());
ctx->SetArgDWord(1, flyable->getOwnerId());
ctx->SetArgObject(2, &obj_id);
});
}
flyable->hit(NULL, obj);
if (obj->isSoccerBall() &&
race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
{
int kartId = p->getUserPointer(0)->getPointerFlyable()->getOwnerId();
SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld();
soccerWorld->setBallHitter(kartId);
}
}
else if(p->getUserPointer(1)->is(UserPointer::UP_KART))
{
// Projectile hits kart
// --------------------
// Only explode a bowling ball if the target is
// not invulnerable
AbstractKart* target_kart = p->getUserPointer(1)->getPointerKart();
PowerupManager::PowerupType type = p->getUserPointer(0)->getPointerFlyable()->getType();
if(type != PowerupManager::POWERUP_BOWLING || !target_kart->isInvulnerable())
{
Flyable *f = p->getUserPointer(0)->getPointerFlyable();
f->hit(target_kart);
// Check for achievements
AbstractKart * kart = World::getWorld()->getKart(f->getOwnerId());
LocalPlayerController *lpc =
dynamic_cast<LocalPlayerController*>(kart->getController());
// Check that it's not a kart hitting itself (this can
// happen at the time a flyable is shot - release too close
// to the kart, and it's the current player. At this stage
// only the current player can get achievements.
if (target_kart != kart && lpc && lpc->canGetAchievements())
{
if (type == PowerupManager::POWERUP_BOWLING)
{
PlayerManager::increaseAchievement(AchievementsStatus::BOWLING_HIT, 1);
if (race_manager->isLinearRaceMode())
PlayerManager::increaseAchievement(AchievementsStatus::BOWLING_HIT_1RACE, 1);
} // is bowling ball
} // if target_kart != kart && is a player kart and is current player
}
}
else
{
// Projectile hits projectile
// --------------------------
p->getUserPointer(0)->getPointerFlyable()->hit(NULL);
p->getUserPointer(1)->getPointerFlyable()->hit(NULL);
}
} // for all p in m_all_collisions
m_physics_loop_active = false;
// Now remove the karts that were removed while the above loop
// was active. Now we can safely call removeKart, since the loop
// is finished and m_physics_world_active is not set anymore.
for(unsigned int i=0; i<m_karts_to_delete.size(); i++)
removeKart(m_karts_to_delete[i]);
m_karts_to_delete.clear();
PROFILER_POP_CPU_MARKER();
} // update
示例15: drawGlobalPlayerIcons
//.........这里部分代码省略.........
pos_top.UpperLeftCorner.X = x_base;
static video::SColor color = video::SColor(255, 255, 255, 255);
pos_top.LowerRightCorner = pos_top.UpperLeftCorner;
font->draw(StringUtils::insertValues( m_string_top, position-1 ), pos_top, color);
break;
}
if (m_kart_display_infos[kart_id].m_text.size() > 0)
{
core::rect<s32> pos(x+ICON_PLAYER_WIDTH, y+5,
x+ICON_PLAYER_WIDTH, y+5);
core::stringw s=info.m_text.c_str();
font->draw(s.c_str(), pos, info.m_color, false, false, NULL,
true /* ignore RTL */);
}
if (info.special_title.size() > 0)
{
core::rect<s32> pos(x+ICON_PLAYER_WIDTH, y+5,
x+ICON_PLAYER_WIDTH, y+5);
core::stringw s(info.special_title.c_str());
font->draw(s.c_str(), pos, info.m_color, false, false, NULL,
true /* ignore RTL */);
}
// draw icon
video::ITexture *icon =
kart->getKartProperties()->getIconMaterial()->getTexture();
int w =
kart->getController()->isPlayerController() ? ICON_PLAYER_WIDTH
: ICON_WIDTH;
const core::rect<s32> pos(x, y, x+w, y+w);
//to bring to light the player's icon: add a background
if (kart->getController()->isPlayerController())
{
video::SColor colors[4];
for (unsigned int i=0;i<4;i++)
{
colors[i]=kart->getKartProperties()->getColor();
colors[i].setAlpha(
100+(int)(100*cos(M_PI/2*i+World::getWorld()->getTime()*2)));
}
const core::rect<s32> rect(core::position2d<s32>(0,0),
m_icons_frame->getTexture()->getOriginalSize());
draw2DImage(
m_icons_frame->getTexture(), pos, rect,NULL, colors, true);
}
// Fixes crash bug, why are certain icons not showing up?
if (icon && !kart->getKartAnimation() && !kart->isSquashed())
{
const core::rect<s32> rect(core::position2d<s32>(0,0),
icon->getOriginalSize());
draw2DImage(icon, pos, rect,
NULL, NULL, true);
}
//draw status info - icon fade out in case of rescue/explode
if (icon && dynamic_cast<RescueAnimation*>(kart->getKartAnimation()))
{