Example #1
0
bool GameScene::init()
{
	if(Scene::initWithPhysics())
	{
		//this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
		this->getPhysicsWorld()->setGravity(Vect(0,-900));
	}

	//Ìí¼Ó±³¾°
	auto backgroundLayer=BackgroundLayer::create();
	if(backgroundLayer)
	{
		this->addChild(backgroundLayer);
	}
	
	auto statusLayer=StatusLayer::create();

	//Ìí¼ÓÖ÷ÓÎÏ·²ã
	auto gameLayer = GameLayer::create();
	if(gameLayer) 
	{
		gameLayer->setPhyWorld(this->getPhysicsWorld());
		gameLayer->setDelegator(statusLayer);
		this->addChild(gameLayer);
	}

	//Ìí¼ÓÓÎϷ״̬²ã
	if(statusLayer)
	{
		this->addChild(statusLayer);
	}

	//Ìí¼Ó¿ØÖƲã
	auto optionLayer=OptionLayer::create();
	if(optionLayer)
	{
		optionLayer->setDelegator(gameLayer);
		this->addChild(optionLayer);
	}

	return true;
}
Example #2
0
Scene* BattleScene::scene(const std::string& level)
{
    Scene *scene = Scene::createWithPhysics();
    Size size=Director::getInstance()->getVisibleSize();
    
    //通过ECS创建场景
    auto layer=new BattleScene();
    if( layer && layer->initWithColor(Color4B(255*0.91,255*0.91,255*0.91,255),size.width,size.height))
    {
        layer->autorelease();
        
        scene->getPhysicsWorld()->setGravity(Vect(0,0));

        GX::Entity* welcome=GX::GameSystem::getInstance()->getECS()->createEntity("Battle.json");
        layer->addChild(welcome->getNode());
        scene->addChild(layer);
    }
    
    return scene;
}
Example #3
0
void TestScene::update(float delta)
{
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();


	int chance = random(1, 100);
	float yPos = random(0.0f, visibleSize.height);
	if (chance <= 5)
	{
		Sprite* mailbox = Sprite::create("mailbox.png");
		auto spriteBody = PhysicsBody::createBox(mailbox->boundingBox().size, PhysicsMaterial(1.0f, 0.5f, 0.5f));
		mailbox->setPhysicsBody(spriteBody);
		mailbox->setPosition(Point(visibleSize.width + origin.x, yPos + origin.y));
		mailbox->getPhysicsBody()->setVelocity(Vect(-500, 0));
		this->addChild(mailbox);
	}


}
Example #4
0
void UserScene::load(){
  CCLOG("User Scene load");
  getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
    
  getPhysicsWorld()->setGravity(Vect(0,-100));
  getPhysicsWorld()->setSpeed(3.0);


  syslayer = SysLayer::create();
  worldlayer = WorldLayer::create();
  worldlayer->setUserScene(this);

  battlelayer = BattleLayer::create();

  worldlayer->addChild(battlelayer,10);
  this->addChild(syslayer);
  this->addChild(worldlayer);

  WorldSize = worldlayer->getWorldSize();
}
Example #5
0
Scene* HelloWorld::createScene()
{
    Size visibleSize = Director::getInstance()->getVisibleSize();

    // 'scene' is an autorelease object
    auto scene = Scene::createWithPhysics();
    scene->getPhysicsWorld()->setGravity(Vect(0,0));
    //scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
    
    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();

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

    
    
    // return the scene
    return scene;
}
Example #6
0
void Player::isHit()
{
	if (invurnerable)
		return;

	this->HP -= 10;
	this->invurnerable = true;
	this->invurnerableTime = 90;

	// TODO: discuss if this is necessary
	this->getPhysicsBody()->applyImpulse(Vect(-70, 0));

	//FadeIn* fadeIn = FadeIn::create(0.5f);
	//FadeOut* fadeOut = FadeOut::create(0.5f);
	TintBy* tintToWhite = TintBy::create(1, 0, 255, 255);
	TintBy* tintBack = tintToWhite->reverse();
	//Sequence* sequence = Sequence::create(fadeOut, fadeIn, fadeOut,fadeIn,fadeOut, fadeIn, nullptr);
	Sequence* sequence = Sequence::create(tintToWhite, tintToWhite, tintToWhite, nullptr);
	
	this->runAction(sequence);
}
bool EllipseObstacle::performCollide (
  Vect pos, Vect::Component rad, Vect spd, float delta,
  Vect& outPos, Vect& outSpd, float& outDelta, Vect& norm
) {
  if (rad > Ball::MIN_PARTICLE_RADIUS) {
    EllipseObstacle el {_center, _rx+rad, _ry+rad, _ang};
    return el.collide(pos, 0, spd, delta, outPos, outSpd, outDelta);
  }

  Matr mScale = Matr::scale(1.f/_rx, 1.f/_ry);
  Matr mTrans = Matr::translate(-_center.x(), -_center.y());
  Matr mRot = Matr::rotate(_ang);

  Vect tPos = pos * mTrans * mRot * mScale;
  Vect tSpd = spd * mRot * mScale;

  CircleObstacle co {Vect(0.f, 0.f, 1.f), 1.f};

  Vect tOutPos, tOutSpd;
  bool coll = co.performCollide(
    tPos, rad, tSpd, delta,
    tOutPos, tOutSpd, outDelta,
    norm
  );

  if (!coll) {
    return false;
  }

  norm = (mScale * mRot).transposed() * norm;

  Matr muScale = Matr::scale(_rx, _ry);
  Matr muTrans = Matr::translate(_center.x(), _center.y());
  Matr muRot = Matr::rotate(-_ang);

  outPos = tOutPos * muScale * muRot * muTrans;
  outSpd = spd - norm.project(spd) * 2;

  return true;
}
Example #8
0
// Helper function to fire bullet (if necessary)
void Demo::privFireBullet(const float elapsedTime)
{
	// Delay between shots
	const float waitTime = 2.0f;
	
	static float currTime = waitTime;
	currTime += elapsedTime;

	// Check whether left mouse button is pressed
	short lmb = GetKeyState(VK_LBUTTON);
	bool lmbPressed = (lmb & 0x80) != 0;

	// Fire if button is pressed and the wait time has elapsed
	if (lmbPressed && (!bullet.active || currTime >= waitTime))
	{
		// Need to figure out our target
		float width = cam.nearWidth + (cam.farWidth - cam.nearWidth) * (490.0f - cam.nearDist) / (cam.farDist - cam.nearDist);
		float height = cam.nearHeight + (cam.farHeight - cam.nearHeight) * (490.0f - cam.nearDist) / (cam.farDist - cam.nearDist);

		// Use current crosshair positions (in screen coordinates)
		// and width and height of frustum at distance of blocks
		Vect target;
		target[0] = crosshairX.position[0] * 0.5f * width;
		target[1] = crosshairX.position[1] * 0.5f * height + 50.0f;
		target[2] = -490.0f;
		target[3] = 1.0f;

		currTime = 0.0f;

		// Set our velocity to be toward the target point
		this->bullet.position = this->cam.vPos;
		this->bullet.velocity = target - this->bullet.position;
		this->bullet.velocity.norm();
		this->bullet.velocity *= 1000.0f;
		this->bullet.rotation = Quat(0.0f, 0.0f, 0.0f, 1.0f);
		this->bullet.angVelocity = Vect(0.0f, 0.0f, 0.0f);
		this->bullet.active = 1;
		this->bullet.gravityNow = false;
	}
}
Example #9
0
void MeshEntity::ResetScale()
{
    traceIn(MeshEntity::ResetScale);

    if(!mesh)
    {
        AppWarning(TEXT("ResetScale must be called after MeshEntity::Init()"));
        return;
    }
    bounds = mesh->bounds;

    bHasScale = !scale.CloseTo(Vect(1.0f, 1.0f, 1.0f));
    if(bHasScale)
    {
        bounds.Min *= scale;
        bounds.Max *= scale;
    }
    else
        scale = 1.0f;

    traceOut;
}
Example #10
0
bool GameScene::init(){
	if(Scene::initWithPhysics()){
//		this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
        this->getPhysicsWorld()->setGravity(Vect(0, -900));

		// Add the background
		auto backgroundLayer = BackgroundLayer::create();
		if(backgroundLayer) {
			this->addChild(backgroundLayer);
		}

		auto statusLayer = StatusLayer::create();


		// Add the main game layer
		auto gameLayer = GameLayer::create();
		if(gameLayer) {
			gameLayer->setPhyWorld(this->getPhysicsWorld());
			gameLayer->setDelegator(statusLayer);
			this->addChild(gameLayer);
		}

		// Add the game status layer to show the score and game status
		if(statusLayer) {
			this->addChild(statusLayer);
		}

		// Add operation layer to control the game
		auto optionLayer = OptionLayer::create();
		if(optionLayer) {
			optionLayer->setDelegator(gameLayer);
			this->addChild(optionLayer);
		}
		return true;
	}else {
		return false;
	}
}
Example #11
0
bool GameScene::init()
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(!Scene::initWithPhysics());
		this->getPhysicsWorld()->setGravity(Vect(0, -900));

		auto backgroundLayer = BackgroundLayer::create();
		if(backgroundLayer) {
			this->addChild(backgroundLayer);
		}

		auto statusLayer = StatusLayer::create();
		auto gameLayer = GameLayer::create();
		if(gameLayer) {
			gameLayer->setPhyWorld(this->getPhysicsWorld());
			gameLayer->setDelegator(statusLayer);
			this->addChild(gameLayer);
		}

		if(statusLayer) {
			this->addChild(statusLayer);
		}


		
		auto optionLayer = OptionLayer::create();
		if(optionLayer) {
			optionLayer->setDelegator(gameLayer);
			this->addChild(optionLayer);
		}
		
		bRet = true;
	} while (0);

	return bRet;
}
Example #12
0
// Jump action of the Player
// Creates an animation , smooth jumping, and possibility of double-jumping if
// jump key is pressed during this action.
// Sets action to JUMPING
void Player::jump()
{
	// Set current action to JUMPING
	this->currentAction = Action::JUMPING;

	//Stop running animation and replace the sprite png to the jumping one
	this->getActionManager()->removeActionByTag(PLAYER_ANIMATION_RUNNING, this);

	//TODO: Insert the jumping animation instead of a single frame

	// Get resource loader instance
	ResourceLoader resLoader = ResourceLoader::getInstance();

	// Get running animation
	Vector<SpriteFrame*> runningAnimation = resLoader.getAnimation(PLAYER_ANIMATION_RUNNING);
	this->setDisplayFrame(runningAnimation.at(1));

	//JUMP
	//this->getPhysicsBody()->applyImpulse(Vect(0, Director::getInstance()->getWinSize().height *500.0 / 600));
	this->getPhysicsBody()->applyImpulse(Vect(0, (Director::getInstance()->getWinSize().height - 600)/3.5 + 500));


}
void PumpkinObject::transform(void)
{
    // create temp matrices
    Matrix Scale(SCALE, 0.75f, 0.75f, 0.75f);
    Matrix Trans(TRANS, this->pos[x], this->pos[y], this->pos[z]);

    // create local to world matrix (ie Model)
    this->World = Scale * Trans;

    // camera or object can move over, combined is one relationship ---> ModelView (World * View)
    // some pipelines have the project concatenated, others don't
    // best to keep them separated, you can always join them with a multiply
    this->ModelView = this->World * pCamera->getViewMatrix();

    // *************Culling against Frustum**********************
    Vect center = this->model->getModelCenter();
    center = Vect(0,0,0); // an object's local center will always be its origin?
    frustumCalc->setRadius(1.0f);
    // update the center and radius of object's bounding sphere with the same World matrix
    this->frustumCalc->updateSphere(this->World, center);
    // test by picking two corners of camera frustum, test against normals, return true/false (in/out)
    this->inView = this->frustumCalc->insideFrustum(center, pCamera);
};
Example #14
0
Scene* SceneGame::create() {
    auto scene = Scene::createWithPhysics();

    scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

    auto visibleSize = Director::getInstance()->getVisibleSize();
    auto body = PhysicsBody::createEdgeBox(visibleSize,
                                           PHYSICSBODY_MATERIAL_DEFAULT, 5.0f);
    auto edgeNode = Node::create();
    edgeNode->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
    edgeNode->setPhysicsBody(body);
    scene->addChild(edgeNode);
    Vect gravity = Vect(0.0f, 0.0f);
    scene->getPhysicsWorld()->setGravity(gravity);

    auto layerBg = LayerOfBg::create();
    scene->addChild(layerBg, 10);

    auto layerRole = LayerOfRole::create();
    scene->addChild(layerRole, 20);

    return scene;
}
Example #15
0
// on "init" you need to initialize your instance
bool PopUp::init()
{
	//////////////////////////////
	// 1. super init first
	if (!PopUp::initWithColor(Color4B(255, 102, 0, 255)))
	{
		return false;
	}

	this->setVisible(false);

	ignoreAnchorPointForPosition(false);
	this->setAnchorPoint(Vect(0.5, 0.5));
	this->setContentSize(Size(300,200));
		
	this->titleLabel = Label::createWithTTF("", "fonts/Marker Felt.ttf", 32);
	this->titleLabel->setTextColor(Color4B(255, 255, 255, 255));

	this->messageLabel = Label::createWithTTF("", "fonts/Marker Felt.ttf", 32);
	this->messageLabel->setTextColor(Color4B(255, 255, 255, 255));

	button = ui::Button::create("option.png", "option.png");

	Size dialogSize = this->getContentSize();

	titleLabel->setPosition(Vec2(dialogSize.width / 2, dialogSize.height - 20));
	
	messageLabel->setPosition(Vec2(dialogSize.width / 2, dialogSize.height - 70));

	button ->setPosition(Vec2(dialogSize.width / 2, dialogSize.height - 150));

	this->addChild(titleLabel);
	this->addChild(messageLabel);
	this->addChild(button);

	return true;
}
Example #16
0
void PlayLayer::inputUpdate(float dt)
{
    Point velocity = mJoystick->getVelocity();
    //std::cout << velocity.x << std::endl;

    if (velocity.x >= 0.4f || velocity.x <= -0.4f ||
            velocity.y >= 0.4f || velocity.y <= -0.4f) {
        Vect force = Vect(10000.0f * velocity.x, 10000.0f * velocity.y);
        ball->getPhysicsBody()->applyImpulse(force);
        Point p = paddle->getPosition();
        float s = p.x + velocity.x * 5;
        if(s < 0)
            s = 0;
        else if (s > Director::getInstance()->getVisibleSize().width)
            s = Director::getInstance()->getVisibleSize().width;
        else{
            s = s;
        }
        paddle->setPositionX(s);
    }
    if(mButtonA->getIsActive()){
        ball->setPosition(100,100);
    }
}
Example #17
0
void GameLayer::onTouch() {
    if(this->gameStatus == GAME_STATUS_OVER) {
        return;
    }
    
    SimpleAudioEngine::getInstance()->playEffect("sfx_wing.ogg");
    if(this->gameStatus == GAME_STATUS_READY) {
        this->delegator->onGameStart();
        this->bird->fly();
        
        //	ball->getPhysicsBody()->setGravityEnable(true);
        this->gameStatus = GAME_STATUS_START;
        this->createPips();
    }else if(this->gameStatus == GAME_STATUS_START) {
        this->bird->getPhysicsBody()->setVelocity(Vect(0, 260));
        
        /*
         if (!BallisTouch)
         {
         this->ball->getPhysicsBody()->setVelocity(Vect(0,260));
         }
         */
    }
}
Example #18
0
bool MonsterD::init() {
	count = 0; lift = 1;
	visibleSize = Director::getInstance()->getVisibleSize();
	Sprite::initWithFile("monster/purple.png");
	body = PhysicsBody::createCircle(this->getContentSize().width/2);
	body->setGravityEnable(1);
//设置怪物的速度;
//	auto tmpx = sqrt(visibleSize.width / 5);
//	auto tmpx = visibleSize.width / 100000;
	Vect impulse = Vect(0.0, 0.0f);
	body->setVelocity(impulse);
	body->setRotationEnable(false);//设置怪物能不能滚动;
	setPhysicsBody(body);
	schedule(schedule_selector(MonsterD::MyUpdate), 0.2f);	//每0.2秒执行一次

	contactListener = EventListenerPhysicsContact::create();
	contactListener->onContactBegin = CC_CALLBACK_1(MonsterD::onContactBegin, this);
	contactListener->onContactPostSolve = CC_CALLBACK_2(MonsterD::onContactPostSolve, this);
	contactListener->onContactPreSolve = CC_CALLBACK_2(MonsterD::onContactPreSolve, this);
	contactListener->onContactSeparate = CC_CALLBACK_1(MonsterD::onContactSeparate, this);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener, this);

	return true;
}
Example #19
0
bool GameScene::init()
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(!Scene::initWithPhysics());
		//this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
		this->getPhysicsWorld()->setGravity(Vect(0, -900));
		Background* backgroundLayer = Background::create();
		this->addChild(backgroundLayer);
		GameLayer* gameLayer = GameLayer::create();
		StatusLayer* statusLayer = StatusLayer::create();
		gameLayer->setDelegate(statusLayer);
		gameLayer->setPhyWorld(this->getPhysicsWorld());
		this->addChild(gameLayer);
		this->addChild(statusLayer);
		statusLayer->showReady();
		PlayLayer* playLayer = PlayLayer::create();
		playLayer->setDelegate(gameLayer);
		this->addChild(playLayer);
		bRet = true;
	} while (0);
	return bRet;
}
Example #20
0
void TwoBones::SetBoneHierarchy()
{
    // setup the bone model, this case we are using pyramid
    // todo - create a cool Bone Object, ball(drk blue) + pyramid arm (dark yellow)
    Pyramid* pPyramid = new Pyramid();
    pPyramid->loadTexture();
    pPyramid->createVAO();

    // Get the manager
    GraphicsObjectManager *goMgr = GraphicsObjectManager::getInstance();

    // here we insert bones directly into tree - 
    // vs calling goMgr->addObject which inserts every node with root as parent FIXME
    PCSTree* tree = goMgr->getTree();
    PCSNode* root = tree->getRoot();

    // create two bones
    PyramidObject* p0 = new PyramidObject( "name", pPyramid );
    p0->setIndex(0);
    p0->setName("Bone_0");
    tree->insert(p0, root);
    
    p0->setPos( Vect(0.0f, 0.0f, 0.0f) );
    p0->setLightPos( Vect(50.0f, 50.0f, 0.0f) );
    p0->setLightColor( Vect(1.5f, 0.5f, 0.5f) );   // RED
    

    PyramidObject* p1 = new PyramidObject( "name", pPyramid );
    p1->setIndex(1);
    p1->setName("Bone_1");
    tree->insert(p1, p0);

    p1->setPos( Vect(1.0f, 1.0f, 0.0f) );
    p1->setLightPos( Vect(50.0f, 50.0f, 0.0f) );
    p1->setLightColor( Vect(0.5f, 1.5f, 0.5f) );   // Green

    // set the first bone to pass into updateSkeleton in GlobalState.cpp's GameLoop()
    this->SetFirstBone(p0);

    // Debug
    tree->dumpTree();
}
Example #21
0
Light::Light() {
	position = Vect (0, 0, 0);
	color = Color (1, 1, 1, 0);
}
Example #22
0
bool Game1::init()
{
	if (!Layer::init())
	{
		return false;
	}
	padding = 70;
	counts = 25;
	flag = 0;

	//The Size seting.
	auto visibleSize = Director::getInstance()->getVisibleSize();
	auto origin = Director::getInstance()->getVisibleOrigin();

	//Keyboard seting.
	this->setKeyboardEnabled(true);
	this->setKeypadEnabled(true);

	//create the background
	auto BackgroundSprite = Sprite::create("Game/Level_1/background.png");
	BackgroundSprite->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
	addChild(BackgroundSprite);

	//create the bound.
	edgeSp = Sprite::create();
	auto boundBody = PhysicsBody::createEdgeBox(visibleSize, PhysicsMaterial(1.0f, 1.0f, 0.0f), 3);
	edgeSp->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2));
	edgeSp->setTag(0);
	edgeSp->setPhysicsBody(boundBody);
	this->addChild(edgeSp);

	//create the ball
	ba = Ball::create();
	ba->bindSprite(Sprite::create("Game/Level_1/ball.png"));
	this->addChild(ba);
	ball = ba->getSprite();
	ball->setPosition(100, 100);
	auto ballBody = PhysicsBody::createCircle(ball->getContentSize().width / 2, PhysicsMaterial(1.0f, 1.0f, 0.0f));
	ballBody->setGravityEnable(false);
	Vect force = Vect(40000.0f, 40000.0f);
	ballBody->applyImpulse(force);
	ballBody->setCategoryBitmask(0x0001);
	ballBody->setCollisionBitmask(0x0001);
	ballBody->setContactTestBitmask(0x0001);
	ball->setPhysicsBody(ballBody);
	ball->setTag(1);

	//create the paddle.
	pa = Paddle::create();
	pa->bindSprite(Sprite::create("Game/Level_1/paddle.png"));
	paddle = pa->getSprite();
	this->addChild(pa);
	auto paddleBody = PhysicsBody::createBox(paddle->getContentSize(), PhysicsMaterial(10.0f, 1.0f, 0.0f));
	paddleBody->setGravityEnable(false);
	paddleBody->setDynamic(false);
	paddle->setPhysicsBody(paddleBody);
	paddle->setTag(2);
	paddle->setPosition(visibleSize.width / 2, visibleSize.height * 0.05);

	//add the pink block.
	Sprite* block;
	bl = Block::create();
	bl->bindSprite(Sprite::create("block/block4.png"));
	this->addChild(bl);
	block = bl->getSprite();
	auto blockBody = PhysicsBody::createBox(block->getContentSize(), PhysicsMaterial(10.0f, 1.0f, 0.0f));
	blockBody->setDynamic(false);
	blockBody->setCategoryBitmask(0x0001);
	blockBody->setCollisionBitmask(0x0001);
	blockBody->setContactTestBitmask(0x0001);
	block->setPhysicsBody(blockBody);
	block->setTag(10);

	for (int j = 0; j < 5; j++)
	{
		int Xoffset = 120;
		for (int i = 0; i < 5; i++)
		{
			Xoffset = padding + Xoffset;
			if (j == 4 && i == 4)
			{
				block->setPosition(Vec2(Xoffset, visibleSize.height*0.8 - j * 70));
			}
			else
			{
				addBlock(Vec2(Xoffset, visibleSize.height*0.8 - j * 70));
			}
		}
	}

	this->schedule(schedule_selector(Game1::callback4));

	//add the pause btn.
	auto item1 = MenuItemImage::create("Game/btn_pause.png", "Game/btn_pause.png",CC_CALLBACK_1(Game1::call, this));
	auto menu = Menu::create(item1, NULL);
	menu->setPosition(Vec2(visibleSize.width * 0.9, visibleSize.height * 0.95));
	addChild(menu, 1);
	
	//eventlistener
	auto contactListener = EventListenerPhysicsContact::create();
	contactListener->onContactBegin = CC_CALLBACK_1(Game1::onContactBegin, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);
	
	return true;
}
Example #23
0
bool Game1::onContactBegin(const PhysicsContact& contact)
{
	Sprite* spriteA = (Sprite*)contact.getShapeA()->getBody()->getNode();
	Sprite* spriteB = (Sprite*)contact.getShapeB()->getBody()->getNode();
	int tagA = spriteA->getTag();
	int tagB = spriteB->getTag();
	if (tagA >= 3)
	{
		spriteA->removeFromParentAndCleanup(true);
		counts--;
		if (tagA == 3)
		{
			paddle->setScale(1.35f);
		}
		if (tagA == 4)
		{
			paddle->setScale(0.8f);
		}
		if (tagA == 5)
		{
			paddle->setScale(1.2f);
		}
		if (tagA == 10)
		{
			flag = 1;
			ba2 = Ball::create();
			ba2->bindSprite(Sprite::create("Game/Level_1/ball.png"));
			this->addChild(ba2);
			ball2 = ba2->getSprite();
			ball2->setPosition(100, 100);
			auto ballBody = PhysicsBody::createCircle(ball->getContentSize().width / 2.);
			ballBody->getShape(0)->setRestitution(1.0f);
			ballBody->getShape(0)->setFriction(0.0f);
			ballBody->getShape(0)->setDensity(1.0f);
			ballBody->setGravityEnable(false);
			Vect force = Vect(40000.0f, 40000.0f);
			ballBody->applyImpulse(force);
			ballBody->setCategoryBitmask(0x0001);
			ballBody->setCollisionBitmask(0x0001);
			ballBody->setContactTestBitmask(0x0001);
			ball2->setPhysicsBody(ballBody);
			ball2->setTag(1);
			ball2->setScale(1.1f);
		}
	}
	if (tagB >= 3)
	{
		spriteB->removeFromParentAndCleanup(true);
		counts--;
		if (tagB == 3)
		{
			paddle->setScale(1.35f);
		}
		if (tagB == 4)
		{
			paddle->setScale(0.8f);
		}
		if (tagB == 5)
		{
			paddle->setScale(1.2f);
		}
		if (tagB == 10)
		{
			flag = 1;
			ba2 = Ball::create();
			ba2->bindSprite(Sprite::create("Game/Level_1/ball.png"));
			this->addChild(ba2);
			ball2 = ba2->getSprite();
			ball2->setPosition(100, 100);
			auto ballBody = PhysicsBody::createCircle(ball->getContentSize().width / 2.);
			ballBody->getShape(0)->setRestitution(1.0f);
			ballBody->getShape(0)->setFriction(0.0f);
			ballBody->getShape(0)->setDensity(1.0f);
			ballBody->setGravityEnable(false);
			Vect force = Vect(40000.0f, 40000.0f);
			ballBody->applyImpulse(force);
			ballBody->setCategoryBitmask(0x0001);
			ballBody->setCollisionBitmask(0x0001);
			ballBody->setContactTestBitmask(0x0001);
			ball2->setPhysicsBody(ballBody);
			ball2->setTag(1);
			ball2->setScale(1.1f);
		}
	}
	return true;
}
Example #24
0
Vect Vect::vectMult(double scalar) {
	return Vect (x * scalar, y * scalar, z * scalar);
}
Example #25
0
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
bool NumberOneScene::init(){
    if(!Layer::init())
        return false;
    
//    auto onclick = MenuItemImage::create("CloseNormal.png","CloseSelected.png",
//                                         CC_CALLBACK_1(NumberOneScene::menuCloseCallback,this));
//    auto ment = Menu::create(onclick, NULL);
//    ment -> setPosition(Vec2(getContentSize().width/2, getContentSize().height/2));
//    this -> addChild(ment);
//
    
//    Sprite *sp = Sprite::create("CloseNormal.png");
//    sp -> setPosition(900,600);
//    this -> addChild(sp);
//    
//    
//    MenuItemFont * itemFont = MenuItemFont::create("lanou",CC_CALLBACK_1(NumberOneScene::menuCloseCallback, this));
//    MenuItemFont * itemFont2 = MenuItemFont::create("lanou",CC_CALLBACK_1(NumberOneScene::menuCloseCallback, this));
//    itemFont -> setColor(Color3B::GREEN);
//    itemFont2 -> setColor(Color3B::GREEN);
//
//    
//    MenuItemImage *itemImage1 = MenuItemImage::create("btn-a-0.png", "btn-b-0.png",CC_CALLBACK_1(NumberOneScene::onImageClick, this));
//    
//    
//    auto itemOn1 = MenuItemImage::create("btn-a-0.png", "btn-a-0.png");
//    auto itemOn2 = MenuItemImage::create("btn-b-0.png", "btn-b-0.png");
//    auto itemT = MenuItemToggle::createWithCallback(CC_CALLBACK_1(NumberOneScene::onImageClick, this), itemOn1,itemOn2,NULL);
//    
//    
//    menu = Menu::create(itemImage1,itemT,NULL);
//    
//    menu -> alignItemsHorizontallyWithPadding(50);
//    this -> addChild(menu);
    
    for(int i = 1 ; i <= 3 ; i++){
        char c[10];
        sprintf(c, "%d.jpg",i);
        string str = c;
        
        
        Texture2D *tex = Director::getInstance() -> getTextureCache()->addImage(str);

        SpriteFrame *spriteFrame_ =SpriteFrame::createWithTexture(tex,Rect(0,0,tex->getContentSize().width,tex->getContentSize().height));
        SpriteFrameCache::getInstance()-> addSpriteFrame(spriteFrame_, "snow");
        spriteFrames_.pushBack(spriteFrame_);
    }
    auto  bg1 = Sprite::create("bg05a.jpg");
    bg1 -> setPosition(getContentSize().width/2, getContentSize().height/2);
    bg1 -> setTag(9000);
    this -> addChild(bg1);
    
    MenuItemFont *button = MenuItemFont::create("切换背景",CC_CALLBACK_1(NumberOneScene::menuCloseCallback1, this));
    MenuItemFont *jump = MenuItemFont::create("跳转",CC_CALLBACK_1(NumberOneScene::menuCloseCallback, this));
    menu = Menu::create(button,jump,NULL);
    menu->setPosition(Vect(menu ->getPositionX(),menu ->getPositionY() +120));
    menu->alignItemsHorizontallyWithPadding(10);
    this -> addChild(menu);
    
    return true;
    
}
void SetTeddyHierarchy()
{
	// ____________________ ANIMATION TESTING _______________________

	myPyramid = new PyramidModel();
	myPyramid->createVAO();
	
	// ________________________ TEDDY TEST _____________________________
	PCSTree *tree = GraphicsObjMan::getMainTree();
	pRootNode = tree->getRoot();

	PyramidObject *pBip01 = new PyramidObject;
	pBip01->setIndex(0);
	pBip01->setName("Bip01");
	tree->insert( pBip01, pRootNode );

	PyramidObject *pBip01_Pelvis = new PyramidObject;
	pBip01_Pelvis->setIndex(1);
	pBip01_Pelvis->setName("Bip01_Pelvis");
	tree->insert( pBip01_Pelvis, pBip01 );

	PyramidObject *pBip01_Spine = new PyramidObject;
	pBip01_Spine->setIndex(2);
	pBip01_Spine->setName("Bip01_Spine");
	tree->insert( pBip01_Spine, pBip01_Pelvis );

	PyramidObject *pBip01_L_Thigh = new PyramidObject;
	pBip01_L_Thigh->setIndex(3);
	pBip01_L_Thigh->setName("Bip01_L_Thigh");
	tree->insert( pBip01_L_Thigh, pBip01_Spine );

	PyramidObject *pBip01_L_Calf = new PyramidObject;
	pBip01_L_Calf->setIndex(4);
	pBip01_L_Calf->setName("Bip01_L_Calf");
	tree->insert( pBip01_L_Calf, pBip01_L_Thigh );

	PyramidObject *pBip01_L_Foot = new PyramidObject;
	pBip01_L_Foot->setIndex(5);
	pBip01_L_Foot->setName("Bip01_L_Foot");
	tree->insert( pBip01_L_Foot, pBip01_L_Calf );

	PyramidObject *pBip01_R_Thigh = new PyramidObject;
	pBip01_R_Thigh->setIndex(6);
	pBip01_R_Thigh->setName("Bip01_R_Thigh");
	tree->insert( pBip01_R_Thigh, pBip01_Spine );

	PyramidObject *pBip01_R_Calf = new PyramidObject;
	pBip01_R_Calf->setIndex(7);
	pBip01_R_Calf->setName("Bip01_R_Calf");
	tree->insert( pBip01_R_Calf, pBip01_R_Thigh );

	PyramidObject *pBip01_R_Foot = new PyramidObject;
	pBip01_R_Foot->setIndex(8);
	pBip01_R_Foot->setName("Bip01_R_Foot");
	tree->insert( pBip01_R_Foot, pBip01_R_Calf );

	PyramidObject *pBip01_Spine1 = new PyramidObject;
	pBip01_Spine1->setIndex(9);
	pBip01_Spine1->setName("Bip01_Spine1");
	tree->insert( pBip01_Spine1, pBip01_Spine );

	PyramidObject *pBip01_Neck = new PyramidObject;
	pBip01_Neck->setIndex(10);
	pBip01_Neck->setName("Bip01_Neck");
	tree->insert( pBip01_Neck, pBip01_Spine1 );

	PyramidObject *pBip01_L_Clavicle = new PyramidObject;
	pBip01_L_Clavicle->setIndex(11);
	pBip01_L_Clavicle->setName("Bip01_L_Clavicle");
	tree->insert( pBip01_L_Clavicle, pBip01_Neck );

	PyramidObject *pBip01_L_UpperArm = new PyramidObject;
	pBip01_L_UpperArm->setIndex(12);
	pBip01_L_UpperArm->setName("Bip01_L_UpperArm");
	tree->insert( pBip01_L_UpperArm, pBip01_L_Clavicle );

	PyramidObject *pBip01_L_Forearm = new PyramidObject;
	pBip01_L_Forearm->setIndex(13);
	pBip01_L_Forearm->setName("Bip01_L_Forearm");
	tree->insert( pBip01_L_Forearm, pBip01_L_UpperArm );

	PyramidObject *pBip01_L_Hand = new PyramidObject;
	pBip01_L_Hand->setIndex(14);
	pBip01_L_Hand->setName("Bip01_L_Hand");
	tree->insert( pBip01_L_Hand, pBip01_L_Forearm );

	PyramidObject *pBip01_R_Clavicle = new PyramidObject;
	pBip01_R_Clavicle->setIndex(15);
	pBip01_R_Clavicle->setName("Bip01_R_Clavicle");
	tree->insert( pBip01_R_Clavicle, pBip01_Neck );

	PyramidObject *pBip01_R_UpperArm = new PyramidObject;
	pBip01_R_UpperArm->setIndex(16);
	pBip01_R_UpperArm->setName("Bip01_R_UpperArm");
	tree->insert( pBip01_R_UpperArm, pBip01_R_Clavicle );

	PyramidObject *pBip01_R_Forearm = new PyramidObject;
	pBip01_R_Forearm->setIndex(17);
	pBip01_R_Forearm->setName("Bip01_R_Forearm");
	tree->insert( pBip01_R_Forearm, pBip01_R_UpperArm );

	PyramidObject *pBip01_R_Hand = new PyramidObject;
	pBip01_R_Hand->setIndex(18);
	pBip01_R_Hand->setName("Bip01_R_Hand");
	tree->insert( pBip01_R_Hand, pBip01_R_Forearm );

	PyramidObject *pBip01_Head = new PyramidObject;
	pBip01_Head->setIndex(19);
	pBip01_Head->setName("Bip01_Head");
	tree->insert( pBip01_Head, pBip01_Neck );

	pBip01->setLightColor( Vect(0.5f, 1.5f, 0.5f) );
	pBip01_L_Foot->setLightColor( Vect(1.5f, 0.5f, 0.5f) );
	pBip01_R_Foot->setLightColor( Vect(0.5f, 0.5f, 1.5f) );
}
Malla* GeneraFromArchivosXYZU::aplicar() {
	int n_triangulos = 0, n_cuadrilateros = 0; // cantidad de caras de tres y cuatro lados
	//Lineas necesarias para que scanf lea archivo en computadores seteados en otro lenguaje.
	setlocale(LC_NUMERIC, "POSIX");

    FILE *arch_x = fopen(archivo_x.c_str(),"r");
    FILE *arch_y = fopen(archivo_y.c_str(),"r");
    FILE *arch_z = fopen(archivo_z.c_str(),"r");
    FILE *arch_u = fopen(archivo_u.c_str(),"r");

    char line[50];
    char cx[16];
    char cy[16];
    char cz[16];
    int num_puntos, num_caras;
    float x,y,z,nx,ny,nz,u;
    fscanf(arch_x,"%s %s\n",line,line);
    fscanf(arch_y,"%s %s\n",line,line);
    fscanf(arch_z,"%s %s\n",line,line);
    fscanf(arch_u,"%s %s\n",line,line);

    num_puntos=0;
    Nodos *nodos = new Nodos();
    Nodo *nodo;
    while(true) {
        fscanf(arch_x,"%s %s %s\n",cx,cy,cz);
        fscanf(arch_y,"%s %s %s\n",cx,cy,cz);
        fscanf(arch_z,"%s %s %s\n",cx,cy,cz);
        fscanf(arch_u,"%s %s %s\n",cx,cy,cz);
        if(strcmp(cx,"%") == 0) {
            break;
        }
        sscanf(cx,"%f",&x);
        sscanf(cy,"%f",&y);
        sscanf(cz,"%f",&z);
        nodo = new Nodo(Punto(x,y,z));
        nodos->addNodo(nodo);
        num_puntos++;

    }

    map<pair<int,int>,int> ind_arcos;
    map<pair<int,int>,int>::iterator iter1;
	map<pair<int,int>,int>::iterator iter2;
    vector<int> indice_puntos;
    vector<int> indice_arcos;
    Arcos *arcos = new Arcos();
    Caras *caras = new Caras();
    Cara *c;
    int indice;
    char *token;

    int indices[4];
    int n_lados;
    num_caras=0;
    while(true) {
        fgets(line, 50, arch_x);
        fgets(line, 50, arch_y);
        fgets(line, 50, arch_z);
        fgets(line, 50, arch_u);
        if(strpbrk("%",line) != NULL) {
            break;
        }
        token = strtok(line," ");
        for(int i=0; i<3; ++i) {
            sscanf(token,"%d",&indices[i]);
            token = strtok(NULL, " ");
        }
        if(token == NULL) { // Caso triángulos
        	n_triangulos++;
            n_lados = 3;
        }
        else { // Caso cuadriláteros
            sscanf(token,"%d",&indices[3]);
            n_cuadrilateros++;
            n_lados = 4;
        }

        //Nota: Por bug en los archivos de entrada, debo invertir el orden para que las normales queden bien.
        //for(int i=n_lados-1; i>=0; --i) // invertido por bug archivo entrada
        for(int i=0; i<n_lados; ++i) // así debiera ser
            indice_puntos.push_back(indices[i]-1);

        for(int j=0; j<n_lados; j++) {
            int ind1 = indice_puntos[j];
            int ind2 = indice_puntos[int(fmod(j+1,n_lados))];
            pair<int,int> pr1(ind1,ind2);
            pair<int,int> pr2(ind2,ind1);
            iter1 = ind_arcos.find(pr1);
			iter2 = ind_arcos.find(pr2);
            if(iter1 != ind_arcos.end())
                indice_arcos.push_back(iter1->second);
			else if(iter2 != ind_arcos.end())
                indice_arcos.push_back(iter2->second);
            else {
                indice = arcos->addArco(new Arco(ind1,ind2));
                indice_arcos.push_back(indice);
                ind_arcos.insert(make_pair(pr1,indice));
                nodos->addArcoNodo(ind1,indice);
                nodos->addArcoNodo(ind2,indice);
            }
        }
        if(n_lados == 3)
            c = new Triangulo(indice_puntos,indice_arcos);
        else // n_lados == 4
            c = new Cuadrilatero(indice_puntos,indice_arcos);
        int ind_cara = caras->addCara(c);
        num_caras++;
        for(int j=0; j<n_lados; j++) {
            arcos->setCaraArco(indice_arcos[j],ind_cara);
            nodos->addCaraNodo(indice_puntos[j],ind_cara);
        }
        indice_puntos.clear();
        indice_arcos.clear();
    }

    float max_concentracion = 0;
    float min_concentracion = 999999999;
    for(int i=0; i<num_puntos; i++) {
        fscanf(arch_x,"%f\n",&nx);
        fscanf(arch_y,"%f\n",&ny);
        fscanf(arch_z,"%f\n",&nz);
        fscanf(arch_u,"%f\n",&u);

        if(u < min_concentracion) {
            min_concentracion = u;
        }
        if(u > max_concentracion) {
            max_concentracion = u;
        }

        Vect normal = Vect(nx,ny,nz);
        nodos->getNodo(i)->setNormal(normal);
        nodos->getNodo(i)->setConcentracion(u);
    }

    cout << "max_concentracion = " << max_concentracion << endl;
    cout << "min_concentracion = " << min_concentracion << endl;

    Malla *malla = 0;
    if(n_cuadrilateros == 0)
    	malla = new MallaTriangulos(nodos,arcos,caras);
	else if(n_triangulos == 0)
		malla = new MallaCuadrilateros(nodos,arcos,caras);
	else
		malla = new Malla(nodos,arcos,caras);
    malla->setConcentracionMax(max_concentracion);
    malla->setConcentracionMin(min_concentracion);

	fclose(arch_x);
	fclose(arch_y);
	fclose(arch_z);
	fclose(arch_u);
	setlocale(LC_NUMERIC, "");

	//Chequeamos consistencia topologica.
	int V=malla->getNumNodos();
	int E=malla->getNumArcos();
	int F=malla->getNumCaras();
	cout << "Numero de nodos=" << V << endl;
	cout << "Numero de arcos=" << E << endl;
	cout << "Numero de caras=" << F << endl;
	if (V-E+F==2 || V-E+F==0)
		cout << "La malla es consistente. Cumple la formula de Euler: V-E+F=2" << endl;
	else
		cout << "Atencion, la malla no es consistente. No cumple la formula de Euler: V(" << V << ")-E(" << E << "+F("<< F << ")=" << V-E+F << " y deberia ser V-E+F=2" << endl;

    assert(malla->checkMalla(true) >= 0);
    return malla;

}
Example #28
0
Vect MrRay::R(float t){return Vect(X(t),Y(t),Z(t),1);}
Example #29
0
namespace cp {
	Float momentForCircle(Float m, Float r1, Float r2, Vect offset = Vect(0, 0));
	Float areaForPoly(const std::vector<cp::Vect>&);
}
Example #30
0
void GameScene::update( float dt )
{
	addBarrier();
	addCloud();

	position = character->getPosition();

	if(gameState == 1)
	{
		dy = position.y + speed.y - visibleSize.height/2;

		if(dy > 0 && speed.y > 0)
		{
			bottomSprite->setPosition(bottomSprite->getPositionX(),bottomSprite->getPositionY()-dy);
			forestSprite->setPosition(forestSprite->getPositionX(),forestSprite->getPositionY()-dy);

			for(int i=0; i<barriers.size(); i++)
			{
				if(barriers.at(i)->isVisible())
				{
					barriers.at(i)->setPositionY(barriers.at(i)->getPositionY()-dy);
				}
				else
				{
					delete barriers.at(i);
					barriers.erase(barriers.begin()+i);
					barrier++;
				}
			}

			for(int i=0; i<clouds.size(); i++)
			{
				if(clouds.at(i)->isVisible())
				{
					clouds.at(i)->setPosition(Vect(clouds.at(i)->getPosition().x,clouds.at(i)->getPosition().y-dy));
				}
				else
				{
					delete clouds.at(i);
					clouds.erase(clouds.begin()+i);
				}
			}

			if(position.x + speed.x > visibleSize.width)
			{
				character->setPosition(Vect(visibleSize.width,visibleSize.height/2));
			}
			else if(position.x + speed.x < 0)
			{
				character->setPosition(Vect(0,visibleSize.height/2));
			}
			else
			{
				character->setPosition(Vect(position.x+speed.x,visibleSize.height/2));
			}
		}
		else
		{
			if(position.y + speed.y < character->getSize().height / 2 + bottomSprite->getPositionY() + bottomSprite->getContentSize().height / 2)
			{
				speed.x = 0;
				speed.y = 0;
				character->setPosition(Vect(position.x,character->getSize().height / 2 + bottomSprite->getPositionY() + bottomSprite->getContentSize().height / 2));
			}
			else
			{
				if(position.x + speed.x > visibleSize.width)
				{
					character->setPosition(Vect(visibleSize.width,position.y+speed.y));
				}
				else if(position.x + speed.x < 0)
				{
					character->setPosition(Vect(0,position.y+speed.y));
				}
				else
				{
					character->setPosition(Vect(position.x+speed.x,position.y+speed.y));
				}
			}
		}

		if(position.y - character->getSize().height / 2 < 0)
		{
			GameOver();
		}

		if(position.y > barriers.at(score-barrier)->getPositionY())
		{
			addScore();
		}

		speed.y = speed.y - 1;
		
	}
	else if(gameState == 2)
	{
		if(position.y - character->getSize().height / 2 < 0)
		{
			GameOver();
		}

		character->setPosition(Vect(position.x,position.y+speed.y));
		speed.y = speed.y - 1;
	}
}