// Learn cc.Class:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({
extends: cc.Component,
properties: {
ballPrefab : cc.Prefab,
imageBg : cc.Node,
stageNode : {
default: [],
type: cc.Prefab,
},
starNode :{
default: [],
type: cc.Node,
},
levelLable : cc.Label,
timeLable : cc.Label,
gameEndLayer : cc.Prefab,
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
//打开物理系统
cc.director.getPhysicsManager().enabled = true;
//cc.director.getPhysicsManager().debugDrawFlags = true;
// 重力加速度的配置
cc.director.getPhysicsManager().gravity = cc.v2(0, -680);
// 小圆
this._smallCircleNode = [];
for(let i = 0; i < 20; i++){
let node = new cc.Node();
let sp = node.addComponent(cc.Sprite);
gameTools.setImgTexture("imageRes/tttby_shoushi_yuandian", node)
node.parent = this.imageBg;
node.active = false;
node.scale = 0.6;
node.zIndex = 101;
this._smallCircleNode[i] = node;
}
// 根据关卡设置场景
this.stageNodeayer = cc.instantiate(this.stageNode[0]);
this.stageNodeayer.parent = this.imageBg;
// 球
this.ballNode = cc.instantiate(this.ballPrefab);
this.ballNode.parent = this.stageNodeayer;
this.ballNode.zIndex = 100;
let js = this.ballNode.getComponent("contact")
js.contactCallBack((selfCollider, otherCollider) => {
let bodyGroup0 = selfCollider.node.group;
let bodyGroup1 = otherCollider.node.group;
// 撞到了星星
if((bodyGroup0 == "ball" && bodyGroup1 == "star")
|| (bodyGroup0 == "star" && bodyGroup1 == "ball")){
// 移除星星
if(bodyGroup0 == "star"){
selfCollider.node.active = false;
}
else{
otherCollider.node.active = false;
}
gameTools.playSound("sound/get_item")
this.starNode[this._getStarCount].active = true;
this._getStarCount = this._getStarCount + 1;
}
// 进球
if ((bodyGroup0 == "ball" && bodyGroup1 == "inball")
|| (bodyGroup0 == "inball" && bodyGroup1 == "ball")){
if(bodyGroup0 == "inball"){
selfCollider.node.active = false;
}
else{
otherCollider.node.active = false;
}
gameTools.playSound("sound/get_item")
this.showGameEndLayer();
this.stopTimeUpdate();
this.ballNode.active = false;
this.ballNode.active = true;
}
});
// 触摸回调
this.node.on(cc.Node.EventType.TOUCH_START, this.onEventStart, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onEventMove, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onEventCancel, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.onEventEnd, this);
this._selectStage = parseInt(cc.sys.localStorage.getItem("selectStage")) || 1;
this.reSetGame();
},
start () {
},
// 重置游戏
reSetGame(){
this.levelLable.string = "LEVEL:"+this._selectStage;
this._useTime = 0;
this.timeLable.string = "TIME:" + this._useTime;
for(let i=0; i<this.starNode.length; i++){
this.starNode[i].active = false;
}
for(let i=1; i<this._smallCircleNode.length; i++){
this._smallCircleNode[i].active = false;
}
this._getStarCount = 0;
this.ballNode.removeFromParent()
if(this.stageNodeayer){
this.stageNodeayer.removeFromParent();
this.stageNodeayer = null;
}
this.stageNodeayer = cc.instantiate(this.stageNode[this._selectStage-1]);
this.stageNodeayer.parent = this.imageBg;
let stageJs = this.stageNodeayer.getComponent("stageGame")
stageJs.setBallStartPos(this.ballNode);
stageJs.showStar();
stageJs.showInBallNode();
this.ballNode.parent = this.stageNodeayer
this.ballNode.active = false;
this.ballNode.active = true;
if(this._gameEndLayer){
this._gameEndLayer.removeFromParent();
this._gameEndLayer = null;
}
this.startTimeUpdate();
},
//屏幕触摸回调
onEventStart : function(event){
this._canShooting = false;
let touchpos = event.getLocation();
let ballPos = this.ballNode.position;
ballPos = this.ballNode.parent.convertToWorldSpaceAR(ballPos)
if(Math.abs(touchpos.x - ballPos.x) < 30 && Math.abs(touchpos.y - ballPos.y) < 30){
this._canShooting = true;
}
},
onEventMove : function(event){
if(this._canShooting){
let touchPos = event.getLocation();
let ballPos = this.ballNode.position;
ballPos = this.ballNode.parent.convertToWorldSpaceAR(ballPos)
this.velocity = this.getVelocityByPos(touchPos, ballPos);
// 设置辅助线条
let g = 0.5 * 4/3*Math.PI*Math.pow(0.3, 3) * 680;
let a = this.getAngleByPos(ballPos, touchPos);
for(let i=1; i<this._smallCircleNode.length; i++){
let speedTime = 0.35*i;
let v0 = Math.sqrt(Math.pow(this.velocity.x, 2) + Math.pow(this.velocity.y, 2));
let posx = v0*Math.cos(a*Math.PI/180)*speedTime;
let posy = v0*Math.sin(a*Math.PI/180)*speedTime-0.5*g*Math.pow(speedTime,2);
let worldPos = cc.v2(ballPos.x + posx, ballPos.y + posy);
let nodePos = this.imageBg.convertToNodeSpaceAR(worldPos);
this._smallCircleNode[i].position = nodePos;
this._smallCircleNode[i].active = true;
}
}
},
onEventEnd : function(event){
for(let i=1; i<this._smallCircleNode.length; i++){
this._smallCircleNode[i].active = false;
}
if(this._canShooting){
this.ballNode.getComponent(cc.RigidBody).applyForceToCenter(cc.v2(this.velocity.x * 340, this.velocity.y * 340));
}
},
onEventCancel : function(event){
for(let i=1; i<this._smallCircleNode.length; i++){
this._smallCircleNode[i].active = false;
}
},
// 获取角度
getAngleByPos : function(startPos, endPos){
let angle = 0;
angle = Math.atan(Math.abs(endPos.x - startPos.x) / Math.abs(endPos.y - startPos.y))*180/3.14
if(startPos.x <= endPos.x && startPos.y <= endPos.y){
angle = 90 - angle;
}
else if(startPos.x <= endPos.x && startPos.y >= endPos.y){
angle = -(90 - angle);
}
else if(startPos.x >= endPos.x && startPos.y >= endPos.y){
angle = 180 + (90-angle);
}
else{
没有合适的资源?快使用搜索试试~ 我知道了~
沙滩足球.zip源码cocos creator项目源码下载
共176个文件
meta:89个
png:51个
mp3:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 119 浏览量
2022-03-18
09:32:17
上传
评论 1
收藏 3.82MB ZIP 举报
温馨提示
沙滩足球.zip源码cocos creator项目源码下载沙滩足球.zip源码cocos creator项目源码下载 1.上线产品适合个人学习技术做项目参考 2.开发脚本为javsScropt或者typeScript 3.上线产品适合小公司开发游戏项目参考
资源推荐
资源详情
资源评论
收起资源包目录
沙滩足球.zip源码cocos creator项目源码下载 (176个子文件)
gamePlay.fire 36KB
gameStart.fire 26KB
gameSelect.fire 25KB
playGame.js 10KB
gameEndLayer.js 4KB
selectItem.js 2KB
StartGame.js 1KB
stageGame.js 1KB
SelectGame.js 1KB
gameTools.js 1KB
contact.js 1KB
services.json 7KB
project.json 993B
builder.json 983B
jsconfig.json 280B
project.json 82B
Plist.plist.meta 2KB
tttby_shoushi_yuandian.png.meta 720B
stzq_shatan1.png.meta 716B
tttby_shoushi_shou.png.meta 716B
stzq_levelselect.png.meta 716B
stzq_chengbao.png.meta 715B
stzq_beachmp.png.meta 714B
hxzjq_start.png.meta 713B
levelselect.png.meta 713B
stzq_biaotibj.png.meta 713B
hxzjq_loading.png.meta 713B
stzq_orangeball.png.meta 713B
stzq_tree1.png.meta 712B
stzq_pangxie.png.meta 712B
touming.png.meta 712B
stzq_bighx.png.meta 712B
hxzjq_loading1.png.meta 712B
stzq_levelbb.png.meta 712B
stzq_tree2.png.meta 712B
hxzjq_loading2.png.meta 712B
stzq_start.png.meta 712B
stzq_logo.png.meta 711B
stzq_timebb.png.meta 711B
btnPlay.png.meta 709B
stzq_shx2.png.meta 707B
btnSound2.png.meta 707B
btnSound1.png.meta 707B
btnMusic1.png.meta 707B
btnMusic2.png.meta 707B
stzq_shx1.png.meta 707B
bg.png.meta 706B
juxing.png.meta 706B
football.png.meta 706B
stzq_hhx.png.meta 706B
goal_2.png.meta 706B
goal_1.png.meta 706B
play.png.meta 706B
clickbox.png.meta 706B
j_sound.png.meta 705B
backbtn.png.meta 705B
j_music.png.meta 705B
Plist.png.meta 705B
di1.png.meta 705B
j_close.png.meta 705B
di3.png.meta 704B
di2.png.meta 703B
again.png.meta 703B
pause.png.meta 703B
star1.png.meta 703B
box.png.meta 703B
home.png.meta 702B
suo.png.meta 701B
StartGame.js.meta 197B
contact.js.meta 197B
stageGame.js.meta 197B
gameEndLayer.js.meta 197B
gameTools.js.meta 197B
playGame.js.meta 197B
selectItem.js.meta 197B
SelectGame.js.meta 197B
Panel_stage3.prefab.meta 148B
Button_bg.prefab.meta 148B
Panel_stage2.prefab.meta 148B
Node_box2.prefab.meta 148B
Panel_stage1.prefab.meta 148B
Node_box.prefab.meta 148B
gameEndNode.prefab.meta 148B
ballSprite.prefab.meta 148B
gameStart.fire.meta 146B
gamePlay.fire.meta 146B
gameSelect.fire.meta 146B
Script.meta 137B
Prefab.meta 137B
resources.meta 137B
fonts.meta 137B
sound.meta 137B
imageRes.meta 137B
bg.meta 137B
Scene.meta 137B
background.mp3.meta 109B
fire.mp3.meta 109B
bgm.mp3.meta 109B
starget.mp3.meta 109B
click.mp3.meta 109B
共 176 条
- 1
- 2
资源评论
- Hyacinu2023-07-04资源中能够借鉴的内容很多,值得学习的地方也很多,大家一起进步!
- tank4261232023-03-10资源使用价值高,内容详实,给了我很多新想法,感谢大佬分享~
yxkfw
- 粉丝: 76
- 资源: 2万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Fortran语言教程,详细地介绍了Fortran语言
- (函数)图论中最短路径计算D算法MATLAB源代码,修改网络上D算法的错误,并编写通用的MATLAB函数.rar
- 基于matlab 2Dijkstra最短路径算法的matlab程序,希望对大家有所帮助.zip
- python入门学习,基础语法,用法等.zip
- Swift代码转换指南(Swift Swift Code Convension Guide .)
- Python入门到精通.zip
- 基于QT+C++开发的炫酷九宫格主界面+源码
- python入门代码测试.zip
- 一种基于Python实现中文编码格式转换工具的源码
- 基于matlab dijkstra算法,可以求解图论中的两点间最短路径.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功