Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1592)

Unified Diff: nacltoons/src/GameplayScene.cc

Issue 12226130: [nacltoons] Add initial frontend and physics game scenes. (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: nacltoons/src/GameplayScene.cc
diff --git a/nacltoons/src/GameplayScene.cc b/nacltoons/src/GameplayScene.cc
index f6f45e40483befb31b0758554ee17dfa6c0daf3d..fde09826da28a4d0892f17c132bb5b637299b50f 100644
--- a/nacltoons/src/GameplayScene.cc
+++ b/nacltoons/src/GameplayScene.cc
@@ -2,45 +2,74 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "GameplayScene.h"
+#include "PhysicsLayer.h"
+
+#define PHYSICS_TAG 101
+#define UI_TAG 102
USING_NS_CC;
-Gameplay::~Gameplay()
-{
+CCScene* Gameplay::scene() {
+ return Gameplay::create();
}
-Gameplay::Gameplay()
-{
+void Gameplay::restart() {
+ removeChild(getChildByTag(PHYSICS_TAG));
+ CCLayer* physics = PhysicsLayer::create();
+ addChild(physics, 2, PHYSICS_TAG);
}
-CCScene* Gameplay::scene()
-{
- CCScene* scene = CCScene::create();
- Gameplay* layer = Gameplay::create();
- scene->addChild(layer);
- return scene;
-}
-bool Gameplay::init()
-{
- CCLayerColor::initWithColor(ccc4(0,0x8F,0xD8,0xD8));
- setTouchEnabled(true);
- schedule(schedule_selector(Gameplay::updateGame));
+bool Gameplay::init() {
+ if (!CCScene::init())
+ return false;
+ CCLayer* ui = UILayer::create();
+ addChild(ui, 1, UI_TAG);
+
+ CCLayer* physics = PhysicsLayer::create();
+ addChild(physics, 2, PHYSICS_TAG);
return true;
}
-void Gameplay::ccTouchesEnded(CCSet* touches, CCEvent* event)
-{
- for (CCSetIterator it = touches->begin(); it != touches->end(); it++)
- {
- CCTouch* touch = (CCTouch*)(*it);
- if (!touch)
- break;
-
- CCPoint location = touch->getLocation();
- CCLog("touch x:%f, y:%f", location.x, location.y);
- }
+
+void UILayer::restart(CCObject* sender) {
+ CCLog("restart pressed");
+ ((Gameplay*)getParent())->restart();
+
+}
+
+
+void UILayer::exit(CCObject* sender) {
+ CCLog("exit pressed");
+ CCDirector::sharedDirector()->popScene();
}
-void Gameplay::updateGame(float dt) {
+
+bool UILayer::init() {
+ if (!CCLayer::init())
+ return false;
+ setTouchEnabled(true);
+
+ // Create the menu.
+ CCLabelTTF* restart_label = CCLabelTTF::create("Restart", "Arial.ttf", 24);
+ CCLabelTTF* exit_label = CCLabelTTF::create("Exit", "Arial.ttf", 24);
+
+ CCMenuItemLabel* restart = CCMenuItemLabel::create(restart_label,
+ this, menu_selector(UILayer::restart));
+
+ CCMenuItemLabel* exit = CCMenuItemLabel::create(exit_label,
+ this, menu_selector(UILayer::exit));
+
+ CCMenu* menu = CCMenu::create(restart, exit, NULL);
+ addChild(menu);
+
+ // Position the menu
+ CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
+ CCSize label_size = restart_label->getContentSize();
+ CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
+ menu->alignItemsVertically();
+ float xpos = origin.x + visibleSize.width*0.05 + label_size.width/2;
+ float ypos = origin.y + visibleSize.height*0.95 - label_size.height;
+ menu->setPosition(ccp(xpos, ypos));
+ return true;
}

Powered by Google App Engine
This is Rietveld 408576698