123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- // 角色类,管理各个动作
- var Serve = require("serve")
- var Pat = require("pat")
- var Idle = require("idle")
- var Peel = require("peel")
- var Fail = require("fail")
- var Win = require("win")
- // 角色的方向
- var RoleDir = cc.Enum ({
- Role_Mine_Left: 1,
- Role_Mine_Right: 2,
- Role_Rival_Left: 3,
- Role_Rival_Right: 4
- });
- cc.Class({
- extends: cc.Component,
- properties: {
- // 发球组件
- serve: {
- default: null,
- type: Serve,
- },
- // 接球组件
- pat: {
- default: null,
- type: Pat,
- },
- // 等待组件
- idle: {
- default: null,
- type: Idle,
- },
- // 削球组件
- peel: {
- default: null,
- type: Peel,
- },
- // 失败组件
- fail: {
- default: null,
- type: Fail,
- },
- // 胜利组件
- win: {
- default: null,
- type: Win,
- },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.initBlocks();
- this.initValues();
- },
- start () {
- this.idle.idle();
- },
- // update (dt) {},
- // 初始化
- // 初始化数据
- initValues:function() {
- this.mineLeft = cc.v2(-137, -176);
- this.mineRight = cc.v2(29, -176);
- this.rivalLeft = cc.v2(-10, 180);
- this.rivalRight = cc.v2(138, 180);
- },
-
- // 初始化各个组件的回调
- initBlocks:function () {
- var self = this;
- // 开始发球的回调
- this.serve.actionStart = function() {
- if (self.serveStart != null) {
- self.serveStart();
- }
- }
- var endBack = function() {
- self.idle.idle();
- };
- // 发球结束的回调
- this.serve.actionEnd = endBack;
- // 接球结束的回调
- this.pat.actionEnd = endBack;
- // 削球结束的回调
- this.peel.actionEnd = endBack;
- },
- // 外部调用
- // 设置位置
- setDir:function(dir) {
- if (dir == RoleDir.Role_Mine_Left) {
- this.node.setPosition(this.mineLeft);
- } else if (dir == RoleDir.Role_Mine_Right) {
- this.node.setPosition(this.mineRight);
- } else if (dir == RoleDir.Role_Rival_Left) {
- this.node.setPosition(this.rivalLeft);
- } else if (dir == RoleDir.Role_Rival_Right) {
- this.node.setPosition(this.rivalRight);
- }
- },
- // 发球
- roleServe:function() {
- this.serve.serve();
- },
- // 停止
- stop:function() {
- this.serve.stop();
- this.pat.stop();
- this.peel.stop();
- },
- // 角色的帧动作
- roleUpdate:function() {
- },
- });
|