123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- import Joystick_mag, { SpeedType } from "../../../joystick/Joystick_mag";
- import { FFAttr } from "../../data/FFCalAttr";
- import { __SkillData } from "../../data/sdata/SManage";
- import { SpeedUpDirection } from "../../element/JG0115";
- import BObject from "../bullet/BObject";
- import FSprite, { SpriteActionType } from "./FSprite";
- import MBomb from "./skill/mainSkill/MBomb";
- import MFWind from "./skill/mainSkill/MFWind";
- import MMagic from "./skill/mainSkill/MMagic";
- import MShotgun from "./skill/mainSkill/MShotgun";
- import SkillBase from "./skill/SkillBase";
- /**
- * 主角
- */
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class MSprite extends FSprite {
- /**
- * 技能1
- * 武器技能
- */
- public skill1: SkillBase
- /**
- * 技能2
- * 职业技能
- */
- public skill2: SkillBase
- private musicWalkId = -1;
- private muiscRunId = -1;
- /**
- * 移动速度
- */
- private speedN = 80000;
- public speedUp: string = "";
- /**
- * 当前是否停用遥感
- */
- public stopJoystick = false
- public start() {
- super.start()
- this.spineEventListener()
- }
- public setAttrData(attrData: FFAttr) {
- super.setAttrData(attrData)
- // attrData.weaponSkill = 1205
- let _skillData = this.ff.main.sManage.getSkillById(attrData.weaponSkill)
- if (_skillData) {
- if (_skillData.type == 1) {//散弹
- let skill1: MShotgun = this.node.addComponent(MShotgun) as any
- skill1.count = _skillData.value2
- skill1.bcount = _skillData.value3
- this.loadSkill(_skillData, skill1)
- this.skill1 = skill1
- } else if (_skillData.type == 2) {//丢炸弹
- let skill1: MBomb = this.node.addComponent(MBomb) as any
- this.loadSkill(_skillData, skill1)
- this.skill1 = skill1
- } else if (_skillData.type == 3) {//法术
- let skill1 = this.node.addComponent(MMagic) as any
- this.loadSkill(_skillData, skill1)
- this.skill1 = skill1
- } else if (_skillData.type == 4) {//龙卷风
- let skill1 = this.node.addComponent(MFWind) as any
- this.loadSkill(_skillData, skill1)
- this.skill1 = skill1
- }
- this.skill1._skillData = _skillData
- }
- }
- private loadSkill(_skillData: __SkillData, skill1) {
- cc.resources.load('icon/skills/' + _skillData.effect + '/bullet', cc.Prefab, (err, prefab: cc.Prefab) => {
- if (err) {
- cc.error(err);
- } else {
- skill1.mBullet = prefab
- }
- });
- }
- public setJoystick(mJoystick: Joystick_mag) {
- mJoystick.setListen((speedType: SpeedType, moveVec?: cc.Vec2) => {
- if(this.stopJoystick){
- return
- }
- if (speedType == SpeedType.STOP) {
- this.stopMove()
- } else {
- this.startMove(moveVec)
- }
- this.playMusic();
- });
- }
- update(dt) {
- if (this.gamePause) {
- return;
- }
- if (this.speedUp != "") return
- if (this.isWalk) {
- this.mRigidBody.applyLinearImpulse(
- cc.v2(this.moveV2.x * this.speedN * dt, this.moveV2.y * this.speedN * dt),
- this.mRigidBody.getWorldCenter(),
- true
- );
- }
- }
- /**
- * @param v2 开始向量移动
- */
- public startMove(v2: cc.Vec2) {
- if (!this.isWalk) {
- if (!this.currentShooting) {
- this.spine.setAnimation(0, SpriteActionType.move, true)
- }
- }
- this.isWalk = true
- this.moveV2 = v2;
- //有怪物的时候,面向怪物
- let enemy = this.findEnemy(2000);
- if (enemy.sprite) {
- let abs = Math.abs(this.spine.node.scaleX);
- if (this.node.x > enemy.sprite.node.x) {
- this.spine.node.scaleX = -abs;
- } else {
- this.spine.node.scaleX = abs;
- }
- } else {
- let abs = Math.abs(this.spine.node.scaleX);
- if (v2.x <= 0.001 && v2.x >= -0.001) {
- } else if (v2.x > 0) {
- this.spine.node.scaleX = abs;
- } else {
- this.spine.node.scaleX = -abs;
- }
- if (this.speedUp != "") {
- if (this.speedUp == SpeedUpDirection.Left) {
- this.spine.node.scaleX = -Math.abs(this.spine.node.scaleX);
- } else {
- this.spine.node.scaleX = Math.abs(this.spine.node.scaleX);
- }
- }
- }
- }
- /**
- * 停止移动
- */
- public stopMove() {
- this.isWalk = false
- if (!this.currentShooting) {
- this.spine.setAnimation(0, SpriteActionType.stand, true)
- }
- }
- /**
- * 设置是否跑
- * @param isRuning
- */
- public setRuning(isRuning: boolean) {
- // super.setRuning(isRuning);
- this.playMusic();
- }
- private playMusic() {
- if (this.isWalk) {
- let setting = this.ff.main.player.setting;
- if (setting.music_ON_OFF_2) {
- if (this.isRuning) {
- if (this.muiscRunId == -1) {
- this.muiscRunId = cc.audioEngine.play(this.ff.mRun, true, setting.music_Slider_2);
- }
- if (this.musicWalkId != -1) {
- cc.audioEngine.stop(this.musicWalkId);
- this.musicWalkId = -1;
- }
- } else {
- if (this.musicWalkId == -1) {
- this.musicWalkId = cc.audioEngine.play(this.ff.mWalk, true, setting.music_Slider_2);
- }
- if (this.muiscRunId != -1) {
- cc.audioEngine.stop(this.muiscRunId);
- this.muiscRunId = -1;
- }
- }
- }
- } else {
- if (this.musicWalkId != -1) {
- cc.audioEngine.stop(this.musicWalkId);
- this.musicWalkId = -1;
- }
- if (this.muiscRunId != -1) {
- cc.audioEngine.stop(this.muiscRunId);
- this.muiscRunId = -1;
- }
- }
- }
- public setPause(pause: boolean) {
- this.gamePause = pause
- if (this.gamePause) {
- this.isWalk = false
- this.currentShooting = false
- this.isShooting = false
- this.spine.setAnimation(0, SpriteActionType.stand, true)
- }
- }
- /**
- * 当前动作是否处于射击状态
- */
- private currentShooting = false;
- /**
- * 设置攻击
- * @param isShooting
- */
- public setShooting(isShooting: boolean) {
- // cc.log('isShooting : ',isShooting);
- this.isShooting = isShooting;
- if (this.isShooting && !this.currentShooting) {
- this.currentShooting = true;
- this.shooting()
- }
- }
- private shooting() {
- this.playAction(SpriteActionType.atk, false, () => {
- if (this.isShooting) {
- this.shooting()
- } else {
- this.endShooting()
- }
- });
- }
- /**
- * 射击结束后
- */
- private endShooting() {
- this.currentShooting = false;
- if (this.mWeapon1) {
- this.mWeapon1.rotation = 180;
- }
- if (this.isWalk) {
- this.spine.setAnimation(0, SpriteActionType.move, true)
- } else {
- this.spine.setAnimation(0, SpriteActionType.stand, true)
- }
- }
- /**
- * 注册帧事件
- */
- private spineEventListener() {
- this.spine.setEventListener((trackEntry, event) => {
- if (this.isValid && !this.gamePause) {
- // var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- // cc.log("[track %s][animation %s] event: %s, %s, %s, %s", trackEntry.trackIndex, animationName, event.data.name, event.intValue, event.floatValue, event.stringValue);
- if (this.node.isValid && event.data.name == 'hit') {
- let node = cc.instantiate(this.mBullet);
- node.group = 'bullet';
- let x = this.node.x + this.mAtkSite.worldX
- let y = this.node.y + this.mAtkSite.worldY
- let pos = cc.v2(x, y);
- node.setPosition(pos);
- let bObject = node.getComponent(BObject);
- bObject.setSprite(this);
- let csprite: FSprite = this.findEnemy(2000).sprite;
- node.parent = this.map.mSprites;
- if (csprite && csprite.isValid) {
- bObject.fire(csprite.node);
- // this.addSendEffect(bObject.mStartEffect, csprite.node);
- } else {//没有目标的时候,向朝向开火
- bObject.fireAngleV2(this.moveV2);
- // this.addSendEffect(bObject.mStartEffect, null);
- }
- let angle = Math.atan2(this.moveV2.y, this.moveV2.x);
- this.setWeaponAngle(angle);
- if (this.fireCallback) {
- this.fireCallback();
- }
- if (this.node == this.ff.mainSprite.node) {
- if (this.hitCount > 4) {
- this.ff.shockMap();
- this.hitCount = 0;
- } else {
- this.hitCount++;
- }
- }
- this.ff.main.playerEffectByPath('music/magic_1001_fs');
- }
- }
- });
- }
- /**
- * 临时捡起的东西
- */
- public tmpObject: cc.Node = null;
- /**
- * 角色举起物品
- * @param object
- */
- public liftObject(object: cc.Node) {
- }
- /**
- * 将捡起来的东西扔出去
- */
- public throwObject() {
- }
- }
|