var AdManager = require("AdManager");
cc.Class({
extends: cc.Component,
properties: {
cameraSpeed:0,
m_nYSpeed:0,
m_nYMaxSpeed:50,
m_nGravity:50,
m_nGround:-1, //1在地面 -1不在地面
m_nXSpeed:0,
m_nJump:0,
// playerName:"",
// startPosY:null,
groundY:-600,
isGameOver:false,
GameView:null,
prePlayerType:null, //场景中的角色类型
curPlayerType:null,//按钮显示的当前玩家类型
playerIndex:0,
touchNumber:0,
invincible:false,//是否无敌
invincibleTime:2, //无敌时间
tempInvincibleTime:0,// 临时时间
absorb:true, //吸收
absorbTime:3,//时间
tempAbsorbTime:0,
ballSprite:null,
},
onLoad:function() {
cc.director.getCollisionManager().enabled = true;
// cc.director.getCollisionManager().enabledDebugDraw = true;
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.onKeyDown,this);
this.ballSprite=cc.find("ball",this.node);
this.ballAni=this.ballSprite.getComponent(cc.Animation);
this.Ani=this.node.getComponent(cc.Animation);
AdManager.init();
if(CC_WECHATGAME)
{
AdManager.registerVideoPlayComplete(this.relive.bind(this));
AdManager.registerVideoPlayFail(this.gameOver.bind(this));
AdManager.registerOnVideoHandler(this.hideVideoAd.bind(this));
}
},
relive()
{
window.AudioController.playerBG(window.Constant.GameClip.gameBgm);
//重玩的逻辑
this.invincible=true;
this.hideRestarBG();
this.collisionY=0;
this.isGameOver=false;
this.node.y=400;
this.m_nXSpeed= this.Speed;
this.node.x=this.GameView.PlayerCamera.x;
this.OnPlayerDataChange(this.prePlayerType);
this.ballAni.play();
},
hideVideoAd()
{
this.gameOver();
},
onEnable()
{
this.arry=new Array();
this.arry.push(window.Constant.PlayerType.NormalBall);
this.arry.push(window.Constant.PlayerType.SteelBall);
this.curPlayerType=this.arry[this.playerIndex];
this.collisionY=0; //0 有重力 -1 无重力
this.collisionX=0; //1 被阻挡了 0无阻挡
this.prePos=this.node.x;
this.isGameOver=false;
this.ballSprite.color=cc.Color.WHITE;
},
///由GameView调用控制 初始化角色数据默认值
init(GameView)
{
this.GameView=GameView;
///前一次的临界点
this.playerIndex=0;
this.curPlayerType=window.Constant.PlayerType.NormalBall;
this.OnPlayerDataChange(this.curPlayerType);
this.addListerner();
},
GetRandomChangePlayerType()
{
if(this.isGameOver)
return;
this.OnPlayerDataChange(this.curPlayerType);
},
OnPlayerDataChange:function(playerType)
{
this.curPlayerType=playerType;
var playerVoData=window.data.PlayerData.GetPlayerData(playerType);
this.ChangePlayerData(playerVoData);
this.ChangeShow(this.playerName);
this.prePlayerType=this.curPlayerType;
//获取下一个玩家信息
this.GetRandomPlayerData();
},
onKeyDown:function(event)
{
switch(event.keyCode)
{
case cc.macro.KEY.j:
this.jump();
break;
case cc.macro.KEY.f:
this.GetRandomChangePlayerType();
break;
case cc.macro.KEY.r:
this.Restart();
break;
}
},
onKeyUp:function(event)
{
},
onCollisionEnter:function(other, self)
{
//限制Y轴
if(other.tag==10)
{
this.touchNumber++;
this.collisionY = -1;
this.m_nYSpeed=0;
this.canJumpCount=0;
var otherAabb = other.world.aabb;
var selfAabb = self.world.aabb;
var otherPreAabb = other.world.preAabb.clone();
var selfPreAabb = self.world.preAabb.clone();
//处理Y轴上的碰撞
selfPreAabb.y = selfAabb.y;
otherPreAabb.y = otherAabb.y;
if(cc.Intersection.rectRect(selfPreAabb,otherPreAabb))
{
if(selfPreAabb.y<otherPreAabb.y)
{
this.collisionY=0;
this.canJumpCount=3;
}else
{
this.m_nGround = 1;
}
var intersection=new cc.Rect();
selfPreAabb.intersection(intersection, otherPreAabb);
this.node.y+=intersection.height;
return;
}
}
//限制X轴
if(other.tag==15)
{
var otherAabb = other.world.aabb;
var selfAabb = self.world.aabb;
var otherPreAabb = other.world.preAabb.clone();
var selfPreAabb = self.world.preAabb.clone();
//处理X轴上的碰撞
selfPreAabb.x = selfAabb.x;
otherPreAabb.x = otherAabb.x;
// this.collisionX=1;
if(cc.Intersection.rectRect(selfPreAabb,otherPreAabb))
{
// this.m_nGround = 1;
var intersection=new cc.Rect();
this.collisionX=1;
selfPreAabb.intersection(intersection, otherPreAabb);
this.node.x-=intersection.width;
}
}
if(other.tag==50)
{
this.PlayerDie("撞到边界线死亡");
}
},
onCollisionExit: function (other) {
if(other.tag==10)
{
this.touchNumber--;
{
if(this.touchNumber==0)
{
this.collisionY = 0;
}
}
}
if(other.tag==15)
{
this.collisionX=0;
}
},
update:function(dt) {
if(this.GameView==null)
return;
this.dt=dt;
this.gravityUp();
this.refresh();
if(this.invincible)
{
this.Invincible();
}
// if(this.absorb)
// {
// this.Absorb();
// }
},
lateUpdate()
{
if(this.GameView==null)
return;
if(this.cameraSpeed==0)
return;
this.GameView.PlayerCamera.x+=this.cameraSpeed;
if(this.isGameOver)
return;
this.GetPlayerDistance();
},
//更换玩家数据
ChangePlayerData(mData)
{
//重玩的速度
// this.Speed=mData.speed;
this.m_nXSpeed=mData.speed;
this.m_nJump=mData.jump;
this.m_nYMaxSpeed=mData.maxYSpeed;
this.m_nGravity=mData.gravity;
this.playerName=mData.path; //图集路径
this.cameraSpeed=mData.speed;
},
// 换图片
ChangeShow:function(name)
{
var path=name;
var spriteObj=this.ballSprite.getComponent(cc.Sprite);
window.ResourceManager.LoadSpriteFrameByName(spriteObj,path);
if(this.curPlayerType==window.Constant.PlayerType.NormalBall)
{
this.ballAni.play();
}else
{
this.ballAni.stop();
}
},
//玩家碰到障碍物
PlayerDie:function(msg)
{
this.collisionY=-1;
this.m_nYSpeed=0;
this.m_nXSpeed=0;
this.m_nGround=1;
this.canJumpCount=0;
// console.log(msg);
this.isGameOver=true;
this.showRestarBG(); //点击播放视频 调用
//this.gameOver(); //震动效果完�
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
白昼之夜creator.zip源码cocos creator游戏项目源码下载白昼之夜creator.zip源码cocos creator游戏项目源码下载 1.适合个人学习技术做项目参考 2.适合学生毕业设计项目参考 3.适合小公司开发游戏项目参考
资源推荐
资源详情
资源评论
收起资源包目录
白昼之夜creator.zip源码cocos creator游戏项目源码下载 (309个子文件)
YM.anim 2KB
scoreFx.anim 1KB
xingxing1.anim 1KB
xingxing2.anim 1KB
xingxing3.anim 1KB
BgTest.anim 778B
monsterAni.anim 771B
player1.anim 671B
DzAni.anim 620B
playerAni.anim 450B
bgMoveAni.anim 370B
Thumbs.db 166KB
Thumbs.db 139KB
Thumbs.db 71KB
MainGame.fire 90KB
loading.fire 6KB
mikado_outline_shadow.fnt 12KB
disNum.fnt 1KB
score.fnt 1KB
PlayerControll.js 13KB
GameView.js 13KB
RoleControl.js 6KB
AdManager.js 5KB
StartView.js 5KB
ResourceManager.js 4KB
RewardItemData.js 4KB
BarrierData.js 4KB
StarRewardData.js 3KB
RewardHandler.js 3KB
Mir.js 3KB
ButtleHandler.js 3KB
GameOver.js 3KB
SpriteTextTool.js 3KB
ButtleData.js 2KB
ScoreEffectData.js 2KB
AudioController.js 2KB
UIManager.js 2KB
CameraTest.js 2KB
Constant.js 2KB
BarrierHandler.js 2KB
YMData.js 2KB
dictionary.js 2KB
BaseWind.js 2KB
BarrierSortData.js 1KB
List.js 1KB
StarSortData.js 1KB
GameTransition.js 1KB
ViewManager.js 1KB
PlayersCfgData.js 1KB
readjson.js 1KB
EventBus.js 943B
ButtlesCfgData.js 895B
BarrierCfgData.js 895B
CfgTestData.js 867B
RewardItemCfgData.js 854B
BarrierSortCfgData.js 841B
StarSortCfgData.js 827B
Score.js 760B
GameRunData.js 563B
ScoreFxHandler.js 555B
GroundUp.js 495B
PlayerData.js 478B
LayerManager.js 476B
GroundLR.js 451B
YM.js 446B
PlayerVoData.js 424B
PlayersCfgVo.js 416B
StarSortCfgVo.js 380B
Main.js 359B
BarrierSortCfgVo.js 314B
ButtlesCfgVo.js 313B
BarrierVoData.js 296B
SortVoData.js 284B
RewardItemCfgVo.js 278B
BarrierCfgVo.js 269B
Loading.js 211B
services.json 24KB
project.json 655B
StarSort.json 542B
players.json 434B
test.json 310B
RewardItem.json 268B
BarrierSort.json 228B
Barrier.json 196B
Buttles.json 107B
project.json 60B
reward.plist.meta 10KB
UI.plist.meta 9KB
YM.plist.meta 7KB
score.plist.meta 6KB
distance.plist.meta 6KB
ball.plist.meta 4KB
barrier.plist.meta 3KB
Monster.plist.meta 2KB
mikado_outline_shadow.png.meta 726B
ball.png.meta 715B
Monster.png.meta 715B
background2.png.meta 715B
background1.png.meta 715B
score_0.png.meta 714B
共 309 条
- 1
- 2
- 3
- 4
资源评论
yxkfw
- 粉丝: 81
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功