本文整理汇总了C++中Being::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Being::setPosition方法的具体用法?C++ Being::setPosition怎么用?C++ Being::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Being
的用法示例。
在下文中一共展示了Being::setPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleBeingEnterMessage
void BeingHandler::handleBeingEnterMessage(Net::MessageIn &msg)
{
int type = msg.readInt8();
int id = msg.readInt16();
Being::Action action = (Being::Action)msg.readInt8();
int px = msg.readInt16();
int py = msg.readInt16();
BeingDirection direction = (BeingDirection)msg.readInt8();
Being *being;
if (!Game::instance()->getCurrentMap()->containsPixel(px, py))
{
logger->log("Warning: Received GPMSG_BEING_ENTER for being id %i "
"with position outside the map boundaries "
"(x = %i, y = %i)", id, px, py);
return;
}
switch (type)
{
case OBJECT_CHARACTER:
{
std::string name = msg.readString();
if (player_node->getName() == name)
{
being = player_node;
being->setId(id);
}
else
{
being = actorSpriteManager->createBeing(id,
ActorSprite::PLAYER, 0);
being->setName(name);
}
int hs = msg.readInt8(), hc = msg.readInt8();
being->setSprite(SPRITE_HAIR, hs * -1, ColorDB::get(hc));
being->setGender(msg.readInt8() == GENDER_MALE ?
GENDER_MALE : GENDER_FEMALE);
handleLooks(being, msg);
} break;
case OBJECT_MONSTER:
case OBJECT_NPC:
{
int subtype = msg.readInt16();
being = actorSpriteManager->createBeing(id, type == OBJECT_MONSTER
? ActorSprite::MONSTER : ActorSprite::NPC, subtype);
std::string name = msg.readString();
if (name.length() > 0) being->setName(name);
} break;
default:
return;
}
being->setPosition(px, py);
being->setDestination(px, py);
being->setDirection(direction);
being->setAction(action);
}
示例2: spawn
static void spawn(Character *from, MonsterClass *specy, int nb)
{
MapComposite *map = from->getMap();
const Point &pos = from->getPosition();
for (int i = 0; i < nb; ++i)
{
Being *monster = new Monster(specy);
monster->setMap(map);
monster->setPosition(pos);
monster->clearDestination();
if (!GameState::insertSafe(monster))
{
// The map is full. Break out.
break;
}
}
}
示例3: handleSpawn
static void handleSpawn(Character *player, std::string &args)
{
MonsterClass *mc;
MapComposite *map = player->getMap();
const Point &pos = player->getPosition();
int value = 0;
// get the arguments
std::string monsterclass = getArgument(args);
std::string valuestr = getArgument(args);
// check all arguments are there
if (monsterclass.empty())
{
say("Invalid amount of arguments given.", player);
say("Usage: @spawn <monster> [number]", player);
return;
}
// identify the monster type
if (utils::isNumeric(monsterclass))
{
int id = utils::stringToInt(monsterclass);
mc = monsterManager->getMonster(id);
}
else
{
mc = monsterManager->getMonsterByName(monsterclass);
}
// check for valid monster
if (!mc)
{
say("Invalid monster", player);
return;
}
//identify the amount
if (valuestr.empty())
{
value = 1;
}
else if (utils::isNumeric(valuestr))
{
value = utils::stringToInt(valuestr);
}
// check for valid amount
if (value <= 0)
{
say("Invalid number of monsters", player);
return;
}
// create the monsters and put them on the map
for (int i = 0; i < value; ++i)
{
Being *monster = new Monster(mc);
monster->setMap(map);
monster->setPosition(pos);
monster->clearDestination();
if (!GameState::insertOrDelete(monster))
{
// The map is full. Break out.
break;
}
// log transaction
std::string msg = "User created monster " + monster->getName();
accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_SPAWN, msg);
}
}
示例4: handleBeingsMoveMessage
void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg)
{
while (msg.getUnreadLength())
{
int id = msg.readInt16();
int flags = msg.readInt8();
Being *being = actorSpriteManager->findBeing(id);
int sx = 0, sy = 0, dx = 0, dy = 0, speed = 0;
if ((!flags & (MOVING_POSITION | MOVING_DESTINATION)))
continue;
if (flags & MOVING_POSITION)
{
sx = msg.readInt16();
sy = msg.readInt16();
}
if (flags & MOVING_DESTINATION)
{
dx = msg.readInt16();
dy = msg.readInt16();
speed = msg.readInt8();
}
if (!being)
continue;
if (speed)
{
/*
* The being's speed is transfered in tiles per second * 10
* to keep it transferable in a Byte.
* We set it back to tiles per second and in a float.
*/
float speedTilesSeconds = (float) speed / 10;
being->setMoveSpeed(Vector(speedTilesSeconds, speedTilesSeconds,
0));
}
// Ignore messages from the server for the local player
if (being == player_node)
continue;
// If the position differs too much from the actual one, we resync
// the being position
if (flags & MOVING_POSITION)
{
if (!being->getMap()->containsPixel(sx, sy))
{
logger->log("Warning: Received GPMSG_BEINGS_MOVE for being id "
"%i with position outside the map boundaries "
"(x = %i, y = %i)", id, sx, sy);
continue;
}
Vector serverPos(sx, sy);
if (serverPos.length()
- being->getPosition().length() > POSITION_DIFF_TOLERANCE)
being->setPosition(serverPos);
}
if (flags & MOVING_DESTINATION)
{
if (!being->getMap()->containsPixel(dx, dy))
{
logger->log("Warning: Received GPMSG_BEINGS_MOVE for being id "
"%i with destination outside the map boundaries "
"(x = %i, y = %i)", id, dx, dy);
continue;
}
being->setDestination(dx, dy);
}
}
}