Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
slackmoehrle committed Jul 21, 2014
1 parent 37516b4 commit f78be94
Show file tree
Hide file tree
Showing 141 changed files with 6,237 additions and 10 deletions.
Binary file added .DS_Store
Binary file not shown.
44 changes: 34 additions & 10 deletions 2.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ Select the `MainScene.h` and paste in the following code:
#ifndef __MAINSCENE_H__
#define __MAINSCENE_H__

#include "cocos2d.h"

#include <iostream>

class MainScene : public cocos2d::Scene
#include "cocos2d.h"

class MainScene
{
public:
MainScene();
~MainScene();

static cocos2d::Scene* createScene();

virtual cocos2d::Scene* getScene() { return scene; };

private:

cocos2d::Scene* scene;
cocos2d::LayerColor* layer;
};

#endif // __MAINSCENE_H__
Expand All @@ -74,16 +77,29 @@ Select the `MainScene.cpp` and paste in the following code:

#include "MainScene.h"

MainScene::MainScene() {}
MainScene::MainScene()
{
// get the display size of the device we are using
cocos2d::Size visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
cocos2d::Vec2 origin = cocos2d::Director::getInstance()->getVisibleOrigin();

// scene
scene = cocos2d::Scene::create();
scene->setContentSize(visibleSize);

// layer
layer = cocos2d::LayerColor::create(cocos2d::Color4B(120, 50, 50, 120), visibleSize.width, visibleSize.height);

// finally add the built up Layer to the Scene.
scene->addChild(layer, 0);
}

MainScene::~MainScene() {}

cocos2d::Scene* MainScene::createScene()
{
cocos2d::Scene* scene = cocos2d::Scene::create();


return scene;
MainScene m;
return m.getScene();
}
```
And finally, in `AppDelegate.cpp`, replace:
Expand All @@ -98,7 +114,15 @@ cocos2d::Scene* scene = MainScene::createScene();

That's it! But the Scene is empty. Lets add some content.

## Adding Content to the Scene
## Adding Content to the SceneLets start to make a simple game!

First, download <> and toss the contents in the `Resources` directory for your project. Add them to your IDE.

Second, past in the following code:

```cpp

```
## Using Actions to Animate Scenes

## Transitioning Between Scenes
Expand Down
Binary file added 2_resources/enemy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2_resources/enemy_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ProgrammerGuideGame/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions ProgrammerGuideGame/.cocos-project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"project_type": "cpp"
}
150 changes: 150 additions & 0 deletions ProgrammerGuideGame/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
cmake_minimum_required(VERSION 2.6)

set(APP_NAME MyGame)
project (${APP_NAME})

include(cocos2d/build/BuildHelpers.CMakeLists.txt)

option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
option(USE_BOX2D "Use box2d for physics library" OFF)
option(DEBUG_MODE "Debug or release?" ON)

if(DEBUG_MODE)
set(CMAKE_BUILD_TYPE DEBUG)
else(DEBUG_MODE)
set(CMAKE_BUILD_TYPE RELEASE)
endif(DEBUG_MODE)

set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

if(USE_CHIPMUNK)
message("Using chipmunk ...")
add_definitions(-DLINUX -DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
elseif(USE_BOX2D)
message("Using box2d ...")
add_definitions(-DLINUX -DCC_ENABLE_BOX2D_INTEGRATION=1)
else(USE_CHIPMUNK)
message(FATAL_ERROR "Must choose a physics library.")
endif(USE_CHIPMUNK)

# architecture
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set(ARCH_DIR "64-bit")
else()
set(ARCH_DIR "32-bit")
endif()


set(GAME_SRC
proj.linux/main.cpp
Classes/AppDelegate.cpp
Classes/HelloWorldScene.cpp
)

set(COCOS2D_ROOT ${CMAKE_SOURCE_DIR}/cocos2d)

include_directories(
/usr/local/include/GLFW
${COCOS2D_ROOT}
${COCOS2D_ROOT}/cocos
${COCOS2D_ROOT}/cocos/audio/include
${COCOS2D_ROOT}/cocos/platform
${COCOS2D_ROOT}/cocos/platform/desktop
${COCOS2D_ROOT}/cocos/platform/linux
${COCOS2D_ROOT}/cocos/editor-support
${COCOS2D_ROOT}/extensions
${COCOS2D_ROOT}/external
${COCOS2D_ROOT}/external/edtaa3func
${COCOS2D_ROOT}/external/jpeg/include/linux
${COCOS2D_ROOT}/external/tiff/include/linux
${COCOS2D_ROOT}/external/webp/include/linux
${COCOS2D_ROOT}/external/tinyxml2
${COCOS2D_ROOT}/external/unzip
${COCOS2D_ROOT}/external/chipmunk/include/chipmunk
${COCOS2D_ROOT}/external/freetype2/include/linux
${COCOS2D_ROOT}/external/websockets/include/linux
${COCOS2D_ROOT}/external/spidermonkey/include/linux
${COCOS2D_ROOT}/external/linux-specific/fmod/include/${ARCH_DIR}
${COCOS2D_ROOT}/external/xxhash
)

link_directories(
/usr/local/lib
${COCOS2D_ROOT}/external/jpeg/prebuilt/linux/${ARCH_DIR}
${COCOS2D_ROOT}/external/tiff/prebuilt/linux/${ARCH_DIR}
${COCOS2D_ROOT}/external/webp/prebuilt/linux/${ARCH_DIR}
${COCOS2D_ROOT}/external/freetype2/prebuilt/linux/${ARCH_DIR}
${COCOS2D_ROOT}/external/websockets/prebuilt/linux/${ARCH_DIR}
${COCOS2D_ROOT}/external/spidermonkey/prebuilt/linux/${ARCH_DIR}
${COCOS2D_ROOT}/external/linux-specific/fmod/prebuilt/${ARCH_DIR}
)

# chipmunk library
add_subdirectory(${COCOS2D_ROOT}/external/chipmunk/src)

# box2d library
add_subdirectory(${COCOS2D_ROOT}/external/Box2D)

# unzip library
add_subdirectory(${COCOS2D_ROOT}/external/unzip)

# tinyxml2 library
add_subdirectory(${COCOS2D_ROOT}/external/tinyxml2)

# audio
add_subdirectory(${COCOS2D_ROOT}/cocos/audio)

# xxhash library
add_subdirectory(${COCOS2D_ROOT}/external/xxhash)

# cocos2d
add_subdirectory(${COCOS2D_ROOT}/cocos)

# extensions
add_subdirectory(${COCOS2D_ROOT}/extensions)

## Editor Support

# spine
add_subdirectory(${COCOS2D_ROOT}/cocos/editor-support/spine)

# cocosbuilder
add_subdirectory(${COCOS2D_ROOT}/cocos/editor-support/cocosbuilder)

# cocostudio
add_subdirectory(${COCOS2D_ROOT}/cocos/editor-support/cocostudio)

# add the executable
add_executable(${APP_NAME}
${GAME_SRC}
)

if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set(FMOD_LIB "fmodex64")
else()
set(FMOD_LIB "fmodex")
endif()

target_link_libraries(${APP_NAME}
spine
cocostudio
cocosbuilder
extensions
audio
cocos2d
)

set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin")

set_target_properties(${APP_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")

pre_build(${APP_NAME}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources
)

Binary file added ProgrammerGuideGame/Classes/.DS_Store
Binary file not shown.
54 changes: 54 additions & 0 deletions ProgrammerGuideGame/Classes/AppDelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "AppDelegate.h"

#include "GameObject.h"
#include "MainScene.h"

USING_NS_CC;

AppDelegate::AppDelegate() {}

AppDelegate::~AppDelegate() {}

bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
director->setOpenGLView(glview);
}

// turn on display FPS
director->setDisplayStats(true);

// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);

// load spritesheets for enemy animations
_spritecache = cocos2d::SpriteFrameCache::getInstance();
_spritecache->addSpriteFramesWithFile("enemy.plist");

// create a scene. it's an autorelease object
_gameObject = GameObject::createGame();

// run
director->runWithScene(_gameObject->Instance()->getMainSceneObject()->getScene());

return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
Director::getInstance()->stopAnimation();

// if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
Director::getInstance()->startAnimation();

// if you use SimpleAudioEngine, it must resume here
// SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}
45 changes: 45 additions & 0 deletions ProgrammerGuideGame/Classes/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_

#include "cocos2d.h"

class GameObject;

/**
@brief The cocos2d Application.
The reason for implement as private inheritance is to hide some interface call by Director.
*/
class AppDelegate : private cocos2d::Application
{
public:
AppDelegate();
virtual ~AppDelegate();

GameObject *_gameObject;

/**
@brief Implement Director and Scene init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching();

/**
@brief The function be called when the application enter background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground();

/**
@brief The function be called when the application enter foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground();

private:
cocos2d::SpriteFrameCache* _spritecache;
};

#endif // _APP_DELEGATE_H_

Loading

0 comments on commit f78be94

Please sign in to comment.