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 @@ + + + + + + + + diff --git a/samples/MoonWarriors/proj.android/.project b/samples/MoonWarriors/proj.android/.project new file mode 100644 index 0000000000..16a1a72d7b --- /dev/null +++ b/samples/MoonWarriors/proj.android/.project @@ -0,0 +1,33 @@ + + + MoonWarriors + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/samples/MoonWarriors/proj.android/AndroidManifest.xml b/samples/MoonWarriors/proj.android/AndroidManifest.xml new file mode 100644 index 0000000000..a7e2802621 --- /dev/null +++ b/samples/MoonWarriors/proj.android/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + diff --git a/samples/MoonWarriors/proj.android/ant.properties b/samples/MoonWarriors/proj.android/ant.properties new file mode 100644 index 0000000000..f8af38bfb4 --- /dev/null +++ b/samples/MoonWarriors/proj.android/ant.properties @@ -0,0 +1 @@ +aapt.ignore.assets="!*.pvr.gz:!*.gz:!.svn:!.git:.*:_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~" diff --git a/samples/MoonWarriors/proj.android/build.xml b/samples/MoonWarriors/proj.android/build.xml new file mode 100644 index 0000000000..ae419c802d --- /dev/null +++ b/samples/MoonWarriors/proj.android/build.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/MoonWarriors/proj.android/build_native.sh b/samples/MoonWarriors/proj.android/build_native.sh new file mode 100644 index 0000000000..0e10e99149 --- /dev/null +++ b/samples/MoonWarriors/proj.android/build_native.sh @@ -0,0 +1,100 @@ +APPNAME="MoonWarriors" + +# options + +buildexternalsfromsource= +PARALLEL_BUILD_FLAG= + +usage(){ +cat << EOF +usage: $0 [options] + +Build C/C++ code for $APPNAME using Android NDK + +OPTIONS: +-s Build externals from source +-p Run make with -j8 option to take advantage of multiple processors +-h this help +EOF +} + +while getopts "sph" OPTION; do +case "$OPTION" in +s) +buildexternalsfromsource=1 +;; +p) +PARALLEL_BUILD_FLAG=\-j8 +;; +h) +usage +exit 0 +;; +esac +done + +# exit this script if any commmand fails +set -e + +# paths + +if [ -z "${NDK_ROOT+aaa}" ];then +echo "please define NDK_ROOT" +exit 1 +fi + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# ... use paths relative to current directory +COCOS2DX_ROOT="$DIR/../../.." +APP_ROOT="$DIR/.." +APP_ANDROID_ROOT="$DIR" + +echo +echo "Paths" +echo " NDK_ROOT = $NDK_ROOT" +echo " COCOS2DX_ROOT = $COCOS2DX_ROOT" +echo " APP_ROOT = $APP_ROOT" +echo " APP_ANDROID_ROOT = $APP_ANDROID_ROOT" +echo + +# make sure assets is exist +if [ -d "$APP_ANDROID_ROOT"/assets ]; then + rm -rf "$APP_ANDROID_ROOT"/assets +fi + +mkdir "$APP_ANDROID_ROOT"/assets + + +# copy resources +for file in "$APP_ROOT"/Resources/* +do +if [ -d "$file" ]; then + cp -rf "$file" "$APP_ANDROID_ROOT"/assets +fi + + +if [ -f "$file" ]; then + cp "$file" "$APP_ANDROID_ROOT"/assets +fi +done + + +rm -f "$APP_ANDROID_ROOT"/assets/Images/landscape-1024x1024-rgba8888.pvr.gz +rm -f "$APP_ANDROID_ROOT"/assets/Images/test_image_rgba4444.pvr.gz +rm -f "$APP_ANDROID_ROOT"/assets/Images/test_1021x1024_a8.pvr.gz +rm -f "$APP_ANDROID_ROOT"/assets/Images/test_1021x1024_rgb888.pvr.gz +rm -f "$APP_ANDROID_ROOT"/assets/Images/test_1021x1024_rgba4444.pvr.gz +rm -f "$APP_ANDROID_ROOT"/assets/Images/test_1021x1024_rgba8888.pvr.gz +rm -f "$APP_ANDROID_ROOT"/assets/Images/test_image_rgba4444.pvr.gz +rm -f "$APP_ANDROID_ROOT"/assets/Images/texture1024x1024_rgba4444.pvr.gz +rm -f "$APP_ANDROID_ROOT"/assets/Images/PlanetCute-1024x1024-rgba4444.pvr.gz + + +echo "Using prebuilt externals" +echo + +set -x + +"$NDK_ROOT"/ndk-build $PARALLEL_BUILD_FLAG -C "$APP_ANDROID_ROOT" $* \ + "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt" \ + NDK_LOG=1 V=1 diff --git a/samples/MoonWarriors/proj.android/jni/Android.mk b/samples/MoonWarriors/proj.android/jni/Android.mk new file mode 100644 index 0000000000..91eb4e64bb --- /dev/null +++ b/samples/MoonWarriors/proj.android/jni/Android.mk @@ -0,0 +1,28 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := moonwarriors_shared + +LOCAL_MODULE_FILENAME := libmoonwarriors + +LOCAL_SRC_FILES := moonwarriors/main.cpp \ + ../../Classes/AppDelegate.cpp + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes + +LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static +LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static +LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static +LOCAL_WHOLE_STATIC_LIBRARIES += spidermonkey_static +LOCAL_WHOLE_STATIC_LIBRARIES += scriptingcore-spidermonkey + +LOCAL_EXPORT_CFLAGS := -DCOCOS2D_DEBUG=2 -DCOCOS2D_JAVASCRIPT + +include $(BUILD_SHARED_LIBRARY) + +$(call import-module,cocos2dx) +$(call import-module,CocosDenshion/android) +$(call import-module,external/chipmunk) +$(call import-module,scripting/javascript/spidermonkey-android) +$(call import-module,scripting/javascript/bindings) diff --git a/samples/MoonWarriors/proj.android/jni/Application.mk b/samples/MoonWarriors/proj.android/jni/Application.mk new file mode 100644 index 0000000000..4b8115b893 --- /dev/null +++ b/samples/MoonWarriors/proj.android/jni/Application.mk @@ -0,0 +1,3 @@ +APP_STL := gnustl_static +APP_CPPFLAGS := -frtti -DCOCOS2D_JAVASCRIPT=1 +APP_CPPFLAGS += -DCOCOS2D_DEBUG=2 diff --git a/samples/MoonWarriors/proj.android/jni/moonwarriors/main.cpp b/samples/MoonWarriors/proj.android/jni/moonwarriors/main.cpp new file mode 100644 index 0000000000..2f2d1e0c10 --- /dev/null +++ b/samples/MoonWarriors/proj.android/jni/moonwarriors/main.cpp @@ -0,0 +1,45 @@ +#include "AppDelegate.h" +#include "cocos2d.h" +#include "platform/android/jni/JniHelper.h" +#include "CCEventType.h" +#include +#include + +#define LOG_TAG "main" +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) + +using namespace cocos2d; + +extern "C" +{ + +jint JNI_OnLoad(JavaVM *vm, void *reserved) +{ + JniHelper::setJavaVM(vm); + + return JNI_VERSION_1_4; +} + +void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) +{ + if (!CCDirector::sharedDirector()->getOpenGLView()) + { + CCEGLView *view = CCEGLView::sharedOpenGLView(); + view->setFrameSize(w, h); + + AppDelegate *pAppDelegate = new AppDelegate(); + CCApplication::sharedApplication()->run(); + } + else + { + ccDrawInit(); + ccGLInvalidateStateCache(); + + CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); + CCTextureCache::reloadAllTextures(); + CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); + CCDirector::sharedDirector()->setGLDefaultValues(); + } +} + +} diff --git a/samples/MoonWarriors/proj.android/proguard-project.txt b/samples/MoonWarriors/proj.android/proguard-project.txt new file mode 100644 index 0000000000..f2fe1559a2 --- /dev/null +++ b/samples/MoonWarriors/proj.android/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/samples/MoonWarriors/proj.android/project.properties b/samples/MoonWarriors/proj.android/project.properties new file mode 100644 index 0000000000..d5f90ebab1 --- /dev/null +++ b/samples/MoonWarriors/proj.android/project.properties @@ -0,0 +1,13 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-8 + +android.library.reference.1=../../../cocos2dx/platform/android/java diff --git a/samples/MoonWarriors/proj.android/res/values/strings.xml b/samples/MoonWarriors/proj.android/res/values/strings.xml new file mode 100644 index 0000000000..707408a4d7 --- /dev/null +++ b/samples/MoonWarriors/proj.android/res/values/strings.xml @@ -0,0 +1,4 @@ + + + MoonWarriors + diff --git a/samples/MoonWarriors/proj.android/src/org/cocos2dx/moonwarriors/MoonWarriors.java b/samples/MoonWarriors/proj.android/src/org/cocos2dx/moonwarriors/MoonWarriors.java new file mode 100644 index 0000000000..46f8edc518 --- /dev/null +++ b/samples/MoonWarriors/proj.android/src/org/cocos2dx/moonwarriors/MoonWarriors.java @@ -0,0 +1,39 @@ +/**************************************************************************** +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. +****************************************************************************/ +package org.cocos2dx.moonwarriors; + +import org.cocos2dx.lib.Cocos2dxActivity; + +import android.os.Bundle; + +public class MoonWarriors extends Cocos2dxActivity{ + + protected void onCreate(Bundle savedInstanceState){ + super.onCreate(savedInstanceState); + } + + static { + System.loadLibrary("moonwarriors"); + } +} diff --git a/samples/MoonWarriors/proj.ios/AppController.h b/samples/MoonWarriors/proj.ios/AppController.h new file mode 100644 index 0000000000..10287bd13f --- /dev/null +++ b/samples/MoonWarriors/proj.ios/AppController.h @@ -0,0 +1,17 @@ +// +// testjsAppController.h +// testjs +// +// Created by Rolando Abarca on 3/19/12. +// Copyright __MyCompanyName__ 2012. All rights reserved. +// + +@class RootViewController; + +@interface AppController : NSObject { + UIWindow *window; + RootViewController *viewController; +} + +@end + diff --git a/samples/MoonWarriors/proj.ios/AppController.mm b/samples/MoonWarriors/proj.ios/AppController.mm new file mode 100644 index 0000000000..3e3e5c9474 --- /dev/null +++ b/samples/MoonWarriors/proj.ios/AppController.mm @@ -0,0 +1,119 @@ +// +// testjsAppController.mm +// testjs +// +// Created by Rolando Abarca on 3/19/12. +// Copyright __MyCompanyName__ 2012. All rights reserved. +// +#import +#import "AppController.h" +#import "cocos2d.h" +#import "EAGLView.h" +#import "AppDelegate.h" + +#import "RootViewController.h" + +@implementation AppController + +#pragma mark - +#pragma mark Application lifecycle + +// cocos2d application instance +static AppDelegate s_sharedApplication; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + // Override point for customization after application launch. + + // Add the view controller's view to the window and display. + window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; + EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] + pixelFormat: kEAGLColorFormatRGBA8 + depthFormat: GL_DEPTH_COMPONENT16 //_OES + preserveBackbuffer: NO + sharegroup: nil + multiSampling: NO + numberOfSamples: 0 ]; + + // Use RootViewController manage EAGLView + viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; + viewController.wantsFullScreenLayout = YES; + viewController.view = __glView; + + // Set RootViewController to window + if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) + { + // warning: addSubView doesn't work on iOS6 + [window addSubview: viewController.view]; + } + else + { + // use this method on ios6 + [window setRootViewController:viewController]; + } + + [window makeKeyAndVisible]; + + [[UIApplication sharedApplication] setStatusBarHidden: YES]; + + cocos2d::CCApplication::sharedApplication()->run(); + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + /* + Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + */ + cocos2d::CCDirector::sharedDirector()->pause(); +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + /* + Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + */ + cocos2d::CCDirector::sharedDirector()->resume(); +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + /* + Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + If your application supports background execution, called instead of applicationWillTerminate: when the user quits. + */ + cocos2d::CCApplication::sharedApplication()->applicationDidEnterBackground(); +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + /* + Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. + */ + cocos2d::CCApplication::sharedApplication()->applicationWillEnterForeground(); +} + +- (void)applicationWillTerminate:(UIApplication *)application { + /* + Called when the application is about to terminate. + See also applicationDidEnterBackground:. + */ +} + + +#pragma mark - +#pragma mark Memory management + +- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { + /* + Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. + */ + cocos2d::CCDirector::sharedDirector()->purgeCachedData(); +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end + diff --git a/samples/MoonWarriors/proj.ios/Default-568h@2x.png.REMOVED.git-id b/samples/MoonWarriors/proj.ios/Default-568h@2x.png.REMOVED.git-id new file mode 100644 index 0000000000..8f5838f3a8 --- /dev/null +++ b/samples/MoonWarriors/proj.ios/Default-568h@2x.png.REMOVED.git-id @@ -0,0 +1 @@ +66c6d1cead373b45218424f6a82f370897e443e4 \ No newline at end of file diff --git a/samples/MoonWarriors/proj.ios/Default@2x.png.REMOVED.git-id b/samples/MoonWarriors/proj.ios/Default@2x.png.REMOVED.git-id new file mode 100644 index 0000000000..8843505b20 --- /dev/null +++ b/samples/MoonWarriors/proj.ios/Default@2x.png.REMOVED.git-id @@ -0,0 +1 @@ +84689888a14a2123d2b39f7f2f61be8c15207479 \ No newline at end of file diff --git a/samples/MoonWarriors/proj.ios/MoonWarriors.xcodeproj/project.pbxproj b/samples/MoonWarriors/proj.ios/MoonWarriors.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..efe0a52e68 --- /dev/null +++ b/samples/MoonWarriors/proj.ios/MoonWarriors.xcodeproj/project.pbxproj @@ -0,0 +1,562 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 1A1D97421625AFB400D5E31D /* js in Resources */ = {isa = PBXBuildFile; fileRef = 1A1D97401625AFB400D5E31D /* js */; }; + 1A1D97431625AFB400D5E31D /* res in Resources */ = {isa = PBXBuildFile; fileRef = 1A1D97411625AFB400D5E31D /* res */; }; + 1A7CC34016257DF6006B3D18 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7CC33F16257DF6006B3D18 /* QuartzCore.framework */; }; + 1A7CC34216257DF6006B3D18 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7CC34116257DF6006B3D18 /* OpenGLES.framework */; }; + 1A7CC34416257DF6006B3D18 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7CC34316257DF6006B3D18 /* OpenAL.framework */; }; + 1A7CC34616257DF6006B3D18 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7CC34516257DF6006B3D18 /* AudioToolbox.framework */; }; + 1A7CC34816257DF6006B3D18 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7CC34716257DF6006B3D18 /* AVFoundation.framework */; }; + 1A7CC34A16257DF6006B3D18 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7CC34916257DF6006B3D18 /* UIKit.framework */; }; + 1A7CC34C16257DF6006B3D18 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7CC34B16257DF6006B3D18 /* Foundation.framework */; }; + 1A7CC34E16257DF6006B3D18 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7CC34D16257DF6006B3D18 /* CoreGraphics.framework */; }; + 1A7CC72116258056006B3D18 /* AppDelegate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC71F16258056006B3D18 /* AppDelegate.cpp */; }; + 1A7CC72816258081006B3D18 /* AppController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC72416258081006B3D18 /* AppController.mm */; }; + 1A7CC72916258081006B3D18 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC72516258081006B3D18 /* main.m */; }; + 1A7CC72A16258081006B3D18 /* RootViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC72716258081006B3D18 /* RootViewController.mm */; }; + 1A7CC75F16258252006B3D18 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1A7CC75D16258252006B3D18 /* Info.plist */; }; + 1A7CC76716258283006B3D18 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1A7CC76016258283006B3D18 /* Default-568h@2x.png */; }; + 1A7CC76816258283006B3D18 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 1A7CC76116258283006B3D18 /* Default.png */; }; + 1A7CC76916258283006B3D18 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1A7CC76216258283006B3D18 /* Default@2x.png */; }; + 1A7CC76A16258283006B3D18 /* Icon-57.png in Resources */ = {isa = PBXBuildFile; fileRef = 1A7CC76316258283006B3D18 /* Icon-57.png */; }; + 1A7CC76B16258283006B3D18 /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 1A7CC76416258283006B3D18 /* Icon-72.png */; }; + 1A7CC76C16258283006B3D18 /* Icon-114.png in Resources */ = {isa = PBXBuildFile; fileRef = 1A7CC76516258283006B3D18 /* Icon-114.png */; }; + 1A7CC76D16258283006B3D18 /* Icon-144.png in Resources */ = {isa = PBXBuildFile; fileRef = 1A7CC76616258283006B3D18 /* Icon-144.png */; }; + 1A7CC77C16258754006B3D18 /* cocos2d_specifics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC76E16258754006B3D18 /* cocos2d_specifics.cpp */; }; + 1A7CC77D16258754006B3D18 /* cocos2dx.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC77116258754006B3D18 /* cocos2dx.cpp */; }; + 1A7CC77E16258754006B3D18 /* cocos2dxapi.js in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC77316258754006B3D18 /* cocos2dxapi.js */; }; + 1A7CC77F16258754006B3D18 /* README in Resources */ = {isa = PBXBuildFile; fileRef = 1A7CC77416258754006B3D18 /* README */; }; + 1A7CC78016258754006B3D18 /* js_manual_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC77616258754006B3D18 /* js_manual_conversions.cpp */; }; + 1A7CC78116258754006B3D18 /* ScriptingCore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC77816258754006B3D18 /* ScriptingCore.cpp */; }; + 1A7CC782162587E0006B3D18 /* libcocos2dx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7CC71D16257E75006B3D18 /* libcocos2dx.a */; }; + 1A7CC79216258828006B3D18 /* CDAudioManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC78916258828006B3D18 /* CDAudioManager.m */; }; + 1A7CC79316258828006B3D18 /* CDOpenALSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC78C16258828006B3D18 /* CDOpenALSupport.m */; }; + 1A7CC79416258828006B3D18 /* CocosDenshion.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC78E16258828006B3D18 /* CocosDenshion.m */; }; + 1A7CC79516258828006B3D18 /* SimpleAudioEngine.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC78F16258828006B3D18 /* SimpleAudioEngine.mm */; }; + 1A7CC79616258828006B3D18 /* SimpleAudioEngine_objc.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC79116258828006B3D18 /* SimpleAudioEngine_objc.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 1A7CC71C16257E75006B3D18 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 1A7CC71516257E74006B3D18 /* cocos2dx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 1551A33F158F2AB200E66CFE; + remoteInfo = cocos2dx; + }; + 1A7CC730162580CE006B3D18 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 1A7CC71516257E74006B3D18 /* cocos2dx.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 1551A33E158F2AB200E66CFE; + remoteInfo = cocos2dx; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 1A1D97401625AFB400D5E31D /* js */ = {isa = PBXFileReference; lastKnownFileType = folder; name = js; path = ../Resources/js; sourceTree = ""; }; + 1A1D97411625AFB400D5E31D /* res */ = {isa = PBXFileReference; lastKnownFileType = folder; name = res; path = ../Resources/res; sourceTree = ""; }; + 1A7CC33B16257DF5006B3D18 /* MoonWarriors.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MoonWarriors.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 1A7CC33F16257DF6006B3D18 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + 1A7CC34116257DF6006B3D18 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; + 1A7CC34316257DF6006B3D18 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; }; + 1A7CC34516257DF6006B3D18 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; + 1A7CC34716257DF6006B3D18 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; + 1A7CC34916257DF6006B3D18 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 1A7CC34B16257DF6006B3D18 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 1A7CC34D16257DF6006B3D18 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + 1A7CC71516257E74006B3D18 /* cocos2dx.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cocos2dx.xcodeproj; path = ../../../cocos2dx/proj.ios/cocos2dx.xcodeproj; sourceTree = ""; }; + 1A7CC71F16258056006B3D18 /* AppDelegate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppDelegate.cpp; sourceTree = ""; }; + 1A7CC72016258056006B3D18 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 1A7CC72316258081006B3D18 /* AppController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppController.h; sourceTree = ""; }; + 1A7CC72416258081006B3D18 /* AppController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AppController.mm; sourceTree = ""; }; + 1A7CC72516258081006B3D18 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 1A7CC72616258081006B3D18 /* RootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = ""; }; + 1A7CC72716258081006B3D18 /* RootViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RootViewController.mm; sourceTree = ""; }; + 1A7CC75D16258252006B3D18 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 1A7CC75E16258252006B3D18 /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = ""; }; + 1A7CC76016258283006B3D18 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; + 1A7CC76116258283006B3D18 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; + 1A7CC76216258283006B3D18 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; }; + 1A7CC76316258283006B3D18 /* Icon-57.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-57.png"; sourceTree = ""; }; + 1A7CC76416258283006B3D18 /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72.png"; sourceTree = ""; }; + 1A7CC76516258283006B3D18 /* Icon-114.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-114.png"; sourceTree = ""; }; + 1A7CC76616258283006B3D18 /* Icon-144.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-144.png"; sourceTree = ""; }; + 1A7CC76E16258754006B3D18 /* cocos2d_specifics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cocos2d_specifics.cpp; sourceTree = ""; }; + 1A7CC76F16258754006B3D18 /* cocos2d_specifics.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cocos2d_specifics.hpp; sourceTree = ""; }; + 1A7CC77116258754006B3D18 /* cocos2dx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cocos2dx.cpp; sourceTree = ""; }; + 1A7CC77216258754006B3D18 /* cocos2dx.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cocos2dx.hpp; sourceTree = ""; }; + 1A7CC77316258754006B3D18 /* cocos2dxapi.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = cocos2dxapi.js; sourceTree = ""; }; + 1A7CC77416258754006B3D18 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = ""; }; + 1A7CC77516258754006B3D18 /* js_bindings_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_config.h; sourceTree = ""; }; + 1A7CC77616258754006B3D18 /* js_manual_conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_manual_conversions.cpp; sourceTree = ""; }; + 1A7CC77716258754006B3D18 /* js_manual_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_manual_conversions.h; sourceTree = ""; }; + 1A7CC77816258754006B3D18 /* ScriptingCore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptingCore.cpp; sourceTree = ""; }; + 1A7CC77916258754006B3D18 /* ScriptingCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptingCore.h; sourceTree = ""; }; + 1A7CC77A16258754006B3D18 /* spidermonkey_specifics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = spidermonkey_specifics.h; sourceTree = ""; }; + 1A7CC77B16258754006B3D18 /* uthash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uthash.h; sourceTree = ""; }; + 1A7CC78516258828006B3D18 /* Export.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Export.h; sourceTree = ""; }; + 1A7CC78616258828006B3D18 /* SimpleAudioEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleAudioEngine.h; sourceTree = ""; }; + 1A7CC78816258828006B3D18 /* CDAudioManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDAudioManager.h; sourceTree = ""; }; + 1A7CC78916258828006B3D18 /* CDAudioManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDAudioManager.m; sourceTree = ""; }; + 1A7CC78A16258828006B3D18 /* CDConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDConfig.h; sourceTree = ""; }; + 1A7CC78B16258828006B3D18 /* CDOpenALSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDOpenALSupport.h; sourceTree = ""; }; + 1A7CC78C16258828006B3D18 /* CDOpenALSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDOpenALSupport.m; sourceTree = ""; }; + 1A7CC78D16258828006B3D18 /* CocosDenshion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocosDenshion.h; sourceTree = ""; }; + 1A7CC78E16258828006B3D18 /* CocosDenshion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocosDenshion.m; sourceTree = ""; }; + 1A7CC78F16258828006B3D18 /* SimpleAudioEngine.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SimpleAudioEngine.mm; sourceTree = ""; }; + 1A7CC79016258828006B3D18 /* SimpleAudioEngine_objc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleAudioEngine_objc.h; sourceTree = ""; }; + 1A7CC79116258828006B3D18 /* SimpleAudioEngine_objc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SimpleAudioEngine_objc.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 1A7CC33816257DF5006B3D18 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A7CC782162587E0006B3D18 /* libcocos2dx.a in Frameworks */, + 1A7CC34016257DF6006B3D18 /* QuartzCore.framework in Frameworks */, + 1A7CC34216257DF6006B3D18 /* OpenGLES.framework in Frameworks */, + 1A7CC34416257DF6006B3D18 /* OpenAL.framework in Frameworks */, + 1A7CC34616257DF6006B3D18 /* AudioToolbox.framework in Frameworks */, + 1A7CC34816257DF6006B3D18 /* AVFoundation.framework in Frameworks */, + 1A7CC34A16257DF6006B3D18 /* UIKit.framework in Frameworks */, + 1A7CC34C16257DF6006B3D18 /* Foundation.framework in Frameworks */, + 1A7CC34E16257DF6006B3D18 /* CoreGraphics.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 1A7CC33016257DF5006B3D18 = { + isa = PBXGroup; + children = ( + 1A7CC71516257E74006B3D18 /* cocos2dx.xcodeproj */, + 1A7CC732162580F9006B3D18 /* bindings */, + 1A7CC71E16258056006B3D18 /* Classes */, + 1A7CC78316258819006B3D18 /* CocosDenshion */, + 1A7CC33E16257DF5006B3D18 /* Frameworks */, + 1A7CC7221625806F006B3D18 /* ios */, + 1A7CC33C16257DF5006B3D18 /* Products */, + 1A7CC72B162580AD006B3D18 /* Resources */, + ); + sourceTree = ""; + }; + 1A7CC33C16257DF5006B3D18 /* Products */ = { + isa = PBXGroup; + children = ( + 1A7CC33B16257DF5006B3D18 /* MoonWarriors.app */, + ); + name = Products; + sourceTree = ""; + }; + 1A7CC33E16257DF5006B3D18 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 1A7CC33F16257DF6006B3D18 /* QuartzCore.framework */, + 1A7CC34116257DF6006B3D18 /* OpenGLES.framework */, + 1A7CC34316257DF6006B3D18 /* OpenAL.framework */, + 1A7CC34516257DF6006B3D18 /* AudioToolbox.framework */, + 1A7CC34716257DF6006B3D18 /* AVFoundation.framework */, + 1A7CC34916257DF6006B3D18 /* UIKit.framework */, + 1A7CC34B16257DF6006B3D18 /* Foundation.framework */, + 1A7CC34D16257DF6006B3D18 /* CoreGraphics.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 1A7CC71616257E74006B3D18 /* Products */ = { + isa = PBXGroup; + children = ( + 1A7CC71D16257E75006B3D18 /* libcocos2dx.a */, + ); + name = Products; + sourceTree = ""; + }; + 1A7CC71E16258056006B3D18 /* Classes */ = { + isa = PBXGroup; + children = ( + 1A7CC71F16258056006B3D18 /* AppDelegate.cpp */, + 1A7CC72016258056006B3D18 /* AppDelegate.h */, + ); + name = Classes; + path = ../Classes; + sourceTree = ""; + }; + 1A7CC7221625806F006B3D18 /* ios */ = { + isa = PBXGroup; + children = ( + 1A7CC75D16258252006B3D18 /* Info.plist */, + 1A7CC75E16258252006B3D18 /* Prefix.pch */, + 1A7CC72316258081006B3D18 /* AppController.h */, + 1A7CC72416258081006B3D18 /* AppController.mm */, + 1A7CC72516258081006B3D18 /* main.m */, + 1A7CC72616258081006B3D18 /* RootViewController.h */, + 1A7CC72716258081006B3D18 /* RootViewController.mm */, + ); + name = ios; + sourceTree = ""; + }; + 1A7CC72B162580AD006B3D18 /* Resources */ = { + isa = PBXGroup; + children = ( + 1A1D97401625AFB400D5E31D /* js */, + 1A1D97411625AFB400D5E31D /* res */, + 1A7CC76016258283006B3D18 /* Default-568h@2x.png */, + 1A7CC76116258283006B3D18 /* Default.png */, + 1A7CC76216258283006B3D18 /* Default@2x.png */, + 1A7CC76316258283006B3D18 /* Icon-57.png */, + 1A7CC76416258283006B3D18 /* Icon-72.png */, + 1A7CC76516258283006B3D18 /* Icon-114.png */, + 1A7CC76616258283006B3D18 /* Icon-144.png */, + ); + name = Resources; + sourceTree = ""; + }; + 1A7CC732162580F9006B3D18 /* bindings */ = { + isa = PBXGroup; + children = ( + 1A7CC76E16258754006B3D18 /* cocos2d_specifics.cpp */, + 1A7CC76F16258754006B3D18 /* cocos2d_specifics.hpp */, + 1A7CC77016258754006B3D18 /* generated */, + 1A7CC77516258754006B3D18 /* js_bindings_config.h */, + 1A7CC77616258754006B3D18 /* js_manual_conversions.cpp */, + 1A7CC77716258754006B3D18 /* js_manual_conversions.h */, + 1A7CC77816258754006B3D18 /* ScriptingCore.cpp */, + 1A7CC77916258754006B3D18 /* ScriptingCore.h */, + 1A7CC77A16258754006B3D18 /* spidermonkey_specifics.h */, + 1A7CC77B16258754006B3D18 /* uthash.h */, + ); + name = bindings; + path = ../../../scripting/javascript/bindings; + sourceTree = ""; + }; + 1A7CC77016258754006B3D18 /* generated */ = { + isa = PBXGroup; + children = ( + 1A7CC77116258754006B3D18 /* cocos2dx.cpp */, + 1A7CC77216258754006B3D18 /* cocos2dx.hpp */, + 1A7CC77316258754006B3D18 /* cocos2dxapi.js */, + 1A7CC77416258754006B3D18 /* README */, + ); + path = generated; + sourceTree = ""; + }; + 1A7CC78316258819006B3D18 /* CocosDenshion */ = { + isa = PBXGroup; + children = ( + 1A7CC78416258828006B3D18 /* include */, + 1A7CC78716258828006B3D18 /* ios */, + ); + name = CocosDenshion; + sourceTree = ""; + }; + 1A7CC78416258828006B3D18 /* include */ = { + isa = PBXGroup; + children = ( + 1A7CC78516258828006B3D18 /* Export.h */, + 1A7CC78616258828006B3D18 /* SimpleAudioEngine.h */, + ); + name = include; + path = ../../../CocosDenshion/include; + sourceTree = ""; + }; + 1A7CC78716258828006B3D18 /* ios */ = { + isa = PBXGroup; + children = ( + 1A7CC78816258828006B3D18 /* CDAudioManager.h */, + 1A7CC78916258828006B3D18 /* CDAudioManager.m */, + 1A7CC78A16258828006B3D18 /* CDConfig.h */, + 1A7CC78B16258828006B3D18 /* CDOpenALSupport.h */, + 1A7CC78C16258828006B3D18 /* CDOpenALSupport.m */, + 1A7CC78D16258828006B3D18 /* CocosDenshion.h */, + 1A7CC78E16258828006B3D18 /* CocosDenshion.m */, + 1A7CC78F16258828006B3D18 /* SimpleAudioEngine.mm */, + 1A7CC79016258828006B3D18 /* SimpleAudioEngine_objc.h */, + 1A7CC79116258828006B3D18 /* SimpleAudioEngine_objc.m */, + ); + name = ios; + path = ../../../CocosDenshion/ios; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 1A7CC33A16257DF5006B3D18 /* MoonWarriors */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A7CC70D16257E02006B3D18 /* Build configuration list for PBXNativeTarget "MoonWarriors" */; + buildPhases = ( + 1A7CC33716257DF5006B3D18 /* Sources */, + 1A7CC33816257DF5006B3D18 /* Frameworks */, + 1A7CC33916257DF5006B3D18 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 1A7CC731162580CE006B3D18 /* PBXTargetDependency */, + ); + name = MoonWarriors; + productName = MoonWarriors; + productReference = 1A7CC33B16257DF5006B3D18 /* MoonWarriors.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 1A7CC33216257DF5006B3D18 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0450; + }; + buildConfigurationList = 1A7CC33516257DF5006B3D18 /* Build configuration list for PBXProject "MoonWarriors" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 1A7CC33016257DF5006B3D18; + productRefGroup = 1A7CC33C16257DF5006B3D18 /* Products */; + projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 1A7CC71616257E74006B3D18 /* Products */; + ProjectRef = 1A7CC71516257E74006B3D18 /* cocos2dx.xcodeproj */; + }, + ); + projectRoot = ""; + targets = ( + 1A7CC33A16257DF5006B3D18 /* MoonWarriors */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXReferenceProxy section */ + 1A7CC71D16257E75006B3D18 /* libcocos2dx.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libcocos2dx.a; + remoteRef = 1A7CC71C16257E75006B3D18 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + +/* Begin PBXResourcesBuildPhase section */ + 1A7CC33916257DF5006B3D18 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A7CC75F16258252006B3D18 /* Info.plist in Resources */, + 1A7CC76716258283006B3D18 /* Default-568h@2x.png in Resources */, + 1A7CC76816258283006B3D18 /* Default.png in Resources */, + 1A7CC76916258283006B3D18 /* Default@2x.png in Resources */, + 1A7CC76A16258283006B3D18 /* Icon-57.png in Resources */, + 1A7CC76B16258283006B3D18 /* Icon-72.png in Resources */, + 1A7CC76C16258283006B3D18 /* Icon-114.png in Resources */, + 1A7CC76D16258283006B3D18 /* Icon-144.png in Resources */, + 1A7CC77F16258754006B3D18 /* README in Resources */, + 1A1D97421625AFB400D5E31D /* js in Resources */, + 1A1D97431625AFB400D5E31D /* res in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 1A7CC33716257DF5006B3D18 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A7CC72116258056006B3D18 /* AppDelegate.cpp in Sources */, + 1A7CC72816258081006B3D18 /* AppController.mm in Sources */, + 1A7CC72916258081006B3D18 /* main.m in Sources */, + 1A7CC72A16258081006B3D18 /* RootViewController.mm in Sources */, + 1A7CC77C16258754006B3D18 /* cocos2d_specifics.cpp in Sources */, + 1A7CC77D16258754006B3D18 /* cocos2dx.cpp in Sources */, + 1A7CC77E16258754006B3D18 /* cocos2dxapi.js in Sources */, + 1A7CC78016258754006B3D18 /* js_manual_conversions.cpp in Sources */, + 1A7CC78116258754006B3D18 /* ScriptingCore.cpp in Sources */, + 1A7CC79216258828006B3D18 /* CDAudioManager.m in Sources */, + 1A7CC79316258828006B3D18 /* CDOpenALSupport.m in Sources */, + 1A7CC79416258828006B3D18 /* CocosDenshion.m in Sources */, + 1A7CC79516258828006B3D18 /* SimpleAudioEngine.mm in Sources */, + 1A7CC79616258828006B3D18 /* SimpleAudioEngine_objc.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 1A7CC731162580CE006B3D18 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = cocos2dx; + targetProxy = 1A7CC730162580CE006B3D18 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 1A7CC70B16257E02006B3D18 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + DEBUG, + "COCOS2D_DEBUG=1", + USE_FILE32API, + TARGET_OS_IPHONE, + COCOS2D_JAVASCRIPT, + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "\"$(PROJECT_NAME)/libs/cocos2dx/kazmath/include\"", + "\"$(PROJECT_NAME)/libs/cocos2dx\"", + "\"$(PROJECT_NAME)/libs/CocosDenshion/include\"", + "\"$(SDKROOT)/usr/include/libxml2\"", + "\"$(PROJECT_NAME)/libs/cocos2dx/include\"", + "\"$(PROJECT_NAME)/libs/cocos2dx/platform/third_party/ios\"", + "\"$(PROJECT_NAME)/libs/cocos2dx/platform/ios\"", + ); + IPHONEOS_DEPLOYMENT_TARGET = 6.0; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 1A7CC70C16257E02006B3D18 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_PREPROCESSOR_DEFINITIONS = ( + NDEBUG, + USE_FILE32API, + TARGET_OS_IPHONE, + COCOS2D_JAVASCRIPT, + ); + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "\"$(PROJECT_NAME)/libs/cocos2dx/kazmath/include\"", + "\"$(PROJECT_NAME)/libs/cocos2dx\"", + "\"$(PROJECT_NAME)/libs/CocosDenshion/include\"", + "\"$(SDKROOT)/usr/include/libxml2\"", + "\"$(PROJECT_NAME)/libs/cocos2dx/include\"", + "\"$(PROJECT_NAME)/libs/cocos2dx/platform/third_party/ios\"", + "\"$(PROJECT_NAME)/libs/cocos2dx/platform/ios\"", + ); + IPHONEOS_DEPLOYMENT_TARGET = 6.0; + OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; + SDKROOT = iphoneos; + }; + name = Release; + }; + 1A7CC70E16257E02006B3D18 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_DYNAMIC_NO_PIC = NO; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = Prefix.pch; + "GCC_THUMB_SUPPORT[arch=armv6]" = ""; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)/../../../cocos2dx/kazmath/include\"", + "\"$(SRCROOT)/../../../cocos2dx\"", + "\"$(SRCROOT)/../../../CocosDenshion/include\"", + "\"$(SDKROOT)/usr/include/libxml2\"", + "\"$(SRCROOT)/../../../cocos2dx/include\"", + "\"$(SRCROOT)/../../../cocos2dx/platform/third_party/ios\"", + "\"$(SRCROOT)/../../../cocos2dx/platform/ios\"", + "$(SRCROOT)/../../../scripting/javascript/spidermonkey-ios/include", + "$(SRCROOT)/../../../scripting/javascript/bindings", + ); + INFOPLIST_FILE = Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../scripting/javascript/spidermonkey-ios/lib\""; + OTHER_LDFLAGS = ( + "-lxml2", + "-lz", + "-ljs_static", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + USER_HEADER_SEARCH_PATHS = ""; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + 1A7CC70F16257E02006B3D18 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = Prefix.pch; + "GCC_THUMB_SUPPORT[arch=armv6]" = ""; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)/../../../cocos2dx/kazmath/include\"", + "\"$(SRCROOT)/../../../cocos2dx\"", + "\"$(SRCROOT)/../../../CocosDenshion/include\"", + "\"$(SDKROOT)/usr/include/libxml2\"", + "\"$(SRCROOT)/../../../cocos2dx/include\"", + "\"$(SRCROOT)/../../../cocos2dx/platform/third_party/ios\"", + "\"$(SRCROOT)/../../../cocos2dx/platform/ios\"", + "$(SRCROOT)/../../../scripting/javascript/spidermonkey-ios/include", + "$(SRCROOT)/../../../scripting/javascript/bindings", + ); + INFOPLIST_FILE = Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../scripting/javascript/spidermonkey-ios/lib\""; + OTHER_LDFLAGS = ( + "-lxml2", + "-lz", + "-ljs_static", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + USER_HEADER_SEARCH_PATHS = ""; + VALIDATE_PRODUCT = YES; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1A7CC33516257DF5006B3D18 /* Build configuration list for PBXProject "MoonWarriors" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A7CC70B16257E02006B3D18 /* Debug */, + 1A7CC70C16257E02006B3D18 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1A7CC70D16257E02006B3D18 /* Build configuration list for PBXNativeTarget "MoonWarriors" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A7CC70E16257E02006B3D18 /* Debug */, + 1A7CC70F16257E02006B3D18 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 1A7CC33216257DF5006B3D18 /* Project object */; +} diff --git a/samples/MoonWarriors/proj.ios/Prefix.pch b/samples/MoonWarriors/proj.ios/Prefix.pch new file mode 100644 index 0000000000..b056d8694a --- /dev/null +++ b/samples/MoonWarriors/proj.ios/Prefix.pch @@ -0,0 +1,8 @@ +// +// Prefix header for all source files of the 'testjs' target in the 'testjs' project +// + +#ifdef __OBJC__ + #import + #import +#endif diff --git a/samples/MoonWarriors/proj.ios/RootViewController.h b/samples/MoonWarriors/proj.ios/RootViewController.h new file mode 100644 index 0000000000..a40c2edd28 --- /dev/null +++ b/samples/MoonWarriors/proj.ios/RootViewController.h @@ -0,0 +1,33 @@ +/**************************************************************************** + Copyright (c) 2010-2011 cocos2d-x.org + Copyright (c) 2010 Ricardo Quesada + + 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. + ****************************************************************************/ + +#import + + +@interface RootViewController : UIViewController { + +} + +@end diff --git a/samples/MoonWarriors/proj.ios/RootViewController.mm b/samples/MoonWarriors/proj.ios/RootViewController.mm new file mode 100644 index 0000000000..7a0d59ccc9 --- /dev/null +++ b/samples/MoonWarriors/proj.ios/RootViewController.mm @@ -0,0 +1,73 @@ +// +// testjsAppController.h +// testjs +// +// Created by Rolando Abarca on 3/19/12. +// Copyright __MyCompanyName__ 2012. All rights reserved. +// + +#import "RootViewController.h" + + +@implementation RootViewController + +/* + // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { + // Custom initialization + } + return self; +} +*/ + +/* +// Implement loadView to create a view hierarchy programmatically, without using a nib. +- (void)loadView { +} +*/ + +/* +// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. +- (void)viewDidLoad { + [super viewDidLoad]; +} + +*/ +// Override to allow orientations other than the default portrait orientation. +// This method is deprecated on ios6 +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + return UIInterfaceOrientationIsLandscape( interfaceOrientation ); +} + +// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead +- (NSUInteger) supportedInterfaceOrientations{ +#ifdef __IPHONE_6_0 + return UIInterfaceOrientationMaskAllButUpsideDown; +#endif +} + +- (BOOL) shouldAutorotate { + return YES; +} + +- (void)didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Release any cached data, images, etc that aren't in use. +} + +- (void)viewDidUnload { + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end diff --git a/samples/MoonWarriors/proj.ios/main.m b/samples/MoonWarriors/proj.ios/main.m new file mode 100644 index 0000000000..e3dedca28b --- /dev/null +++ b/samples/MoonWarriors/proj.ios/main.m @@ -0,0 +1,17 @@ +// +// main.m +// testjs +// +// Created by Rolando Abarca on 3/19/12. +// Copyright __MyCompanyName__ 2012. All rights reserved. +// + +#import + +int main(int argc, char *argv[]) { + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); + [pool release]; + return retVal; +} diff --git a/samples/MoonWarriors/proj.win32/MoonWarriors.vcproj b/samples/MoonWarriors/proj.win32/MoonWarriors.vcproj new file mode 100644 index 0000000000..ea77235a92 --- /dev/null +++ b/samples/MoonWarriors/proj.win32/MoonWarriors.vcproj @@ -0,0 +1,295 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/MoonWarriors/proj.win32/MoonWarriors.vcproj.user b/samples/MoonWarriors/proj.win32/MoonWarriors.vcproj.user new file mode 100644 index 0000000000..eb4c2b142b --- /dev/null +++ b/samples/MoonWarriors/proj.win32/MoonWarriors.vcproj.user @@ -0,0 +1,23 @@ + + + + + + + + + + + diff --git a/samples/MoonWarriors/proj.win32/MoonWarriors.vcxproj b/samples/MoonWarriors/proj.win32/MoonWarriors.vcxproj new file mode 100644 index 0000000000..49e05c3542 --- /dev/null +++ b/samples/MoonWarriors/proj.win32/MoonWarriors.vcxproj @@ -0,0 +1,178 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {1DB7C0FC-46FF-4A1B-82E0-C6244EEEC4C2} + MoonWarriors + + + + Application + Unicode + + + Application + Unicode + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + $(SolutionDir)$(Configuration).win32\ + $(Configuration).win32\ + false + $(SolutionDir)$(Configuration).win32\ + $(Configuration).win32\ + false + AllRules.ruleset + + + AllRules.ruleset + + + + + + _DEBUG;%(PreprocessorDefinitions) + false + Win32 + true + $(IntDir)testjs.tlb + testjs.h + + + testjs_i.c + testjs_p.c + + + Disabled + .;..\Classes;$(SolutionDir)scripting\javascript\spidermonkey-win32\include;$(SolutionDir)external\chipmunk\include\chipmunk;$(SolutionDir)scripting\javascript\bindings;$(SolutionDir)extensions;$(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)CocosDenshion\include;%(AdditionalIncludeDirectories) + WIN32;_WINDOWS;STRICT;_DEBUG;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + EditAndContinue + 4267;4251;4244;%(DisableSpecificWarnings) + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + + + if not exist "$(OutDir)" mkdir "$(OutDir)" +xcopy /Y /Q "$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)" + + + + libcocos2d.lib;libExtensions.lib;opengl32.lib;glew32.lib;libCocosDenshion.lib;libchipmunk.lib;mozjs.lib;%(AdditionalDependencies) + $(OutDir);%(AdditionalLibraryDirectories) + true + Windows + MachineX86 + + + + + NDEBUG;%(PreprocessorDefinitions) + false + Win32 + true + $(IntDir)testjs.tlb + testjs.h + + + testjs_i.c + testjs_p.c + + + .;..\Classes;$(SolutionDir)scripting\javascript\spidermonkey-win32\include;$(SolutionDir)external\chipmunk\include\chipmunk;$(SolutionDir)scripting\javascript\bindings;$(SolutionDir)extensions;$(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)CocosDenshion\include;%(AdditionalIncludeDirectories) + WIN32;_WINDOWS;STRICT;NDEBUG;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + MultiThreadedDLL + + + Level3 + + + 4267;4251;4244;%(DisableSpecificWarnings) + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + + + if not exist "$(OutDir)" mkdir "$(OutDir)" +xcopy /Y /Q "$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)" + + + + libcocos2d.lib;libExtensions.lib;opengl32.lib;glew32.lib;libCocosDenshion.lib;libchipmunk.lib;mozjs.lib;%(AdditionalDependencies) + $(OutDir);%(AdditionalLibraryDirectories) + Windows + MachineX86 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {98a51ba8-fc3a-415b-ac8f-8c7bd464e93e} + false + + + {f8edd7fa-9a51-4e80-baeb-860825d2eac6} + false + + + + + + \ No newline at end of file diff --git a/samples/MoonWarriors/proj.win32/MoonWarriors.vcxproj.filters b/samples/MoonWarriors/proj.win32/MoonWarriors.vcxproj.filters new file mode 100644 index 0000000000..37fdd0783f --- /dev/null +++ b/samples/MoonWarriors/proj.win32/MoonWarriors.vcxproj.filters @@ -0,0 +1,86 @@ + + + + + {58ebb5df-595d-4e27-8c01-555be6f1c625} + + + {ca9c9e15-d942-43a1-aa7a-5f0b74ca1afd} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;jpg;jpeg;jpe;png;manifest + + + {ccb2323b-1cfa-41ea-bcf4-ba5f07309396} + + + {e93a77e1-af1e-4400-87d3-504b62ebdbb0} + + + {146f26cf-13e1-4106-891b-4b0118ceac2b} + + + + + win32 + + + Classes + + + bindings + + + bindings + + + bindings + + + bindings + + + bindings\generated + + + + + win32 + + + win32 + + + Classes + + + bindings + + + bindings + + + bindings + + + bindings + + + bindings + + + bindings + + + bindings\generated + + + + + resource + + + + + resource + + + \ No newline at end of file diff --git a/samples/MoonWarriors/proj.win32/MoonWarriors.vcxproj.user b/samples/MoonWarriors/proj.win32/MoonWarriors.vcxproj.user new file mode 100644 index 0000000000..314a27ae4d --- /dev/null +++ b/samples/MoonWarriors/proj.win32/MoonWarriors.vcxproj.user @@ -0,0 +1,11 @@ + + + + $(ProjectDir)..\Resources + WindowsLocalDebugger + + + $(ProjectDir)..\Resources + WindowsLocalDebugger + + \ No newline at end of file diff --git a/samples/MoonWarriors/proj.win32/main.cpp b/samples/MoonWarriors/proj.win32/main.cpp new file mode 100644 index 0000000000..6a84a0be6e --- /dev/null +++ b/samples/MoonWarriors/proj.win32/main.cpp @@ -0,0 +1,37 @@ +#include "main.h" +#include "AppDelegate.h" +#include "CCEGLView.h" + +USING_NS_CC; + +// uncomment below line, open debug console +// #define USE_WIN32_CONSOLE + +int APIENTRY _tWinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPTSTR lpCmdLine, + int nCmdShow) +{ + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); + +#ifdef USE_WIN32_CONSOLE + AllocConsole(); + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); +#endif + + // create the application instance + AppDelegate app; + CCEGLView* eglView = CCEGLView::sharedOpenGLView(); + eglView->setFrameSize(320, 480); + + int ret = CCApplication::sharedApplication()->run(); + +#ifdef USE_WIN32_CONSOLE + FreeConsole(); +#endif + + return ret; +} diff --git a/samples/MoonWarriors/proj.win32/main.h b/samples/MoonWarriors/proj.win32/main.h new file mode 100644 index 0000000000..abe1c3a007 --- /dev/null +++ b/samples/MoonWarriors/proj.win32/main.h @@ -0,0 +1,13 @@ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + +// Windows Header Files: +#include +#include + +// C RunTime Header Files +#include "CCStdC.h" + +#endif // __WINMAIN_H__ diff --git a/samples/MoonWarriors/proj.win32/res/testjs.ico b/samples/MoonWarriors/proj.win32/res/testjs.ico new file mode 100644 index 0000000000..feaf932a74 Binary files /dev/null and b/samples/MoonWarriors/proj.win32/res/testjs.ico differ diff --git a/samples/MoonWarriors/proj.win32/resource.h b/samples/MoonWarriors/proj.win32/resource.h new file mode 100644 index 0000000000..a4cfa38af8 --- /dev/null +++ b/samples/MoonWarriors/proj.win32/resource.h @@ -0,0 +1,20 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by testjs.RC +// + +#define IDS_PROJNAME 100 +#define IDR_TESTJS 100 + +#define ID_FILE_NEW_WINDOW 32771 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 201 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 32775 +#endif +#endif diff --git a/samples/MoonWarriors/proj.win32/testjs.rc b/samples/MoonWarriors/proj.win32/testjs.rc new file mode 100644 index 0000000000..bf10c0e6f0 --- /dev/null +++ b/samples/MoonWarriors/proj.win32/testjs.rc @@ -0,0 +1,86 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#define APSTUDIO_HIDDEN_SYMBOLS +#include "windows.h" +#undef APSTUDIO_HIDDEN_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDR_MAINFRAME ICON "res\\testjs.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904B0" + BEGIN + VALUE "CompanyName", "\0" + VALUE "FileDescription", "testjs Module\0" + VALUE "FileVersion", "1, 0, 0, 1\0" + VALUE "InternalName", "testjs\0" + VALUE "LegalCopyright", "Copyright \0" + VALUE "OriginalFilename", "testjs.exe\0" + VALUE "ProductName", "testjs Module\0" + VALUE "ProductVersion", "1, 0, 0, 1\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 0x04B0 + END +END + +///////////////////////////////////////////////////////////////////////////// +#endif // !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) diff --git a/scripting/javascript/bindings/ScriptingCore.cpp b/scripting/javascript/bindings/ScriptingCore.cpp index b4c6878578..17433f47c1 100644 --- a/scripting/javascript/bindings/ScriptingCore.cpp +++ b/scripting/javascript/bindings/ScriptingCore.cpp @@ -165,10 +165,102 @@ void js_log(const char *format, ...) { } } +#define JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES 1 + +void jsb_register_cocos2d_config( JSContext *_cx, JSObject *cocos2d) +{ + // Config Object + JSObject *ccconfig = JS_NewObject(_cx, NULL, NULL, NULL); + // config.os: The Operating system + // osx, ios, android, windows, linux, etc.. +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + JSString *str = JS_InternString(_cx, "ios"); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + JSString *str = JS_InternString(_cx, "android"); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + JSString *str = JS_InternString(_cx, "windows"); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) + JSString *str = JS_InternString(_cx, "marmalade"); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) + JSString *str = JS_InternString(_cx, "linux"); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_BADA) + JSString *str = JS_InternString(_cx, "bada"); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY) + JSString *str = JS_InternString(_cx, "blackberry"); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) + JSString *str = JS_InternString(_cx, "osx"); +#else + JSString *str = JS_InternString(_cx, "unknown"); +#endif + JS_DefineProperty(_cx, ccconfig, "os", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + + // config.deviceType: Device Type + // 'mobile' for any kind of mobile devices, 'desktop' for PCs, 'browser' for Web Browsers +// #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) +// str = JS_InternString(_cx, "desktop"); +// #else + str = JS_InternString(_cx, "mobile"); +// #endif + JS_DefineProperty(_cx, ccconfig, "deviceType", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + + // config.engine: Type of renderer + // 'cocos2d', 'cocos2d-x', 'cocos2d-html5/canvas', 'cocos2d-html5/webgl', etc.. + str = JS_InternString(_cx, "cocos2d-x"); + JS_DefineProperty(_cx, ccconfig, "engine", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + + // config.arch: CPU Architecture + // i386, ARM, x86_64, web +#ifdef __LP64__ + str = JS_InternString(_cx, "x86_64"); +#elif defined(__arm__) || defined(__ARM_NEON__) + str = JS_InternString(_cx, "arm"); +#else + str = JS_InternString(_cx, "i386"); +#endif + JS_DefineProperty(_cx, ccconfig, "arch", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + + // config.version: Version of cocos2d + renderer + str = JS_InternString(_cx, cocos2dVersion() ); + JS_DefineProperty(_cx, ccconfig, "version", STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + + // config.usesTypedArrays +#if JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES + JSBool b = JS_FALSE; +#else + JSBool b = JS_TRUE; +#endif + JS_DefineProperty(_cx, ccconfig, "usesTypedArrays", BOOLEAN_TO_JSVAL(b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + + // config.debug: Debug build ? +#if COCOS2D_DEBUG > 0 + b = JS_TRUE; +#else + b = JS_FALSE; +#endif + JS_DefineProperty(_cx, ccconfig, "debug", BOOLEAN_TO_JSVAL(b), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + + + // Add "config" to "cc" + JS_DefineProperty(_cx, cocos2d, "config", OBJECT_TO_JSVAL(ccconfig), NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); +} + void registerDefaultClasses(JSContext* cx, JSObject* global) { if (!JS_InitStandardClasses(cx, global)) { js_log("error initializing the standard classes"); } + // first, try to get the ns + jsval nsval; + JSObject *ns; + JS_GetProperty(cx, global, "cc", &nsval); + if (nsval == JSVAL_VOID) { + ns = JS_NewObject(cx, NULL, NULL, NULL); + nsval = OBJECT_TO_JSVAL(ns); + JS_SetProperty(cx, global, "cc", &nsval); + } else { + JS_ValueToObject(cx, nsval, &ns); + } + + jsb_register_cocos2d_config(cx, ns); // // Javascript controller (__jsc__) @@ -462,6 +554,29 @@ JSBool ScriptingCore::removeRootJS(JSContext *cx, uint32_t argc, jsval *vp) return JS_FALSE; } +void ScriptingCore::pauseSchedulesAndActions(CCNode *node) { + + CCArray * arr = JSSchedule::getTargetForNativeNode(node); + if(! arr) return; + for(unsigned int i = 0; i < arr->count(); ++i) { + if(arr->objectAtIndex(i)) { + node->getScheduler()->pauseTarget(arr->objectAtIndex(i)); + } + } +} + + +void ScriptingCore::resumeSchedulesAndActions(CCNode *node) { + + CCArray * arr = JSSchedule::getTargetForNativeNode(node); + if(!arr) return; + for(unsigned int i = 0; i < arr->count(); ++i) { + if(!arr->objectAtIndex(i)) continue; + node->getScheduler()->resumeTarget(arr->objectAtIndex(i)); + } +} + + int ScriptingCore::executeNodeEvent(CCNode* pNode, int nAction) { js_proxy_t * p; @@ -477,10 +592,12 @@ int ScriptingCore::executeNodeEvent(CCNode* pNode, int nAction) if(nAction == kCCNodeOnEnter) { executeJSFunctionWithName(this->cx, p->obj, "onEnter", dataVal, retval); + resumeSchedulesAndActions(pNode); } else if(nAction == kCCNodeOnExit) { executeJSFunctionWithName(this->cx, p->obj, "onExit", dataVal, retval); + pauseSchedulesAndActions(pNode); } else if(nAction == kCCNodeOnEnterTransitionDidFinish) { diff --git a/scripting/javascript/bindings/ScriptingCore.h b/scripting/javascript/bindings/ScriptingCore.h index b3cc01dfe3..4cf47360cf 100644 --- a/scripting/javascript/bindings/ScriptingCore.h +++ b/scripting/javascript/bindings/ScriptingCore.h @@ -57,6 +57,8 @@ public: @return other if the string is excuted wrongly. */ virtual int executeString(const char* codes) { return 0; } + void pauseSchedulesAndActions(CCNode *node); + void resumeSchedulesAndActions(CCNode *node); /** @brief Execute a script file. diff --git a/scripting/javascript/bindings/cocos2d_specifics.cpp b/scripting/javascript/bindings/cocos2d_specifics.cpp index db3e0ec738..51ec52efaf 100644 --- a/scripting/javascript/bindings/cocos2d_specifics.cpp +++ b/scripting/javascript/bindings/cocos2d_specifics.cpp @@ -2,6 +2,9 @@ #include "cocos2d_specifics.hpp" #include +schedFunc_proxy_t *_schedFunc_target_ht = NULL; +schedTarget_proxy_t *_schedTarget_native_ht = NULL; + void JSTouchDelegate::setJSObject(JSObject *obj) { _mObj = obj; } @@ -389,20 +392,20 @@ JSBool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp) if (argc > 0) { arg0 = jsval_to_ccarray(cx, argv[0]); } - cocos2d::CCAnimation* ret; + cocos2d::CCAnimation* ret = NULL; double arg1 = 0.0f; if (argc > 0 && argc == 2) { if (argc == 2) { JS_ValueToNumber(cx, argv[1], &arg1); } - ret = cocos2d::CCAnimation::create(arg0, arg1); - } else if (argc > 0) { + ret = cocos2d::CCAnimation::createWithSpriteFrames(arg0, arg1); + } else if (argc == 3) { unsigned int loops; JS_ValueToNumber(cx, argv[1], &arg1); JS_ValueToECMAUint32(cx, argv[1], &loops); ret = cocos2d::CCAnimation::create(arg0, arg1, loops); - } else if (argc == 0) { - ret = cocos2d::CCAnimation::create(); + } else if (argc == 1) { + ret = cocos2d::CCAnimation::createWithSpriteFrames(arg0); } jsval jsret; if (ret) { @@ -567,6 +570,205 @@ JSBool js_callFunc(JSContext *cx, uint32_t argc, jsval *vp) return JS_TRUE; } + +void JSSchedule::setTargetForSchedule(jsval sched, JSSchedule *target) { + do { + schedFunc_proxy_t *p = (schedFunc_proxy_t *)malloc(sizeof(schedFunc_proxy_t)); + assert(p); + p->ptr = (void *)JSVAL_TO_OBJECT(sched); + p->obj = target; + HASH_ADD_PTR(_schedFunc_target_ht, ptr, p); + } while(0); +} + +JSSchedule * JSSchedule::getTargetForSchedule(jsval sched) { + schedFunc_proxy_t *t; + JSObject *o = JSVAL_TO_OBJECT(sched); + HASH_FIND_PTR(_schedFunc_target_ht, &o, t); + return t->obj; +} + + +void JSSchedule::setTargetForNativeNode(CCNode *pNode, JSSchedule *target) { + schedTarget_proxy_t *t; + HASH_FIND_PTR(_schedTarget_native_ht, &pNode, t); + + CCArray *arr; + if(!t) { + arr = new CCArray(); + } else { + arr = t->obj; + } + + arr->addObject(target); + + schedTarget_proxy_t *p = (schedTarget_proxy_t *)malloc(sizeof(schedTarget_proxy_t)); + assert(p); + p->ptr = (void *)pNode; + p->obj = arr; + HASH_ADD_PTR(_schedTarget_native_ht, ptr, p); +} + +CCArray * JSSchedule::getTargetForNativeNode(CCNode *pNode) { + + schedTarget_proxy_t *t; + HASH_FIND_PTR(_schedTarget_native_ht, &pNode, t); + if(!t) { + return NULL; + } + return t->obj; + +} + +void JSSchedule::setJSScheduleFunc(jsval func) { + jsSchedule = func; +} + +void JSSchedule::setJSScheduleThis(jsval thisObj) { + jsThisObj = thisObj; +} + + + +JSBool js_CCNode_unschedule(JSContext *cx, uint32_t argc, jsval *vp) +{ + + if (argc == 1) { + jsval *argv = JS_ARGV(cx, vp); + + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy; + JS_GET_NATIVE_PROXY(proxy, obj); + cocos2d::CCNode *node = (cocos2d::CCNode *)(proxy ? proxy->ptr : NULL); + + if(!node) return JS_FALSE; + + CCScheduler *sched = node->getScheduler(); + + JSSchedule *tmpCobj = JSSchedule::getTargetForSchedule(argv[0]); + + sched->unscheduleSelector(schedule_selector(JSSchedule::scheduleFunc), tmpCobj); + + JS_SET_RVAL(cx, vp, JSVAL_VOID); + } + return JS_TRUE; +} + + + +JSBool js_CCNode_scheduleOnce(JSContext *cx, uint32_t argc, jsval *vp) +{ + + if (argc >= 1) { + jsval *argv = JS_ARGV(cx, vp); + + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy; + JS_GET_NATIVE_PROXY(proxy, obj); + cocos2d::CCNode *node = (cocos2d::CCNode *)(proxy ? proxy->ptr : NULL); + + CCScheduler *sched = node->getScheduler(); + + JSSchedule *tmpCobj = new JSSchedule(); + + + // + // delay + // + double interval; + if( argc >= 2 ) { + if( ! JS_ValueToNumber(cx, argv[1], &interval ) ) + return JS_FALSE; + } + + tmpCobj->setJSScheduleThis(OBJECT_TO_JSVAL(obj)); + tmpCobj->setJSScheduleFunc(argv[0]); + + JSSchedule::setTargetForSchedule(argv[0], tmpCobj); + JSSchedule::setTargetForNativeNode(node, tmpCobj); + + if(argc == 1) { + sched->scheduleSelector(schedule_selector(JSSchedule::scheduleFunc), tmpCobj, 0, node->isRunning(), 0, 0); + } else { + sched->scheduleSelector(schedule_selector(JSSchedule::scheduleFunc), tmpCobj, interval, node->isRunning(), 0, 0); + } + + JS_SET_RVAL(cx, vp, JSVAL_VOID); + } + return JS_TRUE; +} + + + +JSBool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) +{ + + if (argc >= 1) { + jsval *argv = JS_ARGV(cx, vp); + + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy; + JS_GET_NATIVE_PROXY(proxy, obj); + cocos2d::CCNode *node = (cocos2d::CCNode *)(proxy ? proxy->ptr : NULL); + + CCScheduler *sched = node->getScheduler(); + + JSSchedule *tmpCobj = new JSSchedule(); + + double interval; + if( argc >= 2 ) { + if( ! JS_ValueToNumber(cx, argv[1], &interval ) ) + return JS_FALSE; + } + + // + // repeat + // + double repeat; + if( argc >= 3 ) { + if( ! JS_ValueToNumber(cx, argv[2], &repeat ) ) + return JS_FALSE; + } + + // + // delay + // + double delay; + if( argc >= 4 ) { + if( ! JS_ValueToNumber(cx, argv[3], &delay ) ) + return JS_FALSE; + } + + tmpCobj->setJSScheduleThis(OBJECT_TO_JSVAL(obj)); + tmpCobj->setJSScheduleFunc(argv[0]); + + JSSchedule::setTargetForSchedule(argv[0], tmpCobj); + JSSchedule::setTargetForNativeNode(node, tmpCobj); + + if(argc == 1) { + sched->scheduleSelector(schedule_selector(JSSchedule::scheduleFunc), tmpCobj, 0, node->isRunning()); + } if(argc == 2) { + sched->scheduleSelector(schedule_selector(JSSchedule::scheduleFunc), tmpCobj, interval, node->isRunning()); + } if(argc == 3) { + sched->scheduleSelector(schedule_selector(JSSchedule::scheduleFunc), tmpCobj, 0, node->isRunning(), repeat, 0); + } if (argc == 4) { + sched->scheduleSelector(schedule_selector(JSSchedule::scheduleFunc), tmpCobj, 0, node->isRunning(), repeat, delay); + + } + + JS_SET_RVAL(cx, vp, JSVAL_VOID); + } + return JS_TRUE; +} + + + +JSBool js_doNothing(JSContext *cx, uint32_t argc, jsval *vp) { + return JS_TRUE; +} + + + JSBool js_forceGC(JSContext *cx, uint32_t argc, jsval *vp) { JSRuntime *rt = JS_GetRuntime(cx); JS_GC(rt); @@ -632,6 +834,72 @@ extern JSObject* js_cocos2dx_CCAnimation_prototype; extern JSObject* js_cocos2dx_CCMenuItem_prototype; extern JSObject* js_cocos2dx_CCSpriteFrame_prototype; extern JSObject* js_cocos2dx_CCSet_prototype; +extern JSObject* js_cocos2dx_CCSprite_prototype; +extern JSObject* js_cocos2dx_CCSpriteBatchNode_prototype; +//extern JSObject* js_cocos2dx_CCMotionStreak_prototype; +extern JSObject* js_cocos2dx_CCAtlasNode_prototype; +extern JSObject* js_cocos2dx_CCParticleBatchNode_prototype; +extern JSObject* js_cocos2dx_CCLayerColor_prototype; +extern JSObject* js_cocos2dx_CCParticleSystem_prototype; + +// setBlendFunc +template +JSBool js_cocos2dx_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + JSObject *obj; + T* cobj; + obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj); + cobj = (T*)(proxy ? proxy->ptr : NULL); + TEST_NATIVE_OBJECT(cx, cobj) + if (argc == 2) + { + GLenum src, dst; + JS_ValueToInt32(cx, argv[0], (int32_t*)&src); + JS_ValueToInt32(cx, argv[1], (int32_t*)&dst); + ccBlendFunc blendFunc = {src, dst}; + cobj->setBlendFunc(blendFunc); + return JS_TRUE; + } + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); + return JS_FALSE; +} + +JSBool js_cocos2dx_CCSprite_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + return js_cocos2dx_setBlendFunc(cx, argc, vp); +} + +JSBool js_cocos2dx_CCSpriteBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + return js_cocos2dx_setBlendFunc(cx, argc, vp); +} + +// JSBool js_cocos2dx_CCMotionStreak_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +// { +// return js_cocos2dx_setBlendFunc(cx, argc, vp); +// } + +JSBool js_cocos2dx_CCAtlasNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + return js_cocos2dx_setBlendFunc(cx, argc, vp); +} + +JSBool js_cocos2dx_CCParticleBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + return js_cocos2dx_setBlendFunc(cx, argc, vp); +} + +JSBool js_cocos2dx_CCLayerColor_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + return js_cocos2dx_setBlendFunc(cx, argc, vp); +} + +JSBool js_cocos2dx_CCParticleSystem_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp) +{ + return js_cocos2dx_setBlendFunc(cx, argc, vp); +} void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global) { @@ -653,8 +921,22 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global) JSObject *tmpObj; JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "getChildren", js_cocos2dx_CCNode_getChildren, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "copy", js_cocos2dx_CCNode_copy, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "onExit", js_doNothing, 1, JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "onEnter", js_doNothing, 1, JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "schedule", js_CCNode_schedule, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "scheduleOnce", js_CCNode_scheduleOnce, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "unschedule", js_CCNode_unschedule, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "release", js_cocos2dx_release, 0, JSPROP_READONLY | JSPROP_PERMANENT); + + JS_DefineFunction(cx, js_cocos2dx_CCSprite_prototype, "setBlendFunc", js_cocos2dx_CCSprite_setBlendFunc, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCSpriteBatchNode_prototype, "setBlendFunc", js_cocos2dx_CCSpriteBatchNode_setBlendFunc, 2, JSPROP_READONLY | JSPROP_PERMANENT); + //JS_DefineFunction(cx, js_cocos2dx_CCMotionStreak_prototype, "setBlendFunc", js_cocos2dx_CCMotionStreak_setBlendFunc, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCAtlasNode_prototype, "setBlendFunc", js_cocos2dx_CCAtlasNode_setBlendFunc, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCParticleBatchNode_prototype, "setBlendFunc", js_cocos2dx_CCParticleBatchNode_setBlendFunc, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCLayerColor_prototype, "setBlendFunc", js_cocos2dx_CCLayerColor_setBlendFunc, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCParticleSystem_prototype, "setBlendFunc", js_cocos2dx_CCParticleSystem_setBlendFunc, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, js_cocos2dx_CCAction_prototype, "copy", js_cocos2dx_CCNode_copy, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, js_cocos2dx_CCAction_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, js_cocos2dx_CCAction_prototype, "release", js_cocos2dx_release, 0, JSPROP_READONLY | JSPROP_PERMANENT); @@ -666,6 +948,7 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global) JS_DefineFunction(cx, js_cocos2dx_CCMenuItem_prototype, "setCallback", js_cocos2dx_setCallback, 2, JSPROP_READONLY | JSPROP_PERMANENT); tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.Node.prototype; })()")); JS_DefineFunction(cx, tmpObj, "copy", js_cocos2dx_CCNode_copy, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "schedule", js_CCNode_schedule, 1, JSPROP_READONLY | JSPROP_PERMANENT); tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.Menu; })()")); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCMenu_create, 0, JSPROP_READONLY | JSPROP_PERMANENT); tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.MenuItem; })()")); diff --git a/scripting/javascript/bindings/cocos2d_specifics.hpp b/scripting/javascript/bindings/cocos2d_specifics.hpp index 98d47f3324..fcdb5a7838 100644 --- a/scripting/javascript/bindings/cocos2d_specifics.hpp +++ b/scripting/javascript/bindings/cocos2d_specifics.hpp @@ -85,6 +85,57 @@ private: jsval *extraData; }; +class JSSchedule; + +typedef struct jsScheduleFunc_proxy { + void * ptr; + JSSchedule *obj; + UT_hash_handle hh; +} schedFunc_proxy_t; + +typedef struct jsScheduleTarget_proxy { + void * ptr; + CCArray *obj; + UT_hash_handle hh; +} schedTarget_proxy_t; + + +extern schedFunc_proxy_t *_schedFunc_target_ht; +extern schedTarget_proxy_t *_schedTarget_native_ht; + +class JSSchedule: public CCObject { + +public: + JSSchedule(jsval func): jsSchedule(func) {} + JSSchedule() {} + ~JSSchedule(){} + + static void setTargetForSchedule(jsval sched, JSSchedule *target); + static JSSchedule * getTargetForSchedule(jsval sched); + static void setTargetForNativeNode(CCNode *pNode, JSSchedule *target); + static CCArray * getTargetForNativeNode(CCNode *pNode); + + void setJSScheduleFunc(jsval obj); + void setJSScheduleThis(jsval thisObj); + + void pause(); + + void scheduleFunc(CCNode *node) const { + + jsval retObj = JSVAL_NULL; + ScriptingCore::getInstance()->executeJSFunctionWithThisObj(jsThisObj, + jsSchedule, + retObj); + + } +private: + + jsval jsSchedule; + jsval jsThisObj; + +}; + + class JSTouchDelegate: public CCTouchDelegate, public CCNode { public: void setJSObject(JSObject *obj); diff --git a/scripting/javascript/bindings/generated b/scripting/javascript/bindings/generated index bb14056784..7bee281e6c 160000 --- a/scripting/javascript/bindings/generated +++ b/scripting/javascript/bindings/generated @@ -1 +1 @@ -Subproject commit bb14056784ea0d3ab3f30ae5a86c1bd3ad483703 +Subproject commit 7bee281e6c33d25ed2874261da6658b66a43e073 diff --git a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh index ad6c5c9f33..9023c335e7 100755 --- a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh +++ b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh @@ -2,24 +2,104 @@ # Generate JS bindings for Cocos2D-X # ... using Android NDK system headers +# ... and automatically update submodule references +# ... and push these changes to remote repos -# Dependencies (see ../../../tojs/genbindings.sh +# Dependencies +# +# For bindings generator: +# (see ../../../tojs/genbindings.sh # ... for the defaults used if the environment is not customized) # # * $PYTHON_BIN # * $CLANG_ROOT # * $NDK_ROOT +# +# For automatically pushing changes: +# +# * REMOTE_COCOS2DX_REPOSITORY +# * REMOTE_AUTOGEN_BINDINGS_REPOSITORY +# * Ensure you have ssh access to above repositories -compileresult=0 +# Exit on error +set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -COCOS2DX_ROOT="$DIR"/../../../../ /bin/bash ../../../tojs/genbindings.sh +COCOS2DX_ROOT="$DIR"/../../../.. -compileresult=$[$compileresult+$?] +# 1. Generate JS bindings +COCOS2DX_ROOT="$COCOS2DX_ROOT" /bin/bash ../../../tojs/genbindings.sh -# return the compileresult. -if [ $compileresult != 0 ]; then +echo +echo Bindings generated successfully +echo + +if [ -z "${REMOTE_AUTOGEN_BINDINGS_REPOSITORY+aaa}" ]; then + echo + echo Environment variable must be set REMOTE_AUTOGEN_BINDINGS_REPOSITORY + echo This script expects to automatically push changes + echo to this repo + echo + echo Exiting with failure. + echo +# example +# REMOTE_AUTOGEN_BINDINGS_REPOSITORY="git@github.com:folecr/cocos2dx-autogen-bindings.git" +# REMOTE_AUTOGEN_BINDINGS_REPOSITORY="$HOME/test/cocos2dx-autogen-bindings" exit 1 -else +fi + +if [ -z "${COMMITTAG+aaa}" ]; then +# ... if COMMITTAG is not set, use this machine's hostname + COMMITTAG=`hostname -s` +fi +echo Using "'$COMMITTAG'" in the commit messages + +ELAPSEDSECS=`date +%s` +echo Using "$ELAPSEDSECS" in the branch names for pseudo-uniqueness + +GENERATED_BRANCH=autogeneratedbindings_"$ELAPSEDSECS" +GENERATED_GITDIR="$COCOS2DX_ROOT"/scripting/javascript/bindings/generated/.git +GENERATED_WORKTREE="$COCOS2DX_ROOT"/scripting/javascript/bindings/generated + +# git command shortcut +gitcmd_GEN="git --git-dir=$GENERATED_GITDIR --work-tree=$GENERATED_WORKTREE" + +# testing... +${gitcmd_GEN} status + +# 2. In JSBindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it +${gitcmd_GEN} add README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js +${gitcmd_GEN} checkout origin/master -b "$GENERATED_BRANCH" +${gitcmd_GEN} commit -m "$COMMITTAG : autogenerated bindings" + +# 3. In JSBindings repo, Push the commit with generated bindings to "master" of the auto generated bindings repository +${gitcmd_GEN} push "$REMOTE_AUTOGEN_BINDINGS_REPOSITORY" "$GENERATED_BRANCH":master + +if [ -z "${REMOTE_COCOS2DX_REPOSITORY+aaa}" ]; then + echo + echo Environment variable is not set REMOTE_COCOS2DX_REPOSITORY + echo This script will NOT automatically push changes + echo unless this variable is set. + echo + echo Exiting with success. + echo +# example +# REMOTE_COCOS2DX_REPOSITORY="git@github.com:cocos2d/cocos2d-x.git" +# REMOTE_COCOS2DX_REPOSITORY="$HOME/test/cocos2d-x" exit 0 fi + +COCOS_BRANCH=updategeneratedsubmodule_"$ELAPSEDSECS" + +pushd "${DIR}" + +# 4. In Cocos2D-X repo, Checkout a branch named "updategeneratedsubmodule" Update the submodule reference to point to the commit with generated bindings +cd "${COCOS2DX_ROOT}" +git add scripting/javascript/bindings/generated +git checkout origin/gles20 -b "$COCOS_BRANCH" +git commit -m "$COMMITTAG : updating submodule reference to latest autogenerated bindings" + +# 5. In Cocos2D-X repo, Push the commit with updated submodule to "gles20" of the cocos2d-x repository +git push "$REMOTE_COCOS2DX_REPOSITORY" "$COCOS_BRANCH":gles20 + +popd diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index f444f2336b..c8f0ba2964 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos2dx/include/cocos2d.h %(cocosdir)s/CocosDenshion/inc # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^CCMenu*$". -classes = CCSprite.* CCScene CCNode CCDirector CCLayer.* CCMenu.* CCTouch CC.*Action.* CCMove.* CCRotate.* CCBlink.* CCTint.* CCSequence CCRepeat.* CCFade.* CCEase.* CCScale.* CCTransition.* CCSpawn CCSequence CCAnimat.* CCFlip.* CCDelay.* CCSkew.* CCJump.* CCPlace.* CCShow.* CCProgress.* CCPointArray CCToggleVisibility.* CCHide CCParticle.* CCLabel.* CCAtlas.* CCTextureCache.* CCTexture2D CCCardinal.* CCCatmullRom.* CCParallaxNode CCTileMap.* CCTMX.* CCCallFunc CCRenderTexture CCGridAction CCGrid3DAction CCShaky3D CCWaves3D CCFlipX3D CCFlipY3D CCSpeed CCActionManager CCSet SimpleAudioEngine +classes = CCSprite.* CCScene CCNode CCDirector CCLayer.* CCMenu.* CCTouch CC.*Action.* CCMove.* CCRotate.* CCBlink.* CCTint.* CCSequence CCRepeat.* CCFade.* CCEase.* CCScale.* CCTransition.* CCSpawn CCSequence CCAnimat.* CCFlip.* CCDelay.* CCSkew.* CCJump.* CCPlace.* CCShow.* CCProgress.* CCPointArray CCToggleVisibility.* CCHide CCParticle.* CCLabel.* CCAtlas.* CCTextureCache.* CCTexture2D CCCardinal.* CCCatmullRom.* CCParallaxNode CCTileMap.* CCTMX.* CCCallFunc CCRenderTexture CCGridAction CCGrid3DAction CCShaky3D CCWaves3D CCFlipX3D CCFlipY3D CCSpeed CCActionManager CCSet SimpleAudioEngine CCScheduler CCTimer CCOrbit.* # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -34,9 +34,15 @@ classes = CCSprite.* CCScene CCNode CCDirector CCLayer.* CCMenu.* CCTouch CC.*Ac # add a single "*" as functions. See bellow for several examples. A special class name is "*", which # will apply to all class names. This is a convenience wildcard to be able to skip similar named # functions from all classes. -skip = CCNode::[.*Transform convertToWindowSpace getChildren getGrid setGLServerState description getActionManager getCamera getShaderProgram getUserObject .*UserData getGLServerState], +skip = CCNode::[.*Transform convertToWindowSpace getChildren getGrid setGLServerState description getCamera getShaderProgram getUserObject .*UserData getGLServerState], CCSprite::[getQuad displayFrame getTexture getBlendFunc setBlendFunc getTextureAtlas setSpriteBatchNode getSpriteBatchNode], - CCDirector::[getAccelerometer getKeypadDispatcher getTouchDispatcher getActionManager setWatcherCallbackFun getOpenGLView getScheduler getProjection], + CCSpriteBatchNode::[getBlendFunc setBlendFunc], + CCMotionStreak::[getBlendFunc setBlendFunc], + CCAtlasNode::[getBlendFunc setBlendFunc], + CCParticleBatchNode::[getBlendFunc setBlendFunc], + CCLayerColor::[getBlendFunc setBlendFunc], + CCParticleSystem::[getBlendFunc setBlendFunc], + CCDirector::[getAccelerometer getKeypadDispatcher getTouchDispatcher setWatcherCallbackFun getOpenGLView getScheduler getProjection], CCLayer.*::[didAccelerate (g|s)etBlendFunc], CCMenu.*::[.*Target getSubItems create alignItemsInColumns initWithItems alignItemsInRows], CCMenuItem.*::[create], @@ -86,7 +92,7 @@ skip = CCNode::[.*Transform convertToWindowSpace getChildren getGrid setGLServer *::[copyWith.* onEnter.* onExit.* description getObjectType .*RGB.* .*HSV.*] rename_functions = CCDirector::[sharedDirector=getInstance], - CCSpriteFrameCache::[sharedSpriteFrameCache=getInstance addSpriteFramesWithFile=addSpriteFrames spriteFrameByName=getSpriteFrame], + CCSpriteFrameCache::[sharedSpriteFrameCache=getInstance addSpriteFramesWithFile=addSpriteFrames spriteFrameByName=getSpriteFrame isFlipX=isFlippedX isFlipY=isFlippedY], CCMenuItemFont::[setFontNameObj=setFontName setFontSizeObj=setFontSize fontSizeObj=fontSize fontNameObj=fontName], CCProgressTimer::[setReverseProgress=setReverseDirection], CCTextureCache::[sharedTextureCache=getInstance], @@ -94,6 +100,7 @@ rename_functions = CCDirector::[sharedDirector=getInstance], CCAnimation::[addSpriteFrameWithFileName=addSpriteFrameWithFilename], CCAnimationCache::[sharedAnimationCache=getInstance addAnimationsWithFile=addAnimations animationByName=getAnimation], CCLayerGradient::[initWithColor=init], + CCNode::[boundingBox=getBoundingBox], SimpleAudioEngine::[sharedEngine=getInstance] rename_classes = CCParticleSystemQuad::CCParticleSystem