コード例 #1
0
ファイル: creatures.cpp プロジェクト: Anastaciaa/otclient-1
void Spawn::save(TiXmlElement* node)
{
    const Position& c = getCenterPos();
    node->SetAttribute("centerx", c.x);
    node->SetAttribute("centery", c.y);
    node->SetAttribute("centerz", c.z);

    node->SetAttribute("radius", getRadius());

    TiXmlElement* creatureNode = nullptr;

    for(const auto& pair : m_creatures) {
        const CreatureTypePtr& creature = pair.second;
        if(!(creatureNode = new TiXmlElement(creature->getRace() == CreatureRaceNpc ? "npc" : "monster")))
            stdext::throw_exception("Spawn::save: Ran out of memory while allocating XML element!  Terminating now.");

        creatureNode->SetAttribute("name", creature->getName());
        creatureNode->SetAttribute("spawntime", creature->getSpawnTime());
        creatureNode->SetAttribute("direction", creature->getDirection());

        const Position& placePos = pair.first;
        assert(placePos.isValid());

        creatureNode->SetAttribute("x", placePos.x - c.x);
        creatureNode->SetAttribute("y", placePos.y - c.y);
        creatureNode->SetAttribute("z", placePos.z);

        node->LinkEndChild(creatureNode);
    }
}
コード例 #2
0
ファイル: fighter.cpp プロジェクト: rotonlin/Fighter
void LCBattleScene::createHero() {
    hero = ObjHero::create(backGround, getCenterPos());
    hero->retain();
    //hero->setActiveRange(backGround->getContentSize());
    hero->actionStand();

    hero->getrootObj()->setTag(ETagHero);
}
コード例 #3
0
ファイル: FocusNode.cpp プロジェクト: Pinkof/rpgskyengine
void CFocusNode::setCenterPos(const Vec3D& vPos)
{
	Vec3D vMidPos = getCenterPos();
	FOR_IN(LIST_RENDER_NODE,it,m_mapChildObj)
	{
		Vec3D vObjectPos = (*it)->getPos();
		vObjectPos+=vPos-vMidPos;
		(*it)->setPos(vObjectPos);
		//updateMapObj((*it));
	}
コード例 #4
0
ファイル: missile.cpp プロジェクト: farnyser/towerdefense
Missile::Missile(lo21* g, QList< QPixmap > p, int interval, int agtype, QPointF pos, float velocity, float force, const Enemy *target)
:Object(g, p, interval),
force(force),
velocity(velocity),
target(target),
agtype(agtype)
{
	this->setScale(1.5);
	this->setPos(pos-getCenterPos());
}
コード例 #5
0
ファイル: creatures.cpp プロジェクト: Anastaciaa/otclient-1
void Spawn::addCreature(const Position& placePos, const CreatureTypePtr& cType)
{
    const Position& centerPos = getCenterPos();
    int m_radius = getRadius();
    if(!isInZone(placePos, centerPos, m_radius)) {
        g_logger.warning(stdext::format("cannot place creature at %s (spawn's center position: %s, spawn radius: %d) (increment radius)",
                                               stdext::to_string(placePos), stdext::to_string(centerPos),
                                               m_radius
                                              ));
        return;
    }

    g_map.addThing(cType->cast(), placePos, 4);
    m_creatures.insert(std::make_pair(placePos, cType));
}
コード例 #6
0
ファイル: enemy.cpp プロジェクト: farnyser/towerdefense
Enemy::Enemy(lo21* game, int arg_size, QList<QPixmap> pixmaps, int interval)
 : 
  Object(game, pixmaps, interval), 
  size(arg_size),
  scale(0.1 + arg_size / 20.0),
  wantedRotation(0)
{
	// resize
	setScale(scale);

	// remember current vector
	this->lastVector = game->getStart()->getVector().second - game->getStart()->getVector().first;

	// compute rotation
	qreal angle = 90 - std::atan(lastVector.x() / lastVector.y()) * 360.0 / (2*3.14957);
	
	// set initial orientation
	this->setRotation(angle);

	// set position to the middle of the start tile
	this->setPos(game->getStart()->getCenterPos() - getCenterPos());
}
コード例 #7
0
ファイル: Action.cpp プロジェクト: uvbs/GameProject
	void CircleMove::update( Object& obj , long time )
	{
		float len = m_speed * time / 1000.0f;
		Vec2D dir = getCenterPos( obj ) - org;
		float d   =  sqrtf( dir.length2() );

		if ( d < 0.001 )
			return;

		if( fabs( radius - d ) > len )
		{
			if ( d > radius )
			{
				obj.setVelocity( (-len / d)* dir );
				return;
			}
			else
			{
				obj.setVelocity( (len / d) * dir );
				return;
			}
		}

		float cos_ = ( radius*radius + d*d - len*len ) / ( 2 * radius * d );
		if ( fabs( cos_ ) > 1 )
			return;

		float theta = acos( cos_ );
		Vec2D rDir = ( radius / d ) * dir;
		Vec2D dotDir( -rDir.y , rDir.x );
		if ( !isClockwise )
			dotDir = - dotDir;
		Vec2D outSpeed = ( cos( theta )* rDir)  + ( sin( theta ) * dotDir) - dir;

		obj.setVelocity( outSpeed );
	}
コード例 #8
0
void PlayableEmotion::render() {
    GameObject::render();

    Vec2 pos = getCenterPos() + center_LT_displacement - Camera::getPos(1);

    switch (currentState) {
        case PlayableState::RUNNING:
            spriteRunning.render((int) pos.x, (int) pos.y, rotation,
                                 (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::GETTING_TO_RUN:
            spriteGettingToRun.render((int) pos.x, (int) pos.y, rotation,
                                      (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::IDLE:
            spriteIdle.render((int) pos.x, (int) pos.y, rotation,
                              (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::IDLE_JUMP_START:
            spriteIdleJumpStart.render((int) pos.x, (int) pos.y, rotation,
                                       (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::IDLE_JUMP_JUMPING:
            spriteIdleJumpJumping.render((int) pos.x, (int) pos.y, rotation,
                                         (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL
                                                                                   : SDL_FLIP_NONE);
            break;
        case PlayableState::JUMP_END:
            spriteJumpEnd.render((int) pos.x, (int) pos.y, rotation,
                                 (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::RUNNING_JUMP_START:
            spriteRunningJumpStartJump.render((int) pos.x, (int) pos.y, rotation,
                                              (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL
                                                                                        : SDL_FLIP_NONE);
            break;
        case PlayableState::RUNNING_JUMP_JUMPING:
            spriteRunningJumpJumping.render((int) pos.x, (int) pos.y, rotation,
                                            (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL
                                                                                      : SDL_FLIP_NONE);
            break;
        case PlayableState::RUNNING_JUMP_END:
            spriteJumpEnd.render((int) pos.x, (int) pos.y, rotation,
                                 (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::STOPING_RUN:
            spriteStopingRun.render((int) pos.x, (int) pos.y, rotation,
                                    (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::TURNING:
            spriteTurning.render((int) pos.x, (int) pos.y, rotation,
                                 (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::TURN_RUN:
            spriteTurnRunning.render((int) pos.x, (int) pos.y, rotation,
                                     (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::FALLING:
            spriteFalling.render((int) pos.x, (int) pos.y, rotation,
                                 (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::DASHING:
            spriteDashing.render((int) pos.x, (int) pos.y, rotation,
                                 (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
            break;
        case PlayableState::SMASHING_FORWARD:
            spriteSmashingForward.render((int) pos.x, (int) pos.y, rotation,
                                         (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL
                                                                                   : SDL_FLIP_NONE);
            break;
        case PlayableState::SMASHING_UPWARD:
            spriteSmashingUpward.render((int) pos.x, (int) pos.y, rotation,
                                        (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL
                                                                                  : SDL_FLIP_NONE);
            break;
        case PlayableState::WINNING:
            spriteWinning.render((int) pos.x, (int) pos.y, rotation,
                                 (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL
                                                                           : SDL_FLIP_NONE);
            break;
        case PlayableState::LOSING:
            spriteLosing.render((int) pos.x, (int) pos.y, rotation,
                                (currentlyFacing == PlayableFacing::LEFT) ? SDL_FLIP_HORIZONTAL
                                                                          : SDL_FLIP_NONE);
            break;

        default:
            break;

    }

    for (unsigned k = 0; k < 3; k++)
        auxCollisionVolume[k].render();
}
コード例 #9
0
ファイル: Action.cpp プロジェクト: uvbs/GameProject
	void Follow::update( Object& obj , long time)
	{
		Vec2D dif = destObj->getPos() - getCenterPos( obj );
		float s= sqrtf( dif.length2() );
		obj.setVelocity(  speed * time / (1000 *s )  * dif );
	}
コード例 #10
0
ファイル: fighter.cpp プロジェクト: rotonlin/Fighter
void LCBattleScene::addMonster(int amount) {
    while(amount--) {
        addMonsterAtPosition(ccpAdd(getCenterPos(), Point(rand() % 50, rand() % 60)));
    }
}