123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- import { HttpStateType, ReveData } from "../../../../util/CHttp";
- import FF from "../../FF";
- import FMap from "../../map/FMap";
- import FSprite from "../../object/FSprite";
- import FMapDialog from "../dialog/FMapDialog";
- /**
- * 场景内碰撞事件基类
- */
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class BaseEvent extends cc.Component {
- public ff: FF
- //当前处于碰撞区域的对象
- // public spriteList: Array<FSprite> = [];
- onLoad() {
- this.ff = this.node.parent.parent.getComponent(FMap).ff;
- }
- onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- // if (other.node.group == 'A' && self.tag == 1) {
- // let obj = other.node.getComponent(FSprite);
- // if (this.spriteList.indexOf(obj) == -1) {
- // this.spriteList.push(obj);
- // }
- // }
- if (other.node.group == 'A' && other.tag == 1) {
- let obj = other.node.getComponent(FSprite);
- if (obj == this.ff.mainSprite) {
- this.onBegin(self.tag)
- }
- }
- }
- onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- // if (other.node.group == 'A' && self.tag == 1) {
- // let obj = other.node.getComponent(FSprite);
- // this.removeSprite(obj);
- // }
- if (other.node.group == 'A' && other.tag == 1) {
- let obj = other.node.getComponent(FSprite);
- if (obj == this.ff.mainSprite) {
- this.onEnd(self.tag)
- }
- }
- }
- // private removeSprite(sprite: FSprite) {
- // for (let i = 0; i < this.spriteList.length; i++) {
- // const element = this.spriteList[i];
- // if (element == sprite) {
- // this.spriteList.splice(i, 1);
- // break
- // }
- // }
- // }
- /**
- * 主角进入碰撞区域
- * @param tag 碰撞组件编号
- */
- public onBegin(tag: number) {
- }
- /**
- * 主角离开碰撞区域
- * @param tag 碰撞组件编号
- */
- public onEnd(tag: number) {
- }
- /**
- * 移动摄像机
- * @param pos
- * @param callback
- */
- public moveCamera(pos: cc.Vec2, time: number, callback: () => void) {
- let map = this.ff.mMap;
- let camera = map.mCamera;
- let winsize = cc.winSize;
- pos.x -= winsize.width / 2;
- pos.y -= winsize.height / 2;
- cc.tween(camera.node).sequence(
- cc.moveTo(time, pos).easing(cc.easeOut(time)),
- cc.callFunc(() => {
- callback();
- })
- ).start()
- }
- /**
- * 显示界面上可操作按钮
- */
- public showOpt(spriteFrame: cc.SpriteFrame, callback: () => void) {
- this.ff.control.showEventBt(spriteFrame, callback)
- }
- /**
- * 关闭界面上可操作按钮
- */
- public closeOpt() {
- this.ff.control.closeEventBt()
- }
- /**
- * 全屏按钮(用于处理用户点击任意位置)
- * @param callback
- */
- public showBlockInput(callback: () => void) {
- this.ff.mBlockInputEvents.active = true;
- this.ff.setBlockInputCallback(callback);
- }
- public closeBlockInput() {
- this.ff.mBlockInputEvents.active = false;
- this.ff.setBlockInputCallback(null)
- }
- /**
- * 暂停当前游戏
- */
- public pause() {
- this.ff.pauseSprite(true)
- }
- /**
- * 恢复游戏
- */
- public resume() {
- this.ff.pauseSprite(false)
- }
- /**
- * 根据名字查找精灵节点
- * @param name
- */
- public findByName(name: string) {
- return cc.find(name, this.ff.mMap.mSprites)
- }
- /**
- * 对象头顶显示对话
- */
- public showDialog(node: cc.Node, dialogs: Array<string>, callback: () => void) {
- let mapDialog = new FMapDialog(this.ff, this.ff.mMapDialog);
- let pos = cc.v2();
- pos.x = node.x
- pos.y = node.y + node.height;
- mapDialog.showDialog(dialogs,
- pos,
- null,
- () => {
- callback()
- }
- );
- }
- /**
- * 对象头顶显示对话
- */
- public showDialogPos(pos: cc.Vec2, dialogs: Array<string>, callback: () => void) {
- let mapDialog = new FMapDialog(this.ff, this.ff.mMapDialog);
- mapDialog.showDialog(dialogs,
- pos,
- null,
- () => {
- callback()
- }
- );
- }
- /**
- * 播放spine动画
- * @param spine
- * @param callback
- */
- public spineAction(spine: sp.Skeleton, actionName: string, callback: () => void) {
- spine.setCompleteListener(() => {
- spine.setCompleteListener(null)
- callback()
- })
- spine.setAnimation(0, actionName, false)
- }
- /**
- * 捡起地图上的物品
- * @param objectId
- */
- public getMapObject(objectId: string, callback: Function) {
- let msg = {
- objectId: objectId
- }
- let main = this.ff.main
- main.gameHttp.sendJson('stage/v1/stageObject', msg, (state, reve: ReveData) => {
- main.stopLoad();
- if (state == HttpStateType.SUCCESS) {
- if (reve.retCode == 0) {
- //"_stage":{"good":{"1001":1}}
- let player = main.player;
- let stage = player.stage;
- stage.element.push(objectId);
- if (reve.data._stage) {
- stage.data[this.ff.mFFheader.stageData.id] = reve.data._stage;
- this.ff.mFFheader.flush();
- }
- main.showReward(reve, () => {
- callback && callback()
- })
- } else {
- main.showTips(reve.message);
- }
- } else {
- main.showTips('网络异常');
- }
- });
- }
- }
|