├── .cocos-project.json ├── CMakeLists.txt ├── Classes ├── AppDelegate.cpp ├── AppDelegate.h ├── Background.cpp ├── Background.h ├── CustomTool.cpp ├── CustomTool.h ├── FSM.cpp ├── FSM.h ├── GameOverLayer.cpp ├── GameOverLayer.h ├── MainScene.cpp ├── MainScene.h ├── PauseLayer.cpp ├── PauseLayer.h ├── Player.cpp ├── Player.h ├── Progress.cpp ├── Progress.h ├── StartScene.cpp ├── StartScene.h ├── VisibleRect.cpp └── VisibleRect.h ├── README.md ├── Resources ├── CloseNormal.png ├── CloseSelected.png ├── HelloWorld.png ├── fonts │ └── Marker Felt.ttf ├── image │ ├── background.png │ ├── background2.png │ ├── effect.plist │ ├── effect.pvr.ccz │ ├── role.plist │ ├── role.pvr.ccz │ ├── start-bg.jpg │ ├── ui.plist │ └── ui.pvr.ccz └── win.gif └── proj.win32 ├── Brave_cpp.sln ├── Brave_cpp.v11.suo ├── Brave_cpp.vcxproj ├── Brave_cpp.vcxproj.filters ├── Brave_cpp.vcxproj.user ├── build-cfg.json ├── game.rc ├── main.cpp ├── main.h ├── res └── game.ico └── resource.h /.cocos-project.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_type": "cpp" 3 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | set(APP_NAME MyGame) 4 | project (${APP_NAME}) 5 | 6 | include(cocos2d/build/BuildHelpers.CMakeLists.txt) 7 | 8 | option(USE_CHIPMUNK "Use chipmunk for physics library" ON) 9 | option(USE_BOX2D "Use box2d for physics library" OFF) 10 | option(DEBUG_MODE "Debug or release?" ON) 11 | 12 | if(DEBUG_MODE) 13 | set(CMAKE_BUILD_TYPE DEBUG) 14 | else(DEBUG_MODE) 15 | set(CMAKE_BUILD_TYPE RELEASE) 16 | endif(DEBUG_MODE) 17 | 18 | if (MSVC) 19 | set(CMAKE_C_FLAGS_DEBUG "-DCOCOS2D_DEBUG=1") 20 | set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) 21 | 22 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS") 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS") 24 | 25 | elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) 26 | set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1") 27 | set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) 28 | 29 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") 30 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 31 | 32 | endif() 33 | 34 | if(USE_CHIPMUNK) 35 | message("Using chipmunk ...") 36 | add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1) 37 | if(UNIX) # assuming linux 38 | add_definitions(-DLINUX ) 39 | endif() 40 | elseif(USE_BOX2D) 41 | message("Using box2d ...") 42 | add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1) 43 | if(UNIX) # assuming linux 44 | add_definitions(-DLINUX ) 45 | endif() 46 | else(USE_CHIPMUNK) 47 | message(FATAL_ERROR "Must choose a physics library.") 48 | endif(USE_CHIPMUNK) 49 | 50 | # architecture 51 | if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) 52 | set(ARCH_DIR "64-bit") 53 | else() 54 | set(ARCH_DIR "32-bit") 55 | endif() 56 | 57 | if( UNIX ) #assume linux 58 | set(GAME_SRC 59 | proj.linux/main.cpp 60 | Classes/AppDelegate.cpp 61 | Classes/HelloWorldScene.cpp 62 | ) 63 | elseif ( WIN32 ) 64 | set(GAME_SRC 65 | proj.win32/main.cpp 66 | proj.win32/main.h 67 | proj.win32/resource.h 68 | Classes/AppDelegate.cpp 69 | Classes/HelloWorldScene.cpp 70 | ) 71 | endif() 72 | 73 | set(COCOS2D_ROOT ${CMAKE_SOURCE_DIR}/cocos2d) 74 | if (WIN32) 75 | include_directories( 76 | ${COCOS2D_ROOT} 77 | ${COCOS2D_ROOT}/cocos 78 | ${COCOS2D_ROOT}/cocos/audio/include 79 | ${COCOS2D_ROOT}/cocos/2d 80 | ${COCOS2D_ROOT}/cocos/2d/renderer 81 | ${COCOS2D_ROOT}/cocos/2d/platform 82 | ${COCOS2D_ROOT}/cocos/2d/platform/desktop 83 | ${COCOS2D_ROOT}/cocos/2d/platform/win32 84 | ${COCOS2D_ROOT}/cocos/base 85 | ${COCOS2D_ROOT}/cocos/deprecated 86 | ${COCOS2D_ROOT}/cocos/physics 87 | ${COCOS2D_ROOT}/cocos/editor-support 88 | ${COCOS2D_ROOT}/cocos/math 89 | ${COCOS2D_ROOT}/extensions 90 | ${COCOS2D_ROOT}/external 91 | ${COCOS2D_ROOT}/external/edtaa3func 92 | ${COCOS2D_ROOT}/external/jpeg/include/win32 93 | ${COCOS2D_ROOT}/external/png/include/win32 94 | ${COCOS2D_ROOT}/external/tiff/include/win32 95 | ${COCOS2D_ROOT}/external/webp/include/win32 96 | ${COCOS2D_ROOT}/external/curl/include/win32 97 | ${COCOS2D_ROOT}/external/tinyxml2 98 | ${COCOS2D_ROOT}/external/unzip 99 | ${COCOS2D_ROOT}/external/sqlite3/include 100 | ${COCOS2D_ROOT}/external/chipmunk/include/chipmunk 101 | ${COCOS2D_ROOT}/external/freetype2/include/win32 102 | ${COCOS2D_ROOT}/external/websockets/include/win32 103 | ${COCOS2D_ROOT}/external/spidermonkey/include/win32 104 | ${COCOS2D_ROOT}/external/glfw3/include/win32 105 | ${COCOS2D_ROOT}/external/win32-specific/gles/include/OGLES 106 | ${COCOS2D_ROOT}/external/win32-specific/icon/include 107 | ${COCOS2D_ROOT}/external/win32-specific/zlib/include 108 | ${COCOS2D_ROOT}/external/xxhash 109 | ) 110 | link_directories( 111 | /usr/local/lib 112 | ${COCOS2D_ROOT}/external/png/prebuilt/win32 113 | ${COCOS2D_ROOT}/external/jpeg/prebuilt/win32 114 | ${COCOS2D_ROOT}/external/tiff/prebuilt/win32 115 | ${COCOS2D_ROOT}/external/glfw3/prebuilt/win32 116 | ${COCOS2D_ROOT}/external/webp/prebuilt/win32 117 | ${COCOS2D_ROOT}/external/curl/prebuilt/win32 118 | ${COCOS2D_ROOT}/external/sqlite3/libraries/win32 119 | ${COCOS2D_ROOT}/external/freetype2/prebuilt/win32 120 | ${COCOS2D_ROOT}/external/websockets/prebuilt/win32 121 | ${COCOS2D_ROOT}/external/spidermonkey/prebuilt/win32 122 | ${COCOS2D_ROOT}/external/win32-specific/gles/prebuilt 123 | ${COCOS2D_ROOT}/external/win32-specific/icon/prebuilt 124 | ${COCOS2D_ROOT}/external/win32-specific/zlib/prebuilt 125 | ) 126 | 127 | elseif(UNIX) #assumed linux 128 | include_directories( 129 | /usr/local/include/GLFW 130 | /usr/include/GLFW 131 | ${COCOS2D_ROOT} 132 | ${COCOS2D_ROOT}/cocos 133 | ${COCOS2D_ROOT}/cocos/audio/include 134 | ${COCOS2D_ROOT}/cocos/platform 135 | ${COCOS2D_ROOT}/cocos/platform/desktop 136 | ${COCOS2D_ROOT}/cocos/platform/linux 137 | ${COCOS2D_ROOT}/cocos/editor-support 138 | ${COCOS2D_ROOT}/extensions 139 | ${COCOS2D_ROOT}/external 140 | ${COCOS2D_ROOT}/external/edtaa3func 141 | ${COCOS2D_ROOT}/external/jpeg/include/linux 142 | ${COCOS2D_ROOT}/external/tiff/include/linux 143 | ${COCOS2D_ROOT}/external/webp/include/linux 144 | ${COCOS2D_ROOT}/external/tinyxml2 145 | ${COCOS2D_ROOT}/external/unzip 146 | ${COCOS2D_ROOT}/external/freetype2/include/linux 147 | ${COCOS2D_ROOT}/external/websockets/include/linux 148 | ${COCOS2D_ROOT}/external/spidermonkey/include/linux 149 | ${COCOS2D_ROOT}/external/linux-specific/fmod/include/${ARCH_DIR} 150 | ${COCOS2D_ROOT}/external/xxhash 151 | ) 152 | 153 | link_directories( 154 | /usr/local/lib 155 | ${COCOS2D_ROOT}/external/jpeg/prebuilt/linux/${ARCH_DIR} 156 | ${COCOS2D_ROOT}/external/tiff/prebuilt/linux/${ARCH_DIR} 157 | ${COCOS2D_ROOT}/external/webp/prebuilt/linux/${ARCH_DIR} 158 | ${COCOS2D_ROOT}/external/freetype2/prebuilt/linux/${ARCH_DIR} 159 | ${COCOS2D_ROOT}/external/websockets/prebuilt/linux/${ARCH_DIR} 160 | ${COCOS2D_ROOT}/external/spidermonkey/prebuilt/linux/${ARCH_DIR} 161 | ${COCOS2D_ROOT}/external/linux-specific/fmod/prebuilt/${ARCH_DIR} 162 | ) 163 | endif() 164 | 165 | if(USE_CHIPMUNK) 166 | 167 | include_directories(${COCOS2D_ROOT}/external/chipmunk/include/chipmunk) 168 | # chipmunk library 169 | add_subdirectory(${COCOS2D_ROOT}/external/chipmunk/src) 170 | endif() 171 | 172 | if(USE_BOX2D) 173 | # box2d library 174 | add_subdirectory(${COCOS2D_ROOT}/external/Box2D) 175 | endif() 176 | 177 | # unzip library 178 | add_subdirectory(${COCOS2D_ROOT}/external/unzip) 179 | 180 | # tinyxml2 library 181 | add_subdirectory(${COCOS2D_ROOT}/external/tinyxml2) 182 | 183 | # audio 184 | add_subdirectory(${COCOS2D_ROOT}/cocos/audio) 185 | 186 | # xxhash library 187 | add_subdirectory(${COCOS2D_ROOT}/external/xxhash) 188 | 189 | # cocos2d 190 | add_subdirectory(${COCOS2D_ROOT}/cocos) 191 | 192 | # extensions 193 | add_subdirectory(${COCOS2D_ROOT}/extensions) 194 | 195 | ## Editor Support 196 | 197 | # spine 198 | add_subdirectory(${COCOS2D_ROOT}/cocos/editor-support/spine) 199 | 200 | # cocosbuilder 201 | add_subdirectory(${COCOS2D_ROOT}/cocos/editor-support/cocosbuilder) 202 | 203 | # cocostudio 204 | add_subdirectory(${COCOS2D_ROOT}/cocos/editor-support/cocostudio) 205 | 206 | if ( WIN32 ) 207 | # add the executable 208 | add_executable(${APP_NAME} 209 | WIN32 210 | ${GAME_SRC} 211 | ) 212 | else() 213 | # add the executable 214 | add_executable(${APP_NAME} 215 | ${GAME_SRC} 216 | ) 217 | endif() 218 | 219 | if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) 220 | set(FMOD_LIB "fmodex64") 221 | else() 222 | set(FMOD_LIB "fmodex") 223 | endif() 224 | 225 | target_link_libraries(${APP_NAME} 226 | spine 227 | cocostudio 228 | cocosbuilder 229 | extensions 230 | audio 231 | cocos2d 232 | ) 233 | 234 | set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin") 235 | 236 | set_target_properties(${APP_NAME} PROPERTIES 237 | RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") 238 | 239 | if ( WIN32 ) 240 | #also copying dlls to binary directory for the executable to run 241 | pre_build(${APP_NAME} 242 | COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources 243 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources 244 | COMMAND ${CMAKE_COMMAND} -E copy ${COCOS2D_ROOT}/external/win32-specific/gles/prebuilt/glew32.dll ${APP_BIN_DIR}/${CMAKE_BUILD_TYPE} 245 | COMMAND ${CMAKE_COMMAND} -E copy ${COCOS2D_ROOT}/external/win32-specific/zlib/prebuilt/zlib1.dll ${APP_BIN_DIR}/${CMAKE_BUILD_TYPE} 246 | ) 247 | else() 248 | pre_build(${APP_NAME} 249 | COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources 250 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources 251 | ) 252 | 253 | endif() 254 | -------------------------------------------------------------------------------- /Classes/AppDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "AppDelegate.h" 2 | #include "StartScene.h" 3 | 4 | USING_NS_CC; 5 | 6 | AppDelegate::AppDelegate() { 7 | 8 | } 9 | 10 | AppDelegate::~AppDelegate() 11 | { 12 | } 13 | 14 | bool AppDelegate::applicationDidFinishLaunching() { 15 | // initialize director 16 | auto director = Director::getInstance(); 17 | auto glview = director->getOpenGLView(); 18 | if(!glview) { 19 | glview = GLView::create("Brave C++ version"); 20 | director->setOpenGLView(glview); 21 | } 22 | 23 | // turn on display FPS 24 | director->setDisplayStats(true); 25 | 26 | // set FPS. the default value is 1.0/60 if you don't call this 27 | director->setAnimationInterval(1.0 / 60); 28 | 29 | // create a scene. it's an autorelease object 30 | auto scene = StartScene::createScene(); 31 | 32 | // run 33 | director->runWithScene(scene); 34 | 35 | return true; 36 | } 37 | 38 | // This function will be called when the app is inactive. When comes a phone call,it's be invoked too 39 | void AppDelegate::applicationDidEnterBackground() { 40 | Director::getInstance()->stopAnimation(); 41 | 42 | // if you use SimpleAudioEngine, it must be pause 43 | // SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); 44 | } 45 | 46 | // this function will be called when the app is active again 47 | void AppDelegate::applicationWillEnterForeground() { 48 | Director::getInstance()->startAnimation(); 49 | 50 | // if you use SimpleAudioEngine, it must resume here 51 | // SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); 52 | } 53 | -------------------------------------------------------------------------------- /Classes/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef _APP_DELEGATE_H_ 2 | #define _APP_DELEGATE_H_ 3 | 4 | #include "cocos2d.h" 5 | 6 | /** 7 | @brief The cocos2d Application. 8 | 9 | The reason for implement as private inheritance is to hide some interface call by Director. 10 | */ 11 | class AppDelegate : private cocos2d::Application 12 | { 13 | public: 14 | AppDelegate(); 15 | virtual ~AppDelegate(); 16 | 17 | /** 18 | @brief Implement Director and Scene init code here. 19 | @return true Initialize success, app continue. 20 | @return false Initialize failed, app terminate. 21 | */ 22 | virtual bool applicationDidFinishLaunching(); 23 | 24 | /** 25 | @brief The function be called when the application enter background 26 | @param the pointer of the application 27 | */ 28 | virtual void applicationDidEnterBackground(); 29 | 30 | /** 31 | @brief The function be called when the application enter foreground 32 | @param the pointer of the application 33 | */ 34 | virtual void applicationWillEnterForeground(); 35 | }; 36 | 37 | #endif // _APP_DELEGATE_H_ 38 | 39 | -------------------------------------------------------------------------------- /Classes/Background.cpp: -------------------------------------------------------------------------------- 1 | #include "Background.h" 2 | #include "VisibleRect.h" 3 | 4 | 5 | bool Background::init() 6 | { 7 | _spriteA = Sprite::create("image/background.png"); 8 | _spriteB = Sprite::create("image/background2.png"); 9 | 10 | _spriteA->setPosition(VisibleRect::center()); 11 | _spriteB->setPosition(VisibleRect::center() + VisibleRect::right() - VisibleRect::left()); 12 | this->addChild(_spriteA,-10); 13 | this->addChild(_spriteB,-20); 14 | 15 | _isMoving = false; 16 | return true; 17 | } 18 | 19 | void Background::move(const char* direction, Sprite* withSprite) 20 | { 21 | if(this->_isMoving) 22 | { 23 | log("Moving..."); 24 | return; 25 | } 26 | auto vSize = Director::getInstance()->getVisibleSize(); 27 | float movex = 0; 28 | if(std::string(direction)=="left") 29 | movex = -vSize.width; 30 | else 31 | movex = vSize.width; 32 | 33 | auto seq = Sequence::create(MoveBy::create( 2.0, Vec2( movex, 0)), 34 | CallFunc::create(CC_CALLBACK_0(Background::onMoveEnd,this)), 35 | nullptr); 36 | _spriteA->runAction(MoveBy::create( 2.0, Vec2( movex, 0))); 37 | _spriteB->runAction(seq); 38 | log("Moving...2"); 39 | if(withSprite) 40 | withSprite->runAction(MoveBy::create( 2.0, Vec2( movex, 0))); 41 | 42 | _isMoving = true; 43 | 44 | } 45 | 46 | void Background::onMoveEnd() 47 | { 48 | _isMoving = false; 49 | auto ax = _spriteA->getPosition(); 50 | auto pos = VisibleRect::center() + VisibleRect::right() - VisibleRect::left(); 51 | 52 | if(ax.x < VisibleRect::left().x) 53 | { 54 | _spriteA->setPosition(pos); 55 | } 56 | else 57 | { 58 | _spriteB->setPosition(pos); 59 | } 60 | 61 | 62 | NotificationCenter::getInstance()->postNotification("backgroundMoveEnd"); 63 | } -------------------------------------------------------------------------------- /Classes/Background.h: -------------------------------------------------------------------------------- 1 | #ifndef __Background__ 2 | #define __Background__ 3 | #include "cocos2d.h" 4 | 5 | USING_NS_CC; 6 | 7 | class Background : public Layer 8 | { 9 | public: 10 | bool init(); 11 | CREATE_FUNC(Background); 12 | void move(const char* direction, Sprite* withSprite); 13 | void onMoveEnd(); 14 | private: 15 | bool _isMoving; 16 | Sprite* _spriteA; 17 | Sprite* _spriteB; 18 | }; 19 | 20 | 21 | #endif -------------------------------------------------------------------------------- /Classes/CustomTool.cpp: -------------------------------------------------------------------------------- 1 | #include "CustomTool.h" 2 | 3 | CustomTool* CustomTool::_tool; 4 | 5 | CustomTool* CustomTool::getInstance() 6 | { 7 | if(!_tool) 8 | { 9 | _tool = new CustomTool(); 10 | } 11 | 12 | return _tool; 13 | } 14 | 15 | MenuItemImage* CustomTool::createMenuItemImage(const char* normal, const char* selected, ccMenuCallback callback) 16 | { 17 | auto item = MenuItemImage::create(); 18 | auto nsf = SpriteFrameCache::getInstance()->getSpriteFrameByName(normal); 19 | auto ssf = SpriteFrameCache::getInstance()->getSpriteFrameByName(selected); 20 | item->setNormalSpriteFrame(nsf); 21 | item->setSelectedSpriteFrame(ssf); 22 | item->setCallback(callback); 23 | return item; 24 | } -------------------------------------------------------------------------------- /Classes/CustomTool.h: -------------------------------------------------------------------------------- 1 | #ifndef __CustomTool__ 2 | #define __CustomTool__ 3 | #include "cocos2d.h" 4 | 5 | USING_NS_CC; 6 | 7 | class CustomTool : public Ref 8 | { 9 | public: 10 | static CustomTool* getInstance(); 11 | /* 12 | create MenueItemImage with SpriteFrameName 13 | */ 14 | static MenuItemImage* createMenuItemImage(const char* normal, const char* selected, ccMenuCallback callback); 15 | private: 16 | static CustomTool* _tool; 17 | }; 18 | 19 | #endif -------------------------------------------------------------------------------- /Classes/FSM.cpp: -------------------------------------------------------------------------------- 1 | #include "FSM.h" 2 | 3 | 4 | 5 | FSM::FSM(std::string state, std::function onEnter) 6 | { 7 | _currentState = state; 8 | _previousState = ""; 9 | this->addState(state, onEnter); 10 | } 11 | 12 | FSM* FSM::create(std::string state, std::function onEnter) 13 | { 14 | FSM* fsm = new FSM(state, onEnter); 15 | if(fsm && fsm->init()) 16 | { 17 | fsm->autorelease(); 18 | return fsm; 19 | } 20 | else 21 | { 22 | CC_SAFE_DELETE(fsm); 23 | return nullptr; 24 | } 25 | } 26 | 27 | FSM* FSM::addState(std::string state, std::function onEnter) 28 | { 29 | if("" == state) 30 | { 31 | cocos2d::log("FSM::addState: state can't be empty string!"); 32 | return nullptr; 33 | } 34 | _states.insert(state); 35 | // _onEnters.insert(std::pair>(state, onEnter)); 36 | _onEnters[state] = onEnter; 37 | return this; 38 | } 39 | 40 | bool FSM::isContainState(std::string stateName) 41 | { 42 | return _states.find(stateName) != _states.end(); 43 | } 44 | 45 | void FSM::printState() 46 | { 47 | // std::for_each(_states.begin(), _states.end(), &FSM::print); 48 | cocos2d::log("FSM::printState: list of states"); 49 | for(auto iter = _states.begin(); iter!=_states.end(); iter++) 50 | { 51 | cocos2d::log(iter->c_str()); 52 | } 53 | } 54 | 55 | void FSM::changeToState(std::string state) 56 | { 57 | if(isContainState(state)) 58 | { 59 | _previousState = _currentState; 60 | _currentState = state; 61 | cocos2d::log("FSM::changeToState: %s -> %s", _previousState.c_str(), _currentState.c_str()); 62 | if(_onEnters[state]) 63 | _onEnters[state](); 64 | } 65 | else 66 | { 67 | cocos2d::log("FSM::changeToState: no such state as %s , state unchanged", state.c_str()); 68 | } 69 | } 70 | 71 | FSM* FSM::addEvent(std::string eventName, std::string from, std::string to) 72 | { 73 | if("" == eventName) 74 | { 75 | cocos2d::log("FSM::addEvent: eventName can't be empty!"); 76 | return nullptr; 77 | } 78 | if(!isContainState(from)) 79 | { 80 | cocos2d::log("FSM::addEvent: from state %s does not exit", from.c_str()); 81 | return nullptr; 82 | } 83 | if(!isContainState(to)) 84 | { 85 | cocos2d::log("FSM::addEvent: to state %s does not exit", to.c_str()); 86 | return nullptr; 87 | } 88 | std::unordered_map& oneEvent = _events[eventName]; 89 | oneEvent[from] = to; 90 | return this; 91 | } 92 | 93 | bool FSM::canDoEvent(std::string eventName) 94 | { 95 | return _events[eventName].find(_currentState) != _events[eventName].end(); 96 | } 97 | 98 | void FSM::doEvent(std::string eventName) 99 | { 100 | if(canDoEvent(eventName)) 101 | { 102 | cocos2d::log("FSM::doEvent: doing event %s", eventName.c_str()); 103 | changeToState(_events[eventName][_currentState]); 104 | } 105 | else 106 | { 107 | cocos2d::log("FSM::doEvent: cannot do event %s", eventName.c_str()); 108 | } 109 | } 110 | 111 | void FSM::setOnEnter(std::string state, std::function onEnter) 112 | { 113 | if(isContainState(state)) 114 | { 115 | _onEnters[state] = onEnter; 116 | } 117 | else 118 | { 119 | cocos2d::log("FSM::setOnEnter: no state named %s", state.c_str()); 120 | } 121 | } 122 | 123 | bool FSM::init() 124 | { 125 | this->addState("walking",[](){cocos2d::log("Enter walking");}) 126 | ->addState("attacking",[](){cocos2d::log("Enter attacking");}) 127 | ->addState("dead",[](){cocos2d::log("Enter dead");}) 128 | ->addState("beingHit",[](){cocos2d::log("Enter beingHit");}); 129 | 130 | this->addEvent("walk","idle","walking") 131 | // ->addEvent("walk","attacking","walking") 132 | ->addEvent("attack","idle","attacking") 133 | ->addEvent("attack","walking", "attacking") 134 | ->addEvent("die","idle","dead") 135 | ->addEvent("die","walking","dead") 136 | ->addEvent("die","attacking","dead") 137 | ->addEvent("stop","walking","idle") 138 | ->addEvent("stop","attacking","idle") 139 | ->addEvent("walk","walking","walking") 140 | ->addEvent("beHit","idle","beingHit") 141 | ->addEvent("beHit","walking","beingHit") 142 | // ->addEvent("beHit","attacking","beingHit") can attacking be stoped by beHit? 143 | ->addEvent("die","beingHit","dead") 144 | ->addEvent("stop","beingHit","idle") 145 | ->addEvent("stop","idle","idle"); 146 | 147 | return true; 148 | } 149 | 150 | 151 | -------------------------------------------------------------------------------- /Classes/FSM.h: -------------------------------------------------------------------------------- 1 | #ifndef __FSM__ 2 | #define __FSM__ 3 | 4 | #include "cocos2d.h" 5 | 6 | class FSM :public cocos2d::Ref 7 | { 8 | public: 9 | 10 | bool init(); 11 | //Create FSM with a initial state name and optional callback function 12 | static FSM* create(std::string state, std::function onEnter = nullptr); 13 | 14 | FSM(std::string state, std::function onEnter = nullptr); 15 | //add state into FSM 16 | FSM* addState(std::string state, std::function onEnter = nullptr); 17 | //add Event into FSM 18 | FSM* addEvent(std::string eventName, std::string from, std::string to); 19 | //check if state is already in FSM 20 | bool isContainState(std::string stateName); 21 | //print a list of states 22 | void printState(); 23 | //do the event 24 | void doEvent(std::string eventName); 25 | //check if the event can change state 26 | bool canDoEvent(std::string eventName); 27 | //set the onEnter callback for a specified state 28 | void setOnEnter(std::string state, std::function onEnter); 29 | 30 | std::string getState(){return _currentState;} 31 | private: 32 | //change state and run callback. 33 | void changeToState(std::string state); 34 | private: 35 | std::set _states; 36 | std::unordered_map> _events; 37 | std::unordered_map> _onEnters; 38 | std::string _currentState; 39 | std::string _previousState; 40 | }; 41 | 42 | #endif -------------------------------------------------------------------------------- /Classes/GameOverLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "GameOverLayer.h" 2 | #include "VisibleRect.h" 3 | #include "CustomTool.h" 4 | #include "StartScene.h" 5 | //#include " 6 | 7 | bool GameOverLayer::init() 8 | { 9 | if(!Layer::init()) 10 | { 11 | return false; 12 | } 13 | 14 | Sprite* background = Sprite::createWithSpriteFrameName("pause-bg.png"); 15 | background->setPosition(VisibleRect::center()); 16 | this->addChild(background); 17 | 18 | auto size = background->getContentSize(); 19 | auto title = Sprite::createWithSpriteFrameName("gameover-title.png"); 20 | title->setPosition(size.width/2, size.height); 21 | background->addChild(title); 22 | 23 | auto homeItem = CustomTool::createMenuItemImage("home-1.png","home-2.png", 24 | CC_CALLBACK_1(GameOverLayer::home,this)); 25 | 26 | homeItem->setPosition(size.width/2, size.height/2); 27 | 28 | auto menu = Menu::create(homeItem, NULL); 29 | menu->setPosition(VisibleRect::leftBottom()); 30 | 31 | _label = LabelTTF::create("","fonts/Marker Felt.ttf",34); 32 | _label->setPosition(size.width/2,size.height); 33 | background->addChild(_label); 34 | 35 | background->addChild(menu); 36 | 37 | 38 | return true; 39 | } 40 | 41 | void GameOverLayer::home(Ref* obj) 42 | { 43 | //auto main = dynamic_cast(this->getParent()); 44 | //main->onTouchResume(); 45 | this->removeFromParentAndCleanup(true); 46 | auto start = StartScene::createScene(); 47 | Director::getInstance()->replaceScene(start); 48 | } 49 | 50 | void GameOverLayer::setText(const std::string& text) 51 | { 52 | _label->setString(text); 53 | } -------------------------------------------------------------------------------- /Classes/GameOverLayer.h: -------------------------------------------------------------------------------- 1 | #ifndef __GameOverLayer__ 2 | #define __GameOverLayer__ 3 | #include "cocos2d.h" 4 | 5 | USING_NS_CC; 6 | 7 | class GameOverLayer : public Layer 8 | { 9 | public: 10 | bool init(); 11 | CREATE_FUNC(GameOverLayer); 12 | 13 | void home(Ref* obj); 14 | void setText(const std::string& text); 15 | private: 16 | LabelTTF* _label; 17 | }; 18 | 19 | 20 | #endif -------------------------------------------------------------------------------- /Classes/MainScene.cpp: -------------------------------------------------------------------------------- 1 | #include "MainScene.h" 2 | #include "FSM.h" 3 | #include "VisibleRect.h" 4 | #include "CustomTool.h" 5 | #include "PauseLayer.h" 6 | #include "GameOverLayer.h" 7 | 8 | Scene* MainScene::createScene() 9 | { 10 | // init with physics 11 | auto scene = Scene::createWithPhysics(); 12 | auto layer = MainScene::create(); 13 | //set physics world 14 | layer->setPhysicsWorld(scene->getPhysicsWorld()); 15 | scene->addChild(layer); 16 | return scene; 17 | } 18 | 19 | // on "init" you need to initialize your instance 20 | bool MainScene::init() 21 | { 22 | if ( !Layer::init() ) 23 | { 24 | return false; 25 | } 26 | //load frames into cache 27 | SpriteFrameCache::getInstance()->addSpriteFramesWithFile("image/role.plist","image/role.pvr.ccz"); 28 | SpriteFrameCache::getInstance()->addSpriteFramesWithFile("image/ui.plist","image/ui.pvr.ccz"); 29 | 30 | initLevel(); 31 | addRoles(); 32 | addUI(); 33 | addListener(); 34 | addObserver(); 35 | this->schedule(schedule_selector(MainScene::enemyMove), 3); 36 | 37 | this->scheduleUpdate(); 38 | // _player->playAnimationForever(4); 39 | return true; 40 | } 41 | 42 | void MainScene::initLevel() 43 | { 44 | _level = 0; 45 | _maxLevel = 2; 46 | std::vector types; 47 | types.push_back(Player::ENEMY1); 48 | types.push_back(Player::ENEMY2); 49 | _enemyTypes.push_back(types); 50 | 51 | types.clear(); 52 | types.push_back(Player::ENEMY1); 53 | types.push_back(Player::ENEMY2); 54 | types.push_back(Player::ENEMY2); 55 | _enemyTypes.push_back(types); 56 | 57 | types.clear(); 58 | types.push_back(Player::ENEMY1); 59 | types.push_back(Player::ENEMY1); 60 | types.push_back(Player::ENEMY2); 61 | types.push_back(Player::BOSS); 62 | _enemyTypes.push_back(types); 63 | 64 | std::vector positions; 65 | positions.push_back(VisibleRect::center()); 66 | positions.push_back(VisibleRect::right() - Vec2(200, 0)); 67 | _enemyPositions.push_back(positions); 68 | 69 | positions.clear(); 70 | positions.push_back(VisibleRect::center()); 71 | positions.push_back(VisibleRect::right() - Vec2(200, 0) + Vec2(0, 200)); 72 | positions.push_back(VisibleRect::right() - Vec2(200, 0) - Vec2(0, 200)); 73 | _enemyPositions.push_back(positions); 74 | 75 | positions.clear(); 76 | positions.push_back(VisibleRect::center() + Vec2(0, 200)); 77 | positions.push_back(VisibleRect::center() - Vec2(0, 200)); 78 | positions.push_back(VisibleRect::right() - Vec2(200, 0) + Vec2(0, 200)); 79 | positions.push_back(VisibleRect::right() - Vec2(200, 0) - Vec2(0, 200)); 80 | _enemyPositions.push_back(positions); 81 | 82 | } 83 | 84 | void MainScene::onEnter() 85 | { 86 | Layer::onEnter(); 87 | // set gravity to zero 88 | _world->setGravity(Vec2(0, 0)); 89 | } 90 | 91 | 92 | 93 | 94 | bool MainScene::onTouchBegan(Touch* touch, Event* event) 95 | { 96 | Vec2 pos = this->convertToNodeSpace(touch->getLocation()); 97 | if(_player) 98 | { 99 | _player->walkTo(pos); 100 | } 101 | 102 | // log("MainScene::onTouchBegan"); 103 | return true; 104 | } 105 | 106 | void MainScene::onTouchPause(Ref* sender) 107 | { 108 | Director::getInstance()->pause(); 109 | auto layer = PauseLayer::create(); 110 | this->addChild(layer,10000); 111 | } 112 | 113 | void MainScene::onTouchResume() 114 | { 115 | Director::getInstance()->resume(); 116 | } 117 | 118 | void MainScene::toggleDebug(Ref* pSender) 119 | { 120 | if(_world->getDebugDrawMask() != PhysicsWorld::DEBUGDRAW_NONE) 121 | { 122 | _world->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_NONE); 123 | } 124 | else 125 | { 126 | _world->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL); 127 | } 128 | 129 | } 130 | 131 | bool MainScene::onContactBegin(const PhysicsContact& contact) 132 | { 133 | auto playerA = dynamic_cast(contact.getShapeA()->getBody()->getNode()); 134 | auto playerB = dynamic_cast(contact.getShapeB()->getBody()->getNode()); 135 | auto typeA = playerA->getPlayerType(); 136 | auto typeB = playerB->getPlayerType(); 137 | if(typeA == Player::PlayerType::PLAYER) 138 | { 139 | // only one player so ShapeB must belong to an enemy 140 | log("contact enemy!"); 141 | playerB->setCanAttack(true); 142 | playerA->addAttacker(playerB); 143 | } 144 | if(typeB == Player::PlayerType::PLAYER) 145 | { 146 | // only one player so ShapeA must belong to an enemy 147 | log("contact enemy!"); 148 | playerA->setCanAttack(true); 149 | playerB->addAttacker(playerA); 150 | } 151 | return true; 152 | } 153 | 154 | void MainScene::onContactSeperate(const PhysicsContact& contact) 155 | { 156 | auto playerA = (Player*)contact.getShapeA()->getBody()->getNode(); 157 | auto playerB = (Player*)contact.getShapeB()->getBody()->getNode(); 158 | auto typeA = playerA->getPlayerType(); 159 | auto typeB = playerB->getPlayerType(); 160 | if(typeA == Player::PlayerType::PLAYER) 161 | { 162 | // only one player so ShapeB must belong to an enemy 163 | log("leave enemy!"); 164 | playerB->setCanAttack(false); 165 | playerA->removeAttacker(playerB); 166 | } 167 | 168 | if(typeB == Player::PlayerType::PLAYER) 169 | { 170 | // only one player so ShapeA must belong to an enemy 171 | log("leave enemy!"); 172 | playerA->setCanAttack(false); 173 | playerB->removeAttacker(playerA); 174 | } 175 | } 176 | 177 | void MainScene::clickEnemy(Ref* obj) 178 | { 179 | log("click enemy message received!"); 180 | auto enemy = (Player*)obj; 181 | if(enemy == nullptr) 182 | { 183 | log("enemy null"); 184 | return; 185 | } 186 | if(_player == nullptr) 187 | { 188 | log("player null"); 189 | return; 190 | } 191 | if(enemy->isCanAttack()) 192 | { 193 | if(_player->getState() != "attacking") 194 | { 195 | _player->attack(); 196 | enemy->beHit(_player->getAttack()); 197 | } 198 | 199 | } 200 | else 201 | { 202 | _player->walkTo(enemy->getPosition()); 203 | } 204 | } 205 | 206 | void MainScene::addRoles() 207 | { 208 | //add player 209 | _player = Player::create(Player::PlayerType::PLAYER); 210 | _player->setPosition(VisibleRect::left().x + _player->getContentSize().width/2, VisibleRect::top().y/2); 211 | this->addChild(_player,10); 212 | addEnemyByLevel(0); 213 | } 214 | 215 | void MainScene::addEnemy() 216 | { 217 | //add enemy1 218 | auto _enemy1 = Player::create(Player::PlayerType::ENEMY1); 219 | _enemy1->setPosition(VisibleRect::right().x - _player->getContentSize().width/2, VisibleRect::top().y/3); 220 | this->addChild(_enemy1,10); 221 | _enemys.pushBack(_enemy1); 222 | //add enemy2 223 | auto _enemy2 = Player::create(Player::PlayerType::ENEMY2); 224 | _enemy2->setPosition(VisibleRect::right().x*2/3 - _player->getContentSize().width/2, VisibleRect::top().y/2); 225 | this->addChild(_enemy2,10); 226 | _enemys.pushBack(_enemy2); 227 | // 228 | auto boss = Player::create(Player::PlayerType::BOSS); 229 | boss->setPosition(VisibleRect::right().x - _player->getContentSize().width/2, VisibleRect::top().y/3*2); 230 | this->addChild(boss,10); 231 | _enemys.pushBack(boss); 232 | } 233 | 234 | void MainScene::addUI() 235 | { 236 | //backgound setup 237 | _background = Background::create(); 238 | _background->setPosition(0,0); 239 | this->addChild(_background, -100); 240 | 241 | _progress = Progress::create("player-progress-bg.png","player-progress-fill.png"); 242 | _progress->setPosition(VisibleRect::left().x + _progress->getContentSize().width/2, VisibleRect::top().y - _progress->getContentSize().height/2); 243 | this->addChild(_progress); 244 | 245 | auto pauseItem = CustomTool::createMenuItemImage("pause1.png", "pause2.png", CC_CALLBACK_1(MainScene::onTouchPause,this)); 246 | pauseItem->setTag(1); 247 | pauseItem->setPosition(VisibleRect::right().x - pauseItem->getContentSize().width/2, 248 | VisibleRect::top().y - pauseItem->getContentSize().height/2); 249 | 250 | auto debugItem = MenuItemImage::create( 251 | "CloseNormal.png", 252 | "CloseSelected.png", 253 | CC_CALLBACK_1(MainScene::toggleDebug, this)); 254 | debugItem->setScale(2.0); 255 | debugItem->setPosition(Vec2(VisibleRect::right().x - debugItem->getContentSize().width - pauseItem->getContentSize().width , 256 | VisibleRect::top().y - debugItem->getContentSize().height)); 257 | 258 | auto goItem = CustomTool::createMenuItemImage("go.png", "go.png", CC_CALLBACK_1(MainScene::gotoNextLevel,this)); 259 | goItem->setVisible(false); 260 | goItem->setTag(2); 261 | goItem->setPosition(VisibleRect::right().x - goItem->getContentSize().width/2, VisibleRect::center().y); 262 | _menu = Menu::create(pauseItem, debugItem, goItem, NULL); 263 | _menu->setPosition(0,0); 264 | this->addChild(_menu, 20); 265 | 266 | } 267 | 268 | void MainScene::addListener() 269 | { 270 | _listener_touch = EventListenerTouchOneByOne::create(); 271 | _listener_touch->onTouchBegan = CC_CALLBACK_2(MainScene::onTouchBegan,this); 272 | _eventDispatcher->addEventListenerWithSceneGraphPriority(_listener_touch, this); 273 | 274 | _listener_contact = EventListenerPhysicsContact::create(); 275 | _listener_contact->onContactBegin = CC_CALLBACK_1(MainScene::onContactBegin,this); 276 | _listener_contact->onContactSeperate = CC_CALLBACK_1(MainScene::onContactSeperate,this); 277 | _eventDispatcher->addEventListenerWithFixedPriority(_listener_contact, 10); 278 | } 279 | 280 | void MainScene::addObserver() 281 | { 282 | 283 | NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(MainScene::clickEnemy),"clickEnemy",nullptr); 284 | NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(MainScene::enemyDead),"enemyDead",nullptr); 285 | NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(MainScene::backgroundMoveEnd),"backgroundMoveEnd",nullptr); 286 | } 287 | 288 | 289 | void MainScene::onExit() 290 | { 291 | Layer::onExit(); 292 | _eventDispatcher->removeEventListener(_listener_touch); 293 | _eventDispatcher->removeEventListener(_listener_contact); 294 | NotificationCenter::getInstance()->removeAllObservers(this); 295 | } 296 | 297 | void MainScene::gotoNextLevel(Ref* obj) 298 | { 299 | auto goItem = this->_menu->getChildByTag(2); 300 | goItem->setVisible(false); 301 | goItem->stopAllActions(); 302 | 303 | _background->move("left",_player); 304 | } 305 | 306 | void MainScene::enemyDead(Ref* obj) 307 | { 308 | auto player= dynamic_cast(obj); 309 | if(Player::PlayerType::PLAYER == player->getPlayerType()) 310 | { 311 | _player = nullptr; 312 | auto layer = GameOverLayer::create(); 313 | layer->setText("You Died!"); 314 | this->addChild(layer,10000); 315 | } 316 | else 317 | { 318 | _enemys.eraseObject(player,true); 319 | log("onEnemyDead:%d", _enemys.size()); 320 | if(_enemys.size() == 0) 321 | { 322 | if(_level == 2) 323 | { 324 | auto layer = GameOverLayer::create(); 325 | layer->setText("You Win!"); 326 | this->addChild(layer,10000); 327 | return; 328 | } 329 | showNextLevelItem(); 330 | } 331 | } 332 | } 333 | 334 | void MainScene::backgroundMoveEnd(Ref* obj) 335 | { 336 | _level++; 337 | addEnemyByLevel(_level); 338 | log("adding enemy..."); 339 | } 340 | 341 | void MainScene::showNextLevelItem() 342 | { 343 | auto goItem = this->_menu->getChildByTag(2); 344 | goItem->setVisible(true); 345 | goItem->runAction(RepeatForever::create(Blink::create(1,1))); 346 | } 347 | 348 | void MainScene::enemyMove(float dt) 349 | { 350 | for(auto enemy: _enemys) 351 | { 352 | if("dead" != enemy->getState()&&_player && "dead" != _player->getState()) 353 | { 354 | if(_player->isInRange(enemy)) 355 | { 356 | if("attacking" != enemy->getState()) 357 | { 358 | enemy->attack(); 359 | _player->beHit(enemy->getAttack()); 360 | this->updateHealth(); 361 | } 362 | }else 363 | { 364 | enemy->walkTo(_player->getBestAttackPosition(enemy->getPosition())); 365 | } 366 | } 367 | } 368 | 369 | } 370 | 371 | void MainScene::updateHealth() 372 | { 373 | if(_player) 374 | { 375 | auto health = _player->getHealth(); 376 | auto maxHealth = _player->getMaxHealth(); 377 | _progress->setProgress((float)health/maxHealth*100.0); 378 | } 379 | } 380 | 381 | void MainScene::update(float dt) 382 | { 383 | if(_player) 384 | _player->setZOrder(VisibleRect::top().y - _player->getPosition().y); 385 | for(auto enemy : _enemys) 386 | { 387 | enemy->setZOrder(VisibleRect::top().y - enemy->getPosition().y); 388 | } 389 | } 390 | 391 | void MainScene::addEnemyByLevel(int level) 392 | { 393 | if(level > _maxLevel) 394 | { 395 | return; 396 | } 397 | 398 | auto types = _enemyTypes[level]; 399 | auto positions = _enemyPositions[level]; 400 | 401 | for(int i=0; i< types.size();i++) 402 | { 403 | addOneEnemy(types[i], positions[i]); 404 | } 405 | } 406 | 407 | void MainScene::addOneEnemy(Player::PlayerType type,const Vec2& pos) 408 | { 409 | auto enemy = Player::create(type); 410 | enemy->setPosition(pos); 411 | this->addChild(enemy,10); 412 | _enemys.pushBack(enemy); 413 | } 414 | 415 | -------------------------------------------------------------------------------- /Classes/MainScene.h: -------------------------------------------------------------------------------- 1 | #ifndef __MainScene__ 2 | #define __MainScene__ 3 | 4 | #include "cocos2d.h" 5 | #include "Player.h" 6 | #include "Progress.h" 7 | #include "Background.h" 8 | 9 | USING_NS_CC; 10 | 11 | class MainScene : public cocos2d::Layer 12 | { 13 | public: 14 | // there's no 'id' in cpp, so we recommend returning the class instance pointer 15 | static cocos2d::Scene* createScene(); 16 | 17 | // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone 18 | virtual bool init(); 19 | 20 | 21 | // implement the "static create()" method manually 22 | CREATE_FUNC(MainScene); 23 | 24 | bool onTouchBegan(Touch* touch, Event* event); 25 | 26 | void onTouchPause(Ref* sender); 27 | 28 | void onTouchResume(); 29 | 30 | void setPhysicsWorld(PhysicsWorld* physicsWorld){_world=physicsWorld;} 31 | 32 | void toggleDebug(Ref* pSender); 33 | 34 | void onEnter(); 35 | 36 | bool onContactBegin(const PhysicsContact& contact); 37 | 38 | void onContactSeperate(const PhysicsContact& contact); 39 | 40 | void clickEnemy(Ref* obj); 41 | 42 | void addRoles(); 43 | 44 | void addUI(); 45 | 46 | void addListener(); 47 | 48 | void addObserver(); 49 | 50 | void onExit(); 51 | 52 | void gotoNextLevel(Ref* obj); 53 | 54 | void enemyDead(Ref* obj); 55 | 56 | void backgroundMoveEnd(Ref* obj); 57 | 58 | void showNextLevelItem(); 59 | 60 | void enemyMove(float dt); 61 | 62 | void addEnemy(); 63 | void addEnemyByLevel(int level); 64 | 65 | void updateHealth(); 66 | 67 | void update(float dt); 68 | 69 | void initLevel(); 70 | 71 | void addOneEnemy(Player::PlayerType type,const Vec2& pos); 72 | private: 73 | Player* _player; 74 | //Player* _enemy1; 75 | //Player* _enemy2; 76 | EventListenerTouchOneByOne* _listener_touch; 77 | EventListenerPhysicsContact* _listener_contact; 78 | Progress* _progress; 79 | Menu* _menu; 80 | PhysicsWorld* _world; 81 | Background* _background; 82 | Vector _enemys; 83 | int _maxLevel; 84 | int _level; 85 | std::vector> _enemyTypes; 86 | std::vector> _enemyPositions; 87 | }; 88 | 89 | #endif // __MainScene__ 90 | -------------------------------------------------------------------------------- /Classes/PauseLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "PauseLayer.h" 2 | #include "VisibleRect.h" 3 | #include "CustomTool.h" 4 | #include "StartScene.h" 5 | #include "MainScene.h" 6 | 7 | bool PauseLayer::init() 8 | { 9 | if(!LayerColor::init()) 10 | return false; 11 | 12 | this->initWithColor(Color4B(162, 162, 162, 128)); 13 | 14 | addUI(); 15 | addTouch(); 16 | return true; 17 | } 18 | 19 | void PauseLayer::addUI() 20 | { 21 | auto background = Sprite::createWithSpriteFrameName("pause-bg.png"); 22 | background->setPosition(VisibleRect::center()); 23 | this->addChild(background); 24 | 25 | auto homeItem = CustomTool::createMenuItemImage("home-1.png","home-2.png", 26 | CC_CALLBACK_1(PauseLayer::home,this)); 27 | 28 | auto resumItem = CustomTool::createMenuItemImage("continue-1.png","continue-2.png", 29 | CC_CALLBACK_1(PauseLayer::back,this)); 30 | 31 | auto bgSize = background->getContentSize(); 32 | homeItem->setPosition(bgSize.width/3, bgSize.height/2); 33 | resumItem->setPosition(bgSize.width*2/3,bgSize.height/2); 34 | auto menu = Menu::create(homeItem, resumItem, NULL); 35 | menu->setPosition(VisibleRect::leftBottom()); 36 | 37 | background->addChild(menu); 38 | 39 | } 40 | 41 | void PauseLayer::addTouch() 42 | { 43 | _listener = EventListenerTouchOneByOne::create(); 44 | _listener->onTouchBegan =[&](Touch* touch, Event* event) 45 | { 46 | log("PauseLayer::addTouch"); 47 | return true; 48 | }; 49 | _listener->setSwallowTouches(true); 50 | _eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, this); 51 | } 52 | 53 | void PauseLayer::home(Ref* obj) 54 | { 55 | _eventDispatcher->removeEventListener(_listener); 56 | auto main = (MainScene*)this->getParent(); 57 | main->onTouchResume(); 58 | this->removeFromParentAndCleanup(true); 59 | auto start = StartScene::createScene(); 60 | Director::getInstance()->replaceScene(start); 61 | } 62 | 63 | void PauseLayer::back(Ref* obj) 64 | { 65 | _eventDispatcher->removeEventListener(_listener); 66 | auto main = (MainScene*)this->getParent(); 67 | main->onTouchResume(); 68 | this->removeFromParentAndCleanup(true); 69 | 70 | } -------------------------------------------------------------------------------- /Classes/PauseLayer.h: -------------------------------------------------------------------------------- 1 | #ifndef __PauseLayer__ 2 | #define __PauseLayer__ 3 | #include "cocos2d.h" 4 | 5 | USING_NS_CC; 6 | 7 | class PauseLayer : public LayerColor 8 | { 9 | public: 10 | bool init(); 11 | CREATE_FUNC(PauseLayer); 12 | 13 | void addUI(); 14 | void addTouch(); 15 | void home(Ref* obj); 16 | void back(Ref* obj); 17 | private: 18 | EventListenerTouchOneByOne* _listener; 19 | }; 20 | 21 | #endif -------------------------------------------------------------------------------- /Classes/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | 4 | bool Player::initWithPlayerType(PlayerType type) 5 | { 6 | std::string sfName = ""; 7 | _type = type; 8 | _speed = 100; 9 | _isShowBar = true; 10 | _isCanAttack =false; 11 | _health = 100; 12 | _maxHealth =100; 13 | _attack = 100; 14 | _flip = false; 15 | int animationFrameNum[5] ={4, 4, 4, 2, 4}; 16 | int animationFrameNum2[5] ={3, 3, 3, 2, 0}; 17 | int animationFrameNum3[5] ={1, 5, 4, 2, 0}; 18 | 19 | auto size = this->getContentSize(); 20 | auto body = PhysicsBody::create(); 21 | 22 | //setup according to PlayerType 23 | switch(type) 24 | { 25 | case PlayerType::PLAYER: 26 | sfName = "player1-1-1.png"; 27 | _name = "player1"; 28 | _animationNum = 5; 29 | _animationFrameNum.assign(animationFrameNum, animationFrameNum + 5); 30 | _speed = 125; 31 | _isShowBar = false; 32 | 33 | _flip = true; 34 | // this->setAnchorPoint(Vec2(0, 0)); 35 | 36 | break; 37 | case PlayerType::ENEMY1: 38 | sfName = "enemy1-1-1.png"; 39 | _name = "enemy1"; 40 | _animationNum = 4; 41 | _animationFrameNum.assign(animationFrameNum2, animationFrameNum2 + 5); 42 | // this->setAnchorPoint(Vec2(200, 72)); 43 | _attack = 8; 44 | break; 45 | case PlayerType::ENEMY2: 46 | sfName = "enemy2-1-1.png"; 47 | _name = "enemy2"; 48 | _animationNum = 4; 49 | _animationFrameNum.assign(animationFrameNum2, animationFrameNum2 + 5); 50 | // this->setAnchorPoint(Vec2(200, 75)); 51 | _attack = 8; 52 | break; 53 | case PlayerType::BOSS: 54 | sfName = "df1-1-1.png"; 55 | _name = "df1"; 56 | _animationNum = 4; 57 | _animationFrameNum.assign(animationFrameNum3, animationFrameNum3 + 5); 58 | // this->setAnchorPoint(Vec2(200, 75)); 59 | _attack = 33; 60 | break; 61 | } 62 | this->initWithSpriteFrameName(sfName); 63 | //auto sf = SpriteFrameCache::getInstance()->getSpriteFrameByName(sfName); 64 | //auto texture = sf->getTexture(); 65 | //this->initWithTexture(texture, Rect(0, 38, 247, 163)); 66 | std::string animationNames[] = {"walk", "attack", "dead", "hit", "skill"}; 67 | _animationNames.assign(animationNames, animationNames + 5); 68 | //load animation 69 | this->addAnimation(); 70 | 71 | size = this->getContentSize(); 72 | log("size: %f, %f ",size.width, size.height); 73 | body->addShape(PhysicsShapeBox::create(Size(size.width/3, size.height/2))); 74 | body->setCategoryBitmask(2); 75 | body->setCollisionBitmask(0); 76 | body->setContactTestBitmask(1); 77 | 78 | _flipped = _flip; 79 | if(type == PlayerType::PLAYER) 80 | { 81 | body->setCategoryBitmask(1); 82 | body->setContactTestBitmask(2); 83 | _flipped = !_flip; 84 | } 85 | 86 | this->setPhysicsBody(body); 87 | 88 | 89 | 90 | this->initFSM(); 91 | 92 | 93 | _progress = Progress::create("small-enemy-progress-bg.png","small-enemy-progress-fill.png"); 94 | // _progress->setPosition( size.width*2/3, size.height + _progress->getContentSize().height/2); 95 | _progress->setPosition( 200 , 200); 96 | this->addChild(_progress); 97 | if(!_isShowBar) 98 | { 99 | _progress->setVisible(false); 100 | } 101 | 102 | _listener = EventListenerTouchOneByOne::create(); 103 | _listener->setSwallowTouches(true); 104 | _listener->onTouchBegan = CC_CALLBACK_2(Player::onTouch,this); 105 | _eventDispatcher->addEventListenerWithSceneGraphPriority(_listener,this); 106 | 107 | return true; 108 | } 109 | 110 | 111 | Player* Player::create(PlayerType type) 112 | { 113 | Player* player = new Player(); 114 | if(player && player->initWithPlayerType(type)) 115 | { 116 | player->autorelease(); 117 | return player; 118 | } 119 | else 120 | { 121 | delete player; 122 | player = NULL; 123 | return NULL; 124 | } 125 | } 126 | 127 | 128 | void Player::addAnimation() 129 | { 130 | // check if already loaded 131 | auto animation = AnimationCache::getInstance()->getAnimation(String::createWithFormat("%s-%s",_name.c_str(), 132 | _animationNames[0])->getCString()); 133 | if(animation) 134 | return; 135 | 136 | for(int i=0; i<_animationNum; i++) 137 | { 138 | auto animation = Animation::create(); 139 | animation->setDelayPerUnit(0.2f); 140 | //put frames into animation 141 | for(int j = 0; j< _animationFrameNum[i] ; j++) 142 | { 143 | auto sfName =String::createWithFormat("%s-%d-%d.png",_name.c_str(), i+1, j+1)->getCString(); 144 | // log(sfName); 145 | auto sf = SpriteFrameCache::getInstance()->getSpriteFrameByName(sfName); 146 | // auto texture = sf->getTexture(); 147 | // auto offset = sf->getOffset(); 148 | // auto rect = sf->getRect(); 149 | // sf = SpriteFrame::createWithTexture(texture, Rect(0 + rect.getMinX(), 38 + rect.getMinY(), 247, 163), true, offset, Size(247,163)); 150 | //// this->initWithTexture(texture, Rect(0, 38, 247, 163)); 151 | animation->addSpriteFrame(sf); 152 | } 153 | // put the animation into cache 154 | AnimationCache::getInstance()->addAnimation(animation, String::createWithFormat("%s-%s",_name.c_str(), 155 | _animationNames[i].c_str())->getCString()); 156 | } 157 | } 158 | 159 | 160 | void Player::playAnimationForever(int index) 161 | { 162 | auto act = this->getActionByTag(index); 163 | if(act) 164 | return; 165 | 166 | for(int i=0;i<5;i++) 167 | { 168 | this->stopActionByTag(i); 169 | } 170 | if(index <0 || index >= _animationNum) 171 | { 172 | log("illegal animation index!"); 173 | return; 174 | } 175 | auto str = String::createWithFormat("%s-%s",_name.c_str(), _animationNames[index].c_str())->getCString(); 176 | auto animation = AnimationCache::getInstance()->getAnimation(str); 177 | auto animate = RepeatForever::create(Animate::create(animation)); 178 | animate->setTag(index); 179 | this->runAction(animate); 180 | } 181 | 182 | Animate* Player::getAnimateByType(AnimationType type) 183 | { 184 | if(type <0 || type >= _animationNum) 185 | { 186 | log("illegal animation index!"); 187 | return nullptr; 188 | } 189 | auto str = String::createWithFormat("%s-%s",_name.c_str(), _animationNames[type].c_str())->getCString(); 190 | auto animation = AnimationCache::getInstance()->getAnimation(str); 191 | auto animate = Animate::create(animation); 192 | animate->setTag(type); 193 | return animate; 194 | } 195 | 196 | 197 | void Player::initFSM() 198 | { 199 | _fsm = FSM::create("idle"); 200 | _fsm->retain(); 201 | auto onIdle =[&]() 202 | { 203 | log("onIdle: Enter idle"); 204 | this->stopActionByTag(WALKING); 205 | auto sfName = String::createWithFormat("%s-1-1.png", _name.c_str()); 206 | auto spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(sfName->getCString()); 207 | this->setSpriteFrame(spriteFrame); 208 | }; 209 | _fsm->setOnEnter("idle",onIdle); 210 | 211 | auto onAttacking =[&]() 212 | { 213 | log("onAttacking: Enter Attacking"); 214 | auto animate = getAnimateByType(ATTACKING); 215 | auto func = [&]() 216 | { 217 | this->_fsm->doEvent("stop"); 218 | }; 219 | auto callback = CallFunc::create(func); 220 | auto seq = Sequence::create(animate, callback, nullptr); 221 | this->runAction(seq); 222 | }; 223 | _fsm->setOnEnter("attacking",onAttacking); 224 | 225 | auto onBeingHit = [&]() 226 | { 227 | log("onBeingHit: Enter BeingHit"); 228 | auto animate = getAnimateByType(BEINGHIT); 229 | auto func = [&]() 230 | { 231 | this->_fsm->doEvent("stop"); 232 | }; 233 | auto wait = DelayTime::create(0.6f); 234 | auto callback = CallFunc::create(func); 235 | auto seq = Sequence::create(wait,animate, callback, nullptr); 236 | this->runAction(seq); 237 | }; 238 | _fsm->setOnEnter("beingHit",onBeingHit); 239 | 240 | auto onDead = [&]() 241 | { 242 | this->setCanAttack(false); 243 | log("onDead: Enter Dead"); 244 | auto animate = getAnimateByType(DEAD); 245 | auto func = [&]() 246 | { 247 | log("A charactor died!"); 248 | NotificationCenter::getInstance()->postNotification("enemyDead",this); 249 | this->removeFromParentAndCleanup(true); 250 | }; 251 | auto blink = Blink::create(3,5); 252 | auto callback = CallFunc::create(func); 253 | auto seq = Sequence::create(animate, blink, callback, nullptr); 254 | this->stopAllActions(); 255 | this->runAction(seq); 256 | _progress->setVisible(false); 257 | }; 258 | _fsm->setOnEnter("dead",onDead); 259 | } 260 | 261 | 262 | 263 | void Player::walkTo(Vec2 dest) 264 | { 265 | std::function onWalk = CC_CALLBACK_0(Player::onWalk, this, dest); 266 | _fsm->setOnEnter("walking", onWalk); 267 | _fsm->doEvent("walk"); 268 | } 269 | 270 | 271 | void Player::onWalk(Vec2 dest) 272 | { 273 | log("onIdle: Enter walk"); 274 | this->stopActionByTag(WALKTO_TAG); 275 | auto curPos = this->getPosition(); 276 | 277 | if(curPos.x > dest.x) 278 | { 279 | if(_flipped != _flip) 280 | { 281 | this->setFlippedX(_flip); 282 | _flipped = _flip; 283 | this->setPosition(curPos.x - 88, curPos.y); 284 | this->moveProgress(88); 285 | } 286 | } 287 | else 288 | { 289 | if(_flipped == _flip) 290 | { 291 | this->setFlippedX(!_flip); 292 | _flipped = !_flip; 293 | this->setPosition(curPos.x + 88, curPos.y); 294 | this->moveProgress(-88); 295 | } 296 | } 297 | 298 | auto diff = dest - curPos; 299 | auto time = diff.getLength()/_speed; 300 | auto move = MoveTo::create(time, dest); 301 | auto func = [&]() 302 | { 303 | this->_fsm->doEvent("stop"); 304 | }; 305 | auto callback = CallFunc::create(func); 306 | auto seq = Sequence::create(move, callback, nullptr); 307 | seq->setTag(WALKTO_TAG); 308 | this->runAction(seq); 309 | this->playAnimationForever(WALKING); 310 | } 311 | 312 | void Player::onExit() 313 | { 314 | Sprite::onExit(); 315 | _fsm->release(); 316 | _eventDispatcher->removeEventListener(_listener); 317 | } 318 | 319 | bool Player::onTouch(Touch* touch, Event* event) 320 | { 321 | auto pos = this->convertToNodeSpace(touch->getLocation()); 322 | log("Touching: %f, %f...", pos.x, pos.y); 323 | if(_type == PLAYER) 324 | return false; 325 | 326 | log("Player: touch detected!"); 327 | auto size = this->getContentSize(); 328 | auto rect = Rect(size.width/2, 0, size.width, size.height); 329 | if(rect.containsPoint(pos)) 330 | { 331 | NotificationCenter::getInstance()->postNotification("clickEnemy",this); 332 | log("enemy touched!"); 333 | return true; 334 | } 335 | log("enemy not touched!"); 336 | return false; 337 | } 338 | 339 | void Player::attack() 340 | { 341 | _fsm->doEvent("attack"); 342 | } 343 | 344 | void Player::beHit(int attack) 345 | { 346 | _health -= attack; 347 | if(_health <= 0) 348 | { 349 | _health = 0; 350 | this->_progress->setProgress((float)_health/_maxHealth*100); 351 | _fsm->doEvent("die"); 352 | if(_type == PlayerType::PLAYER) 353 | { 354 | 355 | } 356 | return; 357 | } 358 | else 359 | { 360 | this->_progress->setProgress((float)_health/_maxHealth*100); 361 | _fsm->doEvent("beHit"); 362 | } 363 | } 364 | 365 | void Player::addAttacker(Player* attacker) 366 | { 367 | _attackers.pushBack(attacker); 368 | } 369 | 370 | void Player::removeAttacker(Player* attacker) 371 | { 372 | _attackers.eraseObject(attacker); 373 | } 374 | 375 | bool Player::isInRange(Player* enemy) 376 | { 377 | return _attackers.contains(enemy); 378 | } 379 | 380 | void Player::moveProgress(float dx) 381 | { 382 | auto curPos = _progress->getPosition(); 383 | _progress->setPosition(curPos.x + dx, curPos.y); 384 | } 385 | 386 | Vec2 Player::getBestAttackPosition(const Vec2& pos) 387 | { 388 | auto curPos = this->getPosition(); 389 | auto pos1 = curPos + Vec2(50, 0); 390 | auto pos2 = curPos - Vec2(50, 0); 391 | auto diff1 = pos1 - pos; 392 | auto diff2 = pos2 - pos; 393 | return diff1.length()>diff2.length()?pos2:pos1; 394 | } -------------------------------------------------------------------------------- /Classes/Player.h: -------------------------------------------------------------------------------- 1 | #ifndef __Player__ 2 | #define __Player__ 3 | #include "cocos2d.h" 4 | #include "FSM.h" 5 | #include "Progress.h" 6 | 7 | USING_NS_CC; 8 | 9 | 10 | class Player : public Sprite 11 | { 12 | public: 13 | enum PlayerType 14 | { 15 | PLAYER, 16 | ENEMY1, 17 | ENEMY2, 18 | BOSS 19 | }; 20 | 21 | enum ActionTag 22 | { 23 | WALKTO_TAG =100 24 | }; 25 | 26 | enum AnimationType 27 | { 28 | WALKING = 0, 29 | ATTACKING, 30 | DEAD, 31 | BEINGHIT, 32 | SKILL 33 | }; 34 | 35 | bool initWithPlayerType(PlayerType type); 36 | 37 | static Player* create(PlayerType type); 38 | 39 | // load animation only when it's not loaded 40 | void addAnimation(); 41 | //Repeat the selected animation forever 42 | void playAnimationForever(int index); 43 | 44 | void walkTo(Vec2 dest); 45 | 46 | void initFSM(); 47 | 48 | void onWalk(Vec2 dest); 49 | 50 | void onExit(); 51 | 52 | PlayerType getPlayerType(){return _type;} 53 | 54 | void setCanAttack(bool canAttack){_isCanAttack=canAttack;} 55 | 56 | bool isCanAttack(){return _isCanAttack;} 57 | 58 | Animate* getAnimateByType(AnimationType type); 59 | 60 | bool onTouch(Touch* touch, Event* event); 61 | 62 | void attack(); 63 | 64 | void beHit(int attack); 65 | 66 | int getAttack(){return _attack;} 67 | 68 | std::string getState(){return _fsm->getState();}; 69 | 70 | void addAttacker(Player* attacker); 71 | 72 | void removeAttacker(Player* attacker); 73 | 74 | bool isInRange(Player* enemy); 75 | void moveProgress(float dx); 76 | 77 | Vec2 getBestAttackPosition(const Vec2& pos); 78 | 79 | CC_SYNTHESIZE(int, _health, Health); 80 | CC_SYNTHESIZE(int, _maxHealth, MaxHealth); 81 | 82 | private: 83 | PlayerType _type; 84 | std::string _name; 85 | int _animationNum; 86 | std::vector _animationFrameNum; 87 | std::vector _animationNames; 88 | float _speed; 89 | FSM* _fsm; 90 | Progress* _progress; 91 | bool _isShowBar; 92 | bool _isCanAttack; 93 | EventListenerTouchOneByOne* _listener; 94 | //int _health; 95 | //int _maxHealth; 96 | int _attack; 97 | Vector _attackers; 98 | bool _flip; 99 | bool _flipped; 100 | }; 101 | 102 | #endif -------------------------------------------------------------------------------- /Classes/Progress.cpp: -------------------------------------------------------------------------------- 1 | #include "Progress.h" 2 | 3 | bool Progress::init(const char* background, const char* fillname) 4 | { 5 | this->initWithSpriteFrameName(background); 6 | ProgressTimer* fill = ProgressTimer::create(Sprite::createWithSpriteFrameName(fillname)); 7 | this->setFill(fill); 8 | this->addChild(fill); 9 | 10 | fill->setType(ProgressTimer::Type::BAR); 11 | fill->setMidpoint(Point(0,0.5)); 12 | fill->setBarChangeRate(Point(1.0, 0)); 13 | fill->setPosition(this->getContentSize()/2); 14 | fill->setPercentage(100); 15 | return true; 16 | } 17 | 18 | Progress* Progress::create(const char* background, const char* fillname) 19 | { 20 | Progress* progress = new Progress(); 21 | if(progress && progress->init(background,fillname)) 22 | { 23 | progress->autorelease(); 24 | return progress; 25 | } 26 | else 27 | { 28 | delete progress; 29 | progress = NULL; 30 | return NULL; 31 | } 32 | } -------------------------------------------------------------------------------- /Classes/Progress.h: -------------------------------------------------------------------------------- 1 | #ifndef __Progress__ 2 | #define __Progress__ 3 | #include "cocos2d.h" 4 | USING_NS_CC; 5 | 6 | class Progress : public Sprite 7 | { 8 | public: 9 | bool init(const char* background, const char* fillname); 10 | /* 11 | the inputs are SpriteFrame Names. 12 | they should be loaded into SpriteFrameCache before calling this. 13 | */ 14 | static Progress* create(const char* background, const char* fill); 15 | 16 | void setFill(ProgressTimer* fill){_fill=fill;} 17 | 18 | void setProgress(float percentage){_fill->setPercentage(percentage);} 19 | 20 | private: 21 | ProgressTimer* _fill; 22 | }; 23 | #endif -------------------------------------------------------------------------------- /Classes/StartScene.cpp: -------------------------------------------------------------------------------- 1 | #include "StartScene.h" 2 | #include "MainScene.h" 3 | #include "VisibleRect.h" 4 | #include "CustomTool.h" 5 | 6 | bool StartScene::init() 7 | { 8 | if(!Layer::init()) 9 | return false; 10 | log("StartLayer::init"); 11 | 12 | SpriteFrameCache::getInstance()->addSpriteFramesWithFile("image/role.plist","image/role.pvr.ccz"); 13 | SpriteFrameCache::getInstance()->addSpriteFramesWithFile("image/ui.plist","image/ui.pvr.ccz"); 14 | auto background = Sprite::create("image/start-bg.jpg"); 15 | background->setPosition(VisibleRect::center()); 16 | this->addChild(background); 17 | 18 | auto item = CustomTool::createMenuItemImage("start1.png", "start2.png", CC_CALLBACK_1(StartScene::onStart,this)); 19 | auto menu = Menu::createWithItem(item); 20 | this->addChild(menu); 21 | return true; 22 | } 23 | 24 | 25 | Scene* StartScene::createScene() 26 | { 27 | auto scene = Scene::create(); 28 | auto layer = StartScene::create(); 29 | scene->addChild(layer); 30 | return scene; 31 | } 32 | 33 | 34 | void StartScene::onStart(Ref* obj) 35 | { 36 | log("StartLayer::onStart"); 37 | auto scene = MainScene::createScene(); 38 | Director::getInstance()->replaceScene(scene); 39 | } -------------------------------------------------------------------------------- /Classes/StartScene.h: -------------------------------------------------------------------------------- 1 | #ifndef __StartScene__ 2 | #define __StartScene__ 3 | #include "cocos2d.h" 4 | 5 | USING_NS_CC; 6 | 7 | class StartScene : public Layer 8 | { 9 | public: 10 | bool init(); 11 | static Scene* createScene(); 12 | void onStart(Ref* obj); 13 | CREATE_FUNC(StartScene); 14 | }; 15 | 16 | #endif -------------------------------------------------------------------------------- /Classes/VisibleRect.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2013-2014 Chukong Technologies Inc. 3 | 4 | http://www.cocos2d-x.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | ****************************************************************************/ 24 | 25 | #include "VisibleRect.h" 26 | 27 | USING_NS_CC; 28 | 29 | Rect VisibleRect::s_visibleRect; 30 | 31 | void VisibleRect::lazyInit() 32 | { 33 | // no lazy init 34 | // Useful if we change the resolution in runtime 35 | s_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect(); 36 | } 37 | 38 | Rect VisibleRect::getVisibleRect() 39 | { 40 | lazyInit(); 41 | return s_visibleRect; 42 | } 43 | 44 | Vec2 VisibleRect::left() 45 | { 46 | lazyInit(); 47 | return Vec2(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height/2); 48 | } 49 | 50 | Vec2 VisibleRect::right() 51 | { 52 | lazyInit(); 53 | return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height/2); 54 | } 55 | 56 | Vec2 VisibleRect::top() 57 | { 58 | lazyInit(); 59 | return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height); 60 | } 61 | 62 | Vec2 VisibleRect::bottom() 63 | { 64 | lazyInit(); 65 | return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y); 66 | } 67 | 68 | Vec2 VisibleRect::center() 69 | { 70 | lazyInit(); 71 | return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height/2); 72 | } 73 | 74 | Vec2 VisibleRect::leftTop() 75 | { 76 | lazyInit(); 77 | return Vec2(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height); 78 | } 79 | 80 | Vec2 VisibleRect::rightTop() 81 | { 82 | lazyInit(); 83 | return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height); 84 | } 85 | 86 | Vec2 VisibleRect::leftBottom() 87 | { 88 | lazyInit(); 89 | return s_visibleRect.origin; 90 | } 91 | 92 | Vec2 VisibleRect::rightBottom() 93 | { 94 | lazyInit(); 95 | return Vec2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y); 96 | } 97 | -------------------------------------------------------------------------------- /Classes/VisibleRect.h: -------------------------------------------------------------------------------- 1 | #ifndef __VISIBLERECT_H__ 2 | #define __VISIBLERECT_H__ 3 | 4 | #include "cocos2d.h" 5 | 6 | class VisibleRect 7 | { 8 | public: 9 | static cocos2d::Rect getVisibleRect(); 10 | 11 | static cocos2d::Vec2 left(); 12 | static cocos2d::Vec2 right(); 13 | static cocos2d::Vec2 top(); 14 | static cocos2d::Vec2 bottom(); 15 | static cocos2d::Vec2 center(); 16 | static cocos2d::Vec2 leftTop(); 17 | static cocos2d::Vec2 rightTop(); 18 | static cocos2d::Vec2 leftBottom(); 19 | static cocos2d::Vec2 rightBottom(); 20 | private: 21 | static void lazyInit(); 22 | static cocos2d::Rect s_visibleRect; 23 | }; 24 | 25 | #endif /* __VISIBLERECT_H__ */ 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A cpp version of Brave 2 | based on cocos2dx 3.2 3 | 4 | It is advised to create a new project and then copy Classes and Resources folder into it. 5 | 6 | The original lua version: 7 | https://github.com/rainswan/Brave 8 | 9 | 程序配套教程: 10 | http://cn.cocos2d-x.org/tutorial/lists?id=85 11 | 12 | Demo:
13 | 14 | -------------------------------------------------------------------------------- /Resources/CloseNormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/CloseNormal.png -------------------------------------------------------------------------------- /Resources/CloseSelected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/CloseSelected.png -------------------------------------------------------------------------------- /Resources/HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/HelloWorld.png -------------------------------------------------------------------------------- /Resources/fonts/Marker Felt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/fonts/Marker Felt.ttf -------------------------------------------------------------------------------- /Resources/image/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/image/background.png -------------------------------------------------------------------------------- /Resources/image/background2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/image/background2.png -------------------------------------------------------------------------------- /Resources/image/effect.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | frames 6 | 7 | hit1-1.png 8 | 9 | frame 10 | {{144,2},{46,57}} 11 | offset 12 | {10,2} 13 | rotated 14 | 15 | sourceColorRect 16 | {{24,37},{46,57}} 17 | sourceSize 18 | {74,135} 19 | 20 | hit1-2.png 21 | 22 | frame 23 | {{78,2},{64,97}} 24 | offset 25 | {0,0} 26 | rotated 27 | 28 | sourceColorRect 29 | {{5,19},{64,97}} 30 | sourceSize 31 | {74,135} 32 | 33 | hit1-3.png 34 | 35 | frame 36 | {{2,2},{74,135}} 37 | offset 38 | {0,0} 39 | rotated 40 | 41 | sourceColorRect 42 | {{0,0},{74,135}} 43 | sourceSize 44 | {74,135} 45 | 46 | skill.png 47 | 48 | frame 49 | {{2,139},{98,82}} 50 | offset 51 | {0,0} 52 | rotated 53 | 54 | sourceColorRect 55 | {{0,0},{98,82}} 56 | sourceSize 57 | {98,82} 58 | 59 | 60 | metadata 61 | 62 | format 63 | 2 64 | realTextureFileName 65 | effect.pvr.ccz 66 | size 67 | {256,256} 68 | smartupdate 69 | $TexturePacker:SmartUpdate:4c50d15b66ce5fb080f6ac4a412f02c9:b61d710ab6de7a1b2b613a2292b2a1b2:e0fdcd92bbdb8ab6858982d39ba3f2d9$ 70 | textureFileName 71 | effect.pvr.ccz 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Resources/image/effect.pvr.ccz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/image/effect.pvr.ccz -------------------------------------------------------------------------------- /Resources/image/role.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | frames 6 | 7 | df1-1-1.png 8 | 9 | frame 10 | {{268,569},{254,219}} 11 | offset 12 | {55,1} 13 | rotated 14 | 15 | sourceColorRect 16 | {{110,15},{254,219}} 17 | sourceSize 18 | {364,251} 19 | 20 | df1-2-1.png 21 | 22 | frame 23 | {{268,569},{254,219}} 24 | offset 25 | {55,1} 26 | rotated 27 | 28 | sourceColorRect 29 | {{110,15},{254,219}} 30 | sourceSize 31 | {364,251} 32 | 33 | df1-2-2.png 34 | 35 | frame 36 | {{2,432},{264,221}} 37 | offset 38 | {50,2} 39 | rotated 40 | 41 | sourceColorRect 42 | {{100,13},{264,221}} 43 | sourceSize 44 | {364,251} 45 | 46 | df1-2-3.png 47 | 48 | frame 49 | {{326,344},{266,223}} 50 | offset 51 | {49,3} 52 | rotated 53 | 54 | sourceColorRect 55 | {{98,11},{266,223}} 56 | sourceSize 57 | {364,251} 58 | 59 | df1-2-4.png 60 | 61 | frame 62 | {{697,429},{260,235}} 63 | offset 64 | {52,8} 65 | rotated 66 | 67 | sourceColorRect 68 | {{104,0},{260,235}} 69 | sourceSize 70 | {364,251} 71 | 72 | df1-2-5.png 73 | 74 | frame 75 | {{2,203},{322,227}} 76 | offset 77 | {21,5} 78 | rotated 79 | 80 | sourceColorRect 81 | {{42,7},{322,227}} 82 | sourceSize 83 | {364,251} 84 | 85 | df1-3-1.png 86 | 87 | frame 88 | {{268,569},{254,219}} 89 | offset 90 | {55,1} 91 | rotated 92 | 93 | sourceColorRect 94 | {{110,15},{254,219}} 95 | sourceSize 96 | {364,251} 97 | 98 | df1-3-2.png 99 | 100 | frame 101 | {{704,2},{302,187}} 102 | offset 103 | {31,-15} 104 | rotated 105 | 106 | sourceColorRect 107 | {{62,47},{302,187}} 108 | sourceSize 109 | {364,251} 110 | 111 | df1-3-3.png 112 | 113 | frame 114 | {{368,2},{334,199}} 115 | offset 116 | {15,-26} 117 | rotated 118 | 119 | sourceColorRect 120 | {{30,52},{334,199}} 121 | sourceSize 122 | {364,251} 123 | 124 | df1-3-4.png 125 | 126 | frame 127 | {{2,2},{364,199}} 128 | offset 129 | {0,-25} 130 | rotated 131 | 132 | sourceColorRect 133 | {{0,51},{364,199}} 134 | sourceSize 135 | {364,251} 136 | 137 | df1-4-1.png 138 | 139 | frame 140 | {{2,808},{246,217}} 141 | offset 142 | {59,0} 143 | rotated 144 | 145 | sourceColorRect 146 | {{118,17},{246,217}} 147 | sourceSize 148 | {364,251} 149 | 150 | df1-4-2.png 151 | 152 | frame 153 | {{258,790},{248,215}} 154 | offset 155 | {58,-1} 156 | rotated 157 | 158 | sourceColorRect 159 | {{116,19},{248,215}} 160 | sourceSize 161 | {364,251} 162 | 163 | enemy1-1-1.png 164 | 165 | frame 166 | {{477,1513},{134,137}} 167 | offset 168 | {48,3} 169 | rotated 170 | 171 | sourceColorRect 172 | {{135,0},{134,137}} 173 | sourceSize 174 | {308,143} 175 | 176 | enemy1-1-2.png 177 | 178 | frame 179 | {{2,1798},{134,133}} 180 | offset 181 | {48,4} 182 | rotated 183 | 184 | sourceColorRect 185 | {{135,1},{134,133}} 186 | sourceSize 187 | {308,143} 188 | 189 | enemy1-1-3.png 190 | 191 | frame 192 | {{147,1726},{134,135}} 193 | offset 194 | {48,4} 195 | rotated 196 | 197 | sourceColorRect 198 | {{135,0},{134,135}} 199 | sourceSize 200 | {308,143} 201 | 202 | enemy1-2-1.png 203 | 204 | frame 205 | {{331,1485},{144,137}} 206 | offset 207 | {61,3} 208 | rotated 209 | 210 | sourceColorRect 211 | {{143,0},{144,137}} 212 | sourceSize 213 | {308,143} 214 | 215 | enemy1-2-2.png 216 | 217 | frame 218 | {{539,1238},{164,137}} 219 | offset 220 | {72,2} 221 | rotated 222 | 223 | sourceColorRect 224 | {{144,1},{164,137}} 225 | sourceSize 226 | {308,143} 227 | 228 | enemy1-2-3.png 229 | 230 | frame 231 | {{464,1035},{172,139}} 232 | offset 233 | {29,2} 234 | rotated 235 | 236 | sourceColorRect 237 | {{97,0},{172,139}} 238 | sourceSize 239 | {308,143} 240 | 241 | enemy1-3-1.png 242 | 243 | frame 244 | {{697,666},{254,143}} 245 | offset 246 | {-12,0} 247 | rotated 248 | 249 | sourceColorRect 250 | {{15,0},{254,143}} 251 | sourceSize 252 | {308,143} 253 | 254 | enemy1-3-2.png 255 | 256 | frame 257 | {{326,203},{282,139}} 258 | offset 259 | {-12,-2} 260 | rotated 261 | 262 | sourceColorRect 263 | {{1,4},{282,139}} 264 | sourceSize 265 | {308,143} 266 | 267 | enemy1-3-3.png 268 | 269 | frame 270 | {{697,344},{262,83}} 271 | offset 272 | {-23,-30} 273 | rotated 274 | 275 | sourceColorRect 276 | {{0,60},{262,83}} 277 | sourceSize 278 | {308,143} 279 | 280 | enemy1-4-1.png 281 | 282 | frame 283 | {{647,1405},{134,137}} 284 | offset 285 | {46,3} 286 | rotated 287 | 288 | sourceColorRect 289 | {{133,0},{134,137}} 290 | sourceSize 291 | {308,143} 292 | 293 | enemy1-4-2.png 294 | 295 | frame 296 | {{310,1624},{132,137}} 297 | offset 298 | {48,3} 299 | rotated 300 | 301 | sourceColorRect 302 | {{136,0},{132,137}} 303 | sourceSize 304 | {308,143} 305 | 306 | enemy2-1-1.png 307 | 308 | frame 309 | {{500,1377},{134,145}} 310 | offset 311 | {48,4} 312 | rotated 313 | 314 | sourceColorRect 315 | {{135,0},{134,145}} 316 | sourceSize 317 | {308,153} 318 | 319 | enemy2-1-2.png 320 | 321 | frame 322 | {{2,1662},{134,143}} 323 | offset 324 | {48,5} 325 | rotated 326 | 327 | sourceColorRect 328 | {{135,0},{134,143}} 329 | sourceSize 330 | {308,153} 331 | 332 | enemy2-1-3.png 333 | 334 | frame 335 | {{165,1590},{134,143}} 336 | offset 337 | {48,5} 338 | rotated 339 | 340 | sourceColorRect 341 | {{135,0},{134,143}} 342 | sourceSize 343 | {308,153} 344 | 345 | enemy2-2-1.png 346 | 347 | frame 348 | {{705,1259},{144,145}} 349 | offset 350 | {61,4} 351 | rotated 352 | 353 | sourceColorRect 354 | {{143,0},{144,145}} 355 | sourceSize 356 | {308,153} 357 | 358 | enemy2-2-2.png 359 | 360 | frame 361 | {{2,1373},{164,147}} 362 | offset 363 | {72,3} 364 | rotated 365 | 366 | sourceColorRect 367 | {{144,0},{164,147}} 368 | sourceSize 369 | {308,153} 370 | 371 | enemy2-2-3.png 372 | 373 | frame 374 | {{508,886},{172,147}} 375 | offset 376 | {29,3} 377 | rotated 378 | 379 | sourceColorRect 380 | {{97,0},{172,147}} 381 | sourceSize 382 | {308,153} 383 | 384 | enemy2-3-1.png 385 | 386 | frame 387 | {{2,655},{254,151}} 388 | offset 389 | {-12,1} 390 | rotated 391 | 392 | sourceColorRect 393 | {{15,0},{254,151}} 394 | sourceSize 395 | {308,153} 396 | 397 | enemy2-3-2.png 398 | 399 | frame 400 | {{704,191},{282,151}} 401 | offset 402 | {-12,1} 403 | rotated 404 | 405 | sourceColorRect 406 | {{1,0},{282,151}} 407 | sourceSize 408 | {308,153} 409 | 410 | enemy2-3-3.png 411 | 412 | frame 413 | {{610,203},{262,85}} 414 | offset 415 | {-23,-34} 416 | rotated 417 | 418 | sourceColorRect 419 | {{0,68},{262,85}} 420 | sourceSize 421 | {308,153} 422 | 423 | enemy2-4-1.png 424 | 425 | frame 426 | {{852,1259},{136,145}} 427 | offset 428 | {49,4} 429 | rotated 430 | 431 | sourceColorRect 432 | {{135,0},{136,145}} 433 | sourceSize 434 | {308,153} 435 | 436 | enemy2-4-2.png 437 | 438 | frame 439 | {{852,1397},{134,145}} 440 | offset 441 | {47,4} 442 | rotated 443 | 444 | sourceColorRect 445 | {{134,0},{134,145}} 446 | sourceSize 447 | {308,153} 448 | 449 | player1-1-1.png 450 | 451 | frame 452 | {{372,1176},{146,165}} 453 | offset 454 | {-46,7} 455 | rotated 456 | 457 | sourceColorRect 458 | {{39,22},{146,165}} 459 | sourceSize 460 | {316,223} 461 | 462 | player1-1-2.png 463 | 464 | frame 465 | {{2,1225},{146,165}} 466 | offset 467 | {-46,7} 468 | rotated 469 | 470 | sourceColorRect 471 | {{39,22},{146,165}} 472 | sourceSize 473 | {316,223} 474 | 475 | player1-1-3.png 476 | 477 | frame 478 | {{372,1176},{146,165}} 479 | offset 480 | {-46,7} 481 | rotated 482 | 483 | sourceColorRect 484 | {{39,22},{146,165}} 485 | sourceSize 486 | {316,223} 487 | 488 | player1-1-4.png 489 | 490 | frame 491 | {{2,1522},{138,161}} 492 | offset 493 | {-42,7} 494 | rotated 495 | 496 | sourceColorRect 497 | {{47,24},{138,161}} 498 | sourceSize 499 | {316,223} 500 | 501 | player1-2-1.png 502 | 503 | frame 504 | {{169,1298},{132,165}} 505 | offset 506 | {-38,9} 507 | rotated 508 | 509 | sourceColorRect 510 | {{54,20},{132,165}} 511 | sourceSize 512 | {316,223} 513 | 514 | player1-2-2.png 515 | 516 | frame 517 | {{871,926},{148,169}} 518 | offset 519 | {-45,9} 520 | rotated 521 | 522 | sourceColorRect 523 | {{39,18},{148,169}} 524 | sourceSize 525 | {316,223} 526 | 527 | player1-2-3.png 528 | 529 | frame 530 | {{682,926},{146,187}} 531 | offset 532 | {-46,18} 533 | rotated 534 | 535 | sourceColorRect 536 | {{39,0},{146,187}} 537 | sourceSize 538 | {316,223} 539 | 540 | player1-2-4.png 541 | 542 | frame 543 | {{2,1027},{196,201}} 544 | offset 545 | {-29,-11} 546 | rotated 547 | 548 | sourceColorRect 549 | {{31,22},{196,201}} 550 | sourceSize 551 | {316,223} 552 | 553 | player1-3-1.png 554 | 555 | frame 556 | {{372,1176},{146,165}} 557 | offset 558 | {-46,7} 559 | rotated 560 | 561 | sourceColorRect 562 | {{39,22},{146,165}} 563 | sourceSize 564 | {316,223} 565 | 566 | player1-3-2.png 567 | 568 | frame 569 | {{168,1432},{156,161}} 570 | offset 571 | {-34,7} 572 | rotated 573 | 574 | sourceColorRect 575 | {{46,24},{156,161}} 576 | sourceSize 577 | {316,223} 578 | 579 | player1-3-3.png 580 | 581 | frame 582 | {{250,1007},{212,135}} 583 | offset 584 | {-5,-6} 585 | rotated 586 | 587 | sourceColorRect 588 | {{47,50},{212,135}} 589 | sourceSize 590 | {316,223} 591 | 592 | player1-3-4.png 593 | 594 | frame 595 | {{696,811},{246,113}} 596 | offset 597 | {35,-37} 598 | rotated 599 | 600 | sourceColorRect 601 | {{70,92},{246,113}} 602 | sourceSize 603 | {316,223} 604 | 605 | player1-4-1.png 606 | 607 | frame 608 | {{524,569},{154,171}} 609 | offset 610 | {-47,10} 611 | rotated 612 | 613 | sourceColorRect 614 | {{34,16},{154,171}} 615 | sourceSize 616 | {316,223} 617 | 618 | player1-4-2.png 619 | 620 | frame 621 | {{205,1144},{152,165}} 622 | offset 623 | {-48,7} 624 | rotated 625 | 626 | sourceColorRect 627 | {{34,22},{152,165}} 628 | sourceSize 629 | {316,223} 630 | 631 | player1-5-1.png 632 | 633 | frame 634 | {{638,1074},{162,169}} 635 | offset 636 | {-42,10} 637 | rotated 638 | 639 | sourceColorRect 640 | {{35,17},{162,169}} 641 | sourceSize 642 | {316,223} 643 | 644 | player1-5-2.png 645 | 646 | frame 647 | {{809,1097},{160,169}} 648 | offset 649 | {-41,9} 650 | rotated 651 | 652 | sourceColorRect 653 | {{37,18},{160,169}} 654 | sourceSize 655 | {316,223} 656 | 657 | player1-5-3.png 658 | 659 | frame 660 | {{336,1324},{162,159}} 661 | offset 662 | {-5,4} 663 | rotated 664 | 665 | sourceColorRect 666 | {{72,28},{162,159}} 667 | sourceSize 668 | {316,223} 669 | 670 | player1-5-4.png 671 | 672 | frame 673 | {{524,725},{170,159}} 674 | offset 675 | {4,4} 676 | rotated 677 | 678 | sourceColorRect 679 | {{77,28},{170,159}} 680 | sourceSize 681 | {316,223} 682 | 683 | 684 | metadata 685 | 686 | format 687 | 2 688 | realTextureFileName 689 | role.pvr.ccz 690 | size 691 | {1024,2048} 692 | smartupdate 693 | $TexturePacker:SmartUpdate:b0c59eee3b921578759b7d01d7afd876:77c61d33913491e84839d71b585346a0:c7f724d6c30314d5f0ba98940d931d6f$ 694 | textureFileName 695 | role.pvr.ccz 696 | 697 | 698 | 699 | -------------------------------------------------------------------------------- /Resources/image/role.pvr.ccz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/image/role.pvr.ccz -------------------------------------------------------------------------------- /Resources/image/start-bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/image/start-bg.jpg -------------------------------------------------------------------------------- /Resources/image/ui.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | frames 6 | 7 | boss-progress-bg.png 8 | 9 | frame 10 | {{65,372},{149,27}} 11 | offset 12 | {0,0} 13 | rotated 14 | 15 | sourceColorRect 16 | {{0,0},{149,27}} 17 | sourceSize 18 | {149,27} 19 | 20 | boss-progress-fill.png 21 | 22 | frame 23 | {{94,372},{136,15}} 24 | offset 25 | {0,0} 26 | rotated 27 | 28 | sourceColorRect 29 | {{0,0},{136,15}} 30 | sourceSize 31 | {136,15} 32 | 33 | continue-1.png 34 | 35 | frame 36 | {{914,529},{101,97}} 37 | offset 38 | {-1,1} 39 | rotated 40 | 41 | sourceColorRect 42 | {{0,0},{101,97}} 43 | sourceSize 44 | {103,99} 45 | 46 | continue-2.png 47 | 48 | frame 49 | {{914,329},{103,99}} 50 | offset 51 | {0,0} 52 | rotated 53 | 54 | sourceColorRect 55 | {{0,0},{103,99}} 56 | sourceSize 57 | {103,99} 58 | 59 | gameover-title.png 60 | 61 | frame 62 | {{574,2},{404,119}} 63 | offset 64 | {0,0} 65 | rotated 66 | 67 | sourceColorRect 68 | {{0,0},{404,119}} 69 | sourceSize 70 | {404,119} 71 | 72 | go.png 73 | 74 | frame 75 | {{2,727},{291,81}} 76 | offset 77 | {0,0} 78 | rotated 79 | 80 | sourceColorRect 81 | {{0,0},{291,81}} 82 | sourceSize 83 | {291,81} 84 | 85 | golden.png 86 | 87 | frame 88 | {{914,123},{62,56}} 89 | offset 90 | {0,0} 91 | rotated 92 | 93 | sourceColorRect 94 | {{0,0},{62,56}} 95 | sourceSize 96 | {62,56} 97 | 98 | home-1.png 99 | 100 | frame 101 | {{65,523},{99,95}} 102 | offset 103 | {0,1} 104 | rotated 105 | 106 | sourceColorRect 107 | {{2,1},{99,95}} 108 | sourceSize 109 | {103,99} 110 | 111 | home-2.png 112 | 113 | frame 114 | {{914,430},{103,97}} 115 | offset 116 | {0,0} 117 | rotated 118 | 119 | sourceColorRect 120 | {{0,1},{103,97}} 121 | sourceSize 122 | {103,99} 123 | 124 | pause-bg.png 125 | 126 | frame 127 | {{574,123},{522,338}} 128 | offset 129 | {0,0} 130 | rotated 131 | 132 | sourceColorRect 133 | {{0,0},{522,338}} 134 | sourceSize 135 | {522,338} 136 | 137 | pause1.png 138 | 139 | frame 140 | {{2,647},{81,78}} 141 | offset 142 | {-1,1} 143 | rotated 144 | 145 | sourceColorRect 146 | {{0,0},{81,78}} 147 | sourceSize 148 | {83,80} 149 | 150 | pause2.png 151 | 152 | frame 153 | {{162,469},{83,80}} 154 | offset 155 | {0,0} 156 | rotated 157 | 158 | sourceColorRect 159 | {{0,0},{83,80}} 160 | sourceSize 161 | {83,80} 162 | 163 | player-progress-bg.png 164 | 165 | frame 166 | {{2,372},{259,61}} 167 | offset 168 | {0,0} 169 | rotated 170 | 171 | sourceColorRect 172 | {{0,0},{259,61}} 173 | sourceSize 174 | {259,61} 175 | 176 | player-progress-fill.png 177 | 178 | frame 179 | {{980,2},{227,32}} 180 | offset 181 | {0,0} 182 | rotated 183 | 184 | sourceColorRect 185 | {{0,0},{227,32}} 186 | sourceSize 187 | {227,32} 188 | 189 | retry-1.png 190 | 191 | frame 192 | {{134,372},{95,93}} 193 | offset 194 | {0,1} 195 | rotated 196 | 197 | sourceColorRect 198 | {{4,2},{95,93}} 199 | sourceSize 200 | {103,99} 201 | 202 | retry-2.png 203 | 204 | frame 205 | {{914,628},{99,97}} 206 | offset 207 | {-1,1} 208 | rotated 209 | 210 | sourceColorRect 211 | {{1,0},{99,97}} 212 | sourceSize 213 | {103,99} 214 | 215 | skill1.png 216 | 217 | frame 218 | {{113,624},{90,90}} 219 | offset 220 | {0,0} 221 | rotated 222 | 223 | sourceColorRect 224 | {{0,0},{90,90}} 225 | sourceSize 226 | {90,90} 227 | 228 | skill2.png 229 | 230 | frame 231 | {{85,727},{90,90}} 232 | offset 233 | {0,0} 234 | rotated 235 | 236 | sourceColorRect 237 | {{0,0},{90,90}} 238 | sourceSize 239 | {90,90} 240 | 241 | small-enemy-progress-bg.png 242 | 243 | frame 244 | {{111,372},{119,21}} 245 | offset 246 | {0,0} 247 | rotated 248 | 249 | sourceColorRect 250 | {{0,0},{119,21}} 251 | sourceSize 252 | {119,21} 253 | 254 | small-enemy-progress-fill.png 255 | 256 | frame 257 | {{2,633},{109,12}} 258 | offset 259 | {0,0} 260 | rotated 261 | 262 | sourceColorRect 263 | {{0,0},{109,12}} 264 | sourceSize 265 | {109,12} 266 | 267 | star.png 268 | 269 | frame 270 | {{914,231},{107,96}} 271 | offset 272 | {0,0} 273 | rotated 274 | 275 | sourceColorRect 276 | {{0,0},{107,96}} 277 | sourceSize 278 | {107,96} 279 | 280 | start1.png 281 | 282 | frame 283 | {{2,189},{558,181}} 284 | offset 285 | {0,0} 286 | rotated 287 | 288 | sourceColorRect 289 | {{6,2},{558,181}} 290 | sourceSize 291 | {570,185} 292 | 293 | start2.png 294 | 295 | frame 296 | {{2,2},{570,185}} 297 | offset 298 | {0,0} 299 | rotated 300 | 301 | sourceColorRect 302 | {{0,0},{570,185}} 303 | sourceSize 304 | {570,185} 305 | 306 | 307 | metadata 308 | 309 | format 310 | 2 311 | realTextureFileName 312 | ui.pvr.ccz 313 | size 314 | {1024,1024} 315 | smartupdate 316 | $TexturePacker:SmartUpdate:587dea8dedfe30f620e154b09e977dfe:61cb19d40670807220c17273e755d16f:ce842559b5d294d5ed4628903bfc52df$ 317 | textureFileName 318 | ui.pvr.ccz 319 | 320 | 321 | 322 | -------------------------------------------------------------------------------- /Resources/image/ui.pvr.ccz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/image/ui.pvr.ccz -------------------------------------------------------------------------------- /Resources/win.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/Resources/win.gif -------------------------------------------------------------------------------- /proj.win32/Brave_cpp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Brave_cpp", "Brave_cpp.vcxproj", "{76A39BB2-9B84-4C65-98A5-654D86B86F2A}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} 7 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} = {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} 8 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\cocos2d\cocos\2d\cocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}" 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libchipmunk", "..\cocos2d\external\chipmunk\proj.win32\chipmunk.vcxproj", "{207BC7A9-CCF1-4F2F-A04D-45F72242AE25}" 14 | EndProject 15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libAudio", "..\cocos2d\cocos\audio\proj.win32\CocosDenshion.vcxproj", "{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}" 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Debug|Mixed Platforms = Debug|Mixed Platforms 21 | Debug|Win32 = Debug|Win32 22 | Release|Any CPU = Release|Any CPU 23 | Release|Mixed Platforms = Release|Mixed Platforms 24 | Release|Win32 = Release|Win32 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Any CPU.ActiveCfg = Debug|Win32 28 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 29 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Mixed Platforms.Build.0 = Debug|Win32 30 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Win32.ActiveCfg = Debug|Win32 31 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Win32.Build.0 = Debug|Win32 32 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Any CPU.ActiveCfg = Release|Win32 33 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Mixed Platforms.ActiveCfg = Release|Win32 34 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Mixed Platforms.Build.0 = Release|Win32 35 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Win32.ActiveCfg = Release|Win32 36 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Win32.Build.0 = Release|Win32 37 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Any CPU.ActiveCfg = Debug|Win32 38 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 39 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Mixed Platforms.Build.0 = Debug|Win32 40 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.ActiveCfg = Debug|Win32 41 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.Build.0 = Debug|Win32 42 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Any CPU.ActiveCfg = Release|Win32 43 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Mixed Platforms.ActiveCfg = Release|Win32 44 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Mixed Platforms.Build.0 = Release|Win32 45 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.ActiveCfg = Release|Win32 46 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.Build.0 = Release|Win32 47 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Debug|Any CPU.ActiveCfg = Debug|Win32 48 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 49 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Debug|Mixed Platforms.Build.0 = Debug|Win32 50 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Debug|Win32.ActiveCfg = Debug|Win32 51 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Debug|Win32.Build.0 = Debug|Win32 52 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Release|Any CPU.ActiveCfg = Release|Win32 53 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Release|Mixed Platforms.ActiveCfg = Release|Win32 54 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Release|Mixed Platforms.Build.0 = Release|Win32 55 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Release|Win32.ActiveCfg = Release|Win32 56 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Release|Win32.Build.0 = Release|Win32 57 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Debug|Any CPU.ActiveCfg = Debug|Win32 58 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 59 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Debug|Mixed Platforms.Build.0 = Debug|Win32 60 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Debug|Win32.ActiveCfg = Debug|Win32 61 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Debug|Win32.Build.0 = Debug|Win32 62 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Release|Any CPU.ActiveCfg = Release|Win32 63 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Release|Mixed Platforms.ActiveCfg = Release|Win32 64 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Release|Mixed Platforms.Build.0 = Release|Win32 65 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Release|Win32.ActiveCfg = Release|Win32 66 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Release|Win32.Build.0 = Release|Win32 67 | EndGlobalSection 68 | GlobalSection(SolutionProperties) = preSolution 69 | HideSolutionNode = FALSE 70 | EndGlobalSection 71 | EndGlobal 72 | -------------------------------------------------------------------------------- /proj.win32/Brave_cpp.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/proj.win32/Brave_cpp.v11.suo -------------------------------------------------------------------------------- /proj.win32/Brave_cpp.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A} 15 | test_win32 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | Unicode 22 | true 23 | v100 24 | v110 25 | v110_xp 26 | 27 | 28 | Application 29 | Unicode 30 | v100 31 | v110 32 | v110_xp 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | <_ProjectFileVersion>10.0.40219.1 50 | $(SolutionDir)$(Configuration).win32\ 51 | $(Configuration).win32\ 52 | true 53 | $(SolutionDir)$(Configuration).win32\ 54 | $(Configuration).win32\ 55 | false 56 | AllRules.ruleset 57 | 58 | 59 | AllRules.ruleset 60 | 61 | 62 | 63 | 64 | $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath) 65 | 66 | 67 | $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath) 68 | 69 | 70 | 71 | Disabled 72 | $(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;..\Classes;..;%(AdditionalIncludeDirectories) 73 | WIN32;_DEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 74 | false 75 | EnableFastChecks 76 | MultiThreadedDebugDLL 77 | 78 | 79 | Level3 80 | EditAndContinue 81 | 4267;4251;4244;%(DisableSpecificWarnings) 82 | true 83 | 84 | 85 | %(AdditionalDependencies) 86 | $(OutDir)$(ProjectName).exe 87 | $(OutDir);%(AdditionalLibraryDirectories) 88 | true 89 | Windows 90 | MachineX86 91 | 92 | 93 | 94 | 95 | 96 | 97 | if not exist "$(OutDir)" mkdir "$(OutDir)" 98 | xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" 99 | 100 | 101 | 102 | 103 | MaxSpeed 104 | true 105 | $(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;..\Classes;..;%(AdditionalIncludeDirectories) 106 | WIN32;NDEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 107 | MultiThreadedDLL 108 | true 109 | 110 | 111 | Level3 112 | ProgramDatabase 113 | 4267;4251;4244;%(DisableSpecificWarnings) 114 | true 115 | 116 | 117 | libcurl_imp.lib;websockets.lib;%(AdditionalDependencies) 118 | $(OutDir)$(ProjectName).exe 119 | $(OutDir);%(AdditionalLibraryDirectories) 120 | true 121 | Windows 122 | true 123 | true 124 | MachineX86 125 | 126 | 127 | 128 | 129 | 130 | 131 | if not exist "$(OutDir)" mkdir "$(OutDir)" 132 | xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | {98a51ba8-fc3a-415b-ac8f-8c7bd464e93e} 166 | false 167 | 168 | 169 | {f8edd7fa-9a51-4e80-baeb-860825d2eac6} 170 | 171 | 172 | {207bc7a9-ccf1-4f2f-a04d-45f72242ae25} 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /proj.win32/Brave_cpp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {84a8ebd7-7cf0-47f6-b75e-d441df67da40} 6 | 7 | 8 | {bb6c862e-70e9-49d9-81b7-3829a6f50471} 9 | 10 | 11 | {715254bc-d70b-4ec5-bf29-467dd3ace079} 12 | 13 | 14 | 15 | 16 | win32 17 | 18 | 19 | Classes 20 | 21 | 22 | Classes 23 | 24 | 25 | Classes 26 | 27 | 28 | Classes 29 | 30 | 31 | Classes 32 | 33 | 34 | Classes 35 | 36 | 37 | Classes 38 | 39 | 40 | Classes 41 | 42 | 43 | Classes 44 | 45 | 46 | Classes 47 | 48 | 49 | Classes 50 | 51 | 52 | 53 | 54 | win32 55 | 56 | 57 | Classes 58 | 59 | 60 | Classes 61 | 62 | 63 | Classes 64 | 65 | 66 | Classes 67 | 68 | 69 | Classes 70 | 71 | 72 | Classes 73 | 74 | 75 | Classes 76 | 77 | 78 | Classes 79 | 80 | 81 | Classes 82 | 83 | 84 | Classes 85 | 86 | 87 | Classes 88 | 89 | 90 | 91 | 92 | resource 93 | 94 | 95 | -------------------------------------------------------------------------------- /proj.win32/Brave_cpp.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(ProjectDir)..\Resources 5 | WindowsLocalDebugger 6 | 7 | 8 | $(ProjectDir)..\Resources 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /proj.win32/build-cfg.json: -------------------------------------------------------------------------------- 1 | { 2 | "copy_resources": [ 3 | { 4 | "from": "../Resources", 5 | "to": "" 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /proj.win32/game.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (U.S.) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | #ifdef _WIN32 21 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 22 | #pragma code_page(1252) 23 | #endif //_WIN32 24 | 25 | #ifdef APSTUDIO_INVOKED 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | // TEXTINCLUDE 29 | // 30 | 31 | 1 TEXTINCLUDE 32 | BEGIN 33 | "resource.h\0" 34 | END 35 | 36 | #endif // APSTUDIO_INVOKED 37 | 38 | ///////////////////////////////////////////////////////////////////////////// 39 | // 40 | // Icon 41 | // 42 | 43 | // Icon with lowest ID value placed first to ensure application icon 44 | // remains consistent on all systems. 45 | GLFW_ICON ICON "res\\game.ico" 46 | 47 | ///////////////////////////////////////////////////////////////////////////// 48 | // 49 | // Version 50 | // 51 | 52 | VS_VERSION_INFO VERSIONINFO 53 | FILEVERSION 1,0,0,1 54 | PRODUCTVERSION 1,0,0,1 55 | FILEFLAGSMASK 0x3fL 56 | #ifdef _DEBUG 57 | FILEFLAGS 0x1L 58 | #else 59 | FILEFLAGS 0x0L 60 | #endif 61 | FILEOS 0x4L 62 | FILETYPE 0x2L 63 | FILESUBTYPE 0x0L 64 | BEGIN 65 | BLOCK "StringFileInfo" 66 | BEGIN 67 | BLOCK "040904B0" 68 | BEGIN 69 | VALUE "CompanyName", "\0" 70 | VALUE "FileDescription", "game Module\0" 71 | VALUE "FileVersion", "1, 0, 0, 1\0" 72 | VALUE "InternalName", "game\0" 73 | VALUE "LegalCopyright", "Copyright \0" 74 | VALUE "OriginalFilename", "game.exe\0" 75 | VALUE "ProductName", "game Module\0" 76 | VALUE "ProductVersion", "1, 0, 0, 1\0" 77 | END 78 | END 79 | BLOCK "VarFileInfo" 80 | BEGIN 81 | VALUE "Translation", 0x0409, 0x04B0 82 | END 83 | END 84 | 85 | ///////////////////////////////////////////////////////////////////////////// 86 | #endif // !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 87 | -------------------------------------------------------------------------------- /proj.win32/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "AppDelegate.h" 3 | #include "cocos2d.h" 4 | 5 | USING_NS_CC; 6 | 7 | int APIENTRY _tWinMain(HINSTANCE hInstance, 8 | HINSTANCE hPrevInstance, 9 | LPTSTR lpCmdLine, 10 | int nCmdShow) 11 | { 12 | UNREFERENCED_PARAMETER(hPrevInstance); 13 | UNREFERENCED_PARAMETER(lpCmdLine); 14 | 15 | // create the application instance 16 | AppDelegate app; 17 | return Application::getInstance()->run(); 18 | } 19 | -------------------------------------------------------------------------------- /proj.win32/main.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIN_H__ 2 | #define __MAIN_H__ 3 | 4 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 5 | 6 | // Windows Header Files: 7 | #include 8 | #include 9 | 10 | // C RunTime Header Files 11 | #include "CCStdC.h" 12 | 13 | #endif // __MAIN_H__ 14 | -------------------------------------------------------------------------------- /proj.win32/res/game.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/douxt/Brave_cpp/f2bc630ec8c273874379716392ce8363b2d968d8/proj.win32/res/game.ico -------------------------------------------------------------------------------- /proj.win32/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by game.RC 4 | // 5 | 6 | #define IDS_PROJNAME 100 7 | #define IDR_TESTJS 100 8 | 9 | #define ID_FILE_NEW_WINDOW 32771 10 | 11 | // Next default values for new objects 12 | // 13 | #ifdef APSTUDIO_INVOKED 14 | #ifndef APSTUDIO_READONLY_SYMBOLS 15 | #define _APS_NEXT_RESOURCE_VALUE 201 16 | #define _APS_NEXT_CONTROL_VALUE 1000 17 | #define _APS_NEXT_SYMED_VALUE 101 18 | #define _APS_NEXT_COMMAND_VALUE 32775 19 | #endif 20 | #endif 21 | --------------------------------------------------------------------------------