issue #1469: Added MoonWarriors sources and made it works on windows.

This commit is contained in:
James Chen 2012-10-10 14:50:04 +08:00
parent 14a56ddc8f
commit d03ff0616a
88 changed files with 7161 additions and 0 deletions

View File

@ -0,0 +1,83 @@
#include "AppDelegate.h"
#include "cocos2d.h"
#include "SimpleAudioEngine.h"
#include "ScriptingCore.h"
#include "generated/cocos2dx.hpp"
#include "cocos2d_specifics.hpp"
#include "js_bindings_chipmunk_manual.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());
// 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("MoonWarriors/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();
}

View File

@ -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_

View File

@ -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
});
})();

View File

@ -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("jshelper/jsb_constants.js");
var MW = MW || {};
var 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/GameControlMenu.js',
'MoonWarriors/src/GameLayer.js',
'MoonWarriors/src/GameOver.js',
'MoonWarriors/src/AboutLayer.js',
'MoonWarriors/src/SettingsLayer.js',
'MoonWarriors/src/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);

View File

@ -0,0 +1 @@
59362b16ba4da187e064648be4d0bcb1c09b504d

View File

@ -0,0 +1 @@
c0488f23a6a785893f4845b7fadc59ed892ceedc

View File

@ -0,0 +1 @@
46f10a6bf5c63f03ddf8566f392aa7a8f258d7e8

View File

@ -0,0 +1 @@
97bca7d49fb6ec5c330f6ab6f5f49d335601a669

View File

@ -0,0 +1 @@
ca7905a1a07e2be3e02fbf329772c2c361400af7

View File

@ -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;
};

View File

@ -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);
}
});

View File

@ -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());
};

View File

@ -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);
};

View File

@ -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");
};

View File

@ -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;
};

View File

@ -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;

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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);
}
});

View File

@ -0,0 +1,89 @@
var dirImg = "";
var dirMusic = "";
var musicSuffix = ".mp3";
if( cc.config.deviceType == 'browser' || cc.config.engine == 'cocos2d-x') {
dirImg = "MoonWarriors/res/";
dirMusic = "MoonWarriors/res/Music/";
musicSuffix = "";
}
//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}
];

View File

@ -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;
};

View File

@ -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;
}
});

View File

@ -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;
};

View File

@ -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
}
];

View File

@ -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:[]
};

View File

@ -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]
}*/
]
};

View File

@ -0,0 +1,475 @@
require('jshelper/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;

View File

@ -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;

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MoonWarriors</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>src_common</name>
<type>2</type>
<locationURI>PARENT-3-PROJECT_LOC/cocos2dx/platform/android/java/src_common</locationURI>
</link>
</linkedResources>
</projectDescription>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cocos2dx.testjavascript"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
<application android:label="@string/app_name"
android:debuggable="true"
android:icon="@drawable/icon">
<activity android:name=".MoonWarriors"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<supports-screens android:largeScreens="true"
android:smallScreens="true"
android:anyDensity="true"
android:normalScreens="true"/>
</manifest>

View File

@ -0,0 +1 @@
aapt.ignore.assets="!*.pvr.gz:!*.gz:!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="MoonWarriors" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -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

View File

@ -0,0 +1,28 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test_javascript_shared
LOCAL_MODULE_FILENAME := libtestjavascript
LOCAL_SRC_FILES := testjavascript/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)

View File

@ -0,0 +1,3 @@
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCOCOS2D_JAVASCRIPT=1
APP_CPPFLAGS += -DCOCOS2D_DEBUG=2

View File

@ -0,0 +1,45 @@
#include "AppDelegate.h"
#include "cocos2d.h"
#include "platform/android/jni/JniHelper.h"
#include "CCEventType.h"
#include <jni.h>
#include <android/log.h>
#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();
}
}
}

View File

@ -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 *;
#}

View File

@ -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

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MoonWarriors</string>
</resources>

View File

@ -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.testjavascript;
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("testjavascript");
}
}

View File

@ -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 <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
UIWindow *window;
RootViewController *viewController;
}
@end

View File

@ -0,0 +1,119 @@
//
// testjsAppController.mm
// testjs
//
// Created by Rolando Abarca on 3/19/12.
// Copyright __MyCompanyName__ 2012. All rights reserved.
//
#import <UIKit/UIKit.h>
#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

View File

@ -0,0 +1 @@
66c6d1cead373b45218424f6a82f370897e443e4

View File

@ -0,0 +1 @@
84689888a14a2123d2b39f7f2f61be8c15207479

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
//
// Prefix header for all source files of the 'testjs' target in the 'testjs' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif

View File

@ -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 <UIKit/UIKit.h>
@interface RootViewController : UIViewController {
}
@end

View File

@ -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

View File

@ -0,0 +1,17 @@
//
// main.m
// testjs
//
// Created by Rolando Abarca on 3/19/12.
// Copyright __MyCompanyName__ 2012. All rights reserved.
//
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
[pool release];
return retVal;
}

View File

@ -0,0 +1,295 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="MoonWarriors"
ProjectGUID="{A0EA54FA-6F12-45EC-AD5C-D139AA3CD528}"
RootNamespace="MoonWarriors"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="false"
TargetEnvironment="1"
GenerateStublessProxies="true"
TypeLibraryName="$(IntDir)/testjs.tlb"
HeaderFileName="testjs.h"
DLLDataFileName=""
InterfaceIdentifierFileName="testjs_i.c"
ProxyFileName="testjs_p.c"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".;..\Classes;&quot;$(SolutionDir)scripting\javascript\spidermonkey-win32\include&quot;;&quot;$(SolutionDir)scripting\javascript\bindings&quot;;&quot;$(SolutionDir)external\chipmunk\include\chipmunk&quot;;&quot;$(SolutionDir)extensions&quot;;&quot;$(SolutionDir)cocos2dx&quot;;&quot;$(SolutionDir)cocos2dx\include&quot;;&quot;$(SolutionDir)cocos2dx\kazmath\include&quot;;&quot;$(SolutionDir)cocos2dx\platform\win32&quot;;&quot;$(SolutionDir)cocos2dx\platform\third_party\win32&quot;;&quot;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES&quot;;&quot;$(SolutionDir)CocosDenshion\include&quot;"
PreprocessorDefinitions="WIN32;_WINDOWS;STRICT;DEBUG;_DEBUG;TRACING;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;COCOS2D_DEBUG=1;COCOS2D_JAVASCRIPT;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4267;4251;4244"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
AdditionalIncludeDirectories="$(IntDir)"
/>
<Tool
Name="VCPreLinkEventTool"
CommandLine="if not exist &quot;$(OutDir)&quot; mkdir &quot;$(OutDir)&quot;&#x0D;&#x0A;xcopy /Y /Q &quot;$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*&quot; &quot;$(OutDir)&quot;&#x0D;&#x0A;"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libcocos2d.lib libCocosDenshion.lib libchipmunk.lib mozjs.lib opengl32.lib glew32.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName).win32"
IntermediateDirectory="$(ConfigurationName).win32"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="false"
TargetEnvironment="1"
GenerateStublessProxies="true"
TypeLibraryName="$(IntDir)/testjs.tlb"
HeaderFileName="testjs.h"
DLLDataFileName=""
InterfaceIdentifierFileName="testjs_i.c"
ProxyFileName="testjs_p.c"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=".;..\Classes;&quot;$(SolutionDir)scripting\javascript\spidermonkey-win32\include&quot;;&quot;$(SolutionDir)scripting\javascript\bindings&quot;;&quot;$(SolutionDir)external\chipmunk\include\chipmunk&quot;;&quot;$(SolutionDir)extensions&quot;;&quot;$(SolutionDir)cocos2dx&quot;;&quot;$(SolutionDir)cocos2dx\include&quot;;&quot;$(SolutionDir)cocos2dx\kazmath\include&quot;;&quot;$(SolutionDir)cocos2dx\platform\win32&quot;;&quot;$(SolutionDir)cocos2dx\platform\third_party\win32&quot;;&quot;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES&quot;;&quot;$(SolutionDir)CocosDenshion\include&quot;"
PreprocessorDefinitions="WIN32;_WINDOWS;STRICT;NDEBUG;COCOS2D_JAVASCRIPT;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS"
ExceptionHandling="0"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="0"
DisableSpecificWarnings="4267;4251;4244"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
AdditionalIncludeDirectories="$(IntDir)"
/>
<Tool
Name="VCPreLinkEventTool"
CommandLine="if not exist &quot;$(OutDir)&quot; mkdir &quot;$(OutDir)&quot;&#x0D;&#x0A;xcopy /Y /Q &quot;$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*&quot; &quot;$(OutDir)&quot;&#x0D;&#x0A;"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libcocos2d.lib libCocosDenshion.lib libchipmunk.lib mozjs.lib opengl32.lib glew32.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="$(OutDir)"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="bindings"
>
<File
RelativePath="..\..\..\scripting\javascript\bindings\cocos2d_specifics.cpp"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\cocos2d_specifics.hpp"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\cocosjs_manual_conversions.cpp"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\cocosjs_manual_conversions.h"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\js_bindings_config.h"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\js_manual_conversions.cpp"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\js_manual_conversions.h"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\ScriptingCore.cpp"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\ScriptingCore.h"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\spidermonkey_specifics.h"
>
</File>
<Filter
Name="generated"
>
<File
RelativePath="..\..\..\scripting\javascript\bindings\generated\cocos2dx.cpp"
>
</File>
<File
RelativePath="..\..\..\scripting\javascript\bindings\generated\cocos2dx.hpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="resource"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;jpg;jpeg;jpe;png;manifest"
>
<File
RelativePath=".\res\testjs.ico"
>
</File>
<File
RelativePath=".\testjs.rc"
>
</File>
</Filter>
<Filter
Name="win32"
>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\main.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
</Filter>
<Filter
Name="Classes"
>
<File
RelativePath="..\Classes\AppDelegate.cpp"
>
</File>
<File
RelativePath="..\Classes\AppDelegate.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="9.00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
WorkingDirectory="$(ProjectDir)..\Resources"
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
WorkingDirectory="$(ProjectDir)..\Resources"
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>

View File

@ -0,0 +1,186 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{D0F06A44-A245-4D13-A498-0120C203B539}</ProjectGuid>
<RootNamespace>MoonWarriors</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration).win32\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration).win32\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration).win32\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration).win32\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
<TargetEnvironment>Win32</TargetEnvironment>
<GenerateStublessProxies>true</GenerateStublessProxies>
<TypeLibraryName>$(IntDir)testjs.tlb</TypeLibraryName>
<HeaderFileName>testjs.h</HeaderFileName>
<DllDataFileName>
</DllDataFileName>
<InterfaceIdentifierFileName>testjs_i.c</InterfaceIdentifierFileName>
<ProxyFileName>testjs_p.c</ProxyFileName>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.;..\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)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>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)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DisableSpecificWarnings>4267;4251;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<PreLinkEvent>
<Command>if not exist "$(OutDir)" mkdir "$(OutDir)"
xcopy /Y /Q "$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)"
</Command>
</PreLinkEvent>
<Link>
<AdditionalDependencies>libcocos2d.lib;libExtensions.lib;opengl32.lib;glew32.lib;libCocosDenshion.lib;libchipmunk.lib;mozjs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>false</MkTypLibCompatible>
<TargetEnvironment>Win32</TargetEnvironment>
<GenerateStublessProxies>true</GenerateStublessProxies>
<TypeLibraryName>$(IntDir)testjs.tlb</TypeLibraryName>
<HeaderFileName>testjs.h</HeaderFileName>
<DllDataFileName>
</DllDataFileName>
<InterfaceIdentifierFileName>testjs_i.c</InterfaceIdentifierFileName>
<ProxyFileName>testjs_p.c</ProxyFileName>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>.;..\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)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;NDEBUG;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>
</ExceptionHandling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>
</DebugInformationFormat>
<DisableSpecificWarnings>4267;4251;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<PreLinkEvent>
<Command>if not exist "$(OutDir)" mkdir "$(OutDir)"
xcopy /Y /Q "$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)"
</Command>
</PreLinkEvent>
<Link>
<AdditionalDependencies>libcocos2d.lib;libExtensions.lib;opengl32.lib;glew32.lib;libCocosDenshion.lib;libchipmunk.lib;mozjs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\scripting\javascript\bindings\CCPhysicsSprite.cpp" />
<ClCompile Include="..\..\..\scripting\javascript\bindings\cocos2d_specifics.cpp" />
<ClCompile Include="..\..\..\scripting\javascript\bindings\cocosjs_manual_conversions.cpp" />
<ClCompile Include="..\..\..\scripting\javascript\bindings\generated\cocos2dx.cpp" />
<ClCompile Include="..\..\..\scripting\javascript\bindings\js_bindings_ccbreader.cpp" />
<ClCompile Include="..\..\..\scripting\javascript\bindings\js_bindings_chipmunk_functions.cpp" />
<ClCompile Include="..\..\..\scripting\javascript\bindings\js_bindings_chipmunk_manual.cpp" />
<ClCompile Include="..\..\..\scripting\javascript\bindings\js_manual_conversions.cpp" />
<ClCompile Include="..\..\..\scripting\javascript\bindings\ScriptingCore.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="..\Classes\AppDelegate.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\scripting\javascript\bindings\CCPhysicsSprite.h" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\cocos2d_specifics.hpp" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\cocosjs_manual_conversions.h" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\generated\cocos2dx.hpp" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_bindings_ccbreader.h" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_bindings_chipmunk_functions.hpp" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_bindings_chipmunk_manual.hpp" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_bindings_config.h" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_manual_conversions.h" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\ScriptingCore.h" />
<ClInclude Include="..\..\..\scripting\javascript\bindings\spidermonkey_specifics.h" />
<ClInclude Include="main.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="..\Classes\AppDelegate.h" />
</ItemGroup>
<ItemGroup>
<None Include="res\testjs.ico" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="testjs.rc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\cocos2dx\proj.win32\cocos2d.vcxproj">
<Project>{98a51ba8-fc3a-415b-ac8f-8c7bd464e93e}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\..\CocosDenshion\proj.win32\CocosDenshion.vcxproj">
<Project>{f8edd7fa-9a51-4e80-baeb-860825d2eac6}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="bindings">
<UniqueIdentifier>{58ebb5df-595d-4e27-8c01-555be6f1c625}</UniqueIdentifier>
</Filter>
<Filter Include="resource">
<UniqueIdentifier>{ca9c9e15-d942-43a1-aa7a-5f0b74ca1afd}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;jpg;jpeg;jpe;png;manifest</Extensions>
</Filter>
<Filter Include="win32">
<UniqueIdentifier>{ccb2323b-1cfa-41ea-bcf4-ba5f07309396}</UniqueIdentifier>
</Filter>
<Filter Include="Classes">
<UniqueIdentifier>{e93a77e1-af1e-4400-87d3-504b62ebdbb0}</UniqueIdentifier>
</Filter>
<Filter Include="bindings\generated">
<UniqueIdentifier>{146f26cf-13e1-4106-891b-4b0118ceac2b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>win32</Filter>
</ClCompile>
<ClCompile Include="..\Classes\AppDelegate.cpp">
<Filter>Classes</Filter>
</ClCompile>
<ClCompile Include="..\..\..\scripting\javascript\bindings\js_bindings_chipmunk_functions.cpp">
<Filter>bindings</Filter>
</ClCompile>
<ClCompile Include="..\..\..\scripting\javascript\bindings\js_bindings_chipmunk_manual.cpp">
<Filter>bindings</Filter>
</ClCompile>
<ClCompile Include="..\..\..\scripting\javascript\bindings\js_manual_conversions.cpp">
<Filter>bindings</Filter>
</ClCompile>
<ClCompile Include="..\..\..\scripting\javascript\bindings\ScriptingCore.cpp">
<Filter>bindings</Filter>
</ClCompile>
<ClCompile Include="..\..\..\scripting\javascript\bindings\CCPhysicsSprite.cpp">
<Filter>bindings</Filter>
</ClCompile>
<ClCompile Include="..\..\..\scripting\javascript\bindings\cocos2d_specifics.cpp">
<Filter>bindings</Filter>
</ClCompile>
<ClCompile Include="..\..\..\scripting\javascript\bindings\cocosjs_manual_conversions.cpp">
<Filter>bindings</Filter>
</ClCompile>
<ClCompile Include="..\..\..\scripting\javascript\bindings\js_bindings_ccbreader.cpp">
<Filter>bindings</Filter>
</ClCompile>
<ClCompile Include="..\..\..\scripting\javascript\bindings\generated\cocos2dx.cpp">
<Filter>bindings\generated</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h">
<Filter>win32</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>win32</Filter>
</ClInclude>
<ClInclude Include="..\Classes\AppDelegate.h">
<Filter>Classes</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_bindings_ccbreader.h">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_bindings_chipmunk_functions.hpp">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_bindings_chipmunk_manual.hpp">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_bindings_config.h">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\js_manual_conversions.h">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\ScriptingCore.h">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\spidermonkey_specifics.h">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\CCPhysicsSprite.h">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\cocos2d_specifics.hpp">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\cocosjs_manual_conversions.h">
<Filter>bindings</Filter>
</ClInclude>
<ClInclude Include="..\..\..\scripting\javascript\bindings\generated\cocos2dx.hpp">
<Filter>bindings\generated</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="res\testjs.ico">
<Filter>resource</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="testjs.rc">
<Filter>resource</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)..\Resources</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)..\Resources</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@ -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;
}

View File

@ -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 <windows.h>
#include <tchar.h>
// C RunTime Header Files
#include "CCStdC.h"
#endif // __WINMAIN_H__

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -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

View File

@ -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)

View File

@ -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
});
})();

View File

@ -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/jsb_constants.js");
var MW = MW || {};
var 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/GameControlMenu.js',
'MoonWarriors/src/GameLayer.js',
'MoonWarriors/src/GameOver.js',
'MoonWarriors/src/AboutLayer.js',
'MoonWarriors/src/SettingsLayer.js',
'MoonWarriors/src/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);

View File

@ -0,0 +1 @@
59362b16ba4da187e064648be4d0bcb1c09b504d

View File

@ -0,0 +1 @@
c0488f23a6a785893f4845b7fadc59ed892ceedc

View File

@ -0,0 +1 @@
46f10a6bf5c63f03ddf8566f392aa7a8f258d7e8

View File

@ -0,0 +1 @@
97bca7d49fb6ec5c330f6ab6f5f49d335601a669

View File

@ -0,0 +1 @@
ca7905a1a07e2be3e02fbf329772c2c361400af7

View File

@ -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;
};

View File

@ -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);
}
});

View File

@ -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());
};

View File

@ -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);
};

View File

@ -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");
};

View File

@ -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;
};

View File

@ -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;

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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);
}
});

View File

@ -0,0 +1,89 @@
var dirImg = "";
var dirMusic = "";
var musicSuffix = ".mp3";
if( cc.config.deviceType == 'browser' || cc.config.engine == 'cocos2d-x') {
dirImg = "MoonWarriors/res/";
dirMusic = "MoonWarriors/res/Music/";
musicSuffix = "";
}
//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}
];

View File

@ -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;
};

View File

@ -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;
}
});

View File

@ -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;
};

View File

@ -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
}
];

View File

@ -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:[]
};

View File

@ -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]
}*/
]
};

View File

@ -0,0 +1,475 @@
require('js/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;

View File

@ -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;