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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « nacltoons/src/GameplayScene.h ('k') | nacltoons/src/PhysicsLayer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Native Client Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "GameplayScene.h" 4 #include "GameplayScene.h"
5 #include "PhysicsLayer.h"
6
7 #define PHYSICS_TAG 101
8 #define UI_TAG 102
5 9
6 USING_NS_CC; 10 USING_NS_CC;
7 11
8 Gameplay::~Gameplay() 12 CCScene* Gameplay::scene() {
9 { 13 return Gameplay::create();
10 } 14 }
11 15
12 Gameplay::Gameplay() 16 void Gameplay::Restart() {
13 { 17 removeChild(getChildByTag(PHYSICS_TAG));
18 CCLayer* physics = PhysicsLayer::create();
19 addChild(physics, 2, PHYSICS_TAG);
14 } 20 }
15 21
16 CCScene* Gameplay::scene() 22 bool Gameplay::init() {
17 { 23 if (!CCScene::init())
18 CCScene* scene = CCScene::create(); 24 return false;
19 Gameplay* layer = Gameplay::create(); 25 CCLayer* ui = UILayer::create();
20 scene->addChild(layer); 26 addChild(ui, 1, UI_TAG);
21 return scene;
22 }
23 27
24 bool Gameplay::init() 28 CCLayer* physics = PhysicsLayer::create();
25 { 29 addChild(physics, 2, PHYSICS_TAG);
26 CCLayerColor::initWithColor(ccc4(0,0x8F,0xD8,0xD8));
27 setTouchEnabled(true);
28 schedule(schedule_selector(Gameplay::updateGame));
29 return true; 30 return true;
30 } 31 }
31 32
32 void Gameplay::ccTouchesEnded(CCSet* touches, CCEvent* event) 33 void UILayer::Restart(CCObject* sender) {
33 { 34 CCLog("Restart pressed");
34 for (CCSetIterator it = touches->begin(); it != touches->end(); it++) 35 ((Gameplay*)getParent())->Restart();
35 {
36 CCTouch* touch = (CCTouch*)(*it);
37 if (!touch)
38 break;
39
40 CCPoint location = touch->getLocation();
41 CCLog("touch x:%f, y:%f", location.x, location.y);
42 }
43 } 36 }
44 37
45 void Gameplay::updateGame(float dt) { 38 void UILayer::Exit(CCObject* sender) {
39 CCLog("Exit pressed");
40 CCDirector::sharedDirector()->popScene();
46 } 41 }
42
43 bool UILayer::init() {
44 if (!CCLayer::init())
45 return false;
46 setTouchEnabled(true);
47
48 // Create the menu.
49 CCLabelTTF* restart_label = CCLabelTTF::create("Restart", "Arial.ttf", 24);
50 CCLabelTTF* exit_label = CCLabelTTF::create("Exit", "Arial.ttf", 24);
51
52 CCMenuItemLabel* restart = CCMenuItemLabel::create(
53 restart_label, this, menu_selector(UILayer::Restart));
54
55 CCMenuItemLabel* exit = CCMenuItemLabel::create(
56 exit_label, this, menu_selector(UILayer::Exit));
57
58 CCMenu* menu = CCMenu::create(restart, exit, NULL);
59 addChild(menu);
60
61 // Position the menu
62 CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
63 CCSize label_size = restart_label->getContentSize();
64 CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
65 menu->alignItemsVertically();
66 float xpos = origin.x + visibleSize.width*0.05 + label_size.width/2;
67 float ypos = origin.y + visibleSize.height*0.95 - label_size.height;
68 menu->setPosition(ccp(xpos, ypos));
69 return true;
70 }
OLDNEW
« 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