本文整理汇总了C++中MovingObject类的典型用法代码示例。如果您正苦于以下问题:C++ MovingObject类的具体用法?C++ MovingObject怎么用?C++ MovingObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MovingObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DetectCollisionWithObj
CollisionDirection CollisionHandler::DetectCollisionWithObj(MovingObject& _obj, DisplayableObject& _ref)
{
if (_obj.GetID() == _ref.GetID())
return NO_COL;
return DetectCollisionWithRect(_obj.GetCoordinates(), _ref.GetCoordinates());
}
示例2:
void
FlipLevelTransformer::transform_moving_object(float height, MovingObject& object)
{
Vector pos = object.get_pos();
pos.y = height - pos.y - object.get_bbox().get_height();
object.set_pos(pos);
}
示例3: color
void
Sector::draw(DrawingContext& context)
{
context.set_ambient_color( ambient_light );
context.push_transform();
context.set_translation(camera->get_translation());
for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
GameObjectPtr& object = *i;
if(!object->is_valid())
continue;
if (draw_solids_only)
{
TileMap* tm = dynamic_cast<TileMap*>(object.get());
if (tm && !tm->is_solid())
continue;
}
object->draw(context);
}
if(show_collrects) {
Color color(1.0f, 0.0f, 0.0f, 0.75f);
for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
MovingObject* object = *i;
const Rectf& rect = object->get_bbox();
context.draw_filled_rect(rect, color, LAYER_FOREGROUND1 + 10);
}
}
context.pop_transform();
}
示例4: try_break
HitResponse
Brick::collision(GameObject& other, const CollisionHit& hit_){
Player* player = dynamic_cast<Player*> (&other);
if (player) {
if (player->does_buttjump) try_break(player);
if (player->is_stone() && player->get_velocity().y >= 280) try_break(player); // stoneform breaks through bricks
}
BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
if(badguy) {
// hit contains no information for collisions with blocks.
// Badguy's bottom has to be below the top of the brick
// SHIFT_DELTA is required to slide over one tile gaps.
if( badguy->can_break() && ( badguy->get_bbox().get_bottom() > bbox.get_top() + SHIFT_DELTA ) ){
try_break(player);
}
}
Portable* portable = dynamic_cast<Portable*> (&other);
if(portable) {
MovingObject* moving = dynamic_cast<MovingObject*> (&other);
if(moving->get_bbox().get_top() > bbox.get_bottom() - SHIFT_DELTA) {
try_break(player);
}
}
Explosion* explosion = dynamic_cast<Explosion*> (&other);
if(explosion && explosion->hurts()) {
try_break(player);
}
IceCrusher* icecrusher = dynamic_cast<IceCrusher*> (&other);
if(icecrusher && coin_counter == 0)
try_break(player);
return Block::collision(other, hit_);
}
示例5: try_drop
HitResponse
BonusBlock::collision(GameObject& other, const CollisionHit& hit_){
Player* player = dynamic_cast<Player*> (&other);
if (player) {
if (player->does_buttjump)
try_drop(player);
}
BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
if(badguy) {
// hit contains no information for collisions with blocks.
// Badguy's bottom has to be below the top of the block
// SHIFT_DELTA is required to slide over one tile gaps.
if( badguy->can_break() && ( badguy->get_bbox().get_bottom() > bbox.get_top() + SHIFT_DELTA ) ){
try_open(player);
}
}
Portable* portable = dynamic_cast<Portable*> (&other);
if(portable) {
MovingObject* moving = dynamic_cast<MovingObject*> (&other);
if(moving->get_bbox().get_top() > bbox.get_bottom() - SHIFT_DELTA) {
try_open(player);
}
}
return Block::collision(other, hit_);
}
示例6: switch
bool
MrIceBlock::collision_squished(GameObject& object)
{
switch(ice_state) {
case ICESTATE_KICKED:
case ICESTATE_NORMAL:
squishcount++;
if(squishcount >= MAXSQUISHES) {
kill_fall();
return true;
}
set_state(ICESTATE_FLAT);
nokick_timer.start(NOKICK_TIME);
break;
case ICESTATE_FLAT:
{
MovingObject* movingobject = dynamic_cast<MovingObject*>(&object);
if (movingobject && (movingobject->get_pos().x < get_pos().x)) {
dir = RIGHT;
} else {
dir = LEFT;
}
}
if (nokick_timer.check()) set_state(ICESTATE_KICKED);
break;
case ICESTATE_GRABBED:
assert(false);
break;
}
Player* player = dynamic_cast<Player*>(&object);
if (player) player->bounce(*this);
return true;
}
示例7: onEvent
void NewCharacterReadListener::onEvent(const std::string &_eventType, Event* _event)
{
MovingObject *character = _event->GetMovingObject();
if (character->GetName() == "Mario")
m_gameEngine->SetMarioInitialPosition(character->GetPosition());
m_gameEngine->AddCharacterToArray(character);
m_gameEngine->AddForegroundItemToArray(character);
}
示例8: UpdateCharacterPosition
void GameEngine::UpdateCharacterPosition(MovingObject& _character, float _dt)
{
unsigned int id = _character.GetID();
_character.UpdatePosition(_dt);
sf::Vector2f pos = _character.GetPosition();
m_listForegroundItems[id]->SetX(pos.x);
m_listForegroundItems[id]->SetY(pos.y);
}
示例9: ReactToCollisionsWithObj
void CollisionHandler::ReactToCollisionsWithObj(MovingObject& _obj, DisplayableObject& _ref, CollisionDirection _direction)
{
ReactToCollision(_obj, _ref.GetCoordinates(), _direction);
_obj.UpdateAfterCollision(Util::OppositeCollisionDirection(_direction), _ref.GetClass()); // Updates the state of the object, not its coordinates
_obj.SetPosition(m_gameEngine->GetCoordinatesOfForegroundItem(_obj.GetID()));
_ref.UpdateAfterCollision(_direction, _obj.GetClass());
SendNewObjectPositionToGFX(_ref);
}
示例10: getInput
void Game::getInput()
{
m_player->doSomething();
for (list<MovingObject*>::iterator it = m_movingobjects.begin(); it != m_movingobjects.end(); it++)
{
MovingObject* current = *it;
current->doSomething();
if (m_reset)
return;
}
}
示例11: kill_fall
bool
MrIceBlock::collision_squished(GameObject& object)
{
Player* player = dynamic_cast<Player*>(&object);
if(player && (player->does_buttjump || player->is_invincible())) {
player->bounce(*this);
kill_fall();
return true;
}
switch(ice_state) {
case ICESTATE_KICKED:
{
BadGuy* badguy = dynamic_cast<BadGuy*>(&object);
if (badguy) {
badguy->kill_fall();
break;
}
}
// fall through
case ICESTATE_NORMAL:
{
squishcount++;
if (squishcount >= MAXSQUISHES) {
kill_fall();
return true;
}
}
set_state(ICESTATE_FLAT);
nokick_timer.start(NOKICK_TIME);
break;
case ICESTATE_FLAT:
{
MovingObject* movingobject = dynamic_cast<MovingObject*>(&object);
if (movingobject && (movingobject->get_pos().x < get_pos().x)) {
dir = RIGHT;
} else {
dir = LEFT;
}
}
if (nokick_timer.check()) set_state(ICESTATE_KICKED);
break;
case ICESTATE_GRABBED:
assert(false);
break;
}
if (player) player->bounce(*this);
return true;
}
示例12: kill_fall
bool
Snail::collision_squished(GameObject& object)
{
if (m_frozen)
return WalkingBadguy::collision_squished(object);
Player* player = dynamic_cast<Player*>(&object);
if (player && (player->m_does_buttjump || player->is_invincible())) {
kill_fall();
player->bounce(*this);
return true;
}
switch (state) {
case STATE_KICKED:
case STATE_NORMAL:
// Can't stomp in midair
if (!on_ground())
break;
squishcount++;
if (squishcount >= MAX_SNAIL_SQUISHES) {
kill_fall();
return true;
}
SoundManager::current()->play("sounds/stomp.wav", get_pos());
be_flat();
break;
case STATE_FLAT:
SoundManager::current()->play("sounds/kick.wav", get_pos());
{
MovingObject* movingobject = dynamic_cast<MovingObject*>(&object);
if (movingobject && (movingobject->get_pos().x < get_pos().x)) {
m_dir = Direction::RIGHT;
} else {
m_dir = Direction::LEFT;
}
}
be_kicked();
break;
case STATE_GRABBED:
case STATE_KICKED_DELAY:
break;
}
if (player) player->bounce(*this);
return true;
}
示例13: getMovingObject
void Row::addMovingObjects(std::string type, int distanceBetween, int num ){
MovingObject* first = getMovingObject(type);
distanceBetweenMovingObjects = distanceBetween;
float x = first->getX();
int width = first->getWidth();
movingObjects.push_back(first);
for(int i =1; i < num; i++){
x -= (distanceBetween + width);
MovingObject* entry = getMovingObject(type);
entry->setX(x);
movingObjects.push_back(entry);
}
}
示例14: evade
Vector4 SteeringBehavior::evade(Handle &p_pursuer_handle){
IHasHandle* tmp;
MovingObject* pursuer;
Vector4 toPursuer;
float look_ahead_time;
tmp = theWorld.get(p_pursuer_handle);
if (pursuer = dynamic_cast<MovingObject*>(tmp)){
toPursuer = pursuer->getPosition() - owner->getPosition();
look_ahead_time = toPursuer.length() / (owner->getMaxSpeed() + pursuer->getSpeed());
return flee(pursuer->getPosition() + pursuer->getVelocity() * look_ahead_time);
}
else {
off(BehaviorType::evade);
}
return Vector4();
}
示例15: SendCharacterPosition
// Broadcast character's position
void GameEngine::SendCharacterPosition(int _indexCharacter)
{
MovingObject *character = m_characters[_indexCharacter];
if (character == NULL || character->IsDead())
return;
InfoForDisplay info = character->GetInfoForDisplay();
Event posInfo(&info);
m_eventEngine->dispatch(CHAR_POS_UPDATED, &posInfo);
#ifdef DEBUG_MODE
if (_indexCharacter == m_indexMario)
{
*m_debugInfo = character->GetDebugInfo();
Event debugInfo(m_debugInfo);
m_eventEngine->dispatch(DEBUG_INFO_UPDATED, &debugInfo);
}
#endif
}