Blame view

ios/Runner/Wowgame/Classes/HelloWorldScene.cpp 6.21 KB
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  /****************************************************************************
   Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
   
   http://www.cocos2d-x.org
   
   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:
   
   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.
   
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
   ****************************************************************************/
  
  #include "HelloWorldScene.h"
  #include "game_food/GameConfigParser.h"
  #include "game_food/ResourcesConfig.h"
  #include "game_food/MiscUtils.h"
  #include "game_food/SoundsRepo.h"
  #include "game_food/ScalingUtils.h"
  
  
  #include "game_halloween/HSubGameSceneSpaceInvaders.h"
  #include "game_halloween/HGameConfigParser.h"
  #include "game_halloween/HResourcesConfig.h"
  
  #include "game_toy/ToyMainMenuScene.h"
  #include "game_toy/ToyResourcesConfig.h"
  #include "game_toy/ToySoundsRepo.h"
  
  
  #include "game_animal/AniSoundsRepo.h"
  #include "game_animal/AniResourcesConfig.h"
  #include "game_animal/AniPickLevelScene.h"
  
  USING_NS_CC;
  
  
  static cocos2d::Size designResolutionSize = cocos2d::Size(2732, 2048);
  static cocos2d::Size tinyResolutionSize = cocos2d::Size(1366, 1024);
  
  Scene* HelloWorld::createScene()
  {
      return HelloWorld::create();
  }
  
  // Print useful error message instead of segfaulting when files are not there.
  static void problemLoading(const char* filename)
  {
      printf("Error while loading: %s\n", filename);
      printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
  }
  
  // on "init" you need to initialize your instance
  bool HelloWorld::init()
  {
      //////////////////////////////
      // 1. super init first
      if ( !Scene::init() )
      {
          return false;
      }
  
68a4c50a   xiaoyu   Merge remote-trac...
74
75
76
77
78
79
80
      auto m_eventListener = EventListenerCustom::create("start_gameid", [=](EventCustom* event) {
          char* pData = (char*)event->getUserData();
          intptr_t  gameid = (intptr_t)pData;
          CCLOG("HelloWorld gameid = %d",gameid);
          this->startGameById(gameid);
      });
      Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(m_eventListener, 1);
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
81
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
82
      CCLOG("HelloWorld init");
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
83
84
85
86
      return true;
  }
  
  
68a4c50a   xiaoyu   Merge remote-trac...
87
  void HelloWorld::startGameById(int gameid)
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
88
  {
68a4c50a   xiaoyu   Merge remote-trac...
89
90
      int tag = gameid;
      if (tag == 1)//food
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
91
      {
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
          auto searchPaths = cocos2d::FileUtils::getInstance()->getSearchPaths();
          searchPaths.push_back("game_food");
          if(ScalingUtils::isSmallDevice()){
              searchPaths.push_back("game_food/" + std::string(ResourcesConfig::RES_FOLDER_NAME_TINY));
              searchPaths.push_back("game_food/" + std::string(ResourcesConfig::RES_FOLDER_NAME_XLARGE));
          } else {
              searchPaths.push_back("game_food/" + std::string(ResourcesConfig::RES_FOLDER_NAME_XLARGE));
          }
          searchPaths.push_back("game_food/common");
  
          cocos2d::FileUtils::getInstance()->setSearchPaths(searchPaths);
          // run
          std::string sceneLayoutPath = "graphics/shoot_game/scene_layout.scl";
          GameConfigParser parser("common/games/shoot_game/gconfig.gcf");
          auto newScene = parser.createGameScene(45, sceneLayoutPath);
          Director::getInstance()->replaceScene(newScene);
      }
      
68a4c50a   xiaoyu   Merge remote-trac...
110
      if (tag == 2)//halloween
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
111
      {
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
112
113
          auto searchPaths = cocos2d::FileUtils::getInstance()->getSearchPaths();
          std::string deviceSpecificFolderName;
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
114
115
116
117
118
119
120
121
122
          deviceSpecificFolderName = HResourcesConfig::RES_FOLDER_NAME_XLARGE;//TODO TEMP
          searchPaths.push_back("game_halloween/" + deviceSpecificFolderName);
          searchPaths.push_back("game_halloween/common");
          cocos2d::FileUtils::getInstance()->setSearchPaths(searchPaths);
  
          std::string configFilePath = "game_halloween/common/gconfig.gcf";
          std::string layoutFilePath = "game_halloween/xlarge/scene_layout.scl";
          HGameConfigParser parser(configFilePath);
          auto gameScene = dynamic_cast<HSubGameSceneSpaceInvaders*>(parser.createGameScene(layoutFilePath));
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
123
124
125
          Director::getInstance()->replaceScene(gameScene);
      }
  
68a4c50a   xiaoyu   Merge remote-trac...
126
      if (tag == 3)//toygamerepo
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
127
      {
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
128
129
130
131
132
133
134
135
136
137
138
139
          auto searchPaths = cocos2d::FileUtils::getInstance()->getSearchPaths();
          std::string deviceSpecificFolderName;
          deviceSpecificFolderName = ToyResourcesConfig::RES_FOLDER_NAME_XLARGE;//TODO TEMP
          searchPaths.push_back("game_toy");
          searchPaths.push_back("game_toy/" + deviceSpecificFolderName);
          searchPaths.push_back("game_toy/common");
          cocos2d::FileUtils::getInstance()->setSearchPaths(searchPaths);
          ToySoundsRepo::loadSoundsList();
          srand(time(0));
          // run
          auto _mainScene = ToyMainMenuScene::create("graphics/main_menu/scene_layout.scl");
          Director::getInstance()->replaceScene(_mainScene);
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
140
141
      }
  
68a4c50a   xiaoyu   Merge remote-trac...
142
      if (tag == 4)//animal
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
143
      {
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
144
145
146
147
148
149
150
151
152
153
154
          auto searchPaths = cocos2d::FileUtils::getInstance()->getSearchPaths();
          std::string deviceSpecificFolderName;
          deviceSpecificFolderName = ToyResourcesConfig::RES_FOLDER_NAME_XLARGE;//TODO TEMP
          searchPaths.push_back("game_animal");
          searchPaths.push_back("game_animal/" + deviceSpecificFolderName);
          searchPaths.push_back("game_animal/common");
          cocos2d::FileUtils::getInstance()->setSearchPaths(searchPaths);
          AniSoundsRepo::loadSoundsList();
          srand(time(0));
          auto _mainScene = AniPickLevelScene::create("");
          Director::getInstance()->replaceScene(_mainScene);
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
155
156
      }
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
157
158
159
160
161
162
163
164
  
  
  
  
  
  
  
  
68a4c50a   xiaoyu   Merge remote-trac...
165
  
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
166
167
168
169
170
171
172
173
174
175
176
177
178
  
  
  
  
  
  
  
  
  
  
  
  
  }