工作生活

cocos creator 制作的打砖块游戏

2019-07-04  本文已影响0人  游戏开发大表哥

简介cocos creator1.10.2版本制作, 使用了cocos creator中的物理引擎与碰撞系统

进入游戏, 可以看到游戏分为两种模式, 经典模式和挑战模式 

挑战模式可普通的敲砖块游戏一样, 玩家可以通过一个一个关卡, 通关游戏, 而挑战模式就是一直刷新砖块 

点击设置, 游戏暂停, 可以继续游戏, 重新开始, 和回到主页 

由于本游戏代码比较多, 我们只看比较重要的那一部分点击链接加入群聊【cocos/unity交流群】

constGameModel =require('GameModel');

varsound_manager =require("./sound_manager");

cc.Class({

extends: cc.Component,

properties: {

gameView:require('GameView'),

ball:require('ball'),

player:require('player'),

brickLayout:require('BrickLayout'),

overPanel:require('OverPanel'),

rank_scroll:require("./rank"),

skill:require("./skill"),

ad_over:require("./ad_over"),

ad_err:require("./ad_err"),

info: {

default:null,

type: cc.Node,

},

bg_over: {

default:null,

type: cc.Node,

},

player_Prefab: {

default:null,

type: cc.Prefab,

},

continue_button: {

default:null,

type: cc.Node,

},

add_err: {

default:null,

type: cc.Node,

},

},

// use this for initialization

onLoad:function(){

//安卓返回键退出

cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, (event) => {

if(event.keyCode === cc.KEY.back) {

cc.director.end();

}

});

this.goto_flag =0;

this.ad_flag =0;

this.ball_num =1;

this.ball_node = [];

this.zhuanshi_anim = cc.find("Canvas/wight_top/zhuanshi");

//

// wx.hideShareMenu();

this.physicsManager = cc.director.getPhysicsManager();

this.gameModel =newGameModel();

this.startGame();

},

goto_homeScene() {

if(this.goto_flag ==0) {

this.goto_flag =1;

cc.director.loadScene("home_scene");

}

},

init() {

this.physicsManager.enabled =true;

this.lv =2;

this.gameModel.init();

this.ball.init(this);

this.ball_node.push(this.ball);

this.gameView.init(this);

this.overPanel.init(this);

this.brickLayout.init_2(this);

this.ad_over.init(this);

this.ad_err.init(this);

},

startGame() {

this.init();

},

restartGame() {

cc.director.loadScene("game_basic");

},

pauseGame() {

this.info.active =true;

this.physicsManager.enabled =false;

},

thepauseGame() {

this.physicsManager.enabled =false;

},

resumeGame() {

this.info.active =false;

this.physicsManager.enabled =true;

},

stopGame() {

// this.bg_over.active = true;

this.physicsManager.enabled =false;

this.overPanel.show(this.gameModel.score,this.gameModel.bricksNumber);

},

rank() {

this.rank_scroll.delete_content_childNode();

window.h5api.getRank(function(obj){

console.log('代码:'+ obj.code +',消息:'+ obj.message +',数据:'+ obj.data)

if(obj.code ===10000){

vardata = obj.data

for(vari =0; i < data.length; i++){

this.rank_scroll.add_item(data[i].rank, data[i].score)

}

this.rank_scroll.show_rank();

}else{

console.log('获取失败');

}

}.bind(this))

},

rank_queding() {

this.rank_scroll.hide_rank();

},

play_ad() {

this.ad_over.hide_node_byAd();

this.ad_flag ++;

if(this.ad_flag <3) {

// 先暂停游戏

this.pauseGame();

if(window.h5api.canPlayAd() ==true) {

window.h5api.playAd(function(obj){

// console.log(obj);

if(obj.code ===10000){

// console.log('开始播放');

}elseif(obj.code ===10001){

// 用动画展示

this.skill.addZuanshi(2);

}else{

}

}.bind(this));

}

}else{

this.physicsManager.enabled =false;

this.ad_err.show_ad_err();

}

},

click_skill() {

if(this.skill.click_skill1() ==1) {

this.player.big_player();

}else{// 展示广告

this.ad_over.show_node();

}

},

click_skill2() {// 火焰球  清理所有砖块

if(this.skill.click_skill2() ==1) {

this.brickLayout.getFireNode(3);

}else{

this.ad_over.show_node();

}

},

onSkillContactBrick(ballNode, brickNode, tag) {

sound_manager.play_effect("resources/1.mp3");

varscore =0;

if(tag ==6) {

score =20;

}elseif(tag ==5) {

score =10;

}elseif(tag ==1) {

score =1;

}

brickNode.removeFromParent();

this.gameModel.addScore(score);

this.gameView.updateScore(this.gameModel.score);

this.change_lv();

},

click_skill3() {// 增加一个小球

if(this.skill.click_skill3() ==1) {

varballNode =this.ball.node;

this.ball_num ++;

varplayerNode = cc.instantiate(this.player_Prefab);

playerNode.parent = ballNode.parent;

varnewball = playerNode.getComponent("ball");

this.ball_node.push(newball);

newball.init(this);

newball.continue_1();

}else{

this.ad_over.show_node();

}

},

continue_game() {

this.physicsManager.enabled =true;

switch(this.lv) {

case1:

this.ball.continue_1();

break;

case2:

// this.ball.continue_2();

// this.player.reduce_width_1();

this.ball.continue_1();

break;

case3:

for(leti=0; i

上一篇下一篇

猜你喜欢

热点阅读