本文整理汇总了C++中PhysicalObject::GetEventIdWhenTalking方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicalObject::GetEventIdWhenTalking方法的具体用法?C++ PhysicalObject::GetEventIdWhenTalking怎么用?C++ PhysicalObject::GetEventIdWhenTalking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicalObject
的用法示例。
在下文中一共展示了PhysicalObject::GetEventIdWhenTalking方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _UpdateExplore
void MapMode::_UpdateExplore()
{
// First go to menu mode if the user requested it
if(_menu_enabled && InputManager->MenuPress()) {
MenuMode *MM = new MenuMode();
ModeManager->Push(MM);
return;
}
// Only update the status effect supervisor in Exploration mode
// and if they are allowed.
if (_status_effects_enabled)
_status_effect_supervisor.UpdateEffects();
// Update the running state of the camera object. Check if the character is running and if so,
// update the stamina value if the operation is permitted
_camera->is_running = false;
if(_camera->moved_position && !_running_disabled && InputManager->CancelState() &&
(InputManager->UpState() || InputManager->DownState() || InputManager->LeftState() || InputManager->RightState())) {
if(_unlimited_stamina) {
_camera->is_running = true;
} else if(_run_stamina > SystemManager->GetUpdateTime() * 2) {
_run_stamina -= (SystemManager->GetUpdateTime() * 2);
_camera->is_running = true;
} else {
_run_stamina = 0;
}
}
// Regenerate the stamina at 1/2 the consumption rate
else if(_run_stamina < 10000) {
_run_stamina += SystemManager->GetUpdateTime();
if(_run_stamina > 10000)
_run_stamina = 10000;
}
// If the user requested a confirm event, check if there is a nearby object that the player may interact with
// Interactions are currently limited to dialogue with sprites and opening of treasures
if(InputManager->ConfirmPress()) {
MapObject *obj = _object_supervisor->FindNearestInteractionObject(_camera);
if(obj != NULL) {
if(obj->GetType() == PHYSICAL_TYPE) {
PhysicalObject *phs = reinterpret_cast<PhysicalObject *>(obj);
if(!phs->GetEventIdWhenTalking().empty()) {
_camera->moving = false;
_camera->is_running = false;
if (!_event_supervisor->IsEventActive(phs->GetEventIdWhenTalking()))
_event_supervisor->StartEvent(phs->GetEventIdWhenTalking());
return;
}
}
else if(obj->GetType() == SPRITE_TYPE) {
MapSprite *sp = reinterpret_cast<MapSprite *>(obj);
if(sp->HasAvailableDialogue()) {
_camera->moving = false;
_camera->is_running = false;
sp->InitiateDialogue();
return;
}
} else if(obj->GetType() == TREASURE_TYPE) {
TreasureObject *treasure_object = reinterpret_cast<TreasureObject *>(obj);
if(!treasure_object->GetTreasure()->IsTaken()) {
_camera->moving = false;
treasure_object->Open();
}
} else if(obj->GetType() == SAVE_TYPE && _save_points_enabled) {
// Make sure the character will be centered in the save point
SaveMode *save_mode = new SaveMode(true, obj->GetXPosition(), obj->GetYPosition() - 1.0f);
ModeManager->Push(save_mode, false, false);
}
}
}
// Detect movement input from the user
if(InputManager->UpState() || InputManager->DownState() || InputManager->LeftState() || InputManager->RightState()) {
_camera->moving = true;
} else {
_camera->moving = false;
}
// Determine the direction of movement. Priority of movement is given to: up, down, left, right.
// In the case of diagonal movement, the direction that the sprite should face also needs to be deduced.
if(_camera->moving == true) {
if(InputManager->UpState()) {
if(InputManager->LeftState())
_camera->SetDirection(MOVING_NORTHWEST);
else if(InputManager->RightState())
_camera->SetDirection(MOVING_NORTHEAST);
else
_camera->SetDirection(NORTH);
} else if(InputManager->DownState()) {
if(InputManager->LeftState())
_camera->SetDirection(MOVING_SOUTHWEST);
else if(InputManager->RightState())
_camera->SetDirection(MOVING_SOUTHEAST);
else
_camera->SetDirection(SOUTH);
//.........这里部分代码省略.........
示例2: _SetNextPosition
void VirtualSprite::_SetNextPosition()
{
// Next sprite's position holders
float next_pos_x = GetXPosition();
float next_pos_y = GetYPosition();
float distance_moved = CalculateDistanceMoved();
// Move the sprite the appropriate distance in the appropriate Y and X direction
if(_direction & (NORTH | MOVING_NORTHWEST | MOVING_NORTHEAST))
next_pos_y -= distance_moved;
else if(_direction & (SOUTH | MOVING_SOUTHWEST | MOVING_SOUTHEAST))
next_pos_y += distance_moved;
if(_direction & (WEST | MOVING_NORTHWEST | MOVING_SOUTHWEST))
next_pos_x -= distance_moved;
else if(_direction & (EAST | MOVING_NORTHEAST | MOVING_SOUTHEAST))
next_pos_x += distance_moved;
// When not moving, do not check anything else.
if(next_pos_x == GetXPosition() && next_pos_y == GetYPosition())
return;
// We've got the next position, let's check whether the next position
// should be revised.
// Used to know whether we could fall back to a straight move
// in case of collision.
bool moving_diagonally = (_direction & (MOVING_NORTHWEST | MOVING_NORTHEAST
| MOVING_SOUTHEAST | MOVING_SOUTHWEST));
// Handle collision with the first object encountered
MapObject* collision_object = nullptr;
MapMode* map_mode = MapMode::CurrentInstance();
ObjectSupervisor* object_supervisor = map_mode->GetObjectSupervisor();
COLLISION_TYPE collision_type = object_supervisor->DetectCollision(this, next_pos_x,
next_pos_y,
&collision_object);
// Try to fall back to straight direction
if(moving_diagonally && collision_type != NO_COLLISION) {
// Try on x axis
if(object_supervisor->DetectCollision(this, _tile_position.x, next_pos_y, &collision_object) == NO_COLLISION) {
next_pos_x = _tile_position.x;
collision_type = NO_COLLISION;
} // and then on y axis
else if(object_supervisor->DetectCollision(this, next_pos_x, _tile_position.y, &collision_object) == NO_COLLISION) {
next_pos_y = _tile_position.y;
collision_type = NO_COLLISION;
}
}
// Handles special collision handling first
if(_control_event) {
switch(_control_event->GetEventType()) {
// Don't stuck the player's character or a sprite being controlled by a prepared path.
// Plus, it's better not to change a path with encountered beings once started
// for simplification purpose.
case PATH_MOVE_SPRITE_EVENT:
collision_type = NO_COLLISION;
break;
// Change the direction whenever something blocking is in the way.
case RANDOM_MOVE_SPRITE_EVENT:
if(collision_type != NO_COLLISION) {
SetRandomDirection();
return;
}
default:
break;
}
}
// Try to handle wall and physical collisions after a failed straight or diagonal move
switch(collision_type) {
case NO_COLLISION:
default:
break;
case WALL_COLLISION:
// When being blocked and moving diagonally, the npc is stuck.
if(moving_diagonally)
return;
// Don't consider physical objects with an event to avoid sliding on their edges,
// making them harder to "talk with".
if (collision_object && this == map_mode->GetCamera()) {
PhysicalObject *phs = reinterpret_cast<PhysicalObject *>(collision_object);
if(phs && !phs->GetEventIdWhenTalking().empty())
return;
}
// Fix the direction and destination to walk-around obstacles
if (_HandleWallEdges(next_pos_x, next_pos_y, distance_moved, collision_object))
break;
// We don't do any other checks for the player sprite.
else if (this == map_mode->GetCamera())
return;
// NPC sprites:
// When it's a true wall, try against the collision grid
if(!collision_object) {
// Try a random diagonal to avoid the wall in straight direction
//.........这里部分代码省略.........