Guest User

Untitled

a guest
Jul 29th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. Scene* KZ::createScene()
  2. {
  3.     _scene = Scene::createWithPhysics();
  4.  
  5. #if DEBUG
  6.     _scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
  7. #endif
  8.  
  9.     Size visibleSize = Director::getInstance()->getVisibleSize();
  10.     Vec2 origin = Director::getInstance()->getVisibleOrigin();
  11.  
  12.     // Build the score label.
  13.     string txt = "Score: " + to_string(Ratio);
  14.     scoreLabel = Label::create(txt.c_str() , "fonts\\arial.ttf", 11.2f);
  15.  
  16.     scoreLabel->setPosition(Vec2(origin.x + scoreLabel->getContentSize().width,
  17.         origin.y + visibleSize.height - scoreLabel->getContentSize().height));
  18.  
  19.  
  20.     // Mouse events.
  21.     auto mmove = EventListenerMouse::create();
  22.     mmove->onMouseMove = CC_CALLBACK_1(KZ::onMouseMove, this);
  23.     mmove->onMouseDown = CC_CALLBACK_1(KZ::onMouseDown, this);
  24.  
  25.  
  26.     // Physics contacts.
  27.     auto cphysics = EventListenerPhysicsContact::create();
  28.     cphysics->onContactBegin = CC_CALLBACK_1(KZ::onContactBegin, this);
  29.    
  30.  
  31.     // Our weapon.
  32.     weapon = Sprite::create("weapon.png");
  33.     weapon->setPosition(origin.x + weapon->getContentSize().width,
  34.         origin.y + weapon->getContentSize().height);
  35.  
  36.  
  37.     // Build the image and then animate it.
  38.     enemy = Sprite::create("kz.png");
  39.  
  40.     auto enemyPhysics = PhysicsBody::createBox(enemy->getContentSize());
  41.     enemyPhysics->setDynamic(false);
  42.     enemyPhysics->setContactTestBitmask(0xFFFFFFFF);
  43.  
  44.     enemy->setPhysicsBody(enemyPhysics);
  45.     enemy->setPosition(origin.x,
  46.         origin.y + visibleSize.height - enemy->getContentSize().height / 2);
  47.  
  48.     auto moveby = MoveBy::create(3, Vec2(visibleSize.width - origin.x, 0));
  49.     auto moveby_back = moveby->reverse();
  50.  
  51.     auto seq = Sequence::create(moveby, moveby_back, nullptr);
  52.  
  53.  
  54.     // Update event listeners.
  55.     _scene->getEventDispatcher()->addEventListenerWithSceneGraphPriority(mmove, _scene);
  56.     _scene->getEventDispatcher()->addEventListenerWithSceneGraphPriority(cphysics, _scene);
  57.  
  58.  
  59.     // Fetch everything inside the scene.
  60.     _scene->addChild(scoreLabel);
  61.     _scene->addChild(enemy);
  62.     _scene->addChild(weapon);
  63.  
  64.  
  65.     enemy->runAction(RepeatForever::create(seq));
  66.  
  67.     return _scene;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment