Ejemplo n.º 1
1
void TREnemy::moveAlongPath(){
    planRoute(false);
    if(path.empty()){
        return;
    }
    int topX = path.front().first;
    int topY = path.front().second;
    int curX = getX();
    int curY = getY();
    if(!undoed && curX != topX){
        if(std::abs(curX - topX) < vel){
            if(curX > topX){
                setDirection(TRDirectionLeft);
                curX = topX;
            }else{
                setDirection(TRDirectionRight);
                curX = topX;
            }
        }else{
            if (curX > topX) {
                setDirection(TRDirectionLeft);
                curX -= vel;
            }else{
                setDirection(TRDirectionRight);
                curX += vel;
            }
        }
        if(curX == topX && curY == topY){
            path.pop();
        }
        setX(curX);
        return;
    }
    if(curY != topY){
        undoed = false;
        if(std::abs(curY - topY) < vel){
            if(curY > topY){
                setDirection(TRDirectionUp);
                curY = topY;
            }else{
                setDirection(TRDirectionDown);
                curY = topY;
            }
        }else{
            if (curY > topY) {
                setDirection(TRDirectionUp);
                curY -= vel;
            }else{
                setDirection(TRDirectionDown);
                curY += vel;
            }
        }
        if(curX == topX && curY == topY){
            path.pop();
        }
        setY(curY);
        return;
    }
    if(curX == topX && curY == topY){
        path.pop();
    }
    return;
}
Ejemplo n.º 2
0
static int
pcrotor_stop(ROT *rot)
{
  /* CW=0, CCW=0, Power-up=0 */
  return setDirection(&rot->state.rotport, 0);
}
Ejemplo n.º 3
0
void App::createScene()
{
#pragma region Plane
	// Define the mathematical plane
	Ogre::Plane plane(Vector3::UNIT_Y, 0);
	
	// Create the plane into memory
	Ogre::MeshManager::getSingleton().createPlane(
		"plane",
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		plane,
		500, 500, // size
		25, 25,   // how many quads are used to make the plane
		true,
		1, 5, 5, Vector3::UNIT_Z);

	// Create an instance of the plane
	auto planeEnt = mSceneMgr->createEntity("PlaneEntity", "plane");
	planeEnt->setMaterialName("Examples/BeachStones");

	// Create a node for the plane and attach he plane to it
	mSceneMgr->getRootSceneNode()->createChildSceneNode("planeNode")->attachObject(planeEnt);
#pragma endregion

#pragma region Lights
	// Directional
	auto sunlight = mSceneMgr->createLight("sun");
	sunlight->setType(Ogre::Light::LT_DIRECTIONAL);
	sunlight->setDirection(Ogre::Vector3(0, -1, -1));
	sunlight->setDiffuseColour(Ogre::ColourValue(.30, .30, 0));
	sunlight->setSpecularColour(Ogre::ColourValue(.30, .30, 0));

	// Spotlight
	auto spotlight = mSceneMgr->createLight("spotlight");
	spotlight->setType(Ogre::Light::LT_SPOTLIGHT);
	
	spotlight->setSpotlightRange(
		Ogre::Degree(5.0f),  // inner angle
		Ogre::Degree(15.0f), // outer angle
		0.0f);               // falloff
	
	spotlight->setDiffuseColour(Ogre::ColourValue(1.0f, 0.0f, 0.0f));

	// Sphere to visualize the spotlights source
	auto sphereEnt = mSceneMgr->createEntity("sphere", "sphere.mesh");
	sphereEnt->setMaterialName("Examples/checker");
	auto sphereNode = mSceneMgr->getSceneNode("planeNode")->createChildSceneNode("spotlightNode");
	sphereNode->attachObject(sphereEnt);
	sphereNode->attachObject(spotlight);
	sphereNode->scale(0.02f, 0.02f, 0.02f);
	sphereNode->translate(0.0f, 15.0f, 0.0f);
	sphereNode->lookAt(Ogre::Vector3(0, 0, 0), Ogre::Node::TS_PARENT);
#pragma endregion

#pragma region Entities
	std::array<Ogre::Entity*, 6> entities;
	auto entParentNode = mSceneMgr->getSceneNode("planeNode")->createChildSceneNode("entParentNode");

	float angleOffset = 360.0f / 6.0f;
	float radius = 30.0f;

	for (int i = 0; i < entities.size(); ++i)
	{
		auto e = mSceneMgr->createEntity("Sinbad.mesh");
		entParentNode->createChildSceneNode(Ogre::Vector3(
			radius * Math::Cos(Math::DegreesToRadians(angleOffset * i)),  // x = r cos(t)
			6.75f,                                                        // y = height
			radius * Math::Sin(Math::DegreesToRadians(angleOffset * i)))) // z = r sin(t)
		->attachObject(e);
	}

	// Barrel
	auto barrel = mSceneMgr->createEntity("barrel.mesh");
	mSceneMgr->getSceneNode("planeNode")->createChildSceneNode("barrel", Ogre::Vector3(0, 2.5f, 0))->attachObject(barrel);
#pragma endregion

	// Skybox
	mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 5000, false);
}
Ejemplo n.º 4
0
// -----------------------------------------------------------------------------------------
void CPepeEngineCamera::setDirection(float x, float y, float z)
{
    CPepeEngineVector3 vec(x, y, z);
    setDirection(vec);
}
Ejemplo n.º 5
0
int FrackMan::doSomething() {
	//check if collided with dirt
	bool removedDirt = false;
	for (int i = getX(); i < getX() + 4; i++) {
		for (int j = getY(); j < getY() + 4; j++) {
			if (getStudentWorld()->isDirt(i, j)) {
				getStudentWorld()->removeDirt(i, j);
				removedDirt = true;
			}
		}
	}
	if (removedDirt) {
		getStudentWorld()->playSound(SOUND_DIG);
		getStudentWorld()->setUpdateSearch();
	}
	int ch;
	int originalX = getX(), originalY = getY();
	if (getStudentWorld()->getKey(ch)) {
		switch (ch) {
		case KEY_PRESS_UP: case 'W':
			if (getDirection() == up) moveTo(getX(), getY() + 1);
			else setDirection(up); break;
		case KEY_PRESS_DOWN: case 'S':
			if (getDirection() == down) moveTo(getX(), getY() - 1);
			else setDirection(down); break;
		case KEY_PRESS_RIGHT: case 'D':
			if (getDirection() == right) moveTo(getX() + 1, getY());
			else setDirection(right); break;
		case KEY_PRESS_LEFT: case 'A':
			if (getDirection() == left) moveTo(getX() - 1, getY());
			else setDirection(left); break;
		case KEY_PRESS_TAB:
			if (gold > 0) {
				gold--;
				getStudentWorld()->useGold();
			}
			break;
		case KEY_PRESS_SPACE:
			if (water > 0) {
				water--;
				getStudentWorld()->useWater();
			}
			break;
		case 'z': case 'Z':
			if (sonar > 0) {
				sonar--;
				getStudentWorld()->useSonar();
			}
			break;
		case KEY_PRESS_ESCAPE: return Actor::PLAYER_DIED;
		default: moveTo(originalX, originalY); break;
		}

		//check if collided with edges
		if (getX() < 0 || getY() < 0 || getX() > VIEW_WIDTH - 4 * getSize() || getY() > VIEW_HEIGHT - 4 * getSize())
			for (int i = 0; i < 4; i++) moveTo(originalX, originalY); //run moveTo multiple times to run through animation
		//check collisions with boulders and makes some objects visible if they are close enough
		getStudentWorld()->frackmanCollisions(this, originalX, originalY);
	}
	if(health > 0) return Actor::CONTINUE;
	else return Actor::PLAYER_DIED;
}
Ejemplo n.º 6
0
//
// Private slots
//
void QuickFindMux::changeQuickFind(
        const QString& new_pattern, QFDirection new_direction )
{
    pattern_->changeSearchPattern( new_pattern );
    setDirection( new_direction );
}
Ejemplo n.º 7
0
void ElCamera::lookAt(const D3DXVECTOR3& targetPoint)
{
	updateView();
	setDirection(targetPoint - mRealPosition);
}
Ejemplo n.º 8
0
static int
GPIO_init(GPIO *self, PyObject *args, PyObject *kwds)
{
	int fd = -1;
	int gpio = -1;
	
	PyObject * direction = NULL;
	PyObject * trigger = NULL;
	PyObject * tmp = NULL;

	static char *kwlist[] = { "gpio", "direction", "trigger", NULL };

	if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|OO:__init__",
			kwlist, &gpio, &direction, &trigger ) )
		return -1;

	if (gpio < 0)
		return -1;

	self->gpio = gpio;

	GPIO_VALUE( gpio, self->v_path );
	if ( ( fd = open( self->v_path, O_RDWR, 0 ) ) == -1 ) {
		// try to get gpio exported:
		if ( exportGpio( gpio ) == 0 ) {
			// check if export was (really) successful
			
			if ( ( fd = open( self->v_path, O_RDWR ) ) == -1) {
				// export failed
				PyErr_SetFromErrno( PyExc_IOError );
				return -1;
			}
		} else {
			PyErr_SetString( PyExc_StandardError,
				"Export failed." );
			return -1;
		}
	}

	GPIO_EDGE(gpio, self->e_path);
	GPIO_DIREC(gpio, self->d_path);

	self->fd_val = fd;
	if ( ( self->fd_dir = open( self->d_path, O_RDWR ) ) == -1 ) {
		return -1;
	}

	if ( ( self->fd_edge = open( self->e_path, O_RDWR ) ) == -1 ) {
		return -1;
	}

	if (direction) {
		setDirection( self, direction );
		tmp = self->direction;
		Py_INCREF(direction);
		self->direction = direction;
		Py_XDECREF(tmp);
	} else {
		// no direction requested, use current
		Py_XDECREF(self->direction);
		self->direction = getDirection( self );
		Py_INCREF(self->direction);
	}

	if (trigger) {
		setTrigger( self, trigger );
		tmp = self->trigger;
		Py_INCREF(trigger);
		self->trigger = trigger;
		Py_XDECREF(tmp);
	} else {
		// no trigger requested, use current
		Py_XDECREF(self->trigger);
		self->trigger = getTrigger( self );
		Py_INCREF(self->trigger);
	}

	return 0;
}
Ejemplo n.º 9
0
void inPlaceTurn(int degrees, int maxSpeed, int accel, int decel)
{	
	setDirection(0, 1);
	straight(degrees * 42, 0, maxSpeed, 0, accel, decel);
}
Ejemplo n.º 10
0
ParticleState::ParticleState(int id, double E, Vector3d pos, Vector3d dir) {
	setId(id);
	setEnergy(E);
	setPosition(pos);
	setDirection(dir);
}
Ejemplo n.º 11
0
// Constructor
Light::Light(Rgb normalIrradiance, Rgb ambientIrradiance, Vector3 direction)
{
	setNormalIrradiance(normalIrradiance);
	setAmbientIrradiance(ambientIrradiance);
	setDirection(direction);
}	
Ejemplo n.º 12
0
bool EFX::loadXML(const QDomElement* root)
{
    QString str;
    QDomNode node;
    QDomElement tag;

    Q_ASSERT(root != NULL);

    if (root->tagName() != KXMLQLCFunction)
    {
        qWarning() << "Function node not found!";
        return false;
    }

    if (root->attribute(KXMLQLCFunctionType) != typeToString(Function::EFX))
    {
        qWarning("Function is not an EFX!");
        return false;
    }

    /* Load EFX contents */
    node = root->firstChild();
    while (node.isNull() == false)
    {
        tag = node.toElement();

        if (tag.tagName() == KXMLQLCBus)
        {
            /* Bus */
            str = tag.attribute(KXMLQLCBusRole);
            setBus(tag.text().toUInt());
        }
        else if (tag.tagName() == KXMLQLCEFXFixture)
        {
            EFXFixture* ef = new EFXFixture(this);
            ef->loadXML(&tag);
            if (ef->fixture() != Fixture::invalidId())
            {
                if (addFixture(ef) == false)
                    delete ef;
            }
        }
        else if (tag.tagName() == KXMLQLCEFXPropagationMode)
        {
            /* Propagation mode */
            setPropagationMode(stringToPropagationMode(tag.text()));
        }
        else if (tag.tagName() == KXMLQLCEFXAlgorithm)
        {
            /* Algorithm */
            setAlgorithm(stringToAlgorithm(tag.text()));
        }
        else if (tag.tagName() == KXMLQLCFunctionDirection)
        {
            /* Direction */
            setDirection(Function::stringToDirection(tag.text()));
        }
        else if (tag.tagName() == KXMLQLCFunctionRunOrder)
        {
            /* Run Order */
            setRunOrder(Function::stringToRunOrder(tag.text()));
        }
        else if (tag.tagName() == KXMLQLCEFXWidth)
        {
            /* Width */
            setWidth(tag.text().toInt());
        }
        else if (tag.tagName() == KXMLQLCEFXHeight)
        {
            /* Height */
            setHeight(tag.text().toInt());
        }
        else if (tag.tagName() == KXMLQLCEFXRotation)
        {
            /* Rotation */
            setRotation(tag.text().toInt());
        }
        else if (tag.tagName() == KXMLQLCEFXAxis)
        {
            /* Axes */
            loadXMLAxis(&tag);
        }
        else
        {
            qWarning() << "Unknown EFX tag:" << tag.tagName();
        }

        node = node.nextSibling();
    }

    return true;
}
void CStreamSource::play()
{
	nlassert(!_Playing);
	bool play = false;
	CAudioMixerUser *mixer = CAudioMixerUser::instance();
	
	{
		CAutoMutex<CMutex> autoMutex(m_BufferMutex);
		
		//if ((mixer->getListenPosVector() - _Position).sqrnorm() > m_StreamSound->getMaxDistance() * m_StreamSound->getMaxDistance())
		if ((_RelativeMode ? getPos().sqrnorm() : (mixer->getListenPosVector() - getPos()).sqrnorm()) > m_StreamSound->getMaxDistance() * m_StreamSound->getMaxDistance())
		{
			// Source is too far to play
			if (_Spawn)
			{
				if (_SpawnEndCb != NULL)
					_SpawnEndCb(this, _CbUserParam);
				delete this;
			}
			// nldebug("CStreamSource %p : play FAILED !", (CAudioMixerUser::IMixerEvent*)this);
			return;
		}
		
		CAudioMixerUser *mixer = CAudioMixerUser::instance();

		if (!hasPhysicalSource())
			initPhysicalSource();

		if (hasPhysicalSource())
		{
			ISource *pSource = getPhysicalSource();
			nlassert(pSource != NULL);
			
			for (uint i = 0; i < m_NextBuffer; ++i)
				pSource->submitStreamingBuffer(m_Buffers[i]);
			
			// pSource->setPos( _Position, false);
			pSource->setPos(getVirtualPos(), false);
			if (!m_Buffers[0]->isStereo())
			{
				pSource->setMinMaxDistances(m_StreamSound->getMinDistance(), m_StreamSound->getMaxDistance(), false);
				setDirection(_Direction); // because there is a workaround inside
				pSource->setVelocity(_Velocity);
			}
			pSource->setGain(_Gain);
			pSource->setSourceRelativeMode(_RelativeMode);
			// pSource->setLooping(_Looping);
			pSource->setPitch(_Pitch);
			pSource->setAlpha(m_Alpha);
			
			// and play the sound
			play = pSource->play();
			// nldebug("CStreamSource %p : REAL play done", (CAudioMixerUser::IMixerEvent*)this);
		}
		else
		{
			if (_Priority == HighestPri)
			{
				// This sound is not discardable, add it in waiting playlist
				mixer->addSourceWaitingForPlay(this);
				return;
			}
			else
			{
				// No source available, kill.
				if (_Spawn)
				{
					if (_SpawnEndCb != NULL)
						_SpawnEndCb(this, _CbUserParam);					
					delete this;
				}
				return;
			}
		}
		
		if (play)
			CSourceCommon::play();
	}

	nlassert(play);
}
Ejemplo n.º 14
0
void WGM63::stop()
{
  setDirection(STOP);
}
Ejemplo n.º 15
0
void Listener::setDirection(const Vector3f& direction)
{
    setDirection(direction.x, direction.y, direction.z);
}
Ejemplo n.º 16
0
bool Chaser::loadXML(QDomDocument* doc, QDomElement* root)
{
	t_fixture_id step_fxi = KNoID;
	int step_number = 0;
	QString str;
	
	QDomNode node;
	QDomElement tag;
	
	Q_ASSERT(doc != NULL);
	Q_ASSERT(root != NULL);

	if (root->tagName() != KXMLQLCFunction)
	{
		qWarning("Function node not found!");
		return false;
	}

	/* Load chaser contents */
	node = root->firstChild();
	while (node.isNull() == false)
	{
		tag = node.toElement();
		
		if (tag.tagName() == KXMLQLCBus)
		{
			/* Bus */
			str = tag.attribute(KXMLQLCBusRole);
			Q_ASSERT(str == KXMLQLCBusHold);

			Q_ASSERT(setBus(tag.text().toInt()) == true);
		}
		else if (tag.tagName() == KXMLQLCFunctionDirection)
		{
			/* Direction */
			setDirection(Function::stringToDirection(tag.text()));
		}
		else if (tag.tagName() == KXMLQLCFunctionRunOrder)
		{
			/* Run Order */
			setRunOrder(Function::stringToRunOrder(tag.text()));
		}
		else if (tag.tagName() == KXMLQLCFunctionStep)
		{
			step_number = 
				tag.attribute(KXMLQLCFunctionNumber).toInt();
			step_fxi = tag.text().toInt();

			if (step_number > m_steps.size())
				m_steps.append(step_fxi);
			else
				m_steps.insert(m_steps.at(step_number),
					       step_fxi);
			
		}
		else
		{
			qWarning("Unknown chaser tag: %s",
				 (const char*) tag.tagName());
		}
		
		node = node.nextSibling();
	}

	return true;
}
Ejemplo n.º 17
0
	SphericEmitter::SphericEmitter(const vec3& direction,float angleA,float angleB) :
		Emitter()
	{
		setDirection(direction);
		setAngles(angleA,angleB);
	}
Ejemplo n.º 18
0
/**
 * 断续指定方向移动
 */
void SimpleMoveComponent::continueMoveWithDirection(float direction)
{
	setDirection(direction);
    calcSpeedVector(cosf(direction), sinf(direction));
	m_moveState=MoveContinue;
}
Ejemplo n.º 19
0
void TestList::runThisTest()
{
    _cellTouchEnabled = true;
    auto director = Director::getInstance();
    auto scene = Scene::create();

    auto visibleSize = director->getVisibleSize();
    auto origin = director->getVisibleOrigin();

    auto tableView = TestCustomTableView::create(this, Size(400, visibleSize.height));
    tableView->setPosition(origin.x + (visibleSize.width - 400) / 2, origin.y);
    tableView->setDirection(ScrollView::Direction::VERTICAL);
    tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
    tableView->setDelegate(this);
    scene->addChild(tableView);
    tableView->reloadData();

    if (_shouldRestoreTableOffset)
    {
        tableView->setContentOffset(_tableOffset);
    }

    if (_parentTest)
    {
        //Add back button.
        TTFConfig ttfConfig("fonts/arial.ttf", 20);
        auto label = Label::createWithTTF(ttfConfig, "Back");

        auto menuItem = MenuItemLabel::create(label, std::bind(&TestBase::backsUpOneLevel, this));
        auto menu = Menu::create(menuItem, nullptr);

        menu->setPosition(Vec2::ZERO);
        menuItem->setPosition(Vec2(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25));

        scene->addChild(menu, 1);
    }
    else
    {
        //Add close and "Start AutoTest" button.
        auto closeItem = MenuItemImage::create(s_pathClose, s_pathClose, [](Ref* sender){
            TestController::getInstance()->stopAutoTest();
            TestController::destroyInstance();
            Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
            exit(0);
#endif
        });
        closeItem->setPosition(VisibleRect::right().x - 30, VisibleRect::top().y - 30);

        auto autoTestLabel = Label::createWithTTF("Start AutoTest","fonts/arial.ttf",16);
        auto autoTestItem = MenuItemLabel::create(autoTestLabel, [&](Ref* sender){
            TestController::getInstance()->startAutoTest();
        });
        autoTestItem->setPosition(Vec2(VisibleRect::right().x - 70, VisibleRect::bottom().y + 25));

        auto menu = Menu::create(closeItem, autoTestItem, nullptr);
        menu->setPosition(Vec2::ZERO);
        scene->addChild(menu, 1);
    }

    director->replaceScene(scene);
}
Ejemplo n.º 20
0
void Node::lookAt(Ogre::Vector3 target, Ogre::Vector3 front_vector, RelativeTo rel) {
    setDirection(target - getPosition(rel), front_vector);
}
Ejemplo n.º 21
0
void DirectionalLight::setDirection(float x, float y, float z) {
	setDirection(glm::vec3(x, y, z));
}
Ejemplo n.º 22
0
void Camera::lookAt(const glm::dvec3& center)
{
    setDirection(center - m_position);
}
Ejemplo n.º 23
0
// -----------------------------------------------------------------------------------------
void CPepeEngineCamera::lookAt(const CPepeEngineVector3& point)
{
    setDirection(point - m_position);
    m_bNeedViewUpdate = true;
}
Ejemplo n.º 24
0
void Creature::walk(const Position& position, bool inverse)
{
    // set walking state
    bool sameWalk = m_walking && !m_inverseWalking && inverse;
    m_walking = true;
    m_inverseWalking = inverse;
    int walkTimeFactor = 1;

    // set new direction
    if(m_position + Position(0, -1, 0) == position) {
        setDirection(Otc::North);
        m_walkOffset.y = 32;
    }
    else if(m_position + Position(1, 0, 0) == position) {
        setDirection(Otc::East);
        m_walkOffset.x = -32;
    }
    else if(m_position + Position(0, 1, 0) == position) {
        setDirection(Otc::South);
        m_walkOffset.y = -32;
    }
    else if(m_position + Position(-1, 0, 0) == position) {
        setDirection(Otc::West);
        m_walkOffset.x = 32;
    }
    else if(m_position + Position(1, -1, 0) == position) {
        setDirection(Otc::NorthEast);
        m_walkOffset.x = -32;
        m_walkOffset.y = 32;
        walkTimeFactor = 2;
    }
    else if(m_position + Position(1, 1, 0) == position) {
        setDirection(Otc::SouthEast);
        m_walkOffset.x = -32;
        m_walkOffset.y = -32;
        walkTimeFactor = 2;
    }
    else if(m_position + Position(-1, 1, 0) == position) {
        setDirection(Otc::SouthWest);
        m_walkOffset.x = 32;
        m_walkOffset.y = -32;
        walkTimeFactor = 2;
    }
    else if(m_position + Position(-1, -1, 0) == position) {
        setDirection(Otc::NorthWest);
        m_walkOffset.x = 32;
        m_walkOffset.y = 32;
        walkTimeFactor = 2;
    }
    else { // Teleport
        // we teleported, dont walk or change direction
        m_walking = false;
        m_walkOffset.x = 0;
        m_walkOffset.y = 0;
        m_animation = 0;
    }

    if(!m_inverseWalking) {
        m_walkOffset.x = 0;
        m_walkOffset.y = 0;
    }

    if(m_walking) {
        // get walk speed
        int groundSpeed = 100;

        ItemPtr ground = g_map.getTile(position)->getGround();
        if(ground)
            groundSpeed = ground->getType()->parameters[ThingType::GroundSpeed];

        float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed;
        walkTime = (walkTime == 0) ? 1000 : walkTime;

        m_walkTimePerPixel = walkTime / 32.0;
        if(!sameWalk)
            m_walkStartTicks = g_clock.ticks();
        updateWalk();
    }
}
Ejemplo n.º 25
0
bool VehicleInstance::movementV(int elapsed)
{
    bool updated = false;

    if (!dest_path_.empty()) {
        if (hold_on_.wayFree == 1) {
            return updated;
        } else if (hold_on_.wayFree == 2){
            dest_path_.clear();
            speed_ = 0;
            return updated;
        }
        int adx =
            dest_path_.front().tileX() * 256 + dest_path_.front().offX();
        int ady =
            dest_path_.front().tileY() * 256 + dest_path_.front().offY();
        int atx = tile_x_ * 256 + off_x_;
        int aty = tile_y_ * 256 + off_y_;
        int diffx = adx - atx, diffy = ady - aty;

        if (abs(diffx) < 16 && abs(diffy) < 16) {
            off_y_ = dest_path_.front().offY();
            off_x_ = dest_path_.front().offX();
            tile_y_ = dest_path_.front().tileY();
            tile_x_ = dest_path_.front().tileX();
            dest_path_.pop_front();
            if (dest_path_.size() == 0)
                speed_ = 0;
            updated = true;
        } else {
            setDirection(diffx, diffy, &dir_);
            int dx = 0, dy = 0;
            double d = sqrt((double)(diffx * diffx + diffy * diffy));

            if (abs(diffx) > 0)
                // dx = diffx * (speed_ * elapsed / 1000) / d;
                dx = (int)((diffx * (speed_ * elapsed) / d) / 1000);
            if (abs(diffy) > 0)
                // dy = diffy * (speed_ * elapsed / 1000) / d;
                dy = (int)((diffy * (speed_ * elapsed) / d) / 1000);

            if (abs(dx) > abs(diffx))
                dx = diffx;
            if (abs(dy) > abs(diffy))
                dy = diffy;
            updatePlacement(off_x_ + dx, off_y_ + dy);
#if 0
            if (updatePlacement(off_x_ + dx, off_y_ + dy)) {
                ;
            } else {
                // TODO: avoid obstacles.
                speed_ = 0;
            }
#endif
            if(dest_path_.front().tileX() == tile_x_
                && dest_path_.front().tileY() == tile_y_
                && dest_path_.front().offX() == off_x_
                && dest_path_.front().offY() == off_y_)
                dest_path_.pop_front();
            if (dest_path_.size() == 0)
                speed_ = 0;

            updated = true;
        }
    } else if (speed_) {
        printf("Destination Unknown, full speed driving = %i ... doing full stop\n", speed_);
        speed_ = 0;
    }

    return updated;
}
Ejemplo n.º 26
0
bool BattleSquad::init(std::string srcpath, int team, int unitnum, int x, int y, int d)
{
	if(!Squad::init(srcpath))
		return false;
	DataLibrary *datalib = DataLibrary::getSingletonPtr();
	setTeam(team);
	setGridX(x);
	setGridY(y);
	setDirection(d);

	setUnitNum(unitnum);
	int squadtype2;
	datalib->getData(srcpath + std::string("/Type"), squadtype2);
	if(squadtype2 == SQUAD_NORMAL)
	{
		setUnitMaxNum(unitnum);
		setFormation(Line);
	}
	else
	{
		setUnitMaxNum(20);
		setFormation(Loose);
	}

	float covert;
	covert = getAttr(ATTR_COVERT, ATTRCALC_FULL);
	if(covert > 0.0f)
	{
		switch(getFaction())
		{
		case 0:
			setViewbyPlayer(1);
			setViewbyEnemy1(0);
			setViewbyEnemy2(0);
			setViewbyEnemy3(0);
			break;
		case 1:
			setViewbyPlayer(0);
			setViewbyEnemy1(1);
			setViewbyEnemy2(0);
			setViewbyEnemy3(0);
			break;
		case 2:
			setViewbyPlayer(0);
			setViewbyEnemy1(0);
			setViewbyEnemy2(1);
			setViewbyEnemy3(0);

			break;
		case 3:
			setViewbyPlayer(0);
			setViewbyEnemy1(0);
			setViewbyEnemy2(0);
			setViewbyEnemy3(1);
			break;
		}
	}
	else
	{
		setViewbyPlayer(1);
		setViewbyEnemy1(1);
		setViewbyEnemy2(1);
		setViewbyEnemy3(1);
	}

	setAmbushPlayer(0);
	setAmbushEnemy1(0);
	setAmbushEnemy2(0);
	setAmbushEnemy3(0);

	setActionPoint(0.0f);
	setAPSetup(0.0f);
	setAPBattle(0.0f);
	return true;
}
Ejemplo n.º 27
0
 //-----------------------------------------------------------------------
 void SceneNode::setDirection(Real x, Real y, Real z, TransformSpace relativeTo, 
     const Vector3& localDirectionVector)
 {
     setDirection(Vector3(x,y,z), relativeTo, localDirectionVector);
 }
Ejemplo n.º 28
0
	void UIScrollPage::LoadBinary(NiStream &kStream)
	{
		UIControlBase::LoadBinary(kStream);

		uint32_t contentWidth = 0;
		uint32_t contentHeight = 0;
		uint32_t direction = 0;
		int priority = kCCScrollTouchPriority;

		mutableDic *dic = kStream.GetStreamData();

		// get button click callback function
		kStream.getStringattributeValue(dic, "itemClickedCallback", m_strItemClickedFun);
		kStream.getStringattributeValue(dic, "itemDoubleClickedCallback", m_strItemDoubleClickedFun);
		kStream.getStringattributeValue(dic, "itemDragReleaseCallback", m_strItemDragReleaseFun);
		kStream.getStringattributeValue(dic, "tappedCallback", m_strTappedFun);
		kStream.getStringattributeValue(dic, "tapCancelCallback", m_strTapCancelFun);

		kStream.getIntAttributeValue(dic, "itemType", m_itemType);
		kStream.getIntAttributeValue(dic, "contentWidth", contentWidth);
		kStream.getIntAttributeValue(dic, "contentHeight", contentHeight);
		kStream.getIntAttributeValue(dic, "direction", direction);
		kStream.getSignedIntAttributeValue(dic, "indicatorOffsetX", m_indicatorOffsetX);
		kStream.getSignedIntAttributeValue(dic, "indicatorOffsetY", m_indicatorOffsetY);
        kStream.getSignedIntAttributeValue(dic,"priority",priority);

        contentWidth /= CC_CONTENT_SCALE_FACTOR();
        contentHeight /= CC_CONTENT_SCALE_FACTOR();
        m_indicatorOffsetX /= CC_CONTENT_SCALE_FACTOR();
        m_indicatorOffsetY /= CC_CONTENT_SCALE_FACTOR();
        
		setDirection((EScrollDirection)direction);

		// query frameRect property
		mutableDic* framedic = static_cast<mutableDic*>(dic->objectForKey("frameRect"));
		if( framedic )
		{
			string rectAsIndex = "";			
			kStream.getStringattributeValue(framedic, "rectAsIndex", rectAsIndex);	
			uint32_t  useAscontentRect = 0;
			kStream.getIntAttributeValue(framedic, "useAscontentRect", useAscontentRect);
			if (useAscontentRect)
			{
				CCPoint pt;
				string ASfile = KUI_BIN;
				kStream.getStringattributeValue(framedic, "binFile", ASfile); 
				ASprite *as = AspriteManager::getInstance()->getAsprite(ASfile);   

				int idx = getResourceIDByName(rectAsIndex.c_str());
				CCRect scrollRect = as->getframeRect(idx);
				CCPoint scrollCenter = as->GetFramePointMiddle(idx);

				// re-calculate the local position 
				CCPoint parentWorldPosition = CCPointZero;
				if(m_pParent != NULL)
				{
					parentWorldPosition = m_pParent->getWorldPosition();
				}

				m_ptLocalPosition.x = scrollCenter.x - parentWorldPosition.x;
				m_ptLocalPosition.y = scrollCenter.y - parentWorldPosition.y;

				setContentSize(scrollRect.size);
			}
		}
		else
		{
			setContentSize(CCSize(contentWidth, contentHeight));
		}

		m_pScrollLayer = UIScrollLayer::nodeWithNoLayer(m_contentSize, m_direction);
		m_pScrollLayer->setPosition(m_ptLocalPosition);
		m_pScrollLayer->setPagesIndicatorPosition(ccp(m_indicatorOffsetX, m_indicatorOffsetY));
		m_pScrollLayer->setPriority(priority);
		m_pScrollLayer->setVisible(m_bIsVisible);
		m_pControlNode = m_pScrollLayer->getBaseLayer();

		// add pages
		mutableDic* pageDic = static_cast<mutableDic*>(dic->objectForKey("page"));
		if( pageDic )
		{
			kStream.getIntAttributeValue(pageDic, "count", m_ipageCount); 
			kStream.getIntAttributeValue(pageDic, "column", m_icolumn); 
			kStream.getIntAttributeValue(pageDic, "row", m_irow); 
			kStream.getIntAttributeValue(pageDic, "cellOffsetX", m_celloffsetX); 
			kStream.getIntAttributeValue(pageDic, "cellOffsetY", m_celloffsetY);
            
            m_celloffsetX /= CC_CONTENT_SCALE_FACTOR();
            m_celloffsetY /= CC_CONTENT_SCALE_FACTOR();
            
			m_bIsConfiged = true;
		}

		m_cellAsfile = "";
		kStream.getStringattributeValue(dic, "cellAsIndex", m_cellAsfile);
		m_cellSelectedAsfile = "";
		kStream.getStringattributeValue(dic, "cellSelectedAsIndex", m_cellSelectedAsfile);
		if (m_cellAsfile.empty() == false)
		{
			CCPoint pt;
			m_cellBinFile = KUI_BIN;
			kStream.getStringattributeValue(dic, "binFile", m_cellBinFile); 
			ASprite *as = AspriteManager::getInstance()->getAsprite(m_cellBinFile);   
			int idx = getResourceIDByName(m_cellAsfile.c_str());
			m_cellRect = as->getframeRect(idx);
		}

		for(int i = 0 ; i < (int) m_ipageCount ; i ++)
		{
			addOneEmptyPage(i);
		}
	}
Ejemplo n.º 29
0
 //-----------------------------------------------------------------------
 void Camera::setDirection(Real x, Real y, Real z)
 {
     setDirection(Vector3(x,y,z));
 }
Ejemplo n.º 30
0
void FrackMan::doSomething(){
    if(!isAlive()) return;
    int key;
    if (getWorld()->getKey(key)){
        switch(key){
            case KEY_PRESS_UP:
                if(getDirection() == up) {
                    move(up);
                }
                else setDirection(up);
                break;
            case KEY_PRESS_DOWN:
                if(getDirection() ==  down) {
                    move(down);
                }
                else setDirection(down);
                break;
            case KEY_PRESS_LEFT:
                if(getDirection() == left) {
                    move(left);
                }
                else setDirection(left);
                break;
            case KEY_PRESS_RIGHT:
                if(getDirection() == right) {
                    move(right);
                }
                else setDirection(right);
                break;
            case KEY_PRESS_ESCAPE: setDead();
                break;
            case KEY_PRESS_SPACE:
            {
                if(m_uWater != 0){
                    getWorld()->playSound(SOUND_PLAYER_SQUIRT);
                    Actor* a = new Squirt(getWorld(), getX(), getY(), getDirection());
                    getWorld()->addActor(a);
                    m_uWater--;
                }
                break;
            }
            case KEY_PRESS_TAB:
            {
                if(m_nNuggets != 0){
                    m_nNuggets--;
                    Actor* a = new GoldNugget(getWorld(), getX(), getY(), true);
                    getWorld()->addActor(a);
                }
                break;
            }
            case 'z':
            case 'Z':
            {
                if(m_nCharges !=0){
                    getWorld()->playSound(SOUND_SONAR);
                    getWorld()->revealAllNearbyObjects(getX(), getY(), 12);
                    m_nCharges--;
                }
                break;
            }
        }
        getWorld()->updateFrackmanMap(getX(), getY());
        if(getWorld()->displaceDirt(getX(), getY())) getWorld()->playSound(SOUND_DIG);
    }
}