Exemplo n.º 1
0
Scene*InGameLayer::scene()
{
	auto sc=Scene::createWithPhysics();
	PhysicsWorld* phyWorld = sc->getPhysicsWorld();
	//phyWorld->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
	//0,0不受到重力的影响
	phyWorld->setGravity(Vect(0,0));
	auto lay=InGameLayer::create();
	sc->addChild(lay);
	return sc;
}
Exemplo n.º 2
0
Scene* HelloGravity::createScene() {
    auto scene = Scene::createWithPhysics();
    PhysicsWorld* world = scene->getPhysicsWorld();
    world->setGravity(Vec2(0, -500));
    world->setSpeed(1.0f);
    world->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
    auto layer = HelloGravity::create();
    scene->addChild(layer);

    return scene;
}
Exemplo n.º 3
0
void PlygonDrawer::playBlastAnim(Point2i pos, enNodeColor color) 
{
	auto convt = m_graph->m_coordCvt;
	Vec2 coord = convt.getCoord(pos);

	auto scene = Director::getInstance()->getRunningScene();
	PhysicsWorld* phyWld = scene->getPhysicsWorld();

	for (int i = 0; i < 5; ++i)
	{
		Sprite* spStar = BeadFactory::createBlastStar(color, 0.2 + 0.1 * i);
		float radius = spStar->getContentSize().width/2 * spStar->getScaleX();
		spStar->retain();
		spStar->setPosition(coord);
		/*spStar->runAction( Sequence::createWithTwoActions(MoveBy::create(2.0f, dir),
				CallFunc::create([=]() {
				spStar->removeFromParent();
				spStar->release();
		})));*/
		spStar->runAction( Sequence::createWithTwoActions(DelayTime::create(15.0f),
			CallFunc::create([=]() {
				spStar->removeFromParent();
				spStar->release();
		})));
#define GravityAmpl 50
		PhysicsMaterial phyMat = PHYSICSBODY_MATERIAL_DEFAULT; phyMat.density = 200.0f;
		auto body = PhysicsBody::createCircle(radius, phyMat);
		Vec2 dir = ccp(rand()%100 - 50, rand()%100 - 50);
		dir.normalize(); dir = dir * body->getMass() * 8.0f * GravityAmpl;
		Vect force(dir);
		body->applyImpulse(force);
		body->setDynamic(true);
		//body->setCategoryBitmask(0x04);
		//body->setCollisionBitmask(0x08);
		body->setGroup(-1);
		body->setGravityEnable(true);

		spStar->setPhysicsBody(body);
		m_tileMap->addChild(spStar, 100);
	}

	static bool isPhyInit = false;
	if (! isPhyInit) {
		isPhyInit = true;
		phyWld->setGravity(Vect(0.0f, -9.8f * GravityAmpl));
		//phyWld->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
		phyWld->setUpdateRate(2.5f);
	}
}
Exemplo n.º 4
0
// 物理空間を含めたシーンの生成
Scene* SceneCreator::createPhysicsScene( Layer* childLayer, const Vect& gravity, bool isDebug, float speed )
{
	Scene*			scene	{ Scene::createWithPhysics() };
	PhysicsWorld*	world	{ scene->getPhysicsWorld() };
	
	world->setGravity( gravity );
	world->setSpeed( speed );
	
	if ( isDebug )
	{
		world->setDebugDrawMask( PhysicsWorld::DEBUGDRAW_ALL );
	}
	
	scene->addChild( childLayer );
	
	return scene;
}
Exemplo n.º 5
0
Scene* GamePlayLayer::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::createWithPhysics();
    PhysicsWorld* phyWorld = scene->getPhysicsWorld();
    //phyWorld->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
    //0,0不受到重力的影响
    phyWorld->setGravity(Vect(0,0));

    // 'layer' is an autorelease object
    auto layer = GamePlayLayer::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}
Exemplo n.º 6
0
Scene* Practice1::createScene()
{
	// 'scene' is an autorelease object
	//auto scene = Scene::create();
	auto scene = Scene::createWithPhysics();

	// 'layer' is an autorelease object
	auto layer = Practice1::create();

	// add layer as a child to scene
	scene->addChild(layer);

	PhysicsWorld* world = scene->getPhysicsWorld();
	world->setGravity(Vec2(0, -100));
	world->setSpeed(1.0f);
	world->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

	// return the scene
	return scene;
}
Exemplo n.º 7
0
void SinglePlayerScene::setupPhysics()
{
    Size visibleSize = Director::getInstance()->getVisibleSize();

    float visibleHeight = visibleSize.height;
    PhysicsWorld* world = this->getScene()->getPhysicsWorld();
    world->setGravity(Vec2(0, (visibleHeight / 320.0f) * -98.0f));
    world->setSpeed(GAME_SPEED);

    world->setDebugDrawMask(DEBUGDRAW_OPTIONS);


    Vec2 takyanPos = _takyan->getPosition();
    PhysicsBody *takyanBody = PhysicsBody::createCircle(_takyan->getContentSize().width * BALL_RADIUS, PhysicsMaterial(0.01f, 1.0f, 1.0f)); //_takyan->getPhysicsBody();
    float takyanMass = takyanBody->getMass();
    float velocityLimit = takyanMass * 150.0f;
    takyanBody->setMass(takyanMass * 100.0f);
    takyanBody->setRotationEnable(false);
    takyanBody->setVelocityLimit(velocityLimit);
    _takyan->setPhysicsBody(takyanBody);

    PHYSICS_MASK(takyanBody, MASK_TAKYAN, MASK_BOUNDS | MASK_KICKER, MASK_BOUNDS | MASK_KICKER);

    Size takyanSize = _takyan->getContentSize();
    takyanSize.height *= 0.8f;

    PhysicsMaterial material(0.0025f, 0.0f, 1.0f);
    PhysicsBody *takyanTailBody = PhysicsBody::createCircle(takyanSize.width, material);
    takyanTailBody->setMass(takyanMass * 0.01);
    takyanTailBody->setRotationEnable(false);
    takyanTailBody->setLinearDamping(1.0f);
    takyanTailBody->setVelocityLimit(velocityLimit * 0.5f);
    _takyanTail->setPhysicsBody(takyanTailBody);

    PHYSICS_MASK(takyanTailBody, MASK_TAKYAN_TAIL, 0, MASK_FLOOR);

    Vec2 diff = _takyanTail->getPosition() - _takyan->getPosition();
    Vec2 anch1 = Vec2::ANCHOR_MIDDLE;
    Vec2 anch2 = Vec2::ANCHOR_MIDDLE;
    auto jointS = PhysicsJointLimit::construct(takyanBody, takyanTailBody, anch1, anch2, 0, diff.y);
    jointS->setCollisionEnable(false);
    world->addJoint(jointS);


    PhysicsBody *kickerBody = PhysicsBody::createCircle(_kicker->getContentSize().width * KICKER_RADIUS, PhysicsMaterial(1.0f, 1.0f, 1.0f)); //_kicker->getPhysicsBody();
    kickerBody->setDynamic(false);
    kickerBody->setEnable(false);
    _kicker->setPhysicsBody(kickerBody);

    PHYSICS_MASK(kickerBody, MASK_KICKER, MASK_TAKYAN, MASK_TAKYAN);

    int takyans = MASK_TAKYAN | MASK_TAKYAN_TAIL;

    auto floorBody = PhysicsBody::createBox(_floorBounds->getContentSize(), PhysicsMaterial(1.0f, 0.3f, 0.7f)); //_floorBounds->getPhysicsBody();
    floorBody->setDynamic(false);
    _floorBounds->setPhysicsBody(floorBody);
    PHYSICS_MASK(floorBody, MASK_BOUNDS, takyans, takyans);

    auto ceilingBody = PhysicsBody::createBox(_ceilingBounds->getContentSize(), PhysicsMaterial(1.0f, 0.3f, 0.7f));
    ceilingBody->setDynamic(false);
    _ceilingBounds->setPhysicsBody(ceilingBody);
    PHYSICS_MASK(ceilingBody, MASK_BOUNDS, MASK_TAKYAN, MASK_TAKYAN);

    Size wallSize = _leftWallBounds->getContentSize();
    wallSize.height *= 5.0f;

    auto leftWallBody = PhysicsBody::createBox(wallSize); //_leftWallBounds->getPhysicsBody();
    leftWallBody->setDynamic(false);
    _leftWallBounds->setPhysicsBody(leftWallBody);
    PHYSICS_MASK(leftWallBody, MASK_WALLS, takyans, MASK_TAKYAN);

    auto rightWallBody = PhysicsBody::createBox(wallSize); //_rightWallBounds->getPhysicsBody();
    rightWallBody->setDynamic(false);
    _rightWallBounds->setPhysicsBody(rightWallBody);
    PHYSICS_MASK(rightWallBody, MASK_WALLS, takyans, MASK_TAKYAN);
}