diff --git a/cocos2d-win32.vc2008.sln b/cocos2d-win32.vc2008.sln
index a21437128a..b0a8df1fed 100644
--- a/cocos2d-win32.vc2008.sln
+++ b/cocos2d-win32.vc2008.sln
@@ -53,6 +53,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestLua", "samples\TestLua\
{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MoonWarriors", "samples\MoonWarriors\proj.win32\MoonWarriors.vcproj", "{A0EA54FA-6F12-45EC-AD5C-D139AA3CD528}"
+ ProjectSection(ProjectDependencies) = postProject
+ {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
+ {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
+ EndProjectSection
+EndProject
Global
GlobalSection(DPCodeReviewSolutionGUID) = preSolution
DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}
@@ -106,6 +112,10 @@ Global
{B53D3C68-96DA-4806-BB26-94888B52191A}.Debug|Win32.Build.0 = Debug|Win32
{B53D3C68-96DA-4806-BB26-94888B52191A}.Release|Win32.ActiveCfg = Release|Win32
{B53D3C68-96DA-4806-BB26-94888B52191A}.Release|Win32.Build.0 = Release|Win32
+ {A0EA54FA-6F12-45EC-AD5C-D139AA3CD528}.Debug|Win32.ActiveCfg = Debug|Win32
+ {A0EA54FA-6F12-45EC-AD5C-D139AA3CD528}.Debug|Win32.Build.0 = Debug|Win32
+ {A0EA54FA-6F12-45EC-AD5C-D139AA3CD528}.Release|Win32.ActiveCfg = Release|Win32
+ {A0EA54FA-6F12-45EC-AD5C-D139AA3CD528}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/cocos2d-win32.vc2010.sln b/cocos2d-win32.vc2010.sln
index ddc9efe7a0..bebbee39ce 100644
--- a/cocos2d-win32.vc2010.sln
+++ b/cocos2d-win32.vc2010.sln
@@ -35,6 +35,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestLua", "samples\TestLua\
{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MoonWarriors", "samples\MoonWarriors\proj.win32\MoonWarriors.vcxproj", "{1DB7C0FC-46FF-4A1B-82E0-C6244EEEC4C2}"
+EndProject
Global
GlobalSection(DPCodeReviewSolutionGUID) = preSolution
DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}
@@ -88,6 +90,10 @@ Global
{4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Debug|Win32.Build.0 = Debug|Win32
{4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Release|Win32.ActiveCfg = Release|Win32
{4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Release|Win32.Build.0 = Release|Win32
+ {1DB7C0FC-46FF-4A1B-82E0-C6244EEEC4C2}.Debug|Win32.ActiveCfg = Debug|Win32
+ {1DB7C0FC-46FF-4A1B-82E0-C6244EEEC4C2}.Debug|Win32.Build.0 = Debug|Win32
+ {1DB7C0FC-46FF-4A1B-82E0-C6244EEEC4C2}.Release|Win32.ActiveCfg = Release|Win32
+ {1DB7C0FC-46FF-4A1B-82E0-C6244EEEC4C2}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/cocos2dx/include/cocos2d.h b/cocos2dx/include/cocos2d.h
index 52bd76ad88..fea7298579 100755
--- a/cocos2dx/include/cocos2d.h
+++ b/cocos2dx/include/cocos2d.h
@@ -233,7 +233,7 @@ THE SOFTWARE.
NS_CC_BEGIN
-const char* cocos2dVersion();
+CC_DLL const char* cocos2dVersion();
NS_CC_END
diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp
index bed3dae646..68e63e45f9 100644
--- a/cocos2dx/misc_nodes/CCRenderTexture.cpp
+++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp
@@ -49,6 +49,7 @@ CCRenderTexture::CCRenderTexture()
, m_uDepthRenderBufffer(0)
, m_nOldFBO(0)
, m_pTexture(0)
+, m_pTextureCopy(0)
, m_pUITextureImage(NULL)
, m_ePixelFormat(kCCTexture2DPixelFormat_RGBA8888)
{
@@ -62,6 +63,8 @@ CCRenderTexture::CCRenderTexture()
CCRenderTexture::~CCRenderTexture()
{
+ CC_SAFE_RELEASE(m_pTextureCopy);
+
glDeleteFramebuffers(1, &m_uFBO);
if (m_uDepthRenderBufffer)
{
@@ -168,6 +171,7 @@ bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelForma
CCAssert(m_ePixelFormat != kCCTexture2DPixelFormat_A8, "only RGB and RGBA formats are valid for a render texture");
bool bRet = false;
+ void *data = NULL;
do
{
w *= (int)CC_CONTENT_SCALE_FACTOR();
@@ -179,30 +183,47 @@ bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelForma
unsigned int powW = 0;
unsigned int powH = 0;
- if( CCConfiguration::sharedConfiguration()->supportsNPOT() ) {
+ if (CCConfiguration::sharedConfiguration()->supportsNPOT())
+ {
powW = w;
powH = h;
- } else {
+ }
+ else
+ {
powW = ccNextPOT(w);
powH = ccNextPOT(h);
}
- void *data = malloc((int)(powW * powH * 4));
+ data = malloc((int)(powW * powH * 4));
CC_BREAK_IF(! data);
memset(data, 0, (int)(powW * powH * 4));
m_ePixelFormat = eFormat;
m_pTexture = new CCTexture2D();
- if (m_pTexture) {
- m_pTexture->initWithData(data, (CCTexture2DPixelFormat)m_ePixelFormat, powW, powH, CCSizeMake((float)w, (float)h));
- free( data );
- } else {
- free( data ); // ScopeGuard (a simulated Finally clause) would be more elegant.
- break;
+ if (m_pTexture)
+ {
+ m_pTexture->initWithData(data, (CCTexture2DPixelFormat)m_ePixelFormat, powW, powH, CCSizeMake((float)w, (float)h));
+ }
+ else
+ {
+ break;
}
GLint oldRBO;
glGetIntegerv(GL_RENDERBUFFER_BINDING, &oldRBO);
+
+ if (CCConfiguration::sharedConfiguration()->checkForGLExtension("GL_QCOM"))
+ {
+ m_pTextureCopy = new CCTexture2D();
+ if (m_pTextureCopy)
+ {
+ m_pTextureCopy->initWithData(data, (CCTexture2DPixelFormat)m_ePixelFormat, powW, powH, CCSizeMake((float)w, (float)h));
+ }
+ else
+ {
+ break;
+ }
+ }
// generate FBO
glGenFramebuffers(1, &m_uFBO);
@@ -221,10 +242,11 @@ bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelForma
// if depth format is the one with stencil part, bind same render buffer as stencil attachment
if (uDepthStencilFormat == CC_GL_DEPTH24_STENCIL8)
+ {
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_uDepthRenderBufffer);
+ }
}
-
// check if it worked (probably worth doing :) )
CCAssert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, "Could not attach texture to framebuffer");
@@ -243,8 +265,10 @@ bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelForma
glBindFramebuffer(GL_FRAMEBUFFER, m_nOldFBO);
bRet = true;
} while (0);
- return bRet;
+ CC_SAFE_FREE(data);
+
+ return bRet;
}
void CCRenderTexture::begin()
@@ -271,6 +295,17 @@ void CCRenderTexture::begin()
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_nOldFBO);
glBindFramebuffer(GL_FRAMEBUFFER, m_uFBO);
+
+ /* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of CCRenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
+ */
+ if (CCConfiguration::sharedConfiguration()->checkForGLExtension("GL_QCOM"))
+ {
+ // -- bind a temporary texture so we can clear the render buffer without losing our texture
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTextureCopy->getName(), 0);
+ CHECK_GL_ERROR_DEBUG();
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0);
+ }
}
void CCRenderTexture::beginWithClear(float r, float g, float b, float a)
@@ -444,7 +479,6 @@ CCImage* CCRenderTexture::newCCImage()
{
CC_BREAK_IF(! (pBuffer = new GLubyte[nSavedBufferWidth * nSavedBufferHeight * 4]));
-
if(! (pTempData = new GLubyte[nSavedBufferWidth * nSavedBufferHeight * 4]))
{
delete[] pBuffer;
@@ -462,8 +496,8 @@ CCImage* CCRenderTexture::newCCImage()
for (int i = 0; i < nSavedBufferHeight; ++i)
{
memcpy(&pBuffer[i * nSavedBufferWidth * 4],
- &pTempData[(nSavedBufferHeight - i - 1) * nSavedBufferWidth * 4],
- nSavedBufferWidth * 4);
+ &pTempData[(nSavedBufferHeight - i - 1) * nSavedBufferWidth * 4],
+ nSavedBufferWidth * 4);
}
pImage->initWithImageData(pBuffer, nSavedBufferWidth * nSavedBufferHeight * 4, CCImage::kFmtRawData, nSavedBufferWidth, nSavedBufferHeight, 8);
diff --git a/cocos2dx/misc_nodes/CCRenderTexture.h b/cocos2dx/misc_nodes/CCRenderTexture.h
index 22d9ae8c0b..32bc44cf4d 100644
--- a/cocos2dx/misc_nodes/CCRenderTexture.h
+++ b/cocos2dx/misc_nodes/CCRenderTexture.h
@@ -147,6 +147,7 @@ protected:
GLuint m_uDepthRenderBufffer;
GLint m_nOldFBO;
CCTexture2D* m_pTexture;
+ CCTexture2D* m_pTextureCopy; // a copy of m_pTexture
CCImage* m_pUITextureImage;
GLenum m_ePixelFormat;
};
diff --git a/samples/MoonWarriors/Classes/AppDelegate.cpp b/samples/MoonWarriors/Classes/AppDelegate.cpp
new file mode 100644
index 0000000000..f4947cf2e5
--- /dev/null
+++ b/samples/MoonWarriors/Classes/AppDelegate.cpp
@@ -0,0 +1,82 @@
+#include "AppDelegate.h"
+
+#include "cocos2d.h"
+#include "SimpleAudioEngine.h"
+#include "ScriptingCore.h"
+#include "generated/cocos2dx.hpp"
+#include "cocos2d_specifics.hpp"
+
+USING_NS_CC;
+using namespace CocosDenshion;
+
+AppDelegate::AppDelegate()
+{
+}
+
+AppDelegate::~AppDelegate()
+{
+ CCScriptEngineManager::sharedManager()->purgeSharedManager();
+}
+
+bool AppDelegate::applicationDidFinishLaunching()
+{
+ // initialize director
+ CCDirector *pDirector = CCDirector::sharedDirector();
+ pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
+ CCEGLView::sharedOpenGLView()->setDesignResolutionSize(320, 480, kResolutionShowAll);
+ // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
+ // pDirector->enableRetinaDisplay(true);
+
+ // turn on display FPS
+ pDirector->setDisplayStats(true);
+
+ // set FPS. the default value is 1.0/60 if you don't call this
+ pDirector->setAnimationInterval(1.0 / 60);
+
+ ScriptingCore* sc = ScriptingCore::getInstance();
+ sc->addRegisterCallback(register_all_cocos2dx);
+ sc->addRegisterCallback(register_cocos2dx_js_extensions);
+
+ sc->start();
+
+ CCScriptEngineProtocol *pEngine = ScriptingCore::getInstance();
+ CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
+ ScriptingCore::getInstance()->runScript("js/MoonWarriors-native.js");
+ return true;
+}
+
+void handle_signal(int signal) {
+ static int internal_state = 0;
+ ScriptingCore* sc = ScriptingCore::getInstance();
+ // should start everything back
+ CCDirector* director = CCDirector::sharedDirector();
+ if (director->getRunningScene()) {
+ director->popToRootScene();
+ } else {
+ CCPoolManager::sharedPoolManager()->finalize();
+ if (internal_state == 0) {
+ //sc->dumpRoot(NULL, 0, NULL);
+ sc->start();
+ internal_state = 1;
+ } else {
+ sc->runScript("hello.js");
+ internal_state = 0;
+ }
+ }
+}
+
+// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
+void AppDelegate::applicationDidEnterBackground()
+{
+ CCDirector::sharedDirector()->stopAnimation();
+ SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
+ SimpleAudioEngine::sharedEngine()->pauseAllEffects();
+}
+
+// this function will be called when the app is active again
+void AppDelegate::applicationWillEnterForeground()
+{
+ CCDirector::sharedDirector()->startAnimation();
+ SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
+ SimpleAudioEngine::sharedEngine()->resumeAllEffects();
+}
diff --git a/samples/MoonWarriors/Classes/AppDelegate.h b/samples/MoonWarriors/Classes/AppDelegate.h
new file mode 100644
index 0000000000..6bd9363493
--- /dev/null
+++ b/samples/MoonWarriors/Classes/AppDelegate.h
@@ -0,0 +1,45 @@
+//
+// GCTestAppDelegate.h
+// GCTest
+//
+// Created by Rohan Kuruvilla on 06/08/2012.
+// Copyright __MyCompanyName__ 2012. All rights reserved.
+//
+
+#ifndef _APP_DELEGATE_H_
+#define _APP_DELEGATE_H_
+
+#include "CCApplication.h"
+/**
+ @brief The cocos2d Application.
+
+ The reason for implement as private inheritance is to hide some interface call by CCDirector.
+ */
+class AppDelegate : private cocos2d::CCApplication
+{
+public:
+ AppDelegate();
+ virtual ~AppDelegate();
+
+ /**
+ @brief Implement CCDirector and CCScene 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();
+};
+
+#endif // _APP_DELEGATE_H_
+
diff --git a/samples/MoonWarriors/Resources/js/AboutLayer.js b/samples/MoonWarriors/Resources/js/AboutLayer.js
new file mode 100644
index 0000000000..4d188d335a
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/AboutLayer.js
@@ -0,0 +1,47 @@
+var AboutLayer = cc.Layer.extend({
+ ctor:function () {
+ cc.associateWithNative( this, cc.Layer );
+ },
+ init:function () {
+ var bRet = false;
+ if (this._super()) {
+ var sp = cc.Sprite.create(s_loading);
+ sp.setAnchorPoint(cc.p(0,0));
+ this.addChild(sp, 0, 1);
+
+ var cacheImage = cc.TextureCache.getInstance().addImage(s_menuTitle);
+ var title = cc.Sprite.createWithTexture(cacheImage, cc.rect(0, 36, 100, 34));
+ title.setPosition(cc.p(winSize.width / 2, winSize.height - 60));
+ this.addChild(title);
+
+ // There is a bug in LabelTTF native. Apparently it fails with some unicode chars.
+// var about = cc.LabelTTF.create(" This showcase utilizes many features from Cocos2d-html5 engine, including: Parallax background, tilemap, actions, ease, frame animation, schedule, Labels, keyboard Dispatcher, Scene Transition. \n Art and audio is copyrighted by Enigmata Genus Revenge, you may not use any copyrigted material without permission. This showcase is licensed under GPL. \n \n Programmer: \n Shengxiang Chen (陈升想) \n Dingping Lv (吕定平) \n Effects animation: Hao Wu(吴昊)\n Quality Assurance: Sean Lin(林顺)", "Arial", 14, cc.size(winSize.width * 0.85, 100), cc.TEXT_ALIGNMENT_LEFT );
+ var about = cc.LabelTTF.create(" This showcase utilizes many features from Cocos2d-html5 engine, including: Parallax background, tilemap, actions, ease, frame animation, schedule, Labels, keyboard Dispatcher, Scene Transition. \n Art and audio is copyrighted by Enigmata Genus Revenge, you may not use any copyrigted material without permission. This showcase is licensed under GPL. \n\nProgrammer: \n Shengxiang Chen\n Dingping Lv \n Effects animation: Hao Wu\n Quality Assurance: Sean Lin", "Arial", 14, cc.size(winSize.width * 0.85, 320), cc.TEXT_ALIGNMENT_LEFT );
+ about.setPosition(cc.p(winSize.width / 2, winSize.height/2 -20) );
+ about.setAnchorPoint( cc.p(0.5, 0.5));
+ this.addChild(about);
+
+ var label = cc.LabelTTF.create("Go back", "Arial", 14);
+ var back = cc.MenuItemLabel.create(label, this, this.backCallback);
+ var menu = cc.Menu.create(back);
+ menu.setPosition(cc.p(winSize.width / 2, 40));
+ this.addChild(menu);
+ bRet = true;
+ }
+
+ return bRet;
+ },
+ backCallback:function (pSender) {
+ var scene = cc.Scene.create();
+ scene.addChild(SysMenu.create());
+ cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene));
+ }
+});
+
+AboutLayer.create = function () {
+ var sg = new AboutLayer();
+ if (sg && sg.init()) {
+ return sg;
+ }
+ return null;
+};
diff --git a/samples/MoonWarriors/Resources/js/Bullet.js b/samples/MoonWarriors/Resources/js/Bullet.js
new file mode 100644
index 0000000000..d22c3b015a
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/Bullet.js
@@ -0,0 +1,62 @@
+//bullet
+var Bullet = cc.Sprite.extend({
+ active:true,
+ xVelocity:0,
+ yVelocity:200,
+ power:1,
+ HP:1,
+ moveType:null,
+ zOrder:3000,
+ attackMode:MW.ENEMY_MOVE_TYPE.NORMAL,
+ parentType:MW.BULLET_TYPE.PLAYER,
+ ctor:function (bulletSpeed, weaponType, attackMode) {
+ // needed for JS-Bindings compatibility
+ cc.associateWithNative( this, cc.Sprite );
+
+ this.yVelocity = -bulletSpeed;
+ this.attackMode = attackMode;
+ cc.SpriteFrameCache.getInstance().addSpriteFrames(s_bullet_plist);
+ this.initWithSpriteFrameName(weaponType);
+ this.setBlendFunc(gl.SRC_ALPHA, gl.ONE);
+ /*var tmpAction;
+ switch (this.attackMode) {
+ case MW.ENEMY_MOVE_TYPE.NORMAL:
+ tmpAction = cc.MoveBy.create(2, cc.p(this.getPosition().x, 400));
+ break;
+ case MW.ENEMY_ATTACK_MODE.TSUIHIKIDAN:
+ tmpAction = cc.MoveTo.create(2, GameLayer.create()._ship.getPosition());
+ break;
+ }
+ this.runAction(tmpAction);*/
+ },
+ update:function (dt) {
+ var p = this.getPosition();
+ p.x -= this.xVelocity * dt;
+ p.y -= this.yVelocity * dt;
+ this.setPosition( p );
+ if (this.HP <= 0) {
+ this.active = false;
+ }
+ },
+ destroy:function () {
+ var explode = cc.Sprite.create(s_hit);
+ explode.setBlendFunc(gl.SRC_ALPHA, gl.ONE);
+ explode.setPosition(this.getPosition());
+ explode.setRotation(Math.random()*360);
+ explode.setScale(0.75);
+ this.getParent().addChild(explode,9999);
+ cc.ArrayRemoveObject(MW.CONTAINER.ENEMY_BULLETS,this);
+ cc.ArrayRemoveObject(MW.CONTAINER.PLAYER_BULLETS,this);
+ this.removeFromParentAndCleanup(true);
+ var removeExplode = cc.CallFunc.create(explode,explode.removeFromParentAndCleanup);
+ explode.runAction(cc.ScaleBy.create(0.3, 2,2));
+ explode.runAction(cc.Sequence.create(cc.FadeOut.create(0.3), removeExplode));
+ },
+ hurt:function () {
+ this.HP--;
+ },
+ collideRect:function(){
+ var p = this.getPosition();
+ return cc.rect(p.x - 3, p.y - 3, 6, 6);
+ }
+});
diff --git a/samples/MoonWarriors/Resources/js/Effect.js b/samples/MoonWarriors/Resources/js/Effect.js
new file mode 100644
index 0000000000..faaa03c491
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/Effect.js
@@ -0,0 +1,78 @@
+var flareEffect = function (parent, target, callback) {
+ var flare = cc.Sprite.create(s_flare);
+ flare.setBlendFunc(gl.SRC_ALPHA, gl.ONE);
+ parent.addChild(flare, 10);
+ flare.setOpacity(0);
+ flare.setPosition(cc.p(-30, 297));
+ flare.setRotation(-120);
+ flare.setScale(0.2);
+
+ var opacityAnim = cc.FadeTo.create(0.5, 255);
+ var opacDim = cc.FadeTo.create(1, 0);
+ var biggeAnim = cc.ScaleBy.create(0.7, 1.2, 1.2);
+ var biggerEase = cc.EaseSineOut.create(biggeAnim);
+ var moveAnim = cc.MoveBy.create(0.5, cc.p(328, 0));
+ var easeMove = cc.EaseSineOut.create(moveAnim);
+ var rotateAnim = cc.RotateBy.create(2.5, 90);
+ var rotateEase = cc.EaseExponentialOut.create(rotateAnim);
+ var bigger = cc.ScaleTo.create(0.5, 1);
+
+ var onComplete = cc.CallFunc.create(target, callback);
+ var killflare = cc.CallFunc.create(flare, function () {
+ this.getParent().removeChild(this,true);
+ });
+ flare.runAction(cc.Sequence.create(opacityAnim, biggerEase, opacDim, killflare, onComplete));
+ flare.runAction(easeMove);
+ flare.runAction(rotateEase);
+ flare.runAction(bigger);
+};
+
+var removeFromParent = function( sprite )
+{
+ sprite.removeFromParentAndCleanup( true );
+};
+
+var spark = function (ccpoint, parent, scale, duration) {
+ scale = scale || 0.3;
+ duration = duration || 0.5;
+
+ var one = cc.Sprite.create(s_explode1);
+ var two = cc.Sprite.create(s_explode2);
+ var three = cc.Sprite.create(s_explode3);
+
+ one.setBlendFunc(gl.SRC_ALPHA, gl.ONE);
+ two.setBlendFunc(gl.SRC_ALPHA, gl.ONE);
+ three.setBlendFunc(gl.SRC_ALPHA, gl.ONE);
+
+ one.setPosition(ccpoint);
+ two.setPosition(ccpoint);
+ three.setPosition(ccpoint);
+
+ //parent.addChild(one);
+ parent.addChild(two);
+ parent.addChild(three);
+ one.setScale(scale);
+ two.setScale(scale);
+ three.setScale(scale);
+
+ three.setRotation(Math.random() * 360);
+
+ var left = cc.RotateBy.create(duration, -45);
+ var right = cc.RotateBy.create(duration, 45);
+ var scaleBy = cc.ScaleBy.create(duration, 3, 3);
+ var fadeOut = cc.FadeOut.create(duration);
+ var remove = cc.CallFunc.create(this, removeFromParent );
+ var seq = cc.Sequence.create( fadeOut, remove );
+
+ one.runAction(left);
+ two.runAction(right);
+
+ one.runAction(scaleBy);
+ two.runAction(scaleBy.copy());
+ three.runAction(scaleBy.copy());
+
+ one.runAction(seq);
+ two.runAction(seq.copy() );
+ three.runAction(seq.copy());
+};
+
diff --git a/samples/MoonWarriors/Resources/js/Enemy.js b/samples/MoonWarriors/Resources/js/Enemy.js
new file mode 100644
index 0000000000..e266118547
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/Enemy.js
@@ -0,0 +1,75 @@
+var Enemy = cc.Sprite.extend({
+ eID:0,
+ active:true,
+ speed:200,
+ bulletSpeed:-200,
+ HP:15,
+ bulletPowerValue:1,
+ moveType:null,
+ scoreValue:200,
+ zOrder:1000,
+ delayTime:1 + 1.2 * Math.random(),
+ attackMode:MW.ENEMY_MOVE_TYPE.NORMAL,
+ _hurtColorLife:0,
+ ctor:function (arg) {
+ // needed for JS-Bindings compatibility
+ cc.associateWithNative( this, cc.Sprite );
+
+ this.HP = arg.HP;
+ this.moveType = arg.moveType;
+ this.scoreValue = arg.scoreValue;
+ this.attackMode = arg.attackMode;
+
+ this.initWithSpriteFrameName(arg.textureName);
+ this.schedule(this.shoot, this.delayTime);
+ },
+ _timeTick:0,
+ update:function (dt) {
+ if (this.HP <= 0) {
+ this.active = false;
+ }
+ this._timeTick += dt;
+ if (this._timeTick > 0.1) {
+ this._timeTick = 0;
+ if (this._hurtColorLife > 0) {
+ this._hurtColorLife--;
+ }
+ if (this._hurtColorLife == 1) {
+ this.setColor( cc.WHITE );
+ }
+ }
+ },
+ destroy:function () {
+ MW.SCORE += this.scoreValue;
+ var a = new Explosion();
+ a.setPosition(this.getPosition());
+ this.getParent().addChild(a);
+ spark(this.getPosition(),this.getParent(), 1.2, 0.7);
+ cc.ArrayRemoveObject(MW.CONTAINER.ENEMIES,this);
+ this.removeFromParentAndCleanup(true);
+ if(MW.SOUND){
+ cc.AudioEngine.getInstance().playEffect(s_explodeEffect);
+ }
+ },
+ shoot:function () {
+ var p = this.getPosition();
+ var b = new Bullet(this.bulletSpeed, "W2.png", this.attackMode);
+ MW.CONTAINER.ENEMY_BULLETS.push(b);
+ this.getParent().addChild(b, b.zOrder, MW.UNIT_TAG.ENMEY_BULLET);
+ b.setPosition(cc.p(p.x, p.y - this.getContentSize().height * 0.2));
+ },
+ hurt:function () {
+ this._hurtColorLife = 2;
+ this.HP--;
+ this.setColor( cc.RED );
+ },
+ collideRect:function(){
+ var a = this.getContentSize();
+ var p = this.getPosition();
+ return cc.rect(p.x - a.width/2, p.y - a.height/4,a.width,a.height/2);
+ }
+});
+
+Enemy.sharedEnemy = function(){
+ cc.SpriteFrameCache.getInstance().addSpriteFrames(s_Enemy_plist, s_Enemy);
+};
diff --git a/samples/MoonWarriors/Resources/js/Explosion.js b/samples/MoonWarriors/Resources/js/Explosion.js
new file mode 100644
index 0000000000..8ccd225c5d
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/Explosion.js
@@ -0,0 +1,38 @@
+var Explosion = cc.Sprite.extend({
+ tmpWidth:0,
+ tmpHeight:0,
+ ctor:function () {
+ // needed for JS-Bindings compatibility
+ cc.associateWithNative( this, cc.Sprite );
+
+ var pFrame = cc.SpriteFrameCache.getInstance().getSpriteFrame("explosion_01.png");
+ this.initWithSpriteFrame(pFrame);
+
+ var cs = this.getContentSize();
+ this.tmpWidth = cs.width;
+ this.tmpHeight = cs.height;
+
+ var animation = cc.AnimationCache.getInstance().getAnimation("Explosion");
+ this.runAction(cc.Sequence.create(
+ cc.Animate.create(animation),
+ cc.CallFunc.create(this, this.destroy)
+ ));
+ this.setBlendFunc(gl.SRC_ALPHA, gl.ONE);
+ },
+ destroy:function () {
+ this.getParent().removeChild(this,true);
+ }
+});
+
+Explosion.sharedExplosion = function () {
+ cc.SpriteFrameCache.getInstance().addSpriteFrames(s_explosion_plist);
+ var animFrames = [];
+ var str = "";
+ for (var i = 1; i < 35; i++) {
+ str = "explosion_" + (i < 10 ? ("0" + i) : i) + ".png";
+ var frame = cc.SpriteFrameCache.getInstance().getSpriteFrame(str);
+ animFrames.push(frame);
+ }
+ var animation = cc.Animation.create(animFrames, 0.04);
+ cc.AnimationCache.getInstance().addAnimation(animation, "Explosion");
+};
diff --git a/samples/MoonWarriors/Resources/js/GameControlMenu.js b/samples/MoonWarriors/Resources/js/GameControlMenu.js
new file mode 100644
index 0000000000..3fcdac736e
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/GameControlMenu.js
@@ -0,0 +1,35 @@
+var GameControlMenu = cc.Layer.extend({
+ ctor:function() {
+ // needed for JS-Bindings compatibility
+ cc.associateWithNative( this, cc.Layer);
+ },
+ init:function () {
+ var bRet = false;
+ if (this._super()) {
+ cc.MenuItemFont.setFontSize(18);
+ cc.MenuItemFont.setFontName("Arial");
+ var systemMenu = cc.MenuItemFont.create("Main Menu", this, this.sysMenu);
+ var menu = cc.Menu.create(systemMenu);
+ menu.setPosition(cc.p(0, 0));
+ systemMenu.setAnchorPoint(cc.p(0, 0));
+ systemMenu.setPosition(cc.p(winSize.width-95, 5));
+ this.addChild(menu, 1, 2);
+ bRet = true;
+ }
+
+ return bRet;
+ },
+ sysMenu:function (pSender) {
+ var scene = cc.Scene.create();
+ scene.addChild(SysMenu.create());
+ cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2,scene));
+ }
+});
+
+GameControlMenu.create = function () {
+ var sg = new GameControlMenu();
+ if (sg && sg.init()) {
+ return sg;
+ }
+ return null;
+};
diff --git a/samples/MoonWarriors/Resources/js/GameController.js b/samples/MoonWarriors/Resources/js/GameController.js
new file mode 100644
index 0000000000..d5aed4be94
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/GameController.js
@@ -0,0 +1,70 @@
+/**
+ * Cocos2d-html5 show case : Moon Warriors
+ *
+ * @Licensed:
+ * This showcase is licensed under GPL.
+ *
+ * @Authors:
+ * Programmer: Shengxiang Chen (陈升想), Dingping Lv (吕定平), Ricardo Quesada
+ * Effects animation: Hao Wu (吴昊)
+ * Quality Assurance: Sean Lin (林顺)
+ *
+ * @Links:
+ * http://www.cocos2d-x.org
+ * http://bbs.html5china.com
+ *
+ */
+
+
+MW.GameController = cc.Class.extend({
+ _curScene:null,
+ _gameState:MW.GAME_STATE.HOME,
+ _isNewGame:true,
+ _curLevel:MW.LEVEL.STAGE1,
+ _selectLevel:MW.LEVEL.STAGE1,
+ init:function () {
+ return true;
+ },
+ setCurScene:function (s) {
+ if (this._curScene != s) {
+ if (this._curScene !== null) {
+ this._curScene.onExit();
+ }
+ this._curScene = s;
+ if (this._curScene) {
+ this._curScene.onEnter();
+ cc.Director.getInstance().replaceScene(s);
+ }
+ }
+ },
+ getCurScene:function () {
+ return this._curScene;
+ },
+ runGame:function () {
+
+ },
+ newGame:function () {
+
+ },
+ option:function () {
+
+ },
+ about:function () {
+
+ }
+});
+
+MW.GameController.getInstance = function () {
+ cc.Assert(this._sharedGame, "Havn't call setSharedGame");
+ if (!this._sharedGame) {
+ this._sharedGame = new MW.GameController();
+ if (this._sharedGame.init()) {
+ return this._sharedGame;
+ }
+ } else {
+ return this._sharedGame;
+ }
+ return null;
+};
+
+MW.GameController._sharedGame = null;
\ No newline at end of file
diff --git a/samples/MoonWarriors/Resources/js/GameLayer.js b/samples/MoonWarriors/Resources/js/GameLayer.js
new file mode 100644
index 0000000000..60ee0ba738
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/GameLayer.js
@@ -0,0 +1,315 @@
+//
+// MoonWarriors
+//
+// Handles the Game Logic
+//
+
+STATE_PLAYING = 0;
+STATE_GAMEOVER = 1;
+
+var GameLayer = cc.Layer.extend({
+ _time:null,
+ _ship:null,
+ _backSky:null,
+ _backSkyHeight:0,
+ _backSkyRe:null,
+ _backTileMap:null,
+ _backTileMapHeight:0,
+ _backTileMapRe:null,
+ _levelManager:null,
+ _tmpScore:0,
+ _isBackSkyReload:false,
+ _isBackTileReload:false,
+ lbScore:null,
+ screenRect:null,
+ explosionAnimation:[],
+ _beginPos:cc.p(0, 0),
+ _state:STATE_PLAYING,
+ ctor:function () {
+ cc.associateWithNative( this, cc.Layer );
+ },
+ init:function () {
+ var bRet = false;
+ if (this._super()) {
+
+ // reset global values
+ MW.CONTAINER.ENEMIES = [];
+ MW.CONTAINER.ENEMY_BULLETS = [];
+ MW.CONTAINER.PLAYER_BULLETS = [];
+ MW.SCORE = 0;
+ MW.LIFE = 4;
+ this._state = STATE_PLAYING;
+
+ Explosion.sharedExplosion();
+ Enemy.sharedEnemy();
+ winSize = cc.Director.getInstance().getWinSize();
+ this._levelManager = new LevelManager(this);
+ this.initBackground();
+ this.screenRect = cc.rect(0, 0, winSize.width, winSize.height + 10);
+
+ // score
+ this.lbScore = cc.LabelBMFont.create("Score: 0", s_arial14_fnt);
+ this.lbScore.setAnchorPoint( cc.p(1,0) );
+ this.lbScore.setAlignment( cc.TEXT_ALIGNMENT_RIGHT );
+ this.addChild(this.lbScore, 1000);
+ this.lbScore.setPosition(cc.p(winSize.width - 5 , winSize.height - 30));
+
+ // ship life
+ var shipTexture = cc.TextureCache.getInstance().addImage(s_ship01);
+ var life = cc.Sprite.createWithTexture(shipTexture, cc.rect(0, 0, 60, 38));
+ life.setScale(0.6);
+ life.setPosition(cc.p(30, 460));
+ this.addChild(life, 1, 5);
+
+ // ship Life count
+ this._lbLife = cc.LabelTTF.create("0", "Arial", 20);
+ this._lbLife.setPosition(cc.p(60, 463));
+ this._lbLife.setColor(cc.RED);
+ this.addChild(this._lbLife, 1000);
+
+ // ship
+ this._ship = new Ship();
+ this.addChild(this._ship, this._ship.zOrder, MW.UNIT_TAG.PLAYER);
+
+ // accept touch now!
+
+ var t = cc.config.deviceType;
+ if( t == 'browser' ) {
+ this.setTouchEnabled(true);
+ this.setKeyboardEnabled(true);
+ } else if( t == 'desktop' ) {
+ this.setMouseEnabled(true);
+ } else if( t == 'mobile' ) {
+ this.setTouchEnabled(true);
+ }
+
+ // schedule
+ this.scheduleUpdate();
+ this.schedule(this.scoreCounter, 1);
+
+ if (MW.SOUND) {
+ cc.AudioEngine.getInstance().playBackgroundMusic(s_bgMusic, true);
+ }
+
+ bRet = true;
+ }
+ return bRet;
+ },
+ scoreCounter:function () {
+ if( this._state == STATE_PLAYING ) {
+ this._time++;
+
+ var minute = 0 | (this._time / 60);
+ var second = this._time % 60;
+ minute = minute > 9 ? minute : "0" + minute;
+ second = second > 9 ? second : "0" + second;
+ var curTime = minute + ":" + second;
+ this._levelManager.loadLevelResource(this._time);
+ }
+ },
+
+ onTouchesMoved:function (touches, event) {
+ this.processEvent( touches[0] );
+ },
+
+ onMouseDragged:function( event ) {
+ this.processEvent( event );
+ },
+
+ processEvent:function( event ) {
+ if( this._state == STATE_PLAYING ) {
+ var delta = event.getDelta();
+ var curPos = this._ship.getPosition();
+ curPos= cc.pAdd( curPos, delta );
+ curPos = cc.pClamp(curPos, cc.POINT_ZERO, cc.p(winSize.width, winSize.height) );
+ this._ship.setPosition( curPos );
+ }
+ },
+
+ onKeyDown:function (e) {
+ MW.KEYS[e] = true;
+ },
+
+ onKeyUp:function (e) {
+ MW.KEYS[e] = false;
+ },
+
+ update:function (dt) {
+ if( this._state == STATE_PLAYING ) {
+ this.checkIsCollide();
+ this.removeInactiveUnit(dt);
+ this.checkIsReborn();
+ this.updateUI();
+ }
+
+ if( cc.config.deviceType == 'browser' )
+ cc.$("#cou").innerHTML = "Ship:" + 1 + ", Enemy: " + MW.CONTAINER.ENEMIES.length + ", Bullet:" + MW.CONTAINER.ENEMY_BULLETS.length + "," + MW.CONTAINER.PLAYER_BULLETS.length + " all:" + this.getChildren().length;
+ },
+ checkIsCollide:function () {
+ var selChild, bulletChild;
+ //check collide
+ var i =0;
+ for (i = 0; i < MW.CONTAINER.ENEMIES.length; i++) {
+ selChild = MW.CONTAINER.ENEMIES[i];
+ for (var j = 0; j < MW.CONTAINER.PLAYER_BULLETS.length; j++) {
+ bulletChild = MW.CONTAINER.PLAYER_BULLETS[j];
+ if (this.collide(selChild, bulletChild)) {
+ bulletChild.hurt();
+ selChild.hurt();
+ }
+ if (!cc.rectIntersectsRect(this.screenRect, bulletChild.getBoundingBox() )) {
+ bulletChild.destroy();
+ }
+ }
+ if (this.collide(selChild, this._ship)) {
+ if (this._ship.active) {
+ selChild.hurt();
+ this._ship.hurt();
+ }
+ }
+ if (!cc.rectIntersectsRect(this.screenRect, selChild.getBoundingBox() )) {
+ selChild.destroy();
+ }
+ }
+
+ for (i = 0; i < MW.CONTAINER.ENEMY_BULLETS.length; i++) {
+ selChild = MW.CONTAINER.ENEMY_BULLETS[i];
+ if (this.collide(selChild, this._ship)) {
+ if (this._ship.active) {
+ selChild.hurt();
+ this._ship.hurt();
+ }
+ }
+ if (!cc.rectIntersectsRect(this.screenRect, selChild.getBoundingBox() )) {
+ selChild.destroy();
+ }
+ }
+ },
+ removeInactiveUnit:function (dt) {
+ var selChild, layerChildren = this.getChildren();
+ for (var i in layerChildren) {
+ selChild = layerChildren[i];
+ if (selChild) {
+ if( typeof selChild.update == 'function' ) {
+ selChild.update(dt);
+ var tag = selChild.getTag();
+ if ((tag == MW.UNIT_TAG.PLAYER) || (tag == MW.UNIT_TAG.PLAYER_BULLET) ||
+ (tag == MW.UNIT_TAG.ENEMY) || (tag == MW.UNIT_TAG.ENMEY_BULLET)) {
+ if (selChild && !selChild.active) {
+ selChild.destroy();
+ }
+ }
+ }
+ }
+ }
+ },
+ checkIsReborn:function () {
+ if (MW.LIFE > 0 && !this._ship.active) {
+ // ship
+ this._ship = new Ship();
+ this.addChild(this._ship, this._ship.zOrder, MW.UNIT_TAG.PLAYER);
+ }
+ else if (MW.LIFE <= 0 && !this._ship.active) {
+ this._state = STATE_GAMEOVER;
+ // XXX: needed for JS bindings.
+ this._ship = null;
+ this.runAction(cc.Sequence.create(
+ cc.DelayTime.create(0.2),
+ cc.CallFunc.create(this, this.onGameOver)));
+ }
+ },
+ updateUI:function () {
+ if (this._tmpScore < MW.SCORE) {
+ this._tmpScore += 5;
+ }
+ this._lbLife.setString(MW.LIFE);
+ this.lbScore.setString("Score: " + this._tmpScore);
+ },
+ collide:function (a, b) {
+ var aRect = a.collideRect();
+ var bRect = b.collideRect();
+ if (cc.rectIntersectsRect(aRect, bRect)) {
+ return true;
+ }
+ },
+ initBackground:function () {
+ // bg
+ this._backSky = cc.Sprite.create(s_bg01);
+ this._backSky.setAnchorPoint(cc.p(0, 0));
+ this._backSkyHeight = this._backSky.getContentSize().height;
+ this.addChild(this._backSky, -10);
+
+ //tilemap
+ this._backTileMap = cc.TMXTiledMap.create(s_level01);
+ this.addChild(this._backTileMap, -9);
+ this._backTileMapHeight = this._backTileMap.getMapSize().height * this._backTileMap.getTileSize().height;
+
+ this._backSkyHeight -= 48;
+ this._backTileMapHeight -= 200;
+ this._backSky.runAction(cc.MoveBy.create(3, cc.p(0, -48)));
+ this._backTileMap.runAction(cc.MoveBy.create(3, cc.p(0, -200)));
+
+ this.schedule(this.movingBackground, 3);
+ },
+ movingBackground:function () {
+ this._backSky.runAction(cc.MoveBy.create(3, cc.p(0, -48)));
+ this._backTileMap.runAction(cc.MoveBy.create(3, cc.p(0, -200)));
+ this._backSkyHeight -= 48;
+ this._backTileMapHeight -= 200;
+
+ if (this._backSkyHeight <= winSize.height) {
+ if (!this._isBackSkyReload) {
+ this._backSkyRe = cc.Sprite.create(s_bg01);
+ this._backSkyRe.setAnchorPoint(cc.p(0, 0));
+ this.addChild(this._backSkyRe, -10);
+ this._backSkyRe.setPosition(cc.p(0, winSize.height));
+ this._isBackSkyReload = true;
+ }
+ this._backSkyRe.runAction(cc.MoveBy.create(3, cc.p(0, -48)));
+ }
+ if (this._backSkyHeight <= 0) {
+ this._backSkyHeight = this._backSky.getContentSize().height;
+ this.removeChild(this._backSky, true);
+ this._backSky = this._backSkyRe;
+ this._backSkyRe = null;
+ this._isBackSkyReload = false;
+ }
+
+ if (this._backTileMapHeight <= winSize.height) {
+ if (!this._isBackTileReload) {
+ this._backTileMapRe = cc.TMXTiledMap.create(s_level01);
+ this.addChild(this._backTileMapRe, -9);
+ this._backTileMapRe.setPosition(cc.p(0, winSize.height));
+ this._isBackTileReload = true;
+ }
+ this._backTileMapRe.runAction(cc.MoveBy.create(3, cc.p(0, -200)));
+ }
+ if (this._backTileMapHeight <= 0) {
+ this._backTileMapHeight = this._backTileMapRe.getMapSize().height * this._backTileMapRe.getTileSize().height;
+ this.removeChild(this._backTileMap, true);
+ this._backTileMap = this._backTileMapRe;
+ this._backTileMapRe = null;
+ this._isBackTileReload = false;
+ }
+ },
+ onGameOver:function () {
+ var scene = cc.Scene.create();
+ scene.addChild(GameOver.create());
+ cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene));
+ }
+});
+
+GameLayer.create = function () {
+ var sg = new GameLayer();
+ if (sg && sg.init()) {
+ return sg;
+ }
+ return null;
+};
+
+GameLayer.scene = function () {
+ var scene = cc.Scene.create();
+ var layer = GameLayer.create();
+ scene.addChild(layer, 1);
+ return scene;
+};
diff --git a/samples/MoonWarriors/Resources/js/GameOver.js b/samples/MoonWarriors/Resources/js/GameOver.js
new file mode 100644
index 0000000000..7fcf87c645
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/GameOver.js
@@ -0,0 +1,83 @@
+var GameOver = cc.Layer.extend({
+ _ship:null,
+ _lbScore:0,
+ ctor:function() {
+ // needed for JS-Bindings compatibility
+ cc.associateWithNative( this, cc.Layer);
+ },
+ init:function () {
+ var bRet = false;
+ if (this._super()) {
+ var sp = cc.Sprite.create(s_loading);
+ sp.setAnchorPoint( cc.p(0,0) );
+ this.addChild(sp, 0, 1);
+
+ var logo = cc.Sprite.create(s_gameOver);
+ logo.setAnchorPoint(cc.p(0,0));
+ logo.setPosition(cc.p(0,300));
+ this.addChild(logo,10,1);
+
+ var playAgainNormal = cc.Sprite.create(s_menu, cc.rect(378, 0, 126, 33));
+ var playAgainSelected = cc.Sprite.create(s_menu, cc.rect(378, 33, 126, 33));
+ var playAgainDisabled = cc.Sprite.create(s_menu, cc.rect(378, 33 * 2, 126, 33));
+
+ var cocos2dhtml5 = cc.Sprite.create(s_cocos2dhtml5);
+ cocos2dhtml5.setPosition(cc.p(160,150));
+ this.addChild(cocos2dhtml5,10);
+ var playAgain = cc.MenuItemSprite.create(playAgainNormal, playAgainSelected, playAgainDisabled, this, function(){
+ flareEffect(this,this,this.onPlayAgain);
+ });
+
+ var menu = cc.Menu.create(playAgain);
+ this.addChild(menu, 1, 2);
+ menu.setPosition(cc.p(winSize.width / 2, 220));
+
+ var lbScore = cc.LabelTTF.create("Your Score:"+MW.SCORE,"Arial Bold",16);
+ lbScore.setPosition(cc.p(160,280));
+ lbScore.setColor(cc.c3b(250,179,0));
+ this.addChild(lbScore,10);
+
+ var b1 = cc.LabelTTF.create("Download Cocos2d-html5","Arial",14);
+ var b2 = cc.LabelTTF.create("Download This Sample","Arial",14);
+ var menu1 = cc.MenuItemLabel.create(b1,this,function(){
+ window.location.href = "http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Cocos2d-html5";
+ });
+ var menu2 = cc.MenuItemLabel.create(b2,this,function(){
+ window.location.href = "https://github.com/ShengxiangChen/MoonWarriors";
+ });
+ var cocos2dMenu = cc.Menu.create(menu1,menu2);
+ cocos2dMenu.alignItemsVerticallyWithPadding(10);
+ cocos2dMenu.setPosition(cc.p(160,80));
+ this.addChild(cocos2dMenu);
+
+
+ if(MW.SOUND){
+ cc.AudioEngine.getInstance().playBackgroundMusic(s_mainMainMusic);
+ }
+
+ bRet = true;
+ }
+ return bRet;
+ },
+ onPlayAgain:function (pSender) {
+ var scene = cc.Scene.create();
+ scene.addChild(GameLayer.create());
+ scene.addChild(GameControlMenu.create());
+ cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2,scene));
+ }
+});
+
+GameOver.create = function () {
+ var sg = new GameOver();
+ if (sg && sg.init()) {
+ return sg;
+ }
+ return null;
+};
+
+GameOver.scene = function () {
+ var scene = cc.Scene.create();
+ var layer = GameOver.create();
+ scene.addChild(layer);
+ return scene;
+};
diff --git a/samples/MoonWarriors/Resources/js/LevelManager.js b/samples/MoonWarriors/Resources/js/LevelManager.js
new file mode 100644
index 0000000000..6866d7412f
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/LevelManager.js
@@ -0,0 +1,99 @@
+var LevelManager = cc.Class.extend({
+ _currentLevel:null,
+ _gameLayer:null,
+ ctor:function(gameLayer){
+ if(!gameLayer){
+ throw "gameLayer must be non-nil";
+ }
+ this._currentLevel = Level1;
+ this._gameLayer = gameLayer;
+ this.setLevel(this._currentLevel);
+ },
+
+ setLevel:function(level){
+ for(var i = 0; i< level.enemies.length; i++){
+ this._currentLevel.enemies[i].ShowTime = this._minuteToSecond(this._currentLevel.enemies[i].ShowTime);
+ }
+ },
+ _minuteToSecond:function(minuteStr){
+ if(!minuteStr)
+ return 0;
+ if(typeof(minuteStr) != "number"){
+ var mins = minuteStr.split(':');
+ if(mins.length == 1){
+ return parseInt(mins[0],10);
+ }else {
+ return parseInt(mins[0],10 )* 60 + parseInt(mins[1],10);
+ }
+ }
+ return minuteStr;
+ },
+
+ loadLevelResource:function(deltaTime){
+ //load enemy
+ for(var i = 0; i< this._currentLevel.enemies.length; i++){
+ var selEnemy = this._currentLevel.enemies[i];
+ if(selEnemy){
+ if(selEnemy.ShowType == "Once"){
+ if(selEnemy.ShowTime == deltaTime){
+ for(var tIndex = 0; tIndex < selEnemy.Types.length;tIndex++ ){
+ this.addEnemyToGameLayer(selEnemy.Types[tIndex]);
+ }
+ }
+ }else if(selEnemy.ShowType == "Repeate"){
+ if(deltaTime % selEnemy.ShowTime === 0){
+ for(var rIndex = 0; rIndex < selEnemy.Types.length;rIndex++ ){
+ this.addEnemyToGameLayer(selEnemy.Types[rIndex]);
+ }
+ }
+ }
+ }
+ }
+ },
+
+ addEnemyToGameLayer:function(enemyType){
+ var addEnemy = new Enemy(EnemyType[enemyType]);
+
+ var enemypos = cc.p( 80 + (winSize.width - 160) * Math.random(), winSize.height);
+ var enemycs = addEnemy.getContentSize();
+ addEnemy.setPosition( enemypos );
+
+
+ var offset, tmpAction;
+ var a0=0;
+ var a1=0;
+ switch (addEnemy.moveType) {
+ case MW.ENEMY_MOVE_TYPE.ATTACK:
+ offset = this._gameLayer._ship.getPosition();
+ tmpAction = cc.MoveTo.create(1, offset);
+ break;
+ case MW.ENEMY_MOVE_TYPE.VERTICAL:
+ offset = cc.p(0, -winSize.height - enemycs.height);
+ tmpAction = cc.MoveBy.create(4, offset);
+ break;
+ case MW.ENEMY_MOVE_TYPE.HORIZONTAL:
+ offset = cc.p(0, -100 - 200 * Math.random());
+ a0 = cc.MoveBy.create(0.5, offset);
+ a1 = cc.MoveBy.create(1, cc.p(-50 - 100 * Math.random(), 0));
+ var onComplete = cc.CallFunc.create(addEnemy, function (pSender) {
+ var a2 = cc.DelayTime.create(1);
+ var a3 = cc.MoveBy.create(1, cc.p(100 + 100 * Math.random(), 0));
+ pSender.runAction(cc.RepeatForever.create(
+ cc.Sequence.create(a2, a3, a2.copy(), a3.reverse())
+ ));
+ });
+ tmpAction = cc.Sequence.create(a0, a1, onComplete);
+ break;
+ case MW.ENEMY_MOVE_TYPE.OVERLAP:
+ var newX = (enemypos.x <= winSize.width / 2) ? 320 : -320;
+ a0 = cc.MoveBy.create(4, cc.p(newX, -240));
+ a1 = cc.MoveBy.create(4,cc.p(-newX,-320));
+ tmpAction = cc.Sequence.create(a0,a1);
+ break;
+ }
+
+ this._gameLayer.addChild(addEnemy, addEnemy.zOrder, MW.UNIT_TAG.ENEMY);
+ MW.CONTAINER.ENEMIES.push(addEnemy);
+ addEnemy.runAction(tmpAction);
+ }
+});
diff --git a/samples/MoonWarriors/Resources/js/MoonWarriors-html5.js b/samples/MoonWarriors/Resources/js/MoonWarriors-html5.js
new file mode 100644
index 0000000000..1aee15ae78
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/MoonWarriors-html5.js
@@ -0,0 +1,69 @@
+/****************************************************************************
+ Copyright (c) 2010-2012 cocos2d-x.org
+
+ http://www.cocos2d-x.org
+
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ ****************************************************************************/
+
+// boot code needed for cocos2d-html5
+// Not needed by cocos2d + JS bindings
+
+var MW = MW || {};
+
+(function () {
+ var d = document;
+ var c = {
+ menuType:'canvas', //whether to use canvas mode menu or dom menu
+ COCOS2D_DEBUG:2, //0 to turn debug off, 1 for basic debug, and 2 for full debug
+ showFPS:true,
+ frameRate:60,
+ tag:'gameCanvas', //the dom element to run cocos2d on
+ engineDir:'libs/cocos2d/',
+ appFiles:[
+ 'MoonWarriors/src/Resource.js',
+ 'MoonWarriors/src/config/GameConfig.js',
+ 'MoonWarriors/src/config/EnemyType.js',
+ 'MoonWarriors/src/config/Level.js',
+ 'MoonWarriors/src/Effect.js',
+ 'MoonWarriors/src/Bullet.js',
+ 'MoonWarriors/src/Enemy.js',
+ 'MoonWarriors/src/Explosion.js',
+ 'MoonWarriors/src/Ship.js',
+ 'MoonWarriors/src/LevelManager.js',
+ 'MoonWarriors/src/GameController.js',
+ 'MoonWarriors/src/GameControlMenu.js',
+ 'MoonWarriors/src/GameLayer.js',
+ 'MoonWarriors/src/GameOver.js',
+ 'MoonWarriors/src/AboutLayer.js',
+ 'MoonWarriors/src/SettingsLayer.js',
+ 'MoonWarriors/src/SysMenu.js'
+ ]
+ };
+ window.addEventListener('DOMContentLoaded', function () {
+ //first load engine file if specified
+ var s = d.createElement('script');
+ s.src = c.engineDir + 'platform/jsloader.js';
+ d.body.appendChild(s);
+ s.c = c;
+ s.id = 'cocos2d-html5';
+ //else if single file specified, load singlefile
+ });
+})();
diff --git a/samples/MoonWarriors/Resources/js/MoonWarriors-native.js b/samples/MoonWarriors/Resources/js/MoonWarriors-native.js
new file mode 100644
index 0000000000..d6cce44e24
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/MoonWarriors-native.js
@@ -0,0 +1,69 @@
+/****************************************************************************
+ Copyright (c) 2010-2012 cocos2d-x.org
+
+ http://www.cocos2d-x.org
+
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ ****************************************************************************/
+
+// boot code needed for cocos2d + JS bindings.
+// Not needed by cocos2d-html5
+
+require("js/helper/jsb_constants.js");
+
+var MW = MW || {};
+
+var appFiles = [
+ 'js/Resource.js',
+ 'js/config/GameConfig.js',
+ 'js/config/EnemyType.js',
+ 'js/config/Level.js',
+ 'js/Effect.js',
+ 'js/Bullet.js',
+ 'js/Enemy.js',
+ 'js/Explosion.js',
+ 'js/Ship.js',
+ 'js/LevelManager.js',
+ 'js/GameControlMenu.js',
+ 'js/GameLayer.js',
+ 'js/GameOver.js',
+ 'js/AboutLayer.js',
+ 'js/SettingsLayer.js',
+ 'js/SysMenu.js'
+];
+
+cc.dumpConfig();
+
+for( var i=0; i < appFiles.length; i++) {
+ require( appFiles[i] );
+}
+
+var director = cc.Director.getInstance();
+director.setDisplayStats(true);
+
+// set FPS. the default value is 1.0/60 if you don't call this
+director.setAnimationInterval(1.0 / 60);
+
+// create a scene. it's an autorelease object
+var mainScene = SysMenu.scene();
+
+// run
+director.runWithScene(mainScene);
+
diff --git a/samples/MoonWarriors/Resources/js/Resource.js b/samples/MoonWarriors/Resources/js/Resource.js
new file mode 100644
index 0000000000..340dded6b2
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/Resource.js
@@ -0,0 +1,94 @@
+var dirImg = "";
+var dirMusic = "";
+var musicSuffix = ".mp3";
+if( cc.config.deviceType == 'browser') {
+ dirImg = "res/";
+ dirMusic = "res/Music/";
+ musicSuffix = "";
+}
+else if( cc.config.engine == 'cocos2d-x') {
+ dirImg = "res/";
+ dirMusic = "res/Music/";
+ musicSuffix = ".mp3";
+}
+
+//image
+var s_bg01 = dirImg + "bg01.jpg";
+var s_loading = dirImg + "loading.png";
+var s_ship01 = dirImg + "ship01.png";
+var s_menu = dirImg + "menu.png";
+var s_logo = dirImg + "logo.png";
+var s_cocos2dhtml5 = dirImg + "cocos2d-html5.png";
+var s_gameOver = dirImg + "gameOver.png";
+var s_menuTitle = dirImg + "menuTitle.png";
+var s_Enemy = dirImg + "Enemy.png";
+var s_flare = dirImg + "flare.jpg";
+var s_bullet = dirImg + "bullet.png";
+var s_explosion = dirImg + "explosion.png";
+var s_explode1 = dirImg + "explode1.jpg";
+var s_explode2= dirImg + "explode2.jpg";
+var s_explode3 = dirImg + "explode3.jpg";
+var s_hit = dirImg + "hit.jpg";
+var s_arial14 = dirImg + "arial-14.png";
+var s_arial14_fnt = dirImg + "arial-14.fnt";
+
+//music
+var s_bgMusic = dirMusic + "bgMusic" + musicSuffix;
+var s_mainMainMusic = dirMusic + "mainMainMusic" + musicSuffix;
+
+//effect
+var s_buttonEffect = dirMusic + "buttonEffet" + musicSuffix;
+var s_explodeEffect = dirMusic + "explodeEffect" + musicSuffix;
+var s_fireEffect = dirMusic + "fireEffect" + musicSuffix;
+var s_shipDestroyEffect = dirMusic + "shipDestroyEffect" + musicSuffix;
+
+//tmx
+var s_level01 = dirImg + "level01.tmx";
+
+//plist
+var s_Enemy_plist = dirImg + "Enemy.plist";
+var s_explosion_plist = dirImg + "explosion.plist";
+var s_bullet_plist = dirImg + "bullet.plist";
+
+var g_ressources = [
+ //image
+ {type:"image", src:s_bg01},
+ {type:"image", src:s_loading},
+ {type:"image", src:s_ship01},
+ {type:"image", src:s_menu},
+ {type:"image", src:s_logo},
+ {type:"image", src:s_cocos2dhtml5},
+ {type:"image", src:s_gameOver},
+ {type:"image", src:s_menuTitle},
+ {type:"image", src:s_Enemy},
+ {type:"image", src:s_flare},
+ {type:"image", src:s_bullet},
+ {type:"image", src:s_explosion},
+ {type:"image", src:s_explode1},
+ {type:"image", src:s_explode2},
+ {type:"image", src:s_explode3},
+ {type:"image", src:s_hit},
+ {type:"image", src:s_arial14},
+
+ //tmx
+ {type:"tmx", src:s_level01},
+
+ //plist
+ {type:"plist", src:s_Enemy_plist},
+ {type:"plist", src:s_explosion_plist},
+ {type:"plist", src:s_bullet_plist},
+
+ //music
+ {type:"bgm", src:s_bgMusic},
+ {type:"bgm", src:s_mainMainMusic},
+
+ //effect
+ {type:"effect", src:s_buttonEffect},
+ {type:"effect", src:s_explodeEffect},
+ {type:"effect", src:s_fireEffect},
+ {type:"effect", src:s_shipDestroyEffect},
+
+ // FNT
+ {type:"fnt", src:s_arial14_fnt}
+
+];
diff --git a/samples/MoonWarriors/Resources/js/SettingsLayer.js b/samples/MoonWarriors/Resources/js/SettingsLayer.js
new file mode 100644
index 0000000000..4f8b545311
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/SettingsLayer.js
@@ -0,0 +1,85 @@
+var SettingsLayer = cc.Layer.extend({
+ ctor:function () {
+ cc.associateWithNative( this, cc.Layer );
+ },
+ init:function () {
+ var bRet = false;
+ if (this._super()) {
+ var sp = cc.Sprite.create(s_loading);
+ sp.setAnchorPoint(cc.p(0,0));
+ this.addChild(sp, 0, 1);
+
+ var cacheImage = cc.TextureCache.getInstance().addImage(s_menuTitle);
+ var title = cc.Sprite.createWithTexture(cacheImage, cc.rect(0, 0, 134, 34));
+ title.setPosition(cc.p(winSize.width / 2, winSize.height - 120));
+ this.addChild(title);
+
+
+ cc.MenuItemFont.setFontName("Arial");
+ cc.MenuItemFont.setFontSize(18);
+ var title1 = cc.MenuItemFont.create("Sound");
+ title1.setEnabled(false);
+
+ cc.MenuItemFont.setFontName("Arial");
+ cc.MenuItemFont.setFontSize(26);
+ var item1 = cc.MenuItemToggle.create(
+ cc.MenuItemFont.create("On"),
+ cc.MenuItemFont.create("Off") );
+ item1.setCallback(this, this.soundControl );
+
+ cc.MenuItemFont.setFontName("Arial");
+ cc.MenuItemFont.setFontSize(18);
+ var title2 = cc.MenuItemFont.create("Mode");
+ title2.setEnabled(false);
+
+ cc.MenuItemFont.setFontName("Arial");
+ cc.MenuItemFont.setFontSize(26);
+ var item2 = cc.MenuItemToggle.create(
+ cc.MenuItemFont.create("Easy"),
+ cc.MenuItemFont.create("Normal"),
+ cc.MenuItemFont.create("Hard"));
+ item2.setCallback( this, this.modeControl );
+
+
+ cc.MenuItemFont.setFontName("Arial");
+ cc.MenuItemFont.setFontSize(26);
+ var label = cc.LabelTTF.create("Go back", "Arial", 20);
+ var back = cc.MenuItemLabel.create(label, this, this.backCallback);
+ back.setScale(0.8);
+
+ var menu = cc.Menu.create(title1, title2, item1, item2, back);
+ menu.alignItemsInColumns(2, 2, 1);
+ this.addChild(menu);
+
+ var cp_back = back.getPosition();
+ cp_back.y -= 50.0;
+ back.setPosition(cp_back);
+
+
+ bRet = true;
+ }
+
+ return bRet;
+ },
+ backCallback:function (pSender) {
+ var scene = cc.Scene.create();
+ scene.addChild(SysMenu.create());
+ cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene));
+ },
+ soundControl:function(){
+ MW.SOUND = MW.SOUND ? false : true;
+ if(!MW.SOUND){
+ cc.AudioEngine.getInstance().stopBackgroundMusic();
+ }
+ },
+ modeControl:function(){
+ }
+});
+
+SettingsLayer.create = function () {
+ var sg = new SettingsLayer();
+ if (sg && sg.init()) {
+ return sg;
+ }
+ return null;
+};
diff --git a/samples/MoonWarriors/Resources/js/Ship.js b/samples/MoonWarriors/Resources/js/Ship.js
new file mode 100644
index 0000000000..84aa6342db
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/Ship.js
@@ -0,0 +1,128 @@
+var Ship = cc.Sprite.extend({
+ speed:220,
+ bulletSpeed:900,
+ HP:5,
+ bulletTypeValue:1,
+ bulletPowerValue:1,
+ throwBombing:false,
+ canBeAttack:true,
+ isThrowingBomb:false,
+ zOrder:3000,
+ maxBulletPowerValue:4,
+ appearPosition:cc.p(160, 60),
+ _hurtColorLife:0,
+ active:true,
+ ctor:function () {
+
+ // needed for JS-Bindings compatibility
+ cc.associateWithNative( this, cc.Sprite );
+
+ //init life
+ var shipTexture = cc.TextureCache.getInstance().addImage(s_ship01);
+ this.initWithTexture(shipTexture, cc.rect(0, 0, 60, 38));
+ this.setTag(this.zOrder);
+ this.setPosition(this.appearPosition);
+
+ // set frame
+ var frame0 = cc.SpriteFrame.createWithTexture(shipTexture, cc.rect(0, 0, 60, 38));
+ var frame1 = cc.SpriteFrame.createWithTexture(shipTexture, cc.rect(60, 0, 60, 38));
+
+ var animFrames = [];
+ animFrames.push(frame0);
+ animFrames.push(frame1);
+
+ // ship animate
+ var animation = cc.Animation.create(animFrames, 0.1);
+ var animate = cc.Animate.create(animation);
+ this.runAction(cc.RepeatForever.create(animate));
+ this.schedule(this.shoot, 1 / 6);
+
+ //revive effect
+ this.canBeAttack = false;
+ var ghostSprite = cc.Sprite.createWithTexture(shipTexture, cc.rect(0, 45, 60, 38));
+ ghostSprite.setBlendFunc(gl.SRC_ALPHA, gl.ONE);
+ ghostSprite.setScale(8);
+ ghostSprite.setPosition(cc.p(this.getContentSize().width / 2, 12));
+ this.addChild(ghostSprite, 3000, 99999);
+ ghostSprite.runAction(cc.ScaleTo.create(0.5, 1, 1));
+ var blinks = cc.Blink.create(3, 9);
+ var makeBeAttack = cc.CallFunc.create(this, function (t) {
+ t.canBeAttack = true;
+ t.setVisible(true);
+ t.removeChild(ghostSprite,true);
+ });
+ this.runAction(cc.Sequence.create(cc.DelayTime.create(0.5), blinks, makeBeAttack));
+ },
+ update:function (dt) {
+
+ // Keys are only enabled on the browser
+ if( cc.config.deviceType == 'browser' ) {
+ var pos = this.getPosition();
+ if ((MW.KEYS[cc.KEY.w] || MW.KEYS[cc.KEY.up]) && pos.y <= winSize.height) {
+ pos.y += dt * this.speed;
+ }
+ if ((MW.KEYS[cc.KEY.s] || MW.KEYS[cc.KEY.down]) && pos.y >= 0) {
+ pos.y -= dt * this.speed;
+ }
+ if ((MW.KEYS[cc.KEY.a] || MW.KEYS[cc.KEY.left]) && pos.x >= 0) {
+ pos.x -= dt * this.speed;
+ }
+ if ((MW.KEYS[cc.KEY.d] || MW.KEYS[cc.KEY.right]) && pos.x <= winSize.width) {
+ pos.x += dt * this.speed;
+ }
+ this.setPosition( pos );
+ }
+
+ if (this.HP <= 0) {
+ this.active = false;
+ }
+ this._timeTick += dt;
+ if (this._timeTick > 0.1) {
+ this._timeTick = 0;
+ if (this._hurtColorLife > 0) {
+ this._hurtColorLife--;
+ }
+ if (this._hurtColorLife == 1) {
+ this.setColor(cc.WHITE);
+ }
+ }
+ },
+ shoot:function (dt) {
+ //this.shootEffect();
+ var offset = 13;
+ var p = this.getPosition();
+ var cs = this.getContentSize();
+ var a = new Bullet(this.bulletSpeed, "W1.png", MW.ENEMY_MOVE_TYPE.NORMAL);
+ MW.CONTAINER.PLAYER_BULLETS.push(a);
+ this.getParent().addChild(a, a.zOrder, MW.UNIT_TAG.PLAYER_BULLET);
+ a.setPosition(cc.p(p.x + offset, p.y + 3 + cs.height * 0.3));
+
+ var b = new Bullet(this.bulletSpeed, "W1.png", MW.ENEMY_MOVE_TYPE.NORMAL);
+ MW.CONTAINER.PLAYER_BULLETS.push(b);
+ this.getParent().addChild(b, b.zOrder, MW.UNIT_TAG.PLAYER_BULLET);
+ b.setPosition(cc.p(p.x - offset, p.y + 3 + cs.height * 0.3));
+ },
+ destroy:function () {
+ MW.LIFE--;
+ var p = this.getPosition();
+ var myParent = this.getParent();
+ myParent.addChild( new Explosion(p) );
+ myParent.removeChild(this,true);
+ if (MW.SOUND) {
+ cc.AudioEngine.getInstance().playEffect(s_shipDestroyEffect);
+ }
+ },
+ hurt:function () {
+ if (this.canBeAttack) {
+ this._hurtColorLife = 2;
+ this.HP--;
+ this.setColor(cc.RED);
+ }
+ },
+ collideRect:function(){
+ var p = this.getPosition();
+ var a = this.getContentSize();
+ var r = new cc.rect(p.x - a.width/2, p.y - a.height/2, a.width, a.height/2);
+ return r;
+ }
+});
diff --git a/samples/MoonWarriors/Resources/js/SysMenu.js b/samples/MoonWarriors/Resources/js/SysMenu.js
new file mode 100644
index 0000000000..a265636363
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/SysMenu.js
@@ -0,0 +1,110 @@
+cc.dumpConfig();
+
+var SysMenu = cc.Layer.extend({
+ _ship:null,
+
+ ctor:function () {
+ cc.associateWithNative( this, cc.Layer );
+ },
+ init:function () {
+ var bRet = false;
+ if (this._super()) {
+ winSize = cc.Director.getInstance().getWinSize();
+ var sp = cc.Sprite.create(s_loading);
+ sp.setAnchorPoint(cc.p(0,0));
+ this.addChild(sp, 0, 1);
+
+ var logo = cc.Sprite.create(s_logo);
+ logo.setAnchorPoint(cc.p(0, 0));
+ logo.setPosition(cc.p(0, 250));
+ this.addChild(logo, 10, 1);
+
+ var newGameNormal = cc.Sprite.create(s_menu, cc.rect(0, 0, 126, 33));
+ var newGameSelected = cc.Sprite.create(s_menu, cc.rect(0, 33, 126, 33));
+ var newGameDisabled = cc.Sprite.create(s_menu, cc.rect(0, 33 * 2, 126, 33));
+
+ var gameSettingsNormal = cc.Sprite.create(s_menu, cc.rect(126, 0, 126, 33));
+ var gameSettingsSelected = cc.Sprite.create(s_menu, cc.rect(126, 33, 126, 33));
+ var gameSettingsDisabled = cc.Sprite.create(s_menu, cc.rect(126, 33 * 2, 126, 33));
+
+ var aboutNormal = cc.Sprite.create(s_menu, cc.rect(252, 0, 126, 33));
+ var aboutSelected = cc.Sprite.create(s_menu, cc.rect(252, 33, 126, 33));
+ var aboutDisabled = cc.Sprite.create(s_menu, cc.rect(252, 33 * 2, 126, 33));
+
+ var newGame = cc.MenuItemSprite.create(newGameNormal, newGameSelected, newGameDisabled, this, function () {
+ this.onButtonEffect();
+ flareEffect(this, this, this.onNewGame);
+ });
+ var gameSettings = cc.MenuItemSprite.create(gameSettingsNormal, gameSettingsSelected, gameSettingsDisabled, this, this.onSettings);
+ var about = cc.MenuItemSprite.create(aboutNormal, aboutSelected, aboutDisabled, this, this.onAbout);
+
+ var menu = cc.Menu.create(newGame, gameSettings, about);
+ menu.alignItemsVerticallyWithPadding(10);
+ this.addChild(menu, 1, 2);
+ menu.setPosition(cc.p(winSize.width / 2, winSize.height / 2 - 80));
+ this.schedule(this.update, 0.1);
+
+ var tmp = cc.TextureCache.getInstance().addImage(s_ship01);
+ this._ship = cc.Sprite.createWithTexture(tmp,cc.rect(0, 45, 60, 38));
+ this.addChild(this._ship, 0, 4);
+ var pos = cc.p(Math.random() * winSize.width, 0);
+ this._ship.setPosition( pos );
+ this._ship.runAction(cc.MoveBy.create(2, cc.p(Math.random() * winSize.width, pos.y + winSize.height + 100)));
+
+ if (MW.SOUND) {
+ cc.AudioEngine.getInstance().setBackgroundMusicVolume(0.7);
+ cc.AudioEngine.getInstance().playBackgroundMusic(s_mainMainMusic, true);
+ }
+
+ bRet = true;
+ }
+ return bRet;
+ },
+ onNewGame:function (pSender) {
+ var scene = cc.Scene.create();
+ scene.addChild(GameLayer.create());
+ scene.addChild(GameControlMenu.create());
+ cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene));
+ },
+ onSettings:function (pSender) {
+ this.onButtonEffect();
+ var scene = cc.Scene.create();
+ scene.addChild(SettingsLayer.create());
+ cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene));
+ },
+ onAbout:function (pSender) {
+ this.onButtonEffect();
+ var scene = cc.Scene.create();
+ scene.addChild(AboutLayer.create());
+ cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene));
+ },
+ update:function () {
+ if (this._ship.getPosition().y > 480) {
+ var pos = cc.p(Math.random() * winSize.width, 10);
+ this._ship.setPosition( pos );
+ this._ship.runAction( cc.MoveBy.create(
+ parseInt(5 * Math.random(), 10),
+ cc.p(Math.random() * winSize.width, pos.y + 480)));
+ }
+ },
+ onButtonEffect:function(){
+ if (MW.SOUND) {
+ var s = cc.AudioEngine.getInstance().playEffect(s_buttonEffect);
+ }
+ }
+});
+
+SysMenu.create = function () {
+ var sg = new SysMenu();
+ if (sg && sg.init()) {
+ return sg;
+ }
+ return null;
+};
+
+SysMenu.scene = function () {
+ var scene = cc.Scene.create();
+ var layer = SysMenu.create();
+ scene.addChild(layer);
+ return scene;
+};
diff --git a/samples/MoonWarriors/Resources/js/config/EnemyType.js b/samples/MoonWarriors/Resources/js/config/EnemyType.js
new file mode 100644
index 0000000000..c947d58903
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/config/EnemyType.js
@@ -0,0 +1,56 @@
+var EnemyType = [
+ {
+ type:0,
+ textureName:"E0.png",
+ bulletType:"W2.png",
+ HP:1,
+ moveType:MW.ENEMY_MOVE_TYPE.ATTACK,
+ attackMode:MW.ENEMY_MOVE_TYPE.NORMAL,
+ scoreValue:15
+ },
+ {
+ type:1,
+ textureName:"E1.png",
+ bulletType:"W2.png",
+ HP:2,
+ moveType:MW.ENEMY_MOVE_TYPE.ATTACK,
+ attackMode:MW.ENEMY_MOVE_TYPE.NORMAL,
+ scoreValue:40
+ },
+ {
+ type:2,
+ textureName:"E2.png",
+ bulletType:"W2.png",
+ HP:4,
+ moveType:MW.ENEMY_MOVE_TYPE.HORIZONTAL,
+ attackMode:MW.ENEMY_ATTACK_MODE.TSUIHIKIDAN,
+ scoreValue:60
+ },
+ {
+ type:3,
+ textureName:"E3.png",
+ bulletType:"W2.png",
+ HP:6,
+ moveType:MW.ENEMY_MOVE_TYPE.OVERLAP,
+ attackMode:MW.ENEMY_MOVE_TYPE.NORMAL,
+ scoreValue:80
+ },
+ {
+ type:4,
+ textureName:"E4.png",
+ bulletType:"W2.png",
+ HP:10,
+ moveType:MW.ENEMY_MOVE_TYPE.HORIZONTAL,
+ attackMode:MW.ENEMY_ATTACK_MODE.TSUIHIKIDAN,
+ scoreValue:150
+ },
+ {
+ type:5,
+ textureName:"E5.png",
+ bulletType:"W2.png",
+ HP:15,
+ moveType:MW.ENEMY_MOVE_TYPE.HORIZONTAL,
+ attackMode:MW.ENEMY_MOVE_TYPE.NORMAL,
+ scoreValue:200
+ }
+];
diff --git a/samples/MoonWarriors/Resources/js/config/GameConfig.js b/samples/MoonWarriors/Resources/js/config/GameConfig.js
new file mode 100644
index 0000000000..554d322aa1
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/config/GameConfig.js
@@ -0,0 +1,94 @@
+/**
+ * Cocos2d-html5 show case : Moon Warriors
+ *
+ * @Licensed:
+ * This showcase is licensed under GPL.
+ *
+ * @Authors:
+ * Programmer: Shengxiang Chen (陈升想), Dingping Lv (吕定平), Ricardo Quesada
+ * Effects animation: Hao Wu (吴昊)
+ * Quality Assurance: Sean Lin (林顺)
+ *
+ * @Links:
+ * http://www.cocos2d-x.org
+ * http://bbs.html5china.com
+ *
+ */
+
+//game state
+MW.GAME_STATE = {
+ HOME:0,
+ PLAY:1,
+ OVER:2
+};
+
+//keys
+MW.KEYS = [];
+
+//level
+MW.LEVEL = {
+ STAGE1:1,
+ STAGE2:2,
+ STAGE3:3
+};
+
+//life
+MW.LIFE = 4;
+
+//score
+MW.SCORE = 0;
+
+//sound
+MW.SOUND = true;
+
+//enemy move type
+MW.ENEMY_MOVE_TYPE = {
+ ATTACK:0,
+ VERTICAL:1,
+ HORIZONTAL:2,
+ OVERLAP:3
+};
+
+//delta x
+MW.DELTA_X = -100;
+
+//offset x
+MW.OFFSET_X = -24;
+
+//rot
+MW.ROT = -5.625;
+
+//bullet type
+MW.BULLET_TYPE = {
+ PLAYER:1,
+ ENEMY:2
+};
+
+//weapon type
+MW.WEAPON_TYPE = {
+ ONE:1
+};
+
+//unit tag
+MW.UNIT_TAG = {
+ ENMEY_BULLET:900,
+ PLAYER_BULLET:901,
+ ENEMY:1000,
+ PLAYER:1000
+};
+
+//attack mode
+MW.ENEMY_ATTACK_MODE = {
+ NORMAL:1,
+ TSUIHIKIDAN:2
+};
+
+//life up sorce
+MW.LIFEUP_SORCE = [50000, 100000, 150000, 200000, 250000, 300000];
+
+//container
+MW.CONTAINER = {
+ ENEMIES:[],
+ ENEMY_BULLETS:[],
+ PLAYER_BULLETS:[]
+};
diff --git a/samples/MoonWarriors/Resources/js/config/Level.js b/samples/MoonWarriors/Resources/js/config/Level.js
new file mode 100644
index 0000000000..321a7a270f
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/config/Level.js
@@ -0,0 +1,49 @@
+var Level1 = {
+ enemies:[
+ {
+ ShowType:"Repeate",
+ ShowTime:"00:02",
+ Types:[0,1,2]
+ },
+ {
+ ShowType:"Repeate",
+ ShowTime:"00:05",
+ Types:[3,4,5]
+ }
+ /*{
+ ShowType:"Repeate",
+ ShowTime:"00:08",
+ Types:[0,4,3,5]
+ },
+ {
+ ShowType:"Once",
+ ShowTime:"00:6",
+ Types:[0,2,4,3]
+ },
+ {
+ ShowType:"Once",
+ ShowTime:"00:16",
+ Types:[0,2,5,4,3]
+ },
+ {
+ ShowType:"Once",
+ ShowTime:"00:25",
+ Types:[0,3,5,4,3]
+ },
+ {
+ ShowType:"Once",
+ ShowTime:"00:35",
+ Types:[4,5,3,1,3]
+ },
+ {
+ ShowType:"Once",
+ ShowTime:"00:50",
+ Types:[0,3,2,1,0,3]
+ },
+ {
+ ShowType:"Once",
+ ShowTime:"01:15",
+ Types:[4,5,2,1,0]
+ }*/
+ ]
+};
diff --git a/samples/MoonWarriors/Resources/js/helper/jsb_constants.js b/samples/MoonWarriors/Resources/js/helper/jsb_constants.js
new file mode 100644
index 0000000000..d744f521bf
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/helper/jsb_constants.js
@@ -0,0 +1,475 @@
+require('js/helper/jsb_constants_gl.js');
+// cocos2d Helper
+
+cc.c3 = cc.c3 || function (r, g, b) {
+ return {r: r, g: g, b: b};
+};
+
+cc.c3b = cc.c3;
+
+cc.c4 = cc.c4 || function (r, g, b, o) {
+ return {r: r, g: g, b: b, a: o};
+};
+
+cc.c4b = cc.c4;
+
+cc.c4f = cc.c4f || function (r, g, b, o) {
+ return {r: r, g: g, b: b, a: o};
+};
+
+cc.p = cc.p || function( x, y )
+{
+ return {x:x, y:y};
+};
+
+cc.g = cc.g || cc.p;
+cc.log = cc.log || log;
+
+//
+// cocos2d constants
+//
+cc.TEXTURE_PIXELFORMAT_RGBA8888 = 0;
+cc.TEXTURE_PIXELFORMAT_RGB888 = 1;
+cc.TEXTURE_PIXELFORMAT_RGB565 = 2;
+cc.TEXTURE_PIXELFORMAT_A8 = 3;
+cc.TEXTURE_PIXELFORMAT_I8 = 4;
+cc.TEXTURE_PIXELFORMAT_AI88 = 5;
+cc.TEXTURE_PIXELFORMAT_RGBA4444 = 6;
+cc.TEXTURE_PIXELFORMAT_RGB5A1 = 7;
+cc.TEXTURE_PIXELFORMAT_PVRTC4 = 8;
+cc.TEXTURE_PIXELFORMAT_PVRTC4 = 9;
+cc.TEXTURE_PIXELFORMAT_DEFAULT = cc.TEXTURE_PIXELFORMAT_RGBA8888;
+
+cc.TEXT_ALIGNMENT_LEFT = 0;
+cc.TEXT_ALIGNMENT_CENTER = 1;
+cc.TEXT_ALIGNMENT_RIGHT = 2;
+
+cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0;
+cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1;
+cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2;
+
+cc.IMAGE_FORMAT_JPEG = 0;
+cc.IMAGE_FORMAT_PNG = 0;
+
+cc.PROGRESS_TIMER_TYPE_RADIAL = 0;
+cc.PROGRESS_TIMER_TYPE_BAR = 1;
+
+cc.PARTICLE_TYPE_FREE = 0;
+cc.PARTICLE_TYPE_RELATIVE = 1;
+cc.PARTICLE_TYPE_GROUPED = 2;
+cc.PARTICLE_DURATION_INFINITY = -1;
+cc.PARTICLE_MODE_GRAVITY = 0;
+cc.PARTICLE_MODE_RADIUS = 1;
+cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE = -1;
+cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS = -1;
+
+cc.RED = cc.c3(255,0,0);
+cc.GREEN = cc.c3(0,255,0);
+cc.BLUE = cc.c3(0,0,255);
+cc.BLACK = cc.c3(0,0,0);
+cc.WHITE = cc.c3(255,255,255);
+
+cc.POINT_ZERO = {x:0, y:0};
+
+cc._reuse_p0 = {x:0, y:0};
+cc._reuse_p1 = {x:0, y:0};
+cc._reuse_p_index = 0;
+cc._reuse_color3b = cc.c3(255, 255, 255 );
+cc._reuse_color4b = cc.c4(255, 255, 255, 255 );
+cc._reuse_grid = cc.g(0,0);
+
+// dump config info, but only in debug mode
+cc.dumpConfig = function()
+{
+ if( cc.config.debug ) {
+ for(var i in cc.config)
+ cc.log( i + " = " + cc.config[i] );
+ }
+};
+
+//
+// Point
+//
+cc._p = function( x, y )
+{
+ if( cc._reuse_p_index === 0 ) {
+ cc._reuse_p0.x = x;
+ cc._reuse_p0.y = y;
+ cc._reuse_p_index = 1;
+ return cc._reuse_p0;
+ } else {
+ cc._reuse_p1.x = x;
+ cc._reuse_p1.y = y;
+ cc._reuse_p_index = 0;
+ return cc._reuse_p1;
+ }
+};
+
+cc._to_p = function( point )
+{
+ return point;
+};
+
+cc._from_p = function( size )
+{
+ return size;
+};
+
+//
+// Grid
+//
+cc._g = function( x, y )
+{
+ cc._reuse_grid.x = x;
+ cc._reuse_grid.y = y;
+ return cc._reuse_grid;
+}
+
+//
+// Color
+//
+//
+// Color 3B
+//
+cc.c3b = function( r, g, b )
+{
+ return {r:r, g:g, b:b };
+};
+cc._c3b = function( r, g, b )
+{
+ cc._reuse_color3b.r = r;
+ cc._reuse_color3b.g = g;
+ cc._reuse_color3b.b = b;
+ return cc._reuse_color3b;
+};
+// compatibility
+cc.c3 = cc.c3b;
+cc._c3 = cc._c3b;
+
+//
+// Color 4B
+//
+cc.c4b = function( r, g, b, a )
+{
+ return {r:r, g:g, b:b, a:a };
+};
+cc._c4b = function( r, g, b, a )
+{
+ cc._reuse_color4b.r = r;
+ cc._reuse_color4b.g = g;
+ cc._reuse_color4b.b = b;
+ cc._reuse_color4b.a = a;
+ return cc._reuse_color4b;
+};
+// compatibility
+cc.c4 = cc.c4b;
+cc._c4 = cc._c4b;
+
+
+//
+// Size
+//
+cc.size = function(w,h)
+{
+ return {width:w, height:h};
+}
+
+cc._to_size = function( size )
+{
+ return size;
+}
+
+cc._from_size = function( size )
+{
+ return size;
+}
+
+//
+// Rect
+//
+cc.rect = function(x,y,w,h)
+{
+ return {x:x, y:y, width:w, height:h};
+}
+
+cc._to_rect = function( rect )
+{
+ return rect;
+}
+
+cc._from_rect = function( rect )
+{
+ return rect;
+}
+
+// XXX Should be done in native
+cc.rectIntersectsRect = function( rectA, rectB )
+{
+ var bool = ! ( rectA.x > rectB.x + rectB.width ||
+ rectA.x + rectA.width < rectB.x ||
+ rectA.y > rectB.y +rectB.height ||
+ rectA.y + rectA.height < rectB.y );
+
+ return bool;
+}
+
+// point functions
+cc.pAdd = cc.pAdd || function (p1, p2) {
+ return {x: p1.x + p2.x, y: p1.y + p2.y};
+};
+
+cc.pSub = cc.pSub || function (p1, p2) {
+ return {x: p1.x - p2.x, y: p1.y - p2.y};
+}
+
+cc.pMult = cc.pMult || function (p1, s) {
+ return {x: p1.x * s, y: p1.y * s};
+};
+
+/**
+ * Calculates dot product of two points.
+ * @param {cc.Point} v1
+ * @param {cc.Point} v2
+ * @return {Number}
+ */
+cc.pDot = function (v1, v2) {
+ return v1.x * v2.x + v1.y * v2.y;
+};
+
+/**
+ * Calculates the square length of a cc.Point (not calling sqrt() )
+ * @param {cc.Point} v
+ *@return {cc.pDot}
+ */
+cc.pLengthSQ = function (v) {
+ return cc.pDot(v, v);
+};
+
+/**
+ * Calculates distance between point an origin
+ * @param {cc.Point} v
+ * @return {Number}
+ */
+cc.pLength = function (v) {
+ return Math.sqrt(cc.pLengthSQ(v));
+};
+
+/**
+ * Calculates the distance between two points
+ * @param {cc.Point} v1
+ * @param {cc.Point} v2
+ * @return {cc.pLength}
+ */
+cc.pDistance = function (v1, v2) {
+ return cc.pLength(cc.pSub(v1, v2));
+};
+
+/**
+ * Clamp a value between from and to.
+ * @param {Number} value
+ * @param {Number} min_inclusive
+ * @param {Number} max_inclusive
+ * @return {Number}
+ */
+cc.clampf = function (value, min_inclusive, max_inclusive) {
+ if (min_inclusive > max_inclusive) {
+ var temp = min_inclusive;
+ min_inclusive = max_inclusive;
+ max_inclusive = temp;
+ }
+ return value < min_inclusive ? min_inclusive : value < max_inclusive ? value : max_inclusive;
+};
+
+/**
+ * Clamp a point between from and to.
+ * @param {Number} p
+ * @param {Number} min_inclusive
+ * @param {Number} max_inclusive
+ * @return {cc.Point}
+ */
+cc.pClamp = function (p, min_inclusive, max_inclusive) {
+ return cc.p(cc.clampf(p.x, min_inclusive.x, max_inclusive.x), cc.clampf(p.y, min_inclusive.y, max_inclusive.y));
+};
+
+/**
+ * returns a random float between 0 and 1
+ * @return {Number}
+ * @function
+ */
+cc.RANDOM_0_1 = function () {
+ return Math.random();
+};
+
+/**
+ * Associates a base class with a native superclass
+ * @function
+ * @param {object} jsobj subclass
+ * @param {object} klass superclass
+ */
+cc.associateWithNative = function( jsobj, superclass ) {
+ var native = new superclass();
+ __associateObjWithNative( jsobj, native );
+};
+
+//
+// Array: for cocos2d-hmtl5 compatibility
+//
+cc.ArrayRemoveObject = function (arr, delObj) {
+ for (var i = 0; i < arr.length; i++) {
+ if (arr[i] == delObj) {
+ arr.splice(i, 1);
+ }
+ }
+};
+
+//
+// Google "subclasses"
+// borrowed from closure library
+//
+var goog = goog || {}; // Check to see if already defined in current scope
+goog.inherits = function (childCtor, parentCtor) {
+ /** @constructor */
+ function tempCtor() {};
+ tempCtor.prototype = parentCtor.prototype;
+ childCtor.superClass_ = parentCtor.prototype;
+ childCtor.prototype = new tempCtor();
+ childCtor.prototype.constructor = childCtor;
+
+ // Copy "static" method, but doesn't generate subclasses.
+// for( var i in parentCtor ) {
+// childCtor[ i ] = parentCtor[ i ];
+// }
+};
+goog.base = function(me, opt_methodName, var_args) {
+ var caller = arguments.callee.caller;
+ if (caller.superClass_) {
+ // This is a constructor. Call the superclass constructor.
+ ret = caller.superClass_.constructor.apply( me, Array.prototype.slice.call(arguments, 1));
+
+ // XXX: SpiderMonkey bindings extensions
+// __associateObjWithNative( me, ret );
+ return ret;
+ }
+
+ var args = Array.prototype.slice.call(arguments, 2);
+ var foundCaller = false;
+ for (var ctor = me.constructor;
+ ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
+ if (ctor.prototype[opt_methodName] === caller) {
+ foundCaller = true;
+ } else if (foundCaller) {
+ return ctor.prototype[opt_methodName].apply(me, args);
+ }
+ }
+
+ // If we did not find the caller in the prototype chain,
+ // then one of two things happened:
+ // 1) The caller is an instance method.
+ // 2) This method was not called by the right caller.
+ if (me[opt_methodName] === caller) {
+ return me.constructor.prototype[opt_methodName].apply(me, args);
+ } else {
+ throw Error(
+ 'goog.base called from a method of one name ' +
+ 'to a method of a different name');
+ }
+};
+
+
+//
+// Simple subclass
+//
+
+cc.Class = function(){};
+
+cc.Class.extend = function (prop) {
+ var _super = this.prototype;
+
+ // Instantiate a base class (but only create the instance,
+ // don't run the init constructor)
+ initializing = true;
+ var prototype = new this();
+ initializing = false;
+ fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
+
+ // Copy the properties over onto the new prototype
+ for (var name in prop) {
+ // Check if we're overwriting an existing function
+ prototype[name] = typeof prop[name] == "function" &&
+ typeof _super[name] == "function" && fnTest.test(prop[name]) ?
+ (function (name, fn) {
+ return function () {
+ var tmp = this._super;
+
+ // Add a new ._super() method that is the same method
+ // but on the super-class
+ this._super = _super[name];
+
+ // The method only need to be bound temporarily, so we
+ // remove it when we're done executing
+ var ret = fn.apply(this, arguments);
+ this._super = tmp;
+
+ return ret;
+ };
+ })(name, prop[name]) :
+ prop[name];
+ }
+
+ // The dummy class constructor
+ function Class() {
+ // All construction is actually done in the init method
+ if (!initializing && this.ctor)
+ this.ctor.apply(this, arguments);
+ }
+
+ // Populate our constructed prototype object
+ Class.prototype = prototype;
+
+ // Enforce the constructor to be what we expect
+ Class.prototype.constructor = Class;
+
+ // And make this class extendable
+ Class.extend = arguments.callee;
+
+ return Class;
+};
+
+cc.Layer.extend = cc.Class.extend;
+cc.Scene.extend = cc.Class.extend;
+cc.LayerGradient.extend = cc.Class.extend;
+cc.Sprite.extend = cc.Class.extend;
+cc.MenuItemFont.extend = cc.Class.extend;
+
+//
+// Chipmunk helpers
+//
+var cp = cp || {};
+
+cp.v = cc.p;
+cp._v = cc._p;
+cp.vzero = cp.v(0,0);
+
+//
+// OpenGL Helpers
+//
+var gl = gl || {};
+gl.NEAREST = 0x2600;
+gl.LINEAR = 0x2601;
+gl.REPEAT = 0x2901;
+gl.CLAMP_TO_EDGE = 0x812F;
+gl.CLAMP_TO_BORDER = 0x812D;
+gl.LINEAR_MIPMAP_NEAREST = 0x2701;
+gl.NEAREST_MIPMAP_NEAREST = 0x2700;
+gl.ZERO = 0;
+gl.ONE = 1;
+gl.SRC_COLOR = 0x0300;
+gl.ONE_MINUS_SRC_COLOR = 0x0301;
+gl.SRC_ALPHA = 0x0302;
+gl.ONE_MINUS_SRC_ALPHA = 0x0303;
+gl.DST_ALPHA = 0x0304;
+gl.ONE_MINUS_DST_ALPHA = 0x0305;
+gl.DST_COLOR = 0x0306;
+gl.ONE_MINUS_DST_COLOR = 0x0307;
+gl.SRC_ALPHA_SATURATE = 0x0308;
+
diff --git a/samples/MoonWarriors/Resources/js/helper/jsb_constants_gl.js b/samples/MoonWarriors/Resources/js/helper/jsb_constants_gl.js
new file mode 100644
index 0000000000..8b9d2f701d
--- /dev/null
+++ b/samples/MoonWarriors/Resources/js/helper/jsb_constants_gl.js
@@ -0,0 +1,23 @@
+//
+// OpenGL defines
+//
+
+var gl = gl || {};
+gl.NEAREST = 0x2600;
+gl.LINEAR = 0x2601;
+gl.REPEAT = 0x2901;
+gl.CLAMP_TO_EDGE = 0x812F;
+gl.CLAMP_TO_BORDER = 0x812D;
+gl.LINEAR_MIPMAP_NEAREST = 0x2701;
+gl.NEAREST_MIPMAP_NEAREST = 0x2700;
+gl.ZERO = 0;
+gl.ONE = 1;
+gl.SRC_COLOR = 0x0300;
+gl.ONE_MINUS_SRC_COLOR = 0x0301;
+gl.SRC_ALPHA = 0x0302;
+gl.ONE_MINUS_SRC_ALPHA = 0x0303;
+gl.DST_ALPHA = 0x0304;
+gl.ONE_MINUS_DST_ALPHA = 0x0305;
+gl.DST_COLOR = 0x0306;
+gl.ONE_MINUS_DST_COLOR = 0x0307;
+gl.SRC_ALPHA_SATURATE = 0x0308;
diff --git a/samples/MoonWarriors/Resources/res/Music/bgMusic.mp3.REMOVED.git-id b/samples/MoonWarriors/Resources/res/Music/bgMusic.mp3.REMOVED.git-id
new file mode 100644
index 0000000000..d86bcca004
--- /dev/null
+++ b/samples/MoonWarriors/Resources/res/Music/bgMusic.mp3.REMOVED.git-id
@@ -0,0 +1 @@
+59362b16ba4da187e064648be4d0bcb1c09b504d
\ No newline at end of file
diff --git a/samples/MoonWarriors/Resources/res/Music/mainMainMusic.mp3.REMOVED.git-id b/samples/MoonWarriors/Resources/res/Music/mainMainMusic.mp3.REMOVED.git-id
new file mode 100644
index 0000000000..7a63ad234e
--- /dev/null
+++ b/samples/MoonWarriors/Resources/res/Music/mainMainMusic.mp3.REMOVED.git-id
@@ -0,0 +1 @@
+c0488f23a6a785893f4845b7fadc59ed892ceedc
\ No newline at end of file
diff --git a/samples/MoonWarriors/Resources/res/arial-14.GlyphProject b/samples/MoonWarriors/Resources/res/arial-14.GlyphProject
new file mode 100644
index 0000000000..cbac22bf53
Binary files /dev/null and b/samples/MoonWarriors/Resources/res/arial-14.GlyphProject differ
diff --git a/samples/MoonWarriors/Resources/res/b01.png.REMOVED.git-id b/samples/MoonWarriors/Resources/res/b01.png.REMOVED.git-id
new file mode 100644
index 0000000000..ab880f0157
--- /dev/null
+++ b/samples/MoonWarriors/Resources/res/b01.png.REMOVED.git-id
@@ -0,0 +1 @@
+46f10a6bf5c63f03ddf8566f392aa7a8f258d7e8
\ No newline at end of file
diff --git a/samples/MoonWarriors/Resources/res/explosion.png.REMOVED.git-id b/samples/MoonWarriors/Resources/res/explosion.png.REMOVED.git-id
new file mode 100644
index 0000000000..56b3df641c
--- /dev/null
+++ b/samples/MoonWarriors/Resources/res/explosion.png.REMOVED.git-id
@@ -0,0 +1 @@
+97bca7d49fb6ec5c330f6ab6f5f49d335601a669
\ No newline at end of file
diff --git a/samples/MoonWarriors/Resources/res/loading.png.REMOVED.git-id b/samples/MoonWarriors/Resources/res/loading.png.REMOVED.git-id
new file mode 100644
index 0000000000..a35d4e432f
--- /dev/null
+++ b/samples/MoonWarriors/Resources/res/loading.png.REMOVED.git-id
@@ -0,0 +1 @@
+ca7905a1a07e2be3e02fbf329772c2c361400af7
\ No newline at end of file
diff --git a/samples/MoonWarriors/proj.android/.classpath b/samples/MoonWarriors/proj.android/.classpath
new file mode 100644
index 0000000000..a4763d1eec
--- /dev/null
+++ b/samples/MoonWarriors/proj.android/.classpath
@@ -0,0 +1,8 @@
+
+