Exemplo n.º 1
0
void Level::createPhysicsBody()
{
	for (auto& object : _collisionObjectGroup->getObjects())
	{
		float objectX = object.asValueMap().at("x").asFloat(),
			objectY = object.asValueMap().at("y").asFloat();
		Size s = Size(object.asValueMap().at("width").asFloat(), 
					  object.asValueMap().at("height").asFloat());

		if (object.asValueMap().find("polylinePoints") == object.asValueMap().end())
		{
			PhysicsShapeBox *box = PhysicsShapeBox::create(s, PhysicsMaterial(0.0f, 0.0f, 1.0f),
				Vec2(objectX + s.width / 2, objectY + s.height / 2));
			box->setTag(0);

			PhysicsBody *body = PhysicsBody::create();
			body->setDynamic(false);
			body->setContactTestBitmask(0xFFFFFFFF);
			body->addShape(box);

			Node* node = Node::create();
			node->setPhysicsBody(body);
			//addChild(node);
			_physicsNodes.pushBack(node);
		}
		else
		{
			Vec2 t[2];
			int i = 0;
			for (auto& point : object.asValueMap().at("polylinePoints").asValueVector())
			{
				// convert the points' local coordinates to the world coordinates
				// by doing a translation using the object's position vector

				// We invert the local y because it's based on the top-left space in Tiled
				t[i].x = point.asValueMap().at("x").asInt() + objectX;
				t[i].y = -point.asValueMap().at("y").asInt() + objectY;
				i++;
			}
			PhysicsShapeEdgeSegment *line = PhysicsShapeEdgeSegment::create(t[0], t[1], 
				PhysicsMaterial(0.0f, 0.0f, 1.0f));
			line->setTag(0);

			PhysicsBody *body = PhysicsBody::create();
			body->setDynamic(false);
			body->setContactTestBitmask(0xFFFFFFFF);
			body->addShape(line);

			Node* node = Node::create();
			node->setPhysicsBody(body);
			//addChild(node);
			_physicsNodes.pushBack(node);
		}
	}
}
void PipeSprite::configPipeRandom()
{

    Size visiableSize = Director::getInstance()->getVisibleSize();
    Vec2 visiableOrigin = Director::getInstance()->getVisibleOrigin();
    
    /**********************config upper pipe********************************/
    mUpperPipe->setPosition(Vec2(0, mPipeAccessHeight + 60));
    upperPipeExpand->setPosition(mUpperPipe->getPosition().x, mUpperPipe->getContentSize().height);
    upperPipeExpand->setScaleY((visiableSize.height - mUpperPipe->getPosition().y - mUpperPipe->getContentSize().height) / upperPipeExpand->getContentSize().height);
    /**********************config upper pipe********************************/
    
    /**********************config bottom pipe********************************/
    mBottomPipe->setPosition(Vec2(0, mPipeAccessHeight - 60));
    bottomPipeExpand->setPosition(0, -mBottomPipe->getPosition().y + mLandHeight);
    bottomPipeExpand->setScaleY((mBottomPipe->getPosition().y - mLandHeight) / bottomPipeExpand->getContentSize().height);
    /**********************config bottom pipe********************************/
    
    /****************add upper physics body*******************/
    if (mUpperPipe->getPhysicsBody() != nullptr)
    {
        mUpperPipe->removeComponent(mUpperPipe->getPhysicsBody());
    }
    PhysicsBody * newUpperPipeBody = PhysicsBody::createBox(Size(mUpperPipe->getContentSize().width,
                                                              visiableSize.height - mUpperPipe->getPosition().y),
                                                            PhysicsMaterial(1.0, 1.0, 0));
    newUpperPipeBody->setPositionOffset(Vec2(0, (visiableSize.height - mUpperPipe->getPosition().y - mUpperPipe->getContentSize().height) / 2));
    newUpperPipeBody->setGravityEnable(false);
    newUpperPipeBody->setDynamic(false);
    newUpperPipeBody->setContactTestBitmask(1);
    newUpperPipeBody->setCollisionBitmask(2);
    mUpperPipe->setPhysicsBody(newUpperPipeBody);
    /****************add upper physics body*******************/
    
    /****************add bottom physics body*******************/
    if (mBottomPipe->getPhysicsBody() != nullptr)
    {
        mBottomPipe->removeComponent(mBottomPipe->getPhysicsBody());
    }
    PhysicsBody * newBottomPipeBody = PhysicsBody::createBox(Size(mBottomPipe->getContentSize().width,
                                                                  mBottomPipe->getPosition().y - mLandHeight + mBottomPipe->getContentSize().height),
                                                             PhysicsMaterial(1.0, 1.0, 0));
    newBottomPipeBody->setPositionOffset(Vec2(0, -(mBottomPipe->getPosition().y - mLandHeight) / 2));
    newBottomPipeBody->setGravityEnable(false);
    newBottomPipeBody->setDynamic(false);
    newBottomPipeBody->setContactTestBitmask(1);
    newBottomPipeBody->setCollisionBitmask(2);
    mBottomPipe->setPhysicsBody(newBottomPipeBody);
    /****************add bottom physics body*******************/
}
Exemplo n.º 3
0
bool Car::init(string fileName)
{
	if (!Node::init())
		return false;

	//-------------  Khởi tạo sprite chính -------------
	_sprite = Sprite::create(fileName);
	_sprite->setPosition(0, 0);
	_sprite->setAnchorPoint(Vec2(0.25, 0.25));
	this->addChild(_sprite);

	
	//-------------   Physic Body  --------------
	body = PhysicsBody::createBox(Size(_sprite->getContentSize().width / 2, _sprite->getContentSize().height / 2), PhysicsMaterial(100.0f, 0.0f, 100.0f), Vec2::ZERO);
	body->setDynamic(false);
	body->setTag(Tags::OBSTRUCTION);
	body->setCollisionBitmask(1);
	body->setContactTestBitmask(1);
	this->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	this->setPhysicsBody(body);


	//Mai xe
	auto nodeCar = Node::create();
	nodeCar->setPosition(_sprite->getContentSize().width * 2.1 / 4, _sprite->getContentSize().height * 2.3 / 3);
	nodeCar->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	_sprite->addChild(nodeCar);
	PhysicsBody * bodyNodeCar = PhysicsBody::createBox(Size(_sprite->getContentSize().width * 2.5 / 5, _sprite->getContentSize().height / 3), PhysicsMaterial(100.0f, 0.0f, 100.0f), Vec2::ZERO);
	bodyNodeCar->setTag(Tags::MAIXE);
	bodyNodeCar->setDynamic(false);
	bodyNodeCar->setContactTestBitmask(1);
	bodyNodeCar->setCollisionBitmask(1);
	nodeCar->setPhysicsBody(bodyNodeCar);

	//Score
	auto nodeScore = Node::create();
	nodeScore->setPosition(_sprite->getContentSize().width * 2.1 / 4, _sprite->getContentSize().height);
	nodeScore->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	_sprite->addChild(nodeScore);
	PhysicsBody * bodyNodeScore = PhysicsBody::createBox(Size(_sprite->getContentSize().width * 2.5 / 5, Config::screenSize.height), PhysicsMaterial(100.0f, 0.0f, 100.0f), Vec2::ZERO);
	bodyNodeScore->setTag(Tags::NODE_SCORE);
	bodyNodeScore->setDynamic(false);
	bodyNodeScore->setCategoryBitmask(0x01);
	bodyNodeScore->setContactTestBitmask(1);
	bodyNodeScore->setCollisionBitmask(0x02);
	nodeScore->setPhysicsBody(bodyNodeScore);

	return true;
}
Exemplo n.º 4
0
bool HeroSprite::init() {
	bool bRet = false;

	do {
		CC_BREAK_IF(!Sprite::initWithSpriteFrameName("heroStand_0001.png"));

		Size heroSize = this->getContentSize();
		PhysicsBody *body = PhysicsBody::createBox(heroSize-Size(0,16), PhysicsMaterial(0, 0, 0));
		body->setLinearDamping(0.0f);
		body->setDynamic(true);
		body->setGravityEnable(true);
		body->setTag(TAG_HERO_PHYS_BODY);
		body->setCategoryBitmask(1<<2);
		body->setContactTestBitmask(1<<0 | 1<<1);
		body->setMass(50);
		body->setRotationEnable(false);

		this->setPhysicsBody(body);

		mState = STATE_IDLE;
        mRunAnimate = NULL;
        mSmokeRunAnimate = NULL;

		bRet = true;
	} while(0);

	return bRet;
}
Exemplo n.º 5
0
void ShowLayer::initPhyscsObject(Rect* m)
{
	for (int i = 0; i < 26; i++)
	{
		Sprite* sp = Sprite::create();
		auto maskLayer = LayerColor::create(Color4B(0, 0, 255, 200));
		maskLayer->setContentSize(m[i].size);
		maskLayer->setAnchorPoint(Vec2(0, 0));
		sp->addChild(maskLayer, 15);

		PhysicsBody* playerBody = PhysicsBody::createBox(m[i].size, PHYSICSBODY_MATERIAL_DEFAULT);

		playerBody->setDynamic(false);

		//设置质量
		playerBody->getShape(0)->setMass(100);

		//设置物体是否受重力系数影响
		playerBody->setGravityEnable(false);

		playerBody->setCategoryBitmask(3);
		playerBody->setContactTestBitmask(3);
		playerBody->setCollisionBitmask(3);

		sp->setContentSize(m[i].size);
		sp->setPosition(Vec2(m[i].getMidX(), m[i].getMidY()));
		sp->setAnchorPoint(Vec2(0.0, 0.0));
		sp->setPhysicsBody(playerBody);

		this->addChild(sp);
	}
}
Exemplo n.º 6
0
void Person::addPhysics()
{
	auto size = (this->getBoundingBox()).size;
	log("%lf %lf", size.width, size.height);
	auto material = PhysicsMaterial(100.0f, 0.01f, 1.0f);
	if(_type == TYPE::HERO) size.width /= 2;
	PhysicsBody *body = PhysicsBody::createBox(Size(size.width,size.height),material);
//	body->addShape(PhysicsShapeBox::create(Size(size.width,size.height),material));
	body->setCategoryBitmask(_type);
	if(_type == TYPE::MONSTER) 
	{
		body->setCollisionBitmask(TYPE::MONSTER  | TYPE::BRICK | TYPE::GROUND | 
			TYPE::TANGH | TYPE::BULLET | TYPE::BOSS | TYPE::PLANK);
		body->setContactTestBitmask(TYPE::MONSTER | TYPE::HERO | TYPE::BRICK | 
			TYPE::TANGH | TYPE::BULLET | TYPE::BOSS);
	}
	else if(_type == TYPE::HERO)
	{
		body->setCollisionBitmask( TYPE::HERO | TYPE::GROUND | TYPE::TANGH | TYPE::PLANK);
		body->setContactTestBitmask(TYPE::MONSTER | TYPE::HERO | TYPE::GROUND | 
			TYPE::TANGH | TYPE::BULLET | TYPE::TRAP | TYPE::BOSS |
			TYPE::BULLETENEMY | TYPE::PLANK | TYPE::BUFF);
	}
	else if(_type == TYPE::BOSS)
	{
		body->setCollisionBitmask( TYPE::HERO | TYPE::GROUND | TYPE::BOSS | PLANK);
		body->setContactTestBitmask( TYPE::HERO | TYPE::GROUND | TYPE::BOSS);
	}
	body->setDynamic(true);
	body->setLinearDamping(0.0f);
	body->setRotationEnable(false);
	body->setGravityEnable(true);
	this->setPhysicsBody(body);
}
Exemplo n.º 7
0
void SpeedUpProtect::initBody()
{
	auto s = getContentSize();
	Vec2 vec[7] = 
	{
		Vec2(0,0),
		Vec2(s.width * 0.1, s.height * 0.4),
		Vec2(s.width * 0.26, s.height * 0.72),
		Vec2(s.width * 0.5, s.height),
		Vec2(s.width * 0.74, s.height * 0.72),
		Vec2(s.width * 0.9, s.height * 0.4),
		Vec2(s.width,0),
	};

	PhysicsBody* body = PhysicsBody::createPolygon(vec, 7, PHYSICSBODY_MATERIAL_DEFAULT, Vec2(-s.width*0.5,-s.height*0.5));
	body->setGravityEnable(false);
	body->setRotationEnable(false);
	body->setDynamic(false);
	body->setMass(10000000);
	body->setCategoryBitmask(SELF_SCOPE_CATEGORYBITMASK);
	body->setCollisionBitmask(SELF_SCOPE_COLLISIONBITMASK);
	body->setContactTestBitmask(SELF_SCOPE_CONTACTTESTBITMASK);
	setPhysicsBody(body);
	setInvincible(true);
	m_ContactPro.hurts = -Ene_Plane_Hp_max - 10;
}
Exemplo n.º 8
0
bool guaiwu_js::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    auto root_layer = CSLoader::createNode("LayerUI/Other/guaiwu.csb");
    addChild(root_layer);
    auto rooaby = root_layer->getChildByName<Node*>("FileNode_1")->getChildByName<Sprite*>("anim_guaiwu_zo0001_2");
    PhysicsBody* phybody = PhysicsBody::createBox(Size(rooaby->getContentSize().width-8, rooaby->getContentSize().height-20));
    phybody->setTag(400001);
    phybody->setMass(3000);
    phybody->setRotationEnable(false);
    phybody->setCategoryBitmask(0x01);
    phybody->setCollisionBitmask(0x02);
    phybody->setContactTestBitmask(0x01);
    phybody->setDynamic(true);
    rooaby->setPhysicsBody(phybody);
    guaiwu = CSLoader::createTimeline("Node/animation/guaiwujs.csb");
    guaiwu->gotoFrameAndPlay(0,35, true);
    root_layer->runAction(guaiwu);
    scheduleUpdate();
    //添加碰撞事件
    auto collisionlistener = EventListenerPhysicsContact::create();
    collisionlistener->onContactBegin =CC_CALLBACK_1(guaiwu_js::onCollisionBegin, this);
    collisionlistener->onContactSeparate = CC_CALLBACK_1(guaiwu_js::onContactSeparate,this);
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(collisionlistener, this);
    return true;
}
bool LandSprite::init()
{
    if (!Sprite::init())
    {
        return false;
    }
    
    Size visiableSize = Director::getInstance()->getVisibleSize();
    Vec2 visiableOrigin = Director::getInstance()->getVisibleOrigin();
    
    Sprite * landSprite1 = Sprite::create("assets/land.png");
    landSprite1->setAnchorPoint(Vec2(0, 0));
    landSprite1->setPosition(Vec2(visiableOrigin.x, visiableOrigin.y));
    landSprite1->setScaleX(visiableSize.width / landSprite1->getContentSize().width / 2);
    
    Sprite * landSprite2 = Sprite::create("assets/land.png");
    landSprite2->setAnchorPoint(Vec2(0, 0));
    landSprite2->setPosition(Vec2(visiableOrigin.x + visiableSize.width / 2, visiableOrigin.y));
    landSprite2->setScaleX(visiableSize.width / landSprite2->getContentSize().width / 2);
    
    Sprite * landSprite3 = Sprite::create("assets/land.png");
    landSprite3->setAnchorPoint(Vec2(0, 0));
    landSprite3->setPosition(Vec2(visiableOrigin.x + visiableSize.width, visiableOrigin.y));
    landSprite3->setScaleX(visiableSize.width / landSprite3->getContentSize().width / 2);
    
    Sprite * landSprite4 = Sprite::create("assets/land.png");
    landSprite4->setAnchorPoint(Vec2(0, 0));
    landSprite4->setPosition(Vec2(visiableOrigin.x + visiableSize.width * 1.5, visiableOrigin.y));
    landSprite4->setScaleX(visiableSize.width / landSprite4->getContentSize().width / 2);
    
    Node * landAnimNode = Node::create();    // node hold the land animation
    landAnimNode->addChild(landSprite1);
    landAnimNode->addChild(landSprite2);
    landAnimNode->addChild(landSprite3);
    landAnimNode->addChild(landSprite4);
    
    MoveBy * landForward = MoveBy::create(5, Vec2(-visiableSize.width, 0));
    MoveBy * landBackward = MoveBy::create(0.001, Vec2(visiableSize.width, 0));
    Sequence * moveSeq = Sequence::create(landForward, 0.001, landBackward,NULL);
    landSprite1->runAction(RepeatForever::create(moveSeq));
    landSprite2->runAction(RepeatForever::create(moveSeq->clone()));
    landSprite3->runAction(RepeatForever::create(moveSeq->clone()));
    landSprite4->runAction(RepeatForever::create(moveSeq->clone()));
    
    this->addChild(landAnimNode);
    this->setAnchorPoint(Vec2(0, 0));
    this->setContentSize(Size(visiableSize.width, landSprite1->getContentSize().height));
    
    PhysicsBody * landPhysicsBody = PhysicsBody::createBox(Size(visiableSize.width, landSprite1->getContentSize().height), PhysicsMaterial(1, 1, 0));
    landPhysicsBody->setGravityEnable(false);
    landPhysicsBody->setDynamic(false);
    landPhysicsBody->setContactTestBitmask(1);
    landPhysicsBody->setCollisionBitmask(2);
    this->setPhysicsBody(landPhysicsBody);
    
    
    return true;
}
Exemplo n.º 10
0
void HelloWorld::setCollider (int tag){
    Sprite* floor = (Sprite *)ScreenUtil::getChildbyTagRecursively(this, tag);
    auto size = Size(floor ->getContentSize().width * floor->getScaleX()
                     , floor ->getContentSize().height * floor->getScaleY());
    PhysicsBody* floorPb = PhysicsBody::createBox(size);
    
    floorPb->setDynamic(false);
    floor->setPhysicsBody(floorPb);
}
Exemplo n.º 11
0
void BoySprite::setPhysical() {
	// add the physical body
	PhysicsBody *body = PhysicsBody::create();
	body->addShape(NORMAL_SHAPE);
	body->setDynamic(true);
	body->setLinearDamping(0.0f);
	body->setRotationEnable(false);
	this->setPhysicsBody(body);
}
Exemplo n.º 12
0
void Ball::initPhysics(){
	PhysicsBody *spriteBody = PhysicsBody::createCircle(this->getSprite()->getBoundingBox().size.width , PHYSICSBODY_MATERIAL_DEFAULT);
	spriteBody->setDynamic(true);
	spriteBody->getShape(0)->setRestitution(1.0f);
	spriteBody->getShape(0)->setFriction(0.0f);
	spriteBody->getShape(0)->setDensity(1.0f);
	spriteBody->getShape(0)->setMass(100);
	spriteBody->setGravityEnable(false);
	spriteBody->setVelocity(this->velocity);
	this->getSprite()->setPhysicsBody(spriteBody);
}
Exemplo n.º 13
0
void Hero::initPhysics() {
    PhysicsBody* pbody = nullptr;
    pbody = PhysicsBody::createBox(getSize());
    pbody->setDynamic(true);
    pbody->setRotationEnable(false);
    pbody->setMoment(0);
    pbody->setMass(0.8);
    pbody->setContactTestBitmask(1);
    pbody->setGravityEnable(false);
    getSprite()->setPhysicsBody(pbody);
    
    mEnableGravity = true;
    mEnableForceField = true;
}
Exemplo n.º 14
0
PhysicsBody* PhysicsBody::createEdgeSegment(const Vec2& a, const Vec2& b, const PhysicsMaterial& material, float border/* = 1*/)
{
    PhysicsBody* body = new (std::nothrow) PhysicsBody();
    if (body && body->init())
    {
        body->addShape(PhysicsShapeEdgeSegment::create(a, b, material, border));
        body->setDynamic(false);
        body->autorelease();
        return body;
    }
    
    CC_SAFE_DELETE(body);
    return nullptr;
}
Exemplo n.º 15
0
PhysicsBody* PhysicsBody::createEdgeBox(const Size& size, const PhysicsMaterial& material, float border/* = 1*/, const Vec2& offset)
{
    PhysicsBody* body = new (std::nothrow) PhysicsBody();
    if (body && body->init())
    {
        body->addShape(PhysicsShapeEdgeBox::create(size, material, border, offset));
        body->setDynamic(false);
        body->autorelease();
        return body;
    }
    
    CC_SAFE_DELETE(body);

    return nullptr;
}
Exemplo n.º 16
0
PhysicsBody* PhysicsBody::createEdgeChain(const Vec2* points, int count, const PhysicsMaterial& material, float border/* = 1*/)
{
    PhysicsBody* body = new (std::nothrow) PhysicsBody();
    if (body && body->init())
    {
        body->addShape(PhysicsShapeEdgeChain::create(points, count, material, border));
        body->setDynamic(false);
        body->autorelease();
        return body;
    }
    
    CC_SAFE_DELETE(body);
    
    return nullptr;
}
Exemplo n.º 17
0
BigStone::BigStone(){
	Sprite::init();
	_isDead = false;
	PhysicsMaterial material;
	material.density = 0.f;
	material.restitution = 0.f;
	material.friction = 0.f;
	PhysicsBody* pb = PhysicsBody::createCircle(270,material);
	//物理挙動の設定
	pb->setMass(10000.0f);
	pb->setDynamic(true);
	pb->setContactTestBitmask(true);
	setPhysicsBody(pb);
	setName("BigStone");

	retain();
}
Exemplo n.º 18
0
bool Rock::init()
{
    if (!Sprite::initWithFile("rock.png"))
    {
        return false;
    }
    
    PhysicsBody* rockBody = PhysicsBody::createBox(this->getContentSize(), PhysicsMaterial(DEFAULT_ROCK_MATERIAL));
    rockBody->setDynamic(false);
    rockBody->setContactTestBitmask(ROCK_CONTACT_MASK);
    rockBody->setCategoryBitmask(ROCK_CATEGORY);
    rockBody->setCollisionBitmask(ROCK_COLLISION_MASK);
    rockBody->setGravityEnable(false);
    this->setPhysicsBody(rockBody);
    
    return true;
}
Exemplo n.º 19
0
/*
auto ball = Sprite::create("Ball.png");
        PhysicsBody *ballbody = PhysicsBody::create();
        ballbody->addShape(PhysicsShapeCircle::create(BIRD_RADIUS+5));
		
		
        ballbody->setCategoryBitmask(ColliderTypeBird);
		ballbody->setCollisionBitmask(ColliderTypeLand | ColliderTypePip);
        ballbody->setContactTestBitmask(1);
        ballbody->setDynamic(true);
		ballbody->setLinearDamping(0.0f);
		ballbody->setGravityEnable(true);
		ball->setPhysicsBody(ballbody);
		auto visibleSize = Director::getInstance()->getVisibleSize();
		ball->setPosition(bird->getPositionX()+2*20,visibleSize.height);
		addChild(ball);
*/
void GameLayer::addBallObstacle(float dt)
{
    auto ball = Sprite::create("Ball.png");
        PhysicsBody *ballbody = PhysicsBody::create();
        ballbody->addShape(PhysicsShapeCircle::create(BIRD_RADIUS+5));
		
		
        ballbody->setCategoryBitmask(ColliderTypeBall);
		ballbody->setCollisionBitmask(ColliderTypeLand | ColliderTypePip | ColliderTypeBird | ColliderTypeBall);
        ballbody->setContactTestBitmask(ColliderTypeBird);
        ballbody->setDynamic(true);
		ballbody->setLinearDamping(0.0f);
		ballbody->setGravityEnable(true);
		ball->setPhysicsBody(ballbody);
		auto visibleSize = Director::getInstance()->getVisibleSize();
		ball->setPosition(bird->getPositionX()+2*20,visibleSize.height);
		addChild(ball);
}
Exemplo n.º 20
0
void BlockBase::initPhysics() {
    
    auto size = Size(mSprite->getScaleX() * mImageSize,
                     mSprite->getScaleY() * mImageSize);
    PhysicsBody* pbody = nullptr;
    if(mKind != KIND_DEATH_CIRCLE && mKind != KIND_FORCEFIELD)
        pbody = PhysicsBody::createBox(size);
    else
        pbody = PhysicsBody::createCircle(std::max(size.height/2, size.width/2));
    
    pbody->setDynamic((mKind == KIND_PUSHABLE || mKind == KIND_HERO) ? true : false);
    pbody->setContactTestBitmask(1);
    pbody->setGravityEnable(false);
    
    mEnableGravity = mKind == KIND_PUSHABLE || mKind == KIND_HERO;
    
    mSprite->setPhysicsBody(pbody);
}
Exemplo n.º 21
0
Goal::Goal():clampPos(nullptr){
	Sprite::init();
	_isDead = false;

	PhysicsBody* pb = PhysicsBody::createCircle(25);
	pb->setMass(1000.0f);
	pb->setDynamic(true);
	pb->setContactTestBitmask(true);
	setPhysicsBody(pb);
	setName("Goal");
	
	/*-------
	 当たり判定
	 --------*/
	auto c = CollisionDelegate<Goal>::create(this, &Goal::onContact);
	CollisionFuncManager::getInstance()->addFunc(this->getName(), c);

	retain();
}
Exemplo n.º 22
0
bool Witch::init()
{ 
	mWitch = CCSprite::createWithSpriteFrameName(Tex::Player_0);
	this->addChild(mWitch);
	CCLOG("Witch Width:%f", mWitch->getContentSize().width);
	mWitch->setPosition(0, 0);
	

	PhysicsBody *body = PhysicsBody::create();
	body->setTag(1);
	this->setPhysicsBody(body);
	body->addShape(PhysicsShapeBox::create(Size(mWitch->getContentSize().width, mWitch->getContentSize().height)));
	
	body->setDynamic(true);
	body->setLinearDamping(0.0f);
	body->setGravityEnable(false); 
	
	return true;
}
Exemplo n.º 23
0
CSpikes :: CSpikes(cocos2d::Layer* layer,const float posx,const float posy)
{
	x = posx; y = posy;

	m_Sprite = cocos2d::Sprite::create("CloseNormal.png");
	//m_Sprite->Sprite::setTexture("CloseNormal.png");
	m_Sprite->setScale(10.0f);
	m_Sprite->Sprite::setPosition(Point(x,y));

	const Size size = Size(m_Sprite->getContentSize().width, m_Sprite->getContentSize().width);
	PhysicsBody* body = PhysicsBody::createBox(size);
	body->setCollisionBitmask(2);
	body->setContactTestBitmask(true);
	body->setDynamic(false);
	m_Sprite->setPhysicsBody(body);

	Render(x,y);
	layer->addChild(m_Sprite,0);
	thelayer = layer;
}
Exemplo n.º 24
0
void MonsterPart::init(Monster * _parent, cocos2d::Layer * layer, cocos2d::Vec2 _pos , std::string spriteName, float _sInterval , int zLayer , bool ifPhysics , BulletType _bulletType)
{
    // init parameter
    if (_parent != NULL)
    {
        setPartent(_parent);
    }else
        parent = NULL;
    shootInterval = _sInterval;
    this->bulletType = _bulletType;
    
    // set up the sprite
    pos = _pos;
    sprite = Sprite::create(spriteName);
    sprite->setScale(0.5);
    if (parent != NULL)
    {
        sprite->setPosition(parent->getRelatedPos(pos));
        sprite->setColor(parent->color);
    }
    layer->addChild(sprite, zLayer);
    
//    if (ifPhysics)
    {
        //  1
        auto monsterSize = sprite->getContentSize();
        PhysicsBody* body = PhysicsBody::createBox(Size(monsterSize.width , monsterSize.height),PhysicsMaterial(0.1f, 1.0f, 0.0f));
        // 2
        body->setDynamic(true);
        // 3
        body->setCategoryBitmask(PhysicsCategory::Part);
        body->setCollisionBitmask((int)PhysicsCategory::None);
        body->setContactTestBitmask((int)PhysicsCategory::MonsterA);
        
        UserData* data = new UserData();
        data->part = this;
        sprite->setUserData((void*)data);
        sprite->setPhysicsBody(body);
    }

}
Exemplo n.º 25
0
bool Buff::init(int type)
{
    char txt[100];
    _type = type;
    sprintf(txt, "buff%d.png", type);
    if (!Sprite::initWithFile(txt)) {
        return false;
    }
    this->setTag(TYPE::BUFF);
    auto size = (this->getBoundingBox()).size;
    auto material = PhysicsMaterial(100.0f, 0.01f, 1.0f);
    PhysicsBody *body = PhysicsBody::createBox(Size(size.width,size.height),material);
    //	body->addShape(PhysicsShapeBox::create(Size(size.width,size.height),material));
    body->setCategoryBitmask(TYPE::BUFF);
    body->setCollisionBitmask(0);
    body->setContactTestBitmask(TYPE::BUFF | TYPE::HERO);
    body->setDynamic(false);
    body->setRotationEnable(false);
    this->setPhysicsBody(body);
    return true;
}
Exemplo n.º 26
0
CLaser :: CLaser(cocos2d::Layer* layer,const float posx,const float posy)
{
	index = 0;//default index

	x = posx; y = posy;

	m_Sprite = cocos2d::Sprite::create("CloseNormal.png");
	empty = CCTextureCache::sharedTextureCache()->addImage("empty.png");
	//m_Sprite->Sprite::setTexture("CloseNormal.png");
	m_Sprite->setScale(10.0f);
	m_Sprite->Sprite::setPosition(Point(x,y));

	const Size size = Size(m_Sprite->getContentSize().width, m_Sprite->getContentSize().width);
	PhysicsBody* body = PhysicsBody::createBox(size);
	body->setCollisionBitmask(3);
	body->setContactTestBitmask(true);
	body->setDynamic(false);
	m_Sprite->setPhysicsBody(body);

	Render(x,y);
	layer->addChild(m_Sprite,0);
}
Exemplo n.º 27
0
BoundWall::BoundWall(WallType type, Size screenSize)
{
    PhysicsBody* body = nullptr;
    switch (type)
    {
    case UP:
        this->setAnchorPoint(Vec2(0.5f, 0));
        this->setPosition(Vec2(screenSize.width / 2, screenSize.height));
        body = PhysicsBody::createBox(Size(screenSize.width,5), PhysicsMaterial(1, 0, 0));
        break;
    case DOWN:
        this->setAnchorPoint(Vec2(0.5f, 1));
        this->setPosition(Vec2(screenSize.width / 2, 0));
        body = PhysicsBody::createBox(Size(screenSize.width, 5), PhysicsMaterial(1, 0, 0));
        break;
    case LEFT:
        this->setAnchorPoint(Vec2(1, 0.5f));
        this->setPosition(Vec2(0, screenSize.height / 2));
        body = PhysicsBody::createBox(Size(5, screenSize.height), PhysicsMaterial(1, 0, 0));
        break;
    case RIGHT:
        this->setAnchorPoint(Vec2(0, 0.5f));
        this->setPosition(Vec2(screenSize.width, screenSize.height / 2));
        body = PhysicsBody::createBox(Size(5, screenSize.height), PhysicsMaterial(1, 0, 0));
        break;
    default:
        break;
    }

    body->setGravityEnable(false);
    body->setDynamic(false);
    body->setTag(Tags::GROUND);
    body->setCollisionBitmask(true);
    body->setContactTestBitmask(true);
    this->setPhysicsBody(body);
}
Exemplo n.º 28
0
Vector<Sprite*> Ground::createGround(GameLayer* layer)
{
	//this may need to be moved somewhere else
	srand(time(NULL));

	const int columns = 100 / BLOCK_PERCENT;

	//initialize with capacity for the maximum possible amount of blocks
	Vector<Sprite*> gndBlocks(MAX_ABS*columns);

	//generate height of first column, in number of blocks
	int height = rand() % (MAX_ABS - MIN_ABS) + MIN_ABS;
	int offset, count(0);

	PhysicsBody *body;

	Sprite *newBlock;

	//iterate over columns
	for (int i = 0; i < columns; i++){

		//iterate over the blocks of the current column
		for (int j = 0; j < height; j++){

			if (j == height - 1){ //top block of the column
				newBlock = Sprite::createWithSpriteFrameName("textures/boden_mit_gras.png");
				newBlock->setScale(float(BLOCK_X / GRASS_SIZE));
			}
			else{
				newBlock = Sprite::createWithSpriteFrameName("textures/boden.png");
				newBlock->setScale(float(BLOCK_X / DIRT_SIZE));
			}
			newBlock->setPosition(BLOCK_X / 2 + BLOCK_X*i, BLOCK_Y / 2 + BLOCK_Y*j);

			body = PhysicsBody::createBox(Size(newBlock->getContentSize().width, newBlock->getContentSize().height), PhysicsMaterial(0.1f, 0.0f, 0.5f));
			body->setDynamic(false);
			body->setContactTestBitmask(0xFFFFFFFF);

			newBlock->setPhysicsBody(body);

			newBlock->setTag(GND_TAG);

			gndBlocks.pushBack(newBlock);
			count++;
		}

		//column finished, calculate the height for next one
		offset = rand() % Y_OFFSET * 2 - Y_OFFSET;
		height += offset;
		height = height > MAX_ABS ? MAX_ABS : height;
		height = height < MIN_ABS ? MIN_ABS : height;
	}

	gndBlocks.shrinkToFit();

	for (int i = 0; i < gndBlocks.size(); i++){
		//gndBlocks.at(i)->setZOrder(1);
		layer->addChild(gndBlocks.at(i));
	}

	//create world borders
	//these won't be in the returned vector
	Sprite *borders[4] = { Sprite::create(), Sprite::create(), Sprite::create(), Sprite::create() };
	PhysicsBody* bodyB;

	for (int i = 0; i < 4; i++){
		bodyB = PhysicsBody::createBox(i % 2 == 0 ? Size(WINDOW_W, 4) : Size(4, WINDOW_H), PhysicsMaterial(0.0f, 0.0f, 0.0f));
		bodyB->setDynamic(false);
		bodyB->setContactTestBitmask(0xFFFFFFFF);
		borders[i]->setPhysicsBody(bodyB);
		switch (i){
		case 0://bottom
			borders[i]->setPosition(WINDOW_W / 2, -2.0);
			break;
		case 1://right
			borders[i]->setPosition(WINDOW_W + 2, WINDOW_H / 2);
			break;
		case 2://top
			borders[i]->setPosition(WINDOW_W / 2, WINDOW_H + 2);
			break;
		case 3://left
			borders[i]->setPosition(-2.0, WINDOW_H / 2);
			break;
		}
		borders[i]->setTag(BORDER_TAG);
		layer->addChild(borders[i]);
	}

	return gndBlocks;
}
Exemplo n.º 29
0
// on "init" you need to initialize your instance
bool Level_5::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() ){
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 visiblePoint = Director::getInstance()->getVisibleOrigin();
    auto root_level_5 = CSLoader::createNode("Scene/LevelScene/Level_5.csb");
    root_level_5->setTag(100001);
    this->addChild(root_level_5);
    //设置物理 空心世界
    PhysicsBody* psworld =PhysicsBody::createEdgeBox(Size(visibleSize.width,visibleSize.height*1.2),PHYSICSBODY_MATERIAL_DEFAULT,2);
    psworld->setCategoryBitmask(0x01);
    psworld->setCollisionBitmask(0x01);
    psworld->setContactTestBitmask(0x01);
    root_level_5->setPhysicsBody(psworld);
    //火把
    Node* hb1 = root_level_5->getChildByName<Node*>("FileNode_1");
    //火把
    Node* hb2 = root_level_5->getChildByName<Node*>("FileNode_1_0");
    fire_x* fhb1 = fire_x::create();
    fhb1->setObject(hb1);
    addChild(fhb1);
    fire_x* fhb2 = fire_x::create();
    fhb2->setObject(hb2);
    addChild(fhb2);
    //完成退出
    Sprite* exitl5 = root_level_5->getChildByName<Sprite*>("img_next_27");
    //主要车
    Sprite* carl5 = root_level_5->getChildByName<Sprite*>("img_maincarbody_1");
    //按钮一
    Sprite* btnl5_1 = root_level_5->getChildByName<Sprite*>("btn_010001_50");
    //按钮二
    anim_l5_2 = root_level_5->getChildByName<Node*>("FileNode_2_kill");
    //按钮三
    Sprite* btnl5_3 = root_level_5->getChildByName<Sprite*>("btn_010001_50_0");
    //问题1
    Sprite* questionl4_1 = root_level_5->getChildByName<Sprite*>("anim_question0001_51_0");
    //问题2
    Sprite* questionl4_2 = root_level_5->getChildByName<Sprite*>("anim_question0001_51");
    //问题3
    Sprite* questionl4_3 = root_level_5->getChildByName<Sprite*>("anim_question0001_25");
    //怪物a
    Sprite* monsterl5_0 = root_level_5->getChildByName<Sprite*>("monster_18");
    //怪物
    Sprite* monsterl5_1 = root_level_5->getChildByName<Sprite*>("anim_guaiwu_1");
    //按钮二
    Sprite* monsterl5_2 = root_level_5->getChildByName<Sprite*>("btn_010001_22_0");
    //按钮二
    Sprite* monsterl5_3 = root_level_5->getChildByName<Sprite*>("btn_010001_22_0_0");
    //地面按钮
    Sprite* btngroundl5_2 = root_level_5->getChildByName<Sprite*>("btn_dicar0001_9");
    //地面右上
    Sprite* groundl5_1 = root_level_5->getChildByName<Sprite*>("td4_47_2");
    //地面下
    Sprite* groundl5_2 = root_level_5->getChildByName<Sprite*>("d1_3");
    //地面左上
    Sprite* groundl5_5 = root_level_5->getChildByName<Sprite*>("td4_47_1");
    //地面右上
    Sprite* groundl5_6 = root_level_5->getChildByName<Sprite*>("td4_47_3");
    //弹簧
    Sprite* sprs = root_level_5->getChildByName<Sprite*>("tur0001_47");
    //怪物门
    Sprite* gate = root_level_5->getChildByName<Sprite*>("d3_5");
    //yidong
    Sprite* move_17 = root_level_5->getChildByName<Sprite*>("move_17");
    //电网
    ParticleSystemQuad* particle_1 = root_level_5->getChildByName<ParticleSystemQuad*>("Particle_1");
    particle_1->setContentSize(Size(26.0f,200.0f));
    ToolsFunction::setPhyDynamicSpriteBox(move_17);
    ToolsFunction::setPhyDynamicSpriteBox(groundl5_1);
    ToolsFunction::setPhyDynamicSpriteBox(groundl5_2);
    ToolsFunction::setPhyDynamicSpriteBox(groundl5_5);
    ToolsFunction::setPhyDynamicSpriteBox(groundl5_6);
    
    //设置刚体
    PhysicsBody* psworld2 =PhysicsBody::createBox(Size(particle_1->getContentSize().width,particle_1->getContentSize().height));
    psworld2->setPositionOffset(Vec2(-13.0f, -110.0f));
    //火的碰撞掩码
    psworld2->setTag(PHY_TAG_KILL_FIRE);
    //设置触发 掩码
    psworld2->setContactTestBitmask(0x01);
    psworld2->setCollisionBitmask(0x02);
    psworld2->setDynamic(false);
    particle_1->setPhysicsBody(psworld2);
    
    //添加地面按钮
    Btn_Ground_1* btngr = Btn_Ground_1::create();
    btngr->setObj(btngroundl5_2);
    addChild(btngr);
    
    //创建主要UI界面
    mainui = MainUI::create();
    auto maincar_r = MainCar_R::create();
    mainui->setCar_R(maincar_r);
    maincar_r->setMainUI(mainui);
    maincar_r->setObj(carl5);
    addChild(maincar_r,10);
    addChild(mainui,3000);
    //退出
    Exit* eit = Exit::create();
    eit->setObj(exitl5);
    addChild(eit);
    
    Btn_QuestionSelect* qbs2 = Btn_QuestionSelect::create();
    qbs2->setObj(questionl4_1);
    qbs2->setIBtnMainUI(mainui, btngr);
    addChild(qbs2,30);
    //弹簧按按钮
    Btn_Standard* bs2 = Btn_Standard::create();
    bs2->setObj(btnl5_1);
    addChild(bs2,30);
    Btn_QuestionSelect* qbs3 = Btn_QuestionSelect::create();
    qbs3->setObj(questionl4_2);
    qbs3->setIBtnMainUI(mainui, bs2);
    addChild(qbs3,30);
    //怪物,门
    Btn_Standard* bs3 = Btn_Standard::create();
    bs3->setObj(btnl5_3);
    addChild(bs3,30);
    Btn_QuestionSelect* qbs4 = Btn_QuestionSelect::create();
    qbs4->setObj(questionl4_3);
    qbs4->setIBtnMainUI(mainui, bs3);
    addChild(qbs4,30);
    
    Layer* dlyer = Layer::create();
    dlyer->addChild(groundl5_5);
    addChild(dlyer);
    //怪物移动
    guaiwu_js* gu = guaiwu_js::create();
    gu->setGuanwu(monsterl5_1);
    gu->setMovePosition(monsterl5_2, monsterl5_3, 20.0f);
    addChild(gu);
    PhysicsBody* gua = PhysicsBody::createBox(monsterl5_0->getContentSize());
    gua->setTag(400030);
    gua->setRotationEnable(false);
    gua->setCategoryBitmask(0x01);
    gua->setCollisionBitmask(0x02);
    gua->setContactTestBitmask(0x01);
    gua->setDynamic(true);
    monsterl5_0->setPhysicsBody(gua);
    //添加力度
    bs2->getBtn()->addTouchEventListener([=](Ref* reft, Widget::TouchEventType type)
                                         {
                                             if (type==Widget::TouchEventType::ENDED) {
                                                 //bs2->PlayEffect();
                                                 //spr->addForce(Vec2(1000.0f, 1500.0f));
                                                 if (ismove) {
                                                     auto moveto = MoveTo::create(0.8f, Vec2(384.2f, move_17->getPosition().y));
                                                     move_17->runAction(moveto);
                                                     ismove = false;
                                                 }else{
                                                     auto moveto = MoveTo::create(0.8f, Vec2(159.2f, move_17->getPosition().y));
                                                     move_17->runAction(moveto);
                                                     ismove = true;
                                                 }
                                             }
                                         });
    //关门
    bs3->getBtn()->addTouchEventListener([=](Ref* reft, Widget::TouchEventType type)
                                         {
                                             if (type==Widget::TouchEventType::ENDED) {
                                                 bs2->PlayEffect();
                                                 auto scal = ScaleTo::create(1.0f, -1, 1);
                                                 gate->runAction(scal);
                                                 gua->setEnabled(false);
                                             }
                                         });
    //地面按钮
    btngr->onCallbackTest_2([=]()
                            {
                                if (particle_1) {
                                    particle_1->setVisible(false);
                                    particle_1->getPhysicsBody()->setEnabled(false);
                                }
                            });
    
    
    //怪物动画刚体
    Sprite* sprsphys = root_level_5->getChildByName<Sprite*>("btn_010001_22_1");
    sprsphys->setVisible(false);
    PhysicsBody* guaup = PhysicsBody::createBox(Size(sprsphys->getContentSize().width*1.5f,sprsphys->getContentSize().height));
    guaup->setTag(PHY_TAG_KILL_UP);
    guaup->setRotationEnable(false);
    guaup->setCategoryBitmask(0x01);
    guaup->setCollisionBitmask(0x02);
    guaup->setContactTestBitmask(0x01);
    guaup->setDynamic(true);
    sprsphys->setPhysicsBody(guaup);
    
    //播放怪物动画
    anim = CSLoader::createTimeline("Node/level_animation/l5_updown.csb");
    anim->gotoFrameAndPlay(0, 320, true);
    root_level_5->runAction(anim);
    //怪物下来
    anim->addFrameEndCallFunc(29, "a", [=]()
                              {
                                  guaup->setEnabled(true);
                              });
    //怪物下来
    anim->addFrameEndCallFunc(30, "b", [=]()
                              {
                                 guaup->setEnabled(true);
                              });
    //怪物下来
    anim->addFrameEndCallFunc(74, "c", [=]()
                              {
                                  guaup->setEnabled(false);
                              });
    //怪物下来
    anim->addFrameEndCallFunc(75, "d", [=]()
                              {
                                  guaup->setEnabled(false);
                              });
    scheduleUpdate();
    return true;
}
Exemplo n.º 30
0
bool LevelFifteen::init()
{
	if (!Layer::init())
	{
		return false;
	}

	// 用于解决刚体穿透问题
	this->scheduleUpdate();
	// 计时器
	this->schedule(schedule_selector(LevelFifteen::timeCounter), 1.0f);

	auto visibleSize = Director::getInstance()->getVisibleSize();
	auto origin = Director::getInstance()->getVisibleOrigin();

	// 加载背景贴图
	auto spriteBg = Sprite::create("background.png");
	spriteBg->setAnchorPoint(Vec2::ZERO);
	spriteBg->setPosition(Vec2::ZERO);
	addChild(spriteBg);

	// 将资源加载到精灵帧缓存
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("threeColor.plist");

	ballOne = Sprite::createWithSpriteFrameName("hero.png");
	ballOne->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f);
	auto ballBodyOne = PhysicsBody::createCircle(ballOne->getContentSize().width / 2, PHYSICSBODY_MATERIAL_DEFAULT);
	//是否设置物理为静态
	//ballBodyOne->setDynamic(false);
	//设置物理的恢复力
	ballBodyOne->getShape(0)->setRestitution(0.5f);
	//设置物体的摩擦力
	ballBodyOne->getShape(0)->setFriction(0.0f);
	ballBodyOne->getShape(0)->setDensity(0.3f);
	// 设置质量 质量等于密度乘以面积
	//ballBodyOne->getShape(0)->setMass(5000);
	// 设置物体是否受重力系数影响
	ballBodyOne->setGravityEnable(true);

	ballBodyOne->setCategoryBitmask(1);// 分类掩码
	ballBodyOne->setCollisionBitmask(1 | 2 | 4 | 8);// 碰撞掩码
	ballBodyOne->setContactTestBitmask(2);// 接触测试掩码

	// 把物体添加到精灵
	ballOne->setPhysicsBody(ballBodyOne);
	this->addChild(ballOne);


	// 创建抢食者(黑色)
	Sprite* black = nullptr;
	PhysicsBody* blackBody = nullptr;
	Vec2 arrBlack[] =
	{
		Vec2(-34.00000, -32.50000),
		Vec2(-15.00000, 36.00000),
		Vec2(35.00000, -15.00000)
	};
	int indexBlack = CCRANDOM_0_1() * 3;
	switch (indexBlack)
	{
	case 0:
	{
			  black = Sprite::createWithSpriteFrameName("black1.png");
			  blackBody = PhysicsBody::createBox(black->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT);
	}
		break;
	case 1:
	{
			  black = Sprite::createWithSpriteFrameName("black2.png");
			  blackBody = PhysicsBody::createCircle(black->getContentSize().width / 2.0f, PHYSICSBODY_MATERIAL_DEFAULT);
	}
		break;
	case 2:
	{
			  black = Sprite::createWithSpriteFrameName("black3.png");
			  blackBody = PhysicsBody::createPolygon(arrBlack, 3, PHYSICSBODY_MATERIAL_DEFAULT);
	}
		break;
	default:
		break;
	}
	black->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f);
	blackBody->setDynamic(true);
	blackBody->setGravityEnable(false);
	blackBody->setCategoryBitmask(8);
	blackBody->setCollisionBitmask(1 | 2 | 4 | 8);
	blackBody->setContactTestBitmask(2);
	black->setPhysicsBody(blackBody);
	this->addChild(black);

	//创建一个盒子,用来碰撞
	auto edgeSpace = Sprite::create();
	auto boundBody = PhysicsBody::createEdgeBox(visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3);
	boundBody->getShape(0)->setFriction(0.0f);
	boundBody->getShape(0)->setRestitution(1.0f);

	edgeSpace->setPhysicsBody(boundBody);
	edgeSpace->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
	this->addChild(edgeSpace);
	edgeSpace->setTag(0);

	boundBody->setCategoryBitmask(4);
	boundBody->setCollisionBitmask(1 | 2 | 4 | 8);
	boundBody->setContactTestBitmask(0);

	// 创建yuan
	auto white1 = Sprite::createWithSpriteFrameName("white2.png");
	auto whiteBody1 = PhysicsBody::createCircle(white1->getContentSize().width / 2.0f, PHYSICSBODY_MATERIAL_DEFAULT);
	whiteBody1->setDynamic(false);
	whiteBody1->setCategoryBitmask(4);
	whiteBody1->setCollisionBitmask(1 | 2 | 4 | 8);
	whiteBody1->setContactTestBitmask(0);
	white1->setPhysicsBody(whiteBody1);
	this->addChild(white1);

	// 正方形
	auto white1_2 = Sprite::createWithSpriteFrameName("white1.png");
	auto whiteBody1_2 = PhysicsBody::createBox(white1_2->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT);
	whiteBody1_2->setDynamic(false);
	whiteBody1_2->setCategoryBitmask(4);
	whiteBody1_2->setCollisionBitmask(1 | 2 | 4 | 8);
	whiteBody1_2->setContactTestBitmask(0);
	white1_2->setPhysicsBody(whiteBody1_2);
	this->addChild(white1_2);

	// 创建三角形
	Vec2 arr[] =
	{
		Vec2(-16.50000, 36.00000),
		Vec2(35.50000, -15.00000),
		Vec2(-34.00000, -32.50000)
	};
	auto white3 = Sprite::createWithSpriteFrameName("white3.png");
	auto whiteBody3 = PhysicsBody::createPolygon(arr, 3, PHYSICSBODY_MATERIAL_DEFAULT);
	whiteBody3->setDynamic(false);
	whiteBody3->setCategoryBitmask(4);
	whiteBody3->setCollisionBitmask(1 | 2 | 4 | 8);
	whiteBody3->setContactTestBitmask(0);
	white3->setPhysicsBody(whiteBody3);
	this->addChild(white3);

	// 随机位置
	int index = CCRANDOM_0_1() * 3;
	switch (index)
	{
	case 0:
	{
			  white1->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f + 200.0f);
			  white1_2->setPosition(visibleSize.width / 2.0f + 200.0f, visibleSize.height / 2.0f);
			  white3->setPosition(visibleSize.width / 2.0f - 200.0f, visibleSize.height / 2.0f);
	}
		break;
	case 1:
	{
			  white1_2->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f + 200.0f);
			  white1->setPosition(visibleSize.width / 2.0f + 200.0f, visibleSize.height / 2.0f);
			  white3->setPosition(visibleSize.width / 2.0f - 200.0f, visibleSize.height / 2.0f);
	}
		break;
	case 2:
	{
			  white3->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f + 200.0f);
			  white1->setPosition(visibleSize.width / 2.0f + 200.0f, visibleSize.height / 2.0f);
			  white1_2->setPosition(visibleSize.width / 2.0f - 200.0f, visibleSize.height / 2.0f);
	}
		break;
	default:
		break;
	}

	// 正方形旋转
	auto rotation = RotateBy::create(1, 360);
	auto rotationback = rotation->reverse();
	auto seq = Sequence::create(rotation, rotationback, nullptr);
	auto repeat = RepeatForever::create(seq);
	white1->runAction(repeat);
	// 
	// 第二个正方形旋转
	auto rotation_1 = RotateBy::create(2, 360);
	auto rotationback_1 = rotation_1->reverse();
	auto seq1 = Sequence::create(rotation_1, rotationback_1, nullptr);
	auto repeat1 = RepeatForever::create(seq1);
	white1_2->runAction(repeat1);

	// 三角形旋转
	auto rotation_2 = RotateBy::create(2, 360);
	auto rotationback_2 = rotation_2->reverse();
	auto seq2 = Sequence::create(rotation_2, rotationback_2, nullptr);
	auto repeat2 = RepeatForever::create(seq2);
	white3->runAction(repeat2);

	auto yuantong0 = Sprite::createWithSpriteFrameName("yuantong.png");
	yuantong0->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height + yuantong0->getContentSize().height / 2.0f));

	auto yuantongBody = PhysicsBody::createBox(yuantong0->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT);
	yuantongBody->setDynamic(false);
	yuantongBody->setCategoryBitmask(4);
	yuantongBody->setCollisionBitmask(1 | 2 | 4 | 8);
	yuantongBody->setContactTestBitmask(0);
	yuantong0->setPhysicsBody(yuantongBody);

	this->addChild(yuantong0);

	auto moveby0 = MoveBy::create(1.0f, Vec2(0, -90));
	auto moveby0back = moveby0->reverse();
	auto easein = EaseBackIn::create(moveby0);
	auto seq0 = Sequence::create(easein, CallFuncN::create(CC_CALLBACK_1(LevelFifteen::callbackC, this)), moveby0back, nullptr);
	auto repeat0 = RepeatForever::create(seq0);
	yuantong0->runAction(repeat0);

	listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [=](Touch* touch, Event* event){
		auto touchPosition = touch->getLocation();

		Vec2 force = Vec2::ZERO;
		if ((touchPosition.x > visibleSize.width / 2.0f) && (touchPosition.y < visibleSize.height / 2.0f))
		{
			force = Vec2(50000.0f, 0.0f);
		}
		else if ((touchPosition.y < visibleSize.height / 2.0f) && (touchPosition.x < visibleSize.width / 2.0f))
		{
			force = Vec2(-50000.0f, 0.0f);
		}
		else
		{
			force = Vec2(0.0f, 50000.0f);
		}

		ballOne->getPhysicsBody()->applyImpulse(force);
		return true;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	// 时间显示文本
	test = LabelAtlas::create(StringUtils::toString(nGoal), "1.png", 14, 21, '0');
	test->setScale(2.0f);
	test->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	test->setPosition(Vec2(test->getContentSize().width + 10, visibleSize.height - test->getContentSize().height));
	this->addChild(test);

	test2 = LabelAtlas::create(StringUtils::toString(newTimes), "1.png", 14, 21, '0');
	test2->setScale(2.0f);
	test2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	test2->setPosition(Vec2(visibleSize.width - test2->getContentSize().width - 10, visibleSize.height - test2->getContentSize().height));
	this->addChild(test2);

	test3 = LabelAtlas::create(StringUtils::toString(nTimes), "1.png", 14, 21, '0');
	test3->setScale(2.0f);
	test3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	test3->setPosition(Vec2(test3->getContentSize().width*4.0f + 40, visibleSize.height - test3->getContentSize().height));
	this->addChild(test3);

	return true;
}