Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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);
}