Exemple #1
0
bool Coin::init(){
	if(!Node::init()){
		return false;
	}

	//缓存池
	auto frameCache = SpriteFrameCache::getInstance();
	frameCache->addSpriteFramesWithFile("parkour.plist","parkour.png");

	auto sprite = Sprite::createWithSpriteFrameName("coin0.png");

	//绑定
	setSprite(sprite);
	//执行动作
	getSprite()->runAction(createAnimate(frameCache));
	//绑定刚体
	initBody();

	return true;
}
Exemple #2
0
//--- NGF events ----------------------------------------------------------------
OneWay::OneWay(Ogre::Vector3 pos, Ogre::Quaternion rot, NGF::ID id, NGF::PropertyList properties, Ogre::String name)
    : NGF::GameObject(pos, rot, id , properties, name)
{
    addFlag("OneWay");

    //Python init event.
    NGF_PY_CALL_EVENT(init);

    //Create the Ogre stuff.

    if (mProperties.getValue("brushMeshFile", 0, "n") == "n")
    {
        mEntity = GlbVar.ogreSmgr->createEntity(mOgreName, "OneWay.mesh");

        BtOgre::StaticMeshToShapeConverter converter(mEntity);
        mShape = converter.createBox();
    }
    else
    {
        mEntity = createBrushEntity();

        BtOgre::StaticMeshToShapeConverter converter(mEntity);
        mShape = converter.createTrimesh();
        mShape->setMargin(0);
    }
    mEntity->setMaterialName("Objects/OneWay");

    mNode = GlbVar.ogreSmgr->getRootSceneNode()->createChildSceneNode(mOgreName, pos, rot);
    mNode->attachObject(mEntity);

    //Create the Physics stuff.
    BtOgre::RigidBodyState *state = new BtOgre::RigidBodyState(mNode);
    mBody = new btRigidBody(0, state, mShape, btVector3(0,0,0));
    initBody( DimensionManager::NO_DIM_CHECK
              | DimensionManager::NO_CRATE_CHECK
              | DimensionManager::NO_MOVING_CHECK
              | DimensionManager::NO_BULLET_HIT
            );
    mBody->setCollisionFlags(mBody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
}
Exemple #3
0
bool Runner::init(){
	//加载图片到缓存池
	auto frameCache = SpriteFrameCache::getInstance();
	frameCache->addSpriteFramesWithFile("parkour.plist","parkour.png");

	m_runner = Sprite::createWithSpriteFrameName("runner0.png");

	run_jumpSize = m_runner->getContentSize();
	crouchSize = Sprite::createWithSpriteFrameName("runnerCrouch0.png")->getContentSize();

	this->addChild(m_runner);

	initActionSet(frameCache);//初始化动作集合

	//m_state = running;

	initBody();

	this->scheduleUpdate();
	//设置主角为1,为碰撞做准备
	this->setTag(1);

	return true;
}
Exemple #4
0
//--- NGF events ----------------------------------------------------------------
Crate::Crate(Ogre::Vector3 pos, Ogre::Quaternion rot, NGF::ID id, NGF::PropertyList properties, Ogre::String name)
    : NGF::GameObject(pos, rot, id , properties, name),
      mMoving(false),
      mExploded(false)
{
    addFlag("Crate");
    addFlag("Switcher");

    Ogre::String script = mProperties.getValue("script", 0, "");

    //Python init event.
    NGF_PY_CALL_EVENT(init);

    //Read properties.
    Ogre::Real heightDef = Ogre::StringConverter::parseReal(mProperties.getValue("heightDeficiency", 0, "0"));

    if(!(mProperties.getValue("NGF_SERIALISED", 0, "no") == "yes"))
        pos.y -= heightDef * 0.5; //If deficient in height, move down by half the deficiency because midpoint is local origin.

    //Create the Ogre stuff.
    mEntity = GlbVar.ogreSmgr->createEntity(mOgreName, "Crate.mesh");
    mNode = GlbVar.ogreSmgr->getRootSceneNode()->createChildSceneNode(mOgreName, pos, rot);
    mNode->attachObject(mEntity);

    //Create the Physics stuff. The mesh is a normal box, except in the bottom it's bevelled.
    Ogre::Entity *colMesh = GlbVar.ogreSmgr->createEntity(mOgreName + "_Collision", "Collision_Crate.mesh");
    BtOgre::StaticMeshToShapeConverter converter(colMesh);
    mShape = converter.createConvex();
    GlbVar.ogreSmgr->destroyEntity(colMesh);

    mShape->setMargin(0);
    btScalar mass = 7;
    btVector3 inertia;
    mShape->calculateLocalInertia(mass, inertia);

    BtOgre::RigidBodyState *state = new BtOgre::RigidBodyState(mNode);
    btRigidBody::btRigidBodyConstructionInfo info(mass, state, mShape, inertia);

    mBody = new btRigidBody(info);
    mBody->setActivationState(DISABLE_DEACTIVATION);
    initBody( DimensionManager::LIFTABLE
            );

    //To allow Gravity, but still constraint on XZ plane, we use slider.
    mCastShape = new btBoxShape(btVector3(0.475,0.65,0.475));

    btDefaultMotionState *fixedState = new btDefaultMotionState(btTransform(BtOgre::Convert::toBullet(rot), BtOgre::Convert::toBullet(pos + Ogre::Vector3(0,20,0))));
    mFixedBody = new btRigidBody(0, fixedState, mCastShape);
    mFixedBody->setCollisionFlags(mBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT | btCollisionObject::CF_NO_CONTACT_RESPONSE);
    mFixedBody->setActivationState(DISABLE_DEACTIVATION);
    GlbVar.phyWorld->addRigidBody(mFixedBody, mDimensions 
            | DimensionManager::NO_DIM_CHECK 
            | DimensionManager::NO_MOVING_CHECK 
            | DimensionManager::NO_BULLET_HIT 
            | DimensionManager::NO_CRATE_CHECK 
            | DimensionManager::INVISIBLE
            , mDimensions);

    mConstraint = new btSliderConstraint(*mBody, *mFixedBody, btTransform(btQuaternion(btVector3(0,0,1),Ogre::Math::PI/2.0)), btTransform(btQuaternion(btVector3(0,0,1),Ogre::Math::PI/2.0)), false);
    mConstraint->setLowerLinLimit(1); //Free linear.
    mConstraint->setUpperLinLimit(0);
    mConstraint->setLowerAngLimit(0); //Locked angular.
    mConstraint->setUpperAngLimit(0);
    //mConstraint->setRestitutionOrthoLin(3);

    mBody->setAngularFactor(btVector3(0,0,0));
    mBody->setLinearFactor(btVector3(0,1,0));

    //GlbVar.phyWorld->addConstraint(mConstraint, true);

    //Height deficiency, for some variety in Crates.
    mHeight = 1.5 - heightDef;
    if (heightDef != 0)
    {
        Ogre::Real scale = mHeight / 1.5;
        mNode->setScale(Ogre::Vector3(1,scale,1));
        mShape->setLocalScaling(btVector3(1,scale,1));
        mCastShape->setLocalScaling(btVector3(1,scale,1));
    }

    //Crate materials, again for variety.
    int n = Ogre::Math::Floor(Ogre::Math::RangeRandom(1, MAX_CRATE_MATERIALS + 0.99));
    mEntity->setMaterialName("Objects/Crate" + Ogre::StringConverter::toString(n));

    //Sound.
    mSound = GlbVar.soundMgr->createSound(mOgreName + "_Sound", "CrateMove.ogg", true, false);
    mNode->attachObject(mSound);
    mSound->setReferenceDistance(1.2);
    mSound->setGain(2.1);
}
Exemple #5
0
void Runner::Run(){
	m_state = running;
	initBody();
	doAction("running");
	this->setPosition(runner_posX,ground_hight+getRunJumpSize().height/2);
}
Exemple #6
0
void ExplisonScreen::setBody( float dt )
{
	initBody();
}
Exemple #7
0
void Level13::restart(){
	BaseLevel::restart();

	#define MOVE_BY_X 192

	auto r1 = Ring::create();
	r1->setPosition(E::originX, E::originY + 128);
	r1->setScale(0.2);
	r1->initBody();
	this->addChild(r1);
	r1->runAction(RepeatForever::create(Sequence::create(MoveBy::create(0.5f, Vec2(MOVE_BY_X, 0)), DelayTime::create(1.0f), MoveBy::create(0.5f, Vec2(-MOVE_BY_X, 0)), nullptr)));

	auto r2 = Ring::create();
	r2->setPosition(E::originX + DESIGNED_WIDTH, E::originY + 128);
	r2->setScale(0.2);
	r2->initBody();
	this->addChild(r2);
	r2->runAction(RepeatForever::create(Sequence::create(MoveBy::create(0.5f, Vec2(-MOVE_BY_X, 0)), DelayTime::create(1.0f),MoveBy::create(0.5f, Vec2(MOVE_BY_X, 0)), nullptr)));


	auto t1 = Target::create();
	t1->setPosition(E::originX + DESIGNED_WIDTH / 2, E::originY + 400);
	t1->initBody();
	t1->playAnim(1);
	this->addChild(t1);
	t1->initProtector();

	/*
	auto b_l = Brick::create(E::originX + 96, 32);
	b_l->setPosition(0, E::originY + 32);
	b_l->setRotation(30);
	b_l->initBody();
	this->addChild(b_l);

	auto b_r = Brick::create(E::originX + 96, 32);
	b_r->setPosition(E::originX + DESIGNED_WIDTH - 96, E::originY + 32);
	b_r->setRotation(-30);
	b_r->initBody();
	this->addChild(b_r);
	*/

	ring1 = Ring::create();
	ring1->setPosition(E::originX + DESIGNED_WIDTH / 2 - 80, E::originY + 400);
	ring1->setScale(0.1);
	ring1->initBody();
	this->addChild(ring1);

	ring2 = Ring::create();
	ring2->setPosition(E::originX + DESIGNED_WIDTH / 2 + 80, E::originY + 400);
	ring2->setScale(0.1);
	ring2->initBody();
	this->addChild(ring2);

	auto diamond1 = Diamond::create();
	diamond1->setScale(0.9f);
	diamond1->setRotation(30);
	diamond1->setPosition(E::originX - 128, E::originY + 256 + 64);
	diamond1->initBody();
	this->addChild(diamond1);

	auto diamond2 = Diamond::create();
	diamond2->setScale(0.9f);
	diamond2->setRotation(-30);
	diamond2->setPosition(E::originX + DESIGNED_WIDTH + 128, E::originY + 256 + 64);
	diamond2->initBody();
	this->addChild(diamond2);

	angle = 0;

}
Exemple #8
0
void Level20::restart() {
    BaseLevel::restart();

#define MOVE_BY_X 192

    auto r1 = Target::create();
    r1->setPosition(E::originX, E::originY + 420);
    r1->setRotation(45);
    r1->initBody();
    this->addChild(r1);
    r1->initProtector(192 - 32);
    r1->runAction(RepeatForever::create(Sequence::create(MoveBy::create(0.5f, Vec2(MOVE_BY_X, 0)), DelayTime::create(1.0f), MoveBy::create(0.5f, Vec2(-MOVE_BY_X, 0)), nullptr)));

    auto r2 = Target::create();
    r2->setPosition(E::originX + DESIGNED_WIDTH, E::originY + 420);
    r2->setRotation(-45);
    r2->initBody();
    this->addChild(r2);
    r2->initProtector(192 - 32);
    r2->runAction(RepeatForever::create(Sequence::create(MoveBy::create(0.5f, Vec2(-MOVE_BY_X, 0)), DelayTime::create(1.0f), MoveBy::create(0.5f, Vec2(MOVE_BY_X, 0)), nullptr)));

    auto ring1 = Ring::create();
    ring1->setPosition(E::originX + DESIGNED_WIDTH / 2 - 80, E::originY + 128 + 64);
    ring1->setScale(0.15);
    ring1->initBody();
    this->addChild(ring1);

    auto ring2 = Ring::create();
    ring2->setPosition(E::originX + DESIGNED_WIDTH / 2 + 80, E::originY + 128 + 64);
    ring2->setScale(0.15);
    ring2->initBody();
    this->addChild(ring2);

    auto b1 = Brick::create(192, 24);
    b1->setRotation(45);
    b1->setPosition(E::originX + DESIGNED_WIDTH / 2 - 192 + 32, E::originY + 96 );
    b1->initBody();
    this->addChild(b1);
    auto b12 = Brick::create(192, 16, E::P.C800);
    b12->setRotation(45);
    b12->setPosition(E::originX + DESIGNED_WIDTH / 2 - 192 + 32 + 16, E::originY + 96 + 8);
    b12->initBody();
    this->addChild(b12);

    auto b2 = Brick::create(192, 24);
    b2->setRotation(-45);
    b2->setPosition(E::originX + DESIGNED_WIDTH / 2 - 192 + 32 + 128, E::originY + 96 );
    b2->initBody();
    this->addChild(b2);
    auto b22 = Brick::create(192, 16, E::P.C800);
    b22->setRotation(-45);
    b22->setPosition(E::originX + DESIGNED_WIDTH / 2 - 192 + 32 - 16 + 128, E::originY + 96 + 8);
    b22->initBody();
    this->addChild(b22);

    auto diamond1 = Diamond::create();
    diamond1->setScale(0.9f);
    diamond1->setRotation(30);
    diamond1->setPosition(E::originX - 128, E::originY + 256 + 64);
    diamond1->initBody();
    this->addChild(diamond1);

    auto diamond2 = Diamond::create();
    diamond2->setScale(0.9f);
    diamond2->setRotation(-30);
    diamond2->setPosition(E::originX + DESIGNED_WIDTH + 128, E::originY + 256 + 64);
    diamond2->initBody();
    this->addChild(diamond2);

}
Exemple #9
0
//--- NGF events ----------------------------------------------------------------
SlidingBrush::SlidingBrush(Ogre::Vector3 pos, Ogre::Quaternion rot, NGF::ID id, NGF::PropertyList properties, Ogre::String name)
    : NGF::GameObject(pos, rot, id , properties, name),
      mCurrentPlace(0.5),
      mLastPlace(1),
      mForward(false)
{
    addFlag("SlidingBrush");

    //Save the director event.
    NGF_PY_SAVE_EVENT(point);

    //Python init event.
    NGF_PY_CALL_EVENT(init);
    
    //Get properties.
    mEnabled = Ogre::StringConverter::parseBool(mProperties.getValue("enabled", 0, "yes"));
    mSpeed = Ogre::StringConverter::parseReal(mProperties.getValue("speed", 0, "2"));

    //Create the Ogre stuff.
    mEntity = createBrushEntity();
    mNode = GlbVar.ogreSmgr->getRootSceneNode()->createChildSceneNode(mOgreName, pos, rot);
    mNode->attachObject(mEntity);

    //Create the Physics stuff.
    BtOgre::StaticMeshToShapeConverter converter(mEntity);
    mShape = converter.createConvex();
    mShape->setMargin(0); //Bad, but we gotta.

    BtOgre::RigidBodyState *state = new BtOgre::RigidBodyState(mNode);
    mBody = new btRigidBody(0, state, mShape);
    mBody->setCollisionFlags(mBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
    mBody->setActivationState(DISABLE_DEACTIVATION);
    initBody();

    //First point is here.
    mPoints.push_back(pos);

    //If we're a simple slider, we just move in one direction till a point and then return.
    Ogre::String distanceStr = mProperties.getValue("distance", 0, "n");

    if(!(distanceStr == "n"))
    {
        Ogre::Real distance = Ogre::StringConverter::parseReal(distanceStr);
        mPoints.push_back(pos + (rot * Ogre::Vector3(0,0,-distance)));
    }
    
    mIgnoreCollisions = Ogre::StringConverter::parseBool(mProperties.getValue("ignoreCollisions", 0, "no"));
    //mIgnoreCollisions = true;

    //Make smaller shape for cast.
    //Get vertices.
    btAlignedObjectArray<btVector3> offsetVerts;
    btVector3 *iter = mShape->getUnscaledPoints(); 
    for (int i = 0; i < mShape->getNumPoints(); ++i, ++iter)
        offsetVerts.push_back(*iter);

    //Push 'em in by 0.1;
    btAlignedObjectArray<btVector3> offsetPlanes;
    btGeometryUtil::getPlaneEquationsFromVertices(offsetVerts, offsetPlanes);
    int sz = offsetPlanes.size();
    for (int i=0 ; i<sz ; ++i) 
        offsetPlanes[i][3] += CAST_SHAPE_SHRINK;
    offsetVerts.clear();
    btGeometryUtil::getVerticesFromPlaneEquations(offsetPlanes, offsetVerts);

    //Fill the shape with the new points.
    mCastShape = new btConvexHullShape();
    for (int i = 0; i < offsetVerts.size() ; ++i) 
        mCastShape->addPoint(offsetVerts[i]);
}