var TAG_SPRITE_BALL = ;
var TAG_SPRITE_USER = ;
var TAG_SPRITE_NPC = ;
var PTM_RATIO = ;
var GRABABLE_MASK_BIT = <<;
var NOT_GRABABLE_MASK = ~GRABABLE_MASK_BIT; var MainLayer = cc.Layer.extend({
_ball:null,
_man:null,
_rpc:null,
_leftGoal:null,
_rightGoal:null,
_leftPower:null,
_rightPower:null,
_time:, space:null, ctor:function () {
this._super();
var size = cc.director.getWinSize(); this._ball = new Ball();
this._ball.x = size.width / ;
this._ball.y = size.height / ;
this.addChild(this._ball); // 左方向
var btnLeft = cc.MenuItemImage.create(
res.btn_left_up,
res.btn_left_down,
function () {
this._man.runLeft();
}, this);
btnLeft.x = ; // 右方向
var btnRight = cc.MenuItemImage.create(
res.btn_right_up,
res.btn_right_down,
function () {
this._man.runRight();
}, this);
btnRight.x = ; // power
var btnPower = cc.MenuItemImage.create(
res.btn_power_up,
res.btn_power_down,
function () {
this._man.power();
}, this);
btnPower.x = ; // jump
var btnJump = cc.MenuItemImage.create(
res.btn_jump_up,
res.btn_jump_down,
function () {
this._man.jump();
}, this);
btnJump.x = ; // kick
var btnKick = cc.MenuItemImage.create(
res.btn_kick_up,
res.btn_kick_down,
function () {
this._man.kick();
}, this);
btnKick.x = ; // 暂停
var btnPause = cc.MenuItemImage.create(
"res/pause.png",
"res/pause2.png",
function () {
this.onStop();
}, this);
btnPause.x = size.width - ;
btnPause.y = size.height - ; var menu = cc.Menu.create(btnLeft, btnRight, btnPower, btnJump, btnKick, btnPause);
menu.x = ;
menu.y = ;
this.addChild(menu, ); // 主角
this._man = new Footballer_cn();
this._man.flippedX = true;
this._man.x = ;
this._man.y = ;
this._man.anchorX = 0.5;
this._man.anchorY = ;
this.addChild(this._man,,TAG_SPRITE_USER);
this._npc = new Footballer_br();
this._npc.x = size.width - ;
this._npc.y = ;
this._npc.anchorX = 0.5;
this._npc.anchorY = ;
this.addChild(this._npc,,TAG_SPRITE_NPC); // 球门
this._leftGoal = new Goalpost(true);
this._leftGoal.x = ;
this._leftGoal.y = ;
this._leftGoal.anchorX = ;
this._leftGoal.anchorY = ;
this.addChild(this._leftGoal); this._rightGoal = new Goalpost();
this._rightGoal.x = size.width;
this._rightGoal.y = ;
this._rightGoal.anchorX = ;
this._rightGoal.anchorY = ;
this.addChild(this._rightGoal); // power
this._leftPower = new PowerProgress(size.width/-,size.height-,,0.5,this);
this.addChild(this._leftPower, );
this._rightPower = new PowerProgress(size.width/+,size.height-,,0.5,this);
this.addChild(this._rightPower, ); // 系统计划任务,即每帧调用update函数
this.scheduleUpdate();
// 自定义计划任务
this.schedule(this.uiSchedule, ); cc.sys.dumpRoot();
cc.sys.garbageCollect(); this.initChipmunk(); return true;
},
onStop:function () {
this._bStop = !this._bStop;
if (this._bStop == true) {
cc.director.pause();
}
else {
cc.director.resume();
}
}, update:function (dt) {
this.space.step(dt);
},
uiSchedule:function () {
this._time++;
this._leftPower.showPower();
this._rightPower.showPower();
},
initChipmunk:function() {
this.space = new cp.Space();
var sprite = this.createPhysicsSprite( cc.p(cc.director.getWinSize().width/ , cc.director.getWinSize().height-) );
this.addChild( sprite, ); this.addWalls();
this.space.gravity = cp.v(, -);
},
initPhysics:function() {
var space = this.space ;
var staticBody = space.staticBody;
var winSize = cc.director.getWinSize(); // Walls
var walls = [ new cp.SegmentShape( staticBody, cp.v(,), cp.v(winSize.width,), ), // bottom
new cp.SegmentShape( staticBody, cp.v(,winSize.height), cp.v(winSize.width,winSize.height), ), // top
new cp.SegmentShape( staticBody, cp.v(,), cp.v(,winSize.height), ), // left
new cp.SegmentShape( staticBody, cp.v(winSize.width,), cp.v(winSize.width,winSize.height), ) // right
];
for( var i=; i < walls.length; i++ ) {
var shape = walls[i];
shape.setElasticity();
shape.setFriction();
space.addStaticShape( shape );
} // Gravity
space.gravity = cp.v(, -);
},
addWalls:function() {
// Walls
var winSize = cc.director.getWinSize();
var walls = [ new cp.SegmentShape( this.space.staticBody, cp.v(,), cp.v(winSize.width,), ), // bottom
new cp.SegmentShape( this.space.staticBody, cp.v(,winSize.height), cp.v(winSize.width,winSize.height), ), // top
new cp.SegmentShape( this.space.staticBody, cp.v(,), cp.v(,winSize.height), ), // left
new cp.SegmentShape( this.space.staticBody, cp.v(winSize.width,), cp.v(winSize.width,winSize.height), ) // right
];
for( var i=; i < walls.length; i++ ) {
var shape = walls[i];
shape.setElasticity(0.8);
shape.setFriction(0.1);
this.space.addStaticShape( shape );
}
},
createPhysicsSprite:function( pos ) { var radius = ;
var mass = ; var body = new cp.Body(mass, cp.momentForCircle(mass, , radius,cp.v(, )));
body.setPos( pos );
this.space.addBody( body );
var shape = new cp.CircleShape(body, radius,cp.v(, )); //new cp.BoxShape( body, 48, 108);
shape.setElasticity( );
shape.setFriction( 0.1 ); this.space.addShape( shape ); var sprite = cc.PhysicsSprite.create(res.b_ball_01);
sprite.setBody( body );
return sprite;
},
setupDebugNode:function()
{
// debug only
this._debugNode = cc.PhysicsDebugNode.create( this.space );
this._debugNode.visible = false ;
this.addChild( this._debugNode );
}
}); var MainScene = cc.Scene.extend({
onEnter:function () {
this._super();
this.addChild(new GameBackgroundLayer());
this.addChild(new MainLayer());
}
});

最新文章

  1. javascript原型prototype浅识
  2. system generator 卷积编码器快速设计
  3. [转]服务器自动化操作 RunDeck
  4. ssh登录慢,等待输入密码时间长
  5. 2014多校第六场 1010 || HDU 4930 Fighting the Landlords (模拟)
  6. SQL查看数据库所用用户表数量和使用的空间
  7. clients(PV操作共享内核内存进行输入输出分屏) - server(进程间通信)模型实现
  8. CSS样式的优先机制
  9. Python异常处理体系
  10. Java中的枚举的治理
  11. 一款基于vue2.0的分页组件---写在页面内
  12. UPDATE/INSERT用法研究
  13. MYSQL:RELPACE用法
  14. 日常遇错之Unable to save settings: Failed to save settings. Please restart PyCharm
  15. Java高并发--线程安全策略
  16. 数论-质数 poj2689,阶乘分解,求阶乘的尾零hdu1124, 求尾零为x的最小阶乘
  17. [CC-PERMUTE]Just Some Permutations 3
  18. 为何谷歌围棋AI AlphaGo可能会把李世石击溃
  19. du 查看文件大小
  20. qq远程连接/windows远程桌面/teamviwer/xmanager/vnc的区别

热门文章

  1. HDU 1941 Hide and Seek(离散化+树状数组)
  2. 从零开始学数据分析,什么程度可以找到工作?( 内附20G、5000分钟数据分析工具教程大合集 )
  3. UVa 514 (stack的使用) Rails
  4. mac下编译optool方法
  5. 关于jsp利用EL和struts2标签来遍历ValueStack的东东 ------&gt; List&lt;Map&lt;K,V&gt;&gt; 以及 Map&lt;K,&lt;List&lt;xxx&gt;&gt;&gt; 的结构遍历
  6. (二)win7下用Intelij IDEA 远程调试spark standalone 集群
  7. UVa11582 Colossal Fibonacci Numbers!
  8. AIX系统管理员--第一章笔记
  9. 《C++ Primer 4th》读书笔记 序
  10. 【转】Github轻松上手5-站在巨人的肩膀上(Fork)