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

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
« no previous file with comments | « nacltoons/src/GameplayScene.h ('k') | nacltoons/src/PhysicsLayer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: nacltoons/src/GameplayScene.cc
diff --git a/nacltoons/src/GameplayScene.cc b/nacltoons/src/GameplayScene.cc
index f6f45e40483befb31b0758554ee17dfa6c0daf3d..0560336231c5d284fdde1fe0c4738a338c78f872 100644
--- a/nacltoons/src/GameplayScene.cc
+++ b/nacltoons/src/GameplayScene.cc
@@ -1,46 +1,70 @@
-// Copyright (c) 2013 The Native Client Authors. All rights reserved.
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// 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() {
+ if (!CCScene::init())
+ return false;
+ CCLayer* ui = UILayer::create();
+ addChild(ui, 1, UI_TAG);
-bool Gameplay::init()
-{
- CCLayerColor::initWithColor(ccc4(0,0x8F,0xD8,0xD8));
- setTouchEnabled(true);
- schedule(schedule_selector(Gameplay::updateGame));
+ 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 Gameplay::updateGame(float dt) {
+void UILayer::Exit(CCObject* sender) {
+ CCLog("Exit pressed");
+ CCDirector::sharedDirector()->popScene();
+}
+
+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;
}
« no previous file with comments | « nacltoons/src/GameplayScene.h ('k') | nacltoons/src/PhysicsLayer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698